4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
37 #include <sys/smack.h>
39 #include <libxml/parser.h>
40 #include <libxml/xmlreader.h>
41 #include <libxml/xmlschemas.h>
43 #include <dbus/dbus.h>
44 #include <dbus/dbus-glib-lowlevel.h>
46 /* For multi-user support */
47 #include <tzplatform_config.h>
49 #include "pkgmgr_parser.h"
50 #include "pkgmgr-info-internal.h"
51 #include "pkgmgr-info-debug.h"
52 #include "pkgmgr-info.h"
53 #include "pkgmgr_parser_db.h"
60 #define LOG_TAG "PKGMGR_INFO"
62 #define ASC_CHAR(s) (const char *)s
63 #define XML_CHAR(s) (const xmlChar *)s
65 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
66 #define MAX_QUERY_LEN 4096
67 #define MAX_CERT_TYPE 9
68 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
69 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
70 #define PKG_TYPE_STRING_LEN_MAX 128
71 #define PKG_VERSION_STRING_LEN_MAX 128
72 #define PKG_VALUE_STRING_LEN_MAX 512
73 #define PKG_LOCALE_STRING_LEN_MAX 8
74 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
75 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
76 #define BLOCK_SIZE 4096 /*in bytes*/
80 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
81 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
82 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
84 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
85 "from package_info LEFT OUTER JOIN package_localized_info " \
86 "ON package_info.package=package_localized_info.package " \
87 "and package_localized_info.package_locale='%s' where "
89 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
90 "from package_info LEFT OUTER JOIN package_localized_info " \
91 "ON package_info.package=package_localized_info.package " \
92 "and package_localized_info.package_locale='%s' where "
94 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
95 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
96 "ON package_app_info.app_id=package_app_localized_info.app_id " \
97 "and package_app_localized_info.app_locale='%s' " \
98 "LEFT OUTER JOIN package_app_app_svc " \
99 "ON package_app_info.app_id=package_app_app_svc.app_id " \
100 "LEFT OUTER JOIN package_app_app_category " \
101 "ON package_app_info.app_id=package_app_app_category.app_id where "
103 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
104 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
105 "ON package_app_info.app_id=package_app_localized_info.app_id " \
106 "and package_app_localized_info.app_locale='%s' " \
107 "LEFT OUTER JOIN package_app_app_svc " \
108 "ON package_app_info.app_id=package_app_app_svc.app_id " \
109 "LEFT OUTER JOIN package_app_app_category " \
110 "ON package_app_info.app_id=package_app_app_category.app_id where "
112 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
113 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
114 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
116 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
118 #define LANGUAGE_LENGTH 2
119 #define LIBAIL_PATH "/usr/lib/libail.so.0"
121 #define SERVICE_NAME "org.tizen.system.deviced"
122 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
123 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
124 #define METHOD_NAME "RequestMountApp2ext"
128 typedef struct _pkgmgr_instcertinfo_x {
130 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
131 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
132 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
133 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
134 } pkgmgr_instcertinfo_x;
136 typedef struct _pkgmgr_certindexinfo_x {
139 } pkgmgr_certindexinfo_x;
141 typedef struct _pkgmgr_pkginfo_x {
143 manifest_x *manifest_info;
146 struct _pkgmgr_pkginfo_x *prev;
147 struct _pkgmgr_pkginfo_x *next;
150 typedef struct _pkgmgr_cert_x {
155 typedef struct _pkgmgr_datacontrol_x {
158 } pkgmgr_datacontrol_x;
160 typedef struct _pkgmgr_iconpath_x {
165 typedef struct _pkgmgr_image_x {
169 typedef struct _pkgmgr_locale_x {
173 typedef struct _pkgmgr_appinfo_x {
176 pkgmgrinfo_app_component app_component;
178 uiapplication_x *uiapp_info;
179 serviceapplication_x *svcapp_info;
183 typedef struct _pkgmgr_certinfo_x {
186 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
187 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
191 typedef struct _pkgmgrinfo_filter_x {
194 } pkgmgrinfo_filter_x;
196 typedef struct _pkgmgrinfo_node_x {
202 typedef struct _pkgmgrinfo_appcontrol_x {
211 } pkgmgrinfo_appcontrol_x;
214 typedef struct _db_handle {
220 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
222 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
223 const char *pkgid, const char *key,
224 const char *val, const void *pmsg, void *data);
226 typedef void pkgmgr_client;
227 typedef void pkgmgr_info;
232 PM_REQUEST_GET_SIZE = 2,
233 PM_REQUEST_KILL_APP = 3,
234 PM_REQUEST_CHECK_APP = 4,
236 }pkgmgr_request_service_type;
239 PM_GET_TOTAL_SIZE= 0,
240 PM_GET_DATA_SIZE = 1,
242 PM_GET_SIZE_INFO = 3,
243 PM_GET_TOTAL_AND_DATA = 4,
244 PM_GET_SIZE_FILE = 5,
246 }pkgmgr_getsize_type;
254 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
255 #define MAX_PKG_BUF_LEN 1024
256 #define MAX_PKG_INFO_LEN 10
258 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
259 "(cert_info text not null, " \
260 "cert_id integer, " \
261 "cert_ref_count integer, " \
262 "PRIMARY KEY(cert_id)) "
264 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
265 "(package text not null, " \
266 "author_root_cert integer, " \
267 "author_im_cert integer, " \
268 "author_signer_cert integer, " \
269 "dist_root_cert integer, " \
270 "dist_im_cert integer, " \
271 "dist_signer_cert integer, " \
272 "dist2_root_cert integer, " \
273 "dist2_im_cert integer, " \
274 "dist2_signer_cert integer, " \
275 "PRIMARY KEY(package)) "
278 #define QUERY_ATTACH "attach database '%s' as Global"
279 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select * " \
280 "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)"
281 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\
282 "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)"
283 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select * "\
284 "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)"
285 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select * "\
286 "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)"
287 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select * "\
288 "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)"
289 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select * "\
290 "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)"
291 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select * "\
292 "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)"
293 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select * "\
294 "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)"
295 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select * "\
296 "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)"
297 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select * "\
298 "from (select *,0 as for_all_users from main.package_info union select *,1 as for_all_users from Global.package_info)"
299 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select * "\
300 "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)"
301 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select * "\
302 "from (select *,0 as for_all_users from main.package_localized_info union select *,1 as for_all_users from Global.package_localized_info)"
303 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select * "\
304 "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 )"
305 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select * "\
306 "from (select *,0 as for_all_users from main.package_privilege_info union select *,1 as for_all_users from Global.package_privilege_info)"
308 #define GET_DB(X) (X).dbHandle
309 char *pkgtype = "rpm";
310 __thread db_handle manifest_db;
311 __thread db_handle datacontrol_db;
312 __thread db_handle cert_db;
314 static int __open_manifest_db(uid_t uid);
315 static int __close_manifest_db(void);
316 static int __open_cert_db(uid_t uid);
317 static int __close_cert_db(void);
318 static int __exec_pkginfo_query(char *query, void *data);
319 static int __exec_certinfo_query(char *query, void *data);
320 static int __exec_certindexinfo_query(char *query, void *data);
321 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
322 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
323 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
324 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
325 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
326 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
327 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
328 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
329 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
330 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
331 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
332 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
333 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
334 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
335 static void __destroy_each_node(gpointer data, gpointer user_data);
336 static void __get_filter_condition(gpointer data, char **condition);
337 static void __get_metadata_filter_condition(gpointer data, char **condition);
338 static gint __compare_func(gconstpointer data1, gconstpointer data2);
339 static int __delete_certinfo(const char *pkgid);
340 static int _check_create_Cert_db( sqlite3 *certdb);
341 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
343 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
345 char *error_message = NULL;
346 char query_attach[MAX_QUERY_LEN] = {'\0'};
347 char query_view[MAX_QUERY_LEN] = {'\0'};
349 if(uid != GLOBAL_USER){
350 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
352 sqlite3_exec(handle, query_attach,
353 NULL, NULL, &error_message)) {
354 _LOGD("Don't execute query = %s error message = %s\n",
355 query_attach, error_message);
356 sqlite3_free(error_message);
363 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");
365 sqlite3_exec(handle, query_view,
366 NULL, NULL, &error_message)) {
367 _LOGD("Don't execute query = %s error message = %s\n",
368 query_view, error_message);
369 sqlite3_free(error_message);
371 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");
373 sqlite3_exec(handle, query_view,
374 NULL, NULL, &error_message)) {
375 _LOGD("Don't execute query = %s error message = %s\n",
376 query_view, error_message);
377 sqlite3_free(error_message);
384 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
386 char *error_message = NULL;
387 char query_attach[MAX_QUERY_LEN] = {'\0'};
388 if(uid != GLOBAL_USER){
389 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
391 sqlite3_exec(handle, query_attach,
392 NULL, NULL, &error_message)) {
393 _LOGD("Don't execute query = %s error message = %s\n",
394 query_attach, error_message);
395 sqlite3_free(error_message);
398 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
399 NULL, NULL, &error_message)) {
400 _LOGD("Don't execute query = %s error message = %s\n",
401 QUERY_CREATE_VIEW_1, error_message);
402 sqlite3_free(error_message);
405 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
406 NULL, NULL, &error_message)) {
407 _LOGD("Don't execute query = %s error message = %s\n",
408 QUERY_CREATE_VIEW_2, error_message);
409 sqlite3_free(error_message);
412 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
413 NULL, NULL, &error_message)) {
414 _LOGD("Don't execute query = %s error message = %s\n",
415 QUERY_CREATE_VIEW_3, error_message);
416 sqlite3_free(error_message);
419 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
420 NULL, NULL, &error_message)) {
421 _LOGD("Don't execute query = %s error message = %s\n",
422 QUERY_CREATE_VIEW_4, error_message);
423 sqlite3_free(error_message);
426 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
427 NULL, NULL, &error_message)) {
428 _LOGD("Don't execute query = %s error message = %s\n",
429 QUERY_CREATE_VIEW_5, error_message);
430 sqlite3_free(error_message);
433 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
434 NULL, NULL, &error_message)) {
435 _LOGD("Don't execute query = %s error message = %s\n",
436 QUERY_CREATE_VIEW_6, error_message);
437 sqlite3_free(error_message);
440 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
441 NULL, NULL, &error_message)) {
442 _LOGD("Don't execute query = %s error message = %s\n",
443 QUERY_CREATE_VIEW_7, error_message);
444 sqlite3_free(error_message);
447 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
448 NULL, NULL, &error_message)) {
449 _LOGD("Don't execute query = %s error message = %s\n",
450 QUERY_CREATE_VIEW_8, error_message);
451 sqlite3_free(error_message);
454 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
455 NULL, NULL, &error_message)) {
456 _LOGD("Don't execute query = %s error message = %s\n",
457 QUERY_CREATE_VIEW_9, error_message);
458 sqlite3_free(error_message);
461 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
462 NULL, NULL, &error_message)) {
463 _LOGD("Don't execute query = %s error message = %s\n",
464 QUERY_CREATE_VIEW_10, error_message);
465 sqlite3_free(error_message);
468 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
469 NULL, NULL, &error_message)) {
470 _LOGD("Don't execute query = %s error message = %s\n",
471 QUERY_CREATE_VIEW_11, error_message);
472 sqlite3_free(error_message);
475 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
476 NULL, NULL, &error_message)) {
477 _LOGD("Don't execute query = %s error message = %s\n",
478 QUERY_CREATE_VIEW_12, error_message);
479 sqlite3_free(error_message);
482 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
483 NULL, NULL, &error_message)) {
484 _LOGD("Don't execute query = %s error message = %s\n",
485 QUERY_CREATE_VIEW_13, error_message);
486 sqlite3_free(error_message);
489 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
490 NULL, NULL, &error_message)) {
491 _LOGD("Don't execute query = %s error message = %s\n",
492 QUERY_CREATE_VIEW_14, error_message);
493 sqlite3_free(error_message);
501 static int _check_create_Cert_db( sqlite3 *certdb)
504 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
507 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
513 API char *getIconPath(uid_t uid)
516 struct group *grpinfo = NULL;
517 struct passwd *userinfo = getpwuid(uid);
520 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
523 if (uid != GLOBAL_USER) {
524 if (userinfo == NULL) {
525 _LOGE("getpwuid(%d) returns NULL !", uid);
528 grpinfo = getgrnam("users");
529 if (grpinfo == NULL) {
530 _LOGE("getgrnam(users) returns NULL !");
533 // Compare git_t type and not group name
534 if (grpinfo->gr_gid != userinfo->pw_gid) {
535 _LOGE("UID [%d] does not belong to 'users' group!", uid);
538 ret = asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir);
540 _LOGE("asprintf fails");
545 result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
548 ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
549 if (ret == -1 && errno != EEXIST) {
550 _LOGE("FAIL : to create directory %s %d", result, errno);
551 } else if (getuid() == OWNER_ROOT) {
552 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
555 strerror_r(errno, buf, sizeof(buf));
556 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
562 API char *getUserPkgParserDBPath(void)
564 return getUserPkgParserDBPathUID(GLOBAL_USER);
567 API char *getUserPkgParserDBPathUID(uid_t uid)
569 const char *result = NULL;
570 const char *journal = NULL;
571 struct group *grpinfo = NULL;
573 struct passwd *userinfo = getpwuid(uid);
576 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
579 if (uid != GLOBAL_USER) {
580 if (userinfo == NULL) {
581 _LOGE("getpwuid(%d) returns NULL !", uid);
584 grpinfo = getgrnam("users");
585 if (grpinfo == NULL) {
586 _LOGE("getgrnam(users) returns NULL !");
589 // Compare git_t type and not group name
590 if (grpinfo->gr_gid != userinfo->pw_gid) {
591 _LOGE("UID [%d] does not belong to 'users' group!", uid);
594 ret = asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
596 _LOGE("asprintf fails");
599 ret = asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir);
601 _LOGE("asprintf fails");
605 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
606 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
608 char *temp = strdup(result);
609 dir = strrchr(temp, '/');
617 ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
618 if (ret == -1 && errno != EEXIST) {
619 _LOGE("FAIL : to create directory %s %d", temp, errno);
620 } else if (getuid() == OWNER_ROOT) {
621 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
624 strerror_r(errno, buf, sizeof(buf));
625 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
632 API char *getUserPkgCertDBPath(void)
634 return getUserPkgCertDBPathUID(GLOBAL_USER);
637 API char *getUserPkgCertDBPathUID(uid_t uid)
640 char *journal = NULL;
641 struct group *grpinfo = NULL;
643 struct passwd *userinfo = getpwuid(uid);
646 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
649 if (uid != GLOBAL_USER) {
650 if (userinfo == NULL) {
651 _LOGE("getpwuid(%d) returns NULL !", uid);
654 grpinfo = getgrnam("users");
655 if (grpinfo == NULL) {
656 _LOGE("getgrnam(users) returns NULL !");
659 // Compare git_t type and not group name
660 if (grpinfo->gr_gid != userinfo->pw_gid) {
661 _LOGE("UID [%d] does not belong to 'users' group!", uid);
664 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
665 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_cert.db-journal", userinfo->pw_dir);
667 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
668 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db-journal");
670 char *temp = strdup(result);
671 dir = strrchr(temp, '/');
679 int ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
680 if (ret == -1 && errno != EEXIST) {
681 _LOGE("FAIL : to create directory %s %d", temp, errno);
682 } else if (getuid() == OWNER_ROOT) {
683 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
686 strerror_r(errno, buf, sizeof(buf));
687 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
694 API const char* getUserDesktopPath(uid_t uid)
697 struct group *grpinfo = NULL;
699 struct passwd *userinfo = getpwuid(uid);
702 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
705 if (uid != GLOBAL_USER) {
706 if (userinfo == NULL) {
707 _LOGE("getpwuid(%d) returns NULL !", uid);
710 grpinfo = getgrnam("users");
711 if (grpinfo == NULL) {
712 _LOGE("getgrnam(users) returns NULL !");
715 // Compare git_t type and not group name
716 if (grpinfo->gr_gid != userinfo->pw_gid) {
717 _LOGE("UID [%d] does not belong to 'users' group!", uid);
720 asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir);
722 result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
725 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
726 if (ret == -1 && errno != EEXIST) {
727 _LOGE("FAIL : to create directory %s %d", result, errno);
728 } else if (getuid() == OWNER_ROOT) {
729 ret = chown(result, uid,((grpinfo)?grpinfo->gr_gid:0));
732 strerror_r(errno, buf, sizeof(buf));
733 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
739 API const char* getUserManifestPath(uid_t uid)
742 struct group *grpinfo = NULL;
744 struct passwd *userinfo = getpwuid(uid);
747 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
750 if (uid != GLOBAL_USER) {
751 if (userinfo == NULL) {
752 _LOGE("getpwuid(%d) returns NULL !", uid);
755 grpinfo = getgrnam("users");
756 if (grpinfo == NULL) {
757 _LOGE("getgrnam(users) returns NULL !");
760 // Compare git_t type and not group name
761 if (grpinfo->gr_gid != userinfo->pw_gid) {
762 _LOGE("UID [%d] does not belong to 'users' group!", uid);
765 asprintf(&result, "%s/.applications/manifest/", userinfo->pw_dir);
767 result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
770 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
771 if (ret == -1 && errno != EEXIST) {
772 _LOGE("FAIL : to create directory %s %d", result, errno);
773 } else if (getuid() == OWNER_ROOT) {
774 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
777 strerror_r(errno, buf, sizeof(buf));
778 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
785 static gint __compare_func(gconstpointer data1, gconstpointer data2)
787 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
788 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
789 if (node1->prop == node2->prop)
791 else if (node1->prop > node2->prop)
797 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
800 *p = atoi(coltxt[0]);
801 _LOGE("count value is %d\n", *p);
805 static void __destroy_each_node(gpointer data, gpointer user_data)
807 ret_if(data == NULL);
808 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
821 static void __get_metadata_filter_condition(gpointer data, char **condition)
823 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
824 char key[MAX_QUERY_LEN] = {'\0'};
825 char value[MAX_QUERY_LEN] = {'\0'};
827 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
830 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
835 *condition = strdup(key);
839 static void __get_filter_condition(gpointer data, char **condition)
841 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
842 char buf[MAX_QUERY_LEN + 1] = {'\0'};
843 char temp[PKG_STRING_LEN_MAX] = {'\0'};
844 switch (node->prop) {
845 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
846 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
848 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
849 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
851 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
852 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
854 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
855 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
857 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
858 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
860 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
861 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
863 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
864 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
866 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
867 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
869 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
870 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
872 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
873 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
875 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
876 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
878 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
879 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
881 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
882 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
884 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
885 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
887 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
888 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
891 case E_PMINFO_APPINFO_PROP_APP_ID:
892 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
894 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
895 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
897 case E_PMINFO_APPINFO_PROP_APP_EXEC:
898 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
900 case E_PMINFO_APPINFO_PROP_APP_ICON:
901 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
903 case E_PMINFO_APPINFO_PROP_APP_TYPE:
904 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
906 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
907 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
908 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
910 case E_PMINFO_APPINFO_PROP_APP_URI:
911 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
912 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
914 case E_PMINFO_APPINFO_PROP_APP_MIME:
915 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
916 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
918 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
919 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
920 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
922 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
923 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
925 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
926 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
928 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
929 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
931 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
932 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
934 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
935 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
937 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
938 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
940 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
941 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
943 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
944 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
947 _LOGE("Invalid Property Type\n");
951 *condition = strdup(buf);
955 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
957 if (syslocale == NULL)
958 return strdup(DEFAULT_LOCALE);
960 locale = (char *)calloc(1, 6);
961 retvm_if(!locale, NULL, "Malloc Failed\n");
963 strncpy(locale, syslocale, 2);
964 strncat(locale, "-", 1);
965 locale[3] = syslocale[3] + 32;
966 locale[4] = syslocale[4] + 32;
970 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
972 ret_if(data == NULL);
974 free((void *)data->locale);
978 pkgmgr_parser_free_manifest_xml(data->manifest_info);
984 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
986 ret_if(data == NULL);
988 free((void *)data->package);
989 data->package = NULL;
992 free((void *)data->locale);
996 manifest_x *mfx = calloc(1, sizeof(manifest_x));
997 if (data->app_component == PMINFO_UI_APP)
998 mfx->uiapplication = data->uiapp_info;
999 else if (data->app_component == PMINFO_SVC_APP)
1000 mfx->serviceapplication = data->svcapp_info;
1001 pkgmgr_parser_free_manifest_xml(mfx);
1007 static int __close_manifest_db(void)
1010 if(manifest_db.ref) {
1011 if(--manifest_db.ref == 0)
1012 sqlite3_close(GET_DB(manifest_db));
1019 static int __open_manifest_db(uid_t uid)
1022 if(manifest_db.ref) {
1026 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
1027 if (access(user_pkg_parser, F_OK) == 0) {
1029 db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
1030 SQLITE_OPEN_READONLY, NULL);
1031 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
1033 ret = _pkgmgr_parser_attach_create_view_parserdb(GET_DB(manifest_db),uid);
1034 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
1038 _LOGE("Manifest DB does not exists !!\n");
1042 static int __close_cert_db(void)
1046 if(--cert_db.ref == 0)
1047 sqlite3_close(GET_DB(cert_db));
1049 _LOGE("Certificate DB is already closed !!\n");
1054 static int __open_cert_db(uid_t uid)
1057 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
1058 if (access(user_cert_parser, F_OK) == 0) {
1060 db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
1061 SQLITE_OPEN_READWRITE, NULL);
1062 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
1064 ret = _pkgmgr_parser_attach_create_view_certdb(GET_DB(cert_db),uid);
1065 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
1069 _LOGE("Cert DB does not exists !!\n");
1073 static int __close_datacontrol_db(void)
1076 if(datacontrol_db.ref) {
1077 if(--datacontrol_db.ref == 0)
1078 sqlite3_close(GET_DB(datacontrol_db));
1080 _LOGE("Certificate DB is already closed !!\n");
1084 static int __open_datacontrol_db()
1087 if (access(DATACONTROL_DB, F_OK) == 0) {
1089 db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
1090 SQLITE_OPEN_READONLY, NULL);
1091 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1094 _LOGE("Datacontrol DB does not exists !!\n");
1098 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1100 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1102 pkgmgr_pkginfo_x *info = NULL;
1103 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1104 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1106 LISTADD(udata, info);
1108 for(i = 0; i < ncols; i++)
1110 if (strcmp(colname[i], "package") == 0) {
1112 info->manifest_info->package = strdup(coltxt[i]);
1114 info->manifest_info->package = NULL;
1115 } else if (strcmp(colname[i], "for_all_users") == 0) {
1117 info->manifest_info->for_all_users = strdup(coltxt[i]);
1119 info->manifest_info->for_all_users = NULL;
1124 //by default if views are not set , the column for_all_users doesn't exist,
1125 // in this case we assume we retreive information about app avaible for all users
1126 if (!info->manifest_info->for_all_users)
1127 info->manifest_info->for_all_users = strdup("1");
1132 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1134 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1137 uiapplication_x *uiapp = NULL;
1138 serviceapplication_x *svcapp = NULL;
1139 for(i = 0; i < ncols; i++)
1141 if ((strcmp(colname[i], "app_component") == 0) ||
1142 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1144 if (strcmp(coltxt[i], "uiapp") == 0) {
1145 uiapp = calloc(1, sizeof(uiapplication_x));
1146 if (uiapp == NULL) {
1147 _LOGE("Out of Memory!!!\n");
1150 LISTADD(info->manifest_info->uiapplication, uiapp);
1151 for(j = 0; j < ncols; j++)
1153 if ((strcmp(colname[j], "app_id") == 0) ||
1154 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1156 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1157 } else if (strcmp(colname[j], "package") == 0) {
1159 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1164 svcapp = calloc(1, sizeof(serviceapplication_x));
1165 if (svcapp == NULL) {
1166 _LOGE("Out of Memory!!!\n");
1169 LISTADD(info->manifest_info->serviceapplication, svcapp);
1170 for(j = 0; j < ncols; j++)
1172 if ((strcmp(colname[j], "app_id") == 0) ||
1173 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1175 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1176 } else if (strcmp(colname[j], "package") == 0) {
1178 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1192 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1194 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1196 uiapplication_x *uiapp = NULL;
1197 icon_x *icon = NULL;
1198 label_x *label = NULL;
1200 uiapp = calloc(1, sizeof(uiapplication_x));
1201 LISTADD(info->manifest_info->uiapplication, uiapp);
1202 icon = calloc(1, sizeof(icon_x));
1203 LISTADD(info->manifest_info->uiapplication->icon, icon);
1204 label = calloc(1, sizeof(label_x));
1205 LISTADD(info->manifest_info->uiapplication->label, label);
1207 for(i = 0; i < ncols; i++)
1209 if (strcmp(colname[i], "app_id") == 0) {
1211 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1213 info->manifest_info->uiapplication->appid = NULL;
1214 } else if (strcmp(colname[i], "app_exec") == 0) {
1216 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1218 info->manifest_info->uiapplication->exec = NULL;
1219 } else if (strcmp(colname[i], "app_type") == 0 ){
1221 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1223 info->manifest_info->uiapplication->type = NULL;
1224 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1226 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1228 info->manifest_info->uiapplication->nodisplay = NULL;
1229 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1231 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1233 info->manifest_info->uiapplication->multiple = NULL;
1234 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1236 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1238 info->manifest_info->uiapplication->taskmanage = NULL;
1239 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1241 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1243 info->manifest_info->uiapplication->hwacceleration = NULL;
1244 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1246 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1248 info->manifest_info->uiapplication->screenreader = NULL;
1249 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1251 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1253 info->manifest_info->uiapplication->indicatordisplay = NULL;
1254 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1256 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1258 info->manifest_info->uiapplication->portraitimg = NULL;
1259 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1261 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1263 info->manifest_info->uiapplication->landscapeimg = NULL;
1264 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1266 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1268 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1269 } else if (strcmp(colname[i], "package") == 0 ){
1271 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1273 info->manifest_info->uiapplication->package = NULL;
1274 } else if (strcmp(colname[i], "app_icon") == 0) {
1276 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1278 info->manifest_info->uiapplication->icon->text = NULL;
1279 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1281 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1283 info->manifest_info->uiapplication->enabled = NULL;
1284 } else if (strcmp(colname[i], "app_label") == 0 ) {
1286 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1288 info->manifest_info->uiapplication->label->text = NULL;
1289 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1291 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1293 info->manifest_info->uiapplication->recentimage = NULL;
1294 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1296 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1298 info->manifest_info->uiapplication->mainapp = NULL;
1299 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1301 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1302 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1305 info->manifest_info->uiapplication->icon->lang = NULL;
1306 info->manifest_info->uiapplication->label->lang = NULL;
1308 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1310 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1312 info->manifest_info->uiapplication->permission_type = NULL;
1313 } else if (strcmp(colname[i], "component_type") == 0 ) {
1315 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1317 info->manifest_info->uiapplication->component_type = NULL;
1318 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1320 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1322 info->manifest_info->uiapplication->preload = NULL;
1323 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1325 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1327 info->manifest_info->uiapplication->submode = NULL;
1328 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1330 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1332 info->manifest_info->uiapplication->submode_mainid = NULL;
1339 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1341 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1343 serviceapplication_x *svcapp = NULL;
1344 icon_x *icon = NULL;
1345 label_x *label = NULL;
1347 svcapp = calloc(1, sizeof(serviceapplication_x));
1348 LISTADD(info->manifest_info->serviceapplication, svcapp);
1349 icon = calloc(1, sizeof(icon_x));
1350 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1351 label = calloc(1, sizeof(label_x));
1352 LISTADD(info->manifest_info->serviceapplication->label, label);
1353 for(i = 0; i < ncols; i++)
1355 if (strcmp(colname[i], "app_id") == 0) {
1357 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1359 info->manifest_info->serviceapplication->appid = NULL;
1360 } else if (strcmp(colname[i], "app_exec") == 0) {
1362 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1364 info->manifest_info->serviceapplication->exec = NULL;
1365 } else if (strcmp(colname[i], "app_type") == 0 ){
1367 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1369 info->manifest_info->serviceapplication->type = NULL;
1370 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1372 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1374 info->manifest_info->serviceapplication->onboot = NULL;
1375 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1377 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1379 info->manifest_info->serviceapplication->autorestart = NULL;
1380 } else if (strcmp(colname[i], "package") == 0 ){
1382 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1384 info->manifest_info->serviceapplication->package = NULL;
1385 } else if (strcmp(colname[i], "app_icon") == 0) {
1387 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1389 info->manifest_info->serviceapplication->icon->text = NULL;
1390 } else if (strcmp(colname[i], "app_label") == 0 ) {
1392 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1394 info->manifest_info->serviceapplication->label->text = NULL;
1395 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1397 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1398 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1401 info->manifest_info->serviceapplication->icon->lang = NULL;
1402 info->manifest_info->serviceapplication->label->lang = NULL;
1404 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1406 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1408 info->manifest_info->serviceapplication->permission_type = NULL;
1415 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1417 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1420 uiapplication_x *uiapp = NULL;
1421 serviceapplication_x *svcapp = NULL;
1422 for(j = 0; j < ncols; j++)
1424 if (strcmp(colname[j], "app_component") == 0) {
1426 if (strcmp(coltxt[j], "uiapp") == 0) {
1427 uiapp = calloc(1, sizeof(uiapplication_x));
1428 if (uiapp == NULL) {
1429 _LOGE("Out of Memory!!!\n");
1432 LISTADD(info->manifest_info->uiapplication, uiapp);
1433 for(i = 0; i < ncols; i++)
1435 if (strcmp(colname[i], "app_id") == 0) {
1437 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1439 info->manifest_info->uiapplication->appid = NULL;
1440 } else if (strcmp(colname[i], "app_exec") == 0) {
1442 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1444 info->manifest_info->uiapplication->exec = NULL;
1445 } else if (strcmp(colname[i], "app_type") == 0 ){
1447 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1449 info->manifest_info->uiapplication->type = NULL;
1450 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1452 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1454 info->manifest_info->uiapplication->nodisplay = NULL;
1455 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1457 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1459 info->manifest_info->uiapplication->multiple = NULL;
1460 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1462 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1464 info->manifest_info->uiapplication->taskmanage = NULL;
1465 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1467 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1469 info->manifest_info->uiapplication->hwacceleration = NULL;
1470 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1472 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1474 info->manifest_info->uiapplication->screenreader = NULL;
1475 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1477 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1479 info->manifest_info->uiapplication->indicatordisplay = NULL;
1480 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1482 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1484 info->manifest_info->uiapplication->portraitimg = NULL;
1485 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1487 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1489 info->manifest_info->uiapplication->landscapeimg = NULL;
1490 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1492 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1494 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1495 } else if (strcmp(colname[i], "package") == 0 ){
1497 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1499 info->manifest_info->uiapplication->package = NULL;
1500 } else if (strcmp(colname[i], "app_icon") == 0) {
1502 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1504 info->manifest_info->uiapplication->icon->text = NULL;
1505 } else if (strcmp(colname[i], "app_label") == 0 ) {
1507 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1509 info->manifest_info->uiapplication->label->text = NULL;
1510 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1512 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1514 info->manifest_info->uiapplication->recentimage = NULL;
1515 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1517 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1519 info->manifest_info->uiapplication->mainapp = NULL;
1520 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1522 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1523 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1526 info->manifest_info->uiapplication->icon->lang = NULL;
1527 info->manifest_info->uiapplication->label->lang = NULL;
1529 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1531 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1533 info->manifest_info->uiapplication->permission_type = NULL;
1538 svcapp = calloc(1, sizeof(serviceapplication_x));
1539 if (svcapp == NULL) {
1540 _LOGE("Out of Memory!!!\n");
1543 LISTADD(info->manifest_info->serviceapplication, svcapp);
1544 for(i = 0; i < ncols; i++)
1546 if (strcmp(colname[i], "app_id") == 0) {
1548 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1550 info->manifest_info->serviceapplication->appid = NULL;
1551 } else if (strcmp(colname[i], "app_exec") == 0) {
1553 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1555 info->manifest_info->serviceapplication->exec = NULL;
1556 } else if (strcmp(colname[i], "app_type") == 0 ){
1558 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1560 info->manifest_info->serviceapplication->type = NULL;
1561 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1563 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1565 info->manifest_info->serviceapplication->onboot = NULL;
1566 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1568 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1570 info->manifest_info->serviceapplication->autorestart = NULL;
1571 } else if (strcmp(colname[i], "package") == 0 ){
1573 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1575 info->manifest_info->serviceapplication->package = NULL;
1576 } else if (strcmp(colname[i], "app_icon") == 0) {
1578 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1580 info->manifest_info->serviceapplication->icon->text = NULL;
1581 } else if (strcmp(colname[i], "app_label") == 0 ) {
1583 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1585 info->manifest_info->serviceapplication->label->text = NULL;
1586 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1588 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1589 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1592 info->manifest_info->serviceapplication->icon->lang = NULL;
1593 info->manifest_info->serviceapplication->label->lang = NULL;
1595 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1597 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1599 info->manifest_info->serviceapplication->permission_type = NULL;
1614 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1616 int *p = (int*)data;
1617 *p = atoi(coltxt[0]);
1621 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1623 int *p = (int*)data;
1625 *p = atoi(coltxt[0]);
1629 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1631 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1633 author_x *author = NULL;
1634 icon_x *icon = NULL;
1635 label_x *label = NULL;
1636 description_x *description = NULL;
1637 privilege_x *privilege = NULL;
1639 author = calloc(1, sizeof(author_x));
1640 LISTADD(info->manifest_info->author, author);
1641 icon = calloc(1, sizeof(icon_x));
1642 LISTADD(info->manifest_info->icon, icon);
1643 label = calloc(1, sizeof(label_x));
1644 LISTADD(info->manifest_info->label, label);
1645 description = calloc(1, sizeof(description_x));
1646 LISTADD(info->manifest_info->description, description);
1647 privilege = calloc(1, sizeof(privilege_x));
1648 LISTADD(info->manifest_info->privileges->privilege, privilege);
1649 for(i = 0; i < ncols; i++)
1651 if (strcmp(colname[i], "package_version") == 0) {
1653 info->manifest_info->version = strdup(coltxt[i]);
1655 info->manifest_info->version = NULL;
1656 } else if (strcmp(colname[i], "package_type") == 0) {
1658 info->manifest_info->type = strdup(coltxt[i]);
1660 info->manifest_info->type = NULL;
1661 } else if (strcmp(colname[i], "install_location") == 0) {
1663 info->manifest_info->installlocation = strdup(coltxt[i]);
1665 info->manifest_info->installlocation = NULL;
1666 } else if (strcmp(colname[i], "package_size") == 0) {
1668 info->manifest_info->package_size = strdup(coltxt[i]);
1670 info->manifest_info->package_size = NULL;
1671 } else if (strcmp(colname[i], "author_email") == 0 ){
1673 info->manifest_info->author->email = strdup(coltxt[i]);
1675 info->manifest_info->author->email = NULL;
1676 } else if (strcmp(colname[i], "author_href") == 0 ){
1678 info->manifest_info->author->href = strdup(coltxt[i]);
1680 info->manifest_info->author->href = NULL;
1681 } else if (strcmp(colname[i], "package_label") == 0 ){
1683 info->manifest_info->label->text = strdup(coltxt[i]);
1685 info->manifest_info->label->text = NULL;
1686 } else if (strcmp(colname[i], "package_icon") == 0 ){
1688 info->manifest_info->icon->text = strdup(coltxt[i]);
1690 info->manifest_info->icon->text = NULL;
1691 } else if (strcmp(colname[i], "package_description") == 0 ){
1693 info->manifest_info->description->text = strdup(coltxt[i]);
1695 info->manifest_info->description->text = NULL;
1696 } else if (strcmp(colname[i], "package_author") == 0 ){
1698 info->manifest_info->author->text = strdup(coltxt[i]);
1700 info->manifest_info->author->text = NULL;
1701 } else if (strcmp(colname[i], "package_removable") == 0 ){
1703 info->manifest_info->removable = strdup(coltxt[i]);
1705 info->manifest_info->removable = NULL;
1706 } else if (strcmp(colname[i], "package_preload") == 0 ){
1708 info->manifest_info->preload = strdup(coltxt[i]);
1710 info->manifest_info->preload = NULL;
1711 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1713 info->manifest_info->readonly = strdup(coltxt[i]);
1715 info->manifest_info->readonly = NULL;
1716 } else if (strcmp(colname[i], "package_update") == 0 ){
1718 info->manifest_info->update= strdup(coltxt[i]);
1720 info->manifest_info->update = NULL;
1721 } else if (strcmp(colname[i], "package_system") == 0 ){
1723 info->manifest_info->system= strdup(coltxt[i]);
1725 info->manifest_info->system = NULL;
1726 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1728 info->manifest_info->appsetting = strdup(coltxt[i]);
1730 info->manifest_info->appsetting = NULL;
1731 } else if (strcmp(colname[i], "installed_time") == 0 ){
1733 info->manifest_info->installed_time = strdup(coltxt[i]);
1735 info->manifest_info->installed_time = NULL;
1736 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1738 info->manifest_info->installed_storage = strdup(coltxt[i]);
1740 info->manifest_info->installed_storage = NULL;
1741 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1743 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1745 info->manifest_info->mainapp_id = NULL;
1746 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1748 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1750 info->manifest_info->storeclient_id = NULL;
1751 } else if (strcmp(colname[i], "root_path") == 0 ){
1753 info->manifest_info->root_path = strdup(coltxt[i]);
1755 info->manifest_info->root_path = NULL;
1756 } else if (strcmp(colname[i], "csc_path") == 0 ){
1758 info->manifest_info->csc_path = strdup(coltxt[i]);
1760 info->manifest_info->csc_path = NULL;
1761 } else if (strcmp(colname[i], "privilege") == 0 ){
1763 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1765 info->manifest_info->privileges->privilege->text = NULL;
1766 } else if (strcmp(colname[i], "package_locale") == 0 ){
1768 info->manifest_info->author->lang = strdup(coltxt[i]);
1769 info->manifest_info->icon->lang = strdup(coltxt[i]);
1770 info->manifest_info->label->lang = strdup(coltxt[i]);
1771 info->manifest_info->description->lang = strdup(coltxt[i]);
1774 info->manifest_info->author->lang = NULL;
1775 info->manifest_info->icon->lang = NULL;
1776 info->manifest_info->label->lang = NULL;
1777 info->manifest_info->description->lang = NULL;
1779 } else if (strcmp(colname[i], "package_url") == 0 ){
1781 info->manifest_info->package_url = strdup(coltxt[i]);
1783 info->manifest_info->package_url = NULL;
1791 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1793 if ( strcasecmp(comp, "uiapp") == 0)
1794 return PMINFO_UI_APP;
1795 else if ( strcasecmp(comp, "svcapp") == 0)
1796 return PMINFO_SVC_APP;
1801 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1803 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1805 for(i = 0; i < ncols; i++) {
1806 if (strcmp(colname[i], "cert_id") == 0) {
1808 info->cert_id = atoi(coltxt[i]);
1811 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1813 info->cert_ref_count = atoi(coltxt[i]);
1815 info->cert_ref_count = 0;
1821 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1823 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1825 for(i = 0; i < ncols; i++)
1827 if (strcmp(colname[i], "package") == 0) {
1829 info->pkgid = strdup(coltxt[i]);
1832 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1834 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1836 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1837 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1839 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1841 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1842 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1844 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1846 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1847 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1849 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1851 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1852 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1854 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1856 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1857 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1859 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1861 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1862 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1864 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1866 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1867 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1869 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1871 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1872 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1874 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1876 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1877 } else if (strcmp(colname[i], "cert_info") == 0 ){
1879 info->cert_value = strdup(coltxt[i]);
1881 info->cert_value = NULL;
1888 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1890 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1893 uiapplication_x *uiapp = NULL;
1894 serviceapplication_x *svcapp = NULL;
1895 for(i = 0; i < ncols; i++)
1897 if (strcmp(colname[i], "app_component") == 0) {
1899 if (strcmp(coltxt[i], "uiapp") == 0) {
1900 uiapp = calloc(1, sizeof(uiapplication_x));
1901 if (uiapp == NULL) {
1902 _LOGE("Out of Memory!!!\n");
1905 LISTADD(info->manifest_info->uiapplication, uiapp);
1906 for(j = 0; j < ncols; j++)
1908 if (strcmp(colname[j], "app_id") == 0) {
1910 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1911 } else if (strcmp(colname[j], "app_exec") == 0) {
1913 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1915 info->manifest_info->uiapplication->exec = NULL;
1916 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1918 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1920 info->manifest_info->uiapplication->nodisplay = NULL;
1921 } else if (strcmp(colname[j], "app_type") == 0 ) {
1923 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1925 info->manifest_info->uiapplication->type = NULL;
1926 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1928 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1930 info->manifest_info->uiapplication->multiple = NULL;
1931 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1933 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1935 info->manifest_info->uiapplication->taskmanage = NULL;
1936 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1938 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1940 info->manifest_info->uiapplication->hwacceleration = NULL;
1941 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1943 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1945 info->manifest_info->uiapplication->screenreader = NULL;
1946 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1948 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1950 info->manifest_info->uiapplication->enabled = NULL;
1951 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1953 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1955 info->manifest_info->uiapplication->indicatordisplay = NULL;
1956 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1958 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1960 info->manifest_info->uiapplication->portraitimg = NULL;
1961 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1963 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1965 info->manifest_info->uiapplication->landscapeimg = NULL;
1966 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1968 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1970 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1971 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1973 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1975 info->manifest_info->uiapplication->recentimage = NULL;
1976 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1978 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1980 info->manifest_info->uiapplication->mainapp = NULL;
1981 } else if (strcmp(colname[j], "package") == 0 ) {
1983 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1985 info->manifest_info->uiapplication->package = NULL;
1986 } else if (strcmp(colname[j], "app_component") == 0) {
1988 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1990 info->manifest_info->uiapplication->app_component = NULL;
1991 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1993 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1995 info->manifest_info->uiapplication->permission_type = NULL;
1996 } else if (strcmp(colname[j], "component_type") == 0 ) {
1998 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
2000 info->manifest_info->uiapplication->component_type = NULL;
2001 } else if (strcmp(colname[j], "app_preload") == 0 ) {
2003 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
2005 info->manifest_info->uiapplication->preload = NULL;
2006 } else if (strcmp(colname[j], "app_submode") == 0 ) {
2008 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
2010 info->manifest_info->uiapplication->submode = NULL;
2011 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
2013 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
2015 info->manifest_info->uiapplication->submode_mainid = NULL;
2020 svcapp = calloc(1, sizeof(serviceapplication_x));
2021 if (svcapp == NULL) {
2022 _LOGE("Out of Memory!!!\n");
2025 LISTADD(info->manifest_info->serviceapplication, svcapp);
2026 for(j = 0; j < ncols; j++)
2028 if (strcmp(colname[j], "app_id") == 0) {
2030 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
2031 } else if (strcmp(colname[j], "app_exec") == 0) {
2033 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
2035 info->manifest_info->serviceapplication->exec = NULL;
2036 } else if (strcmp(colname[j], "app_type") == 0 ){
2038 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
2040 info->manifest_info->serviceapplication->type = NULL;
2041 } else if (strcmp(colname[j], "app_onboot") == 0 ){
2043 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
2045 info->manifest_info->serviceapplication->onboot = NULL;
2046 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
2048 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
2050 info->manifest_info->serviceapplication->autorestart = NULL;
2051 } else if (strcmp(colname[j], "package") == 0 ){
2053 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
2055 info->manifest_info->serviceapplication->package = NULL;
2056 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
2058 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
2060 info->manifest_info->serviceapplication->permission_type = NULL;
2073 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
2075 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2077 icon_x *icon = NULL;
2078 label_x *label = NULL;
2079 category_x *category = NULL;
2080 metadata_x *metadata = NULL;
2081 permission_x *permission = NULL;
2082 image_x *image = NULL;
2084 switch (info->app_component) {
2086 icon = calloc(1, sizeof(icon_x));
2087 LISTADD(info->uiapp_info->icon, icon);
2088 label = calloc(1, sizeof(label_x));
2089 LISTADD(info->uiapp_info->label, label);
2090 category = calloc(1, sizeof(category_x));
2091 LISTADD(info->uiapp_info->category, category);
2092 metadata = calloc(1, sizeof(metadata_x));
2093 LISTADD(info->uiapp_info->metadata, metadata);
2094 permission = calloc(1, sizeof(permission_x));
2095 LISTADD(info->uiapp_info->permission, permission);
2096 image = calloc(1, sizeof(image_x));
2097 LISTADD(info->uiapp_info->image, image);
2099 for(i = 0; i < ncols; i++)
2101 if (strcmp(colname[i], "app_id") == 0) {
2102 /*appid being foreign key, is column in every table
2103 Hence appid gets strduped every time leading to memory leak.
2104 If appid is already set, just continue.*/
2105 if (info->uiapp_info->appid)
2108 info->uiapp_info->appid = strdup(coltxt[i]);
2110 info->uiapp_info->appid = NULL;
2111 } else if (strcmp(colname[i], "app_exec") == 0) {
2113 info->uiapp_info->exec = strdup(coltxt[i]);
2115 info->uiapp_info->exec = NULL;
2116 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2118 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2120 info->uiapp_info->nodisplay = NULL;
2121 } else if (strcmp(colname[i], "app_type") == 0 ) {
2123 info->uiapp_info->type = strdup(coltxt[i]);
2125 info->uiapp_info->type = NULL;
2126 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2128 info->uiapp_info->icon->section= strdup(coltxt[i]);
2130 info->uiapp_info->icon->section = NULL;
2131 } else if (strcmp(colname[i], "app_icon") == 0) {
2133 info->uiapp_info->icon->text = strdup(coltxt[i]);
2135 info->uiapp_info->icon->text = NULL;
2136 } else if (strcmp(colname[i], "app_label") == 0 ) {
2138 info->uiapp_info->label->text = strdup(coltxt[i]);
2140 info->uiapp_info->label->text = NULL;
2141 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2143 info->uiapp_info->multiple = strdup(coltxt[i]);
2145 info->uiapp_info->multiple = NULL;
2146 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2148 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2150 info->uiapp_info->taskmanage = NULL;
2151 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2153 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2155 info->uiapp_info->hwacceleration = NULL;
2156 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2158 info->uiapp_info->screenreader = strdup(coltxt[i]);
2160 info->uiapp_info->screenreader = NULL;
2161 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2163 info->uiapp_info->enabled= strdup(coltxt[i]);
2165 info->uiapp_info->enabled = NULL;
2166 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2168 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2170 info->uiapp_info->indicatordisplay = NULL;
2171 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2173 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2175 info->uiapp_info->portraitimg = NULL;
2176 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2178 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2180 info->uiapp_info->landscapeimg = NULL;
2181 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2183 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2185 info->uiapp_info->guestmode_visibility = NULL;
2186 } else if (strcmp(colname[i], "category") == 0 ) {
2188 info->uiapp_info->category->name = strdup(coltxt[i]);
2190 info->uiapp_info->category->name = NULL;
2191 } else if (strcmp(colname[i], "md_key") == 0 ) {
2193 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2195 info->uiapp_info->metadata->key = NULL;
2196 } else if (strcmp(colname[i], "md_value") == 0 ) {
2198 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2200 info->uiapp_info->metadata->value = NULL;
2201 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2203 info->uiapp_info->permission->type= strdup(coltxt[i]);
2205 info->uiapp_info->permission->type = NULL;
2206 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2208 info->uiapp_info->permission->value = strdup(coltxt[i]);
2210 info->uiapp_info->permission->value = NULL;
2211 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2213 info->uiapp_info->recentimage = strdup(coltxt[i]);
2215 info->uiapp_info->recentimage = NULL;
2216 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2218 info->uiapp_info->mainapp = strdup(coltxt[i]);
2220 info->uiapp_info->mainapp = NULL;
2221 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2223 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2224 info->uiapp_info->label->lang = strdup(coltxt[i]);
2227 info->uiapp_info->icon->lang = NULL;
2228 info->uiapp_info->label->lang = NULL;
2230 } else if (strcmp(colname[i], "app_image") == 0) {
2232 info->uiapp_info->image->text= strdup(coltxt[i]);
2234 info->uiapp_info->image->text = NULL;
2235 } else if (strcmp(colname[i], "app_image_section") == 0) {
2237 info->uiapp_info->image->section= strdup(coltxt[i]);
2239 info->uiapp_info->image->section = NULL;
2240 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2242 info->uiapp_info->permission_type = strdup(coltxt[i]);
2244 info->uiapp_info->permission_type = NULL;
2245 } else if (strcmp(colname[i], "component_type") == 0 ) {
2247 info->uiapp_info->component_type = strdup(coltxt[i]);
2249 info->uiapp_info->component_type = NULL;
2250 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2252 info->uiapp_info->preload = strdup(coltxt[i]);
2254 info->uiapp_info->preload = NULL;
2255 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2257 info->uiapp_info->submode = strdup(coltxt[i]);
2259 info->uiapp_info->submode = NULL;
2260 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2262 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2264 info->uiapp_info->submode_mainid = NULL;
2269 case PMINFO_SVC_APP:
2270 icon = calloc(1, sizeof(icon_x));
2271 LISTADD(info->svcapp_info->icon, icon);
2272 label = calloc(1, sizeof(label_x));
2273 LISTADD(info->svcapp_info->label, label);
2274 category = calloc(1, sizeof(category_x));
2275 LISTADD(info->svcapp_info->category, category);
2276 metadata = calloc(1, sizeof(metadata_x));
2277 LISTADD(info->svcapp_info->metadata, metadata);
2278 permission = calloc(1, sizeof(permission_x));
2279 LISTADD(info->svcapp_info->permission, permission);
2280 for(i = 0; i < ncols; i++)
2282 if (strcmp(colname[i], "app_id") == 0) {
2283 /*appid being foreign key, is column in every table
2284 Hence appid gets strduped every time leading to memory leak.
2285 If appid is already set, just continue.*/
2286 if (info->svcapp_info->appid)
2289 info->svcapp_info->appid = strdup(coltxt[i]);
2291 info->svcapp_info->appid = NULL;
2292 } else if (strcmp(colname[i], "app_exec") == 0) {
2294 info->svcapp_info->exec = strdup(coltxt[i]);
2296 info->svcapp_info->exec = NULL;
2297 } else if (strcmp(colname[i], "app_icon") == 0) {
2299 info->svcapp_info->icon->text = strdup(coltxt[i]);
2301 info->svcapp_info->icon->text = NULL;
2302 } else if (strcmp(colname[i], "app_label") == 0 ) {
2304 info->svcapp_info->label->text = strdup(coltxt[i]);
2306 info->svcapp_info->label->text = NULL;
2307 } else if (strcmp(colname[i], "app_type") == 0 ) {
2309 info->svcapp_info->type = strdup(coltxt[i]);
2311 info->svcapp_info->type = NULL;
2312 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2314 info->svcapp_info->onboot = strdup(coltxt[i]);
2316 info->svcapp_info->onboot = NULL;
2317 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2319 info->svcapp_info->autorestart = strdup(coltxt[i]);
2321 info->svcapp_info->autorestart = NULL;
2322 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2324 info->svcapp_info->enabled= strdup(coltxt[i]);
2326 info->svcapp_info->enabled = NULL;
2327 } else if (strcmp(colname[i], "category") == 0 ) {
2329 info->svcapp_info->category->name = strdup(coltxt[i]);
2331 info->svcapp_info->category->name = NULL;
2332 } else if (strcmp(colname[i], "md_key") == 0 ) {
2334 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2336 info->svcapp_info->metadata->key = NULL;
2337 } else if (strcmp(colname[i], "md_value") == 0 ) {
2339 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2341 info->svcapp_info->metadata->value = NULL;
2342 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2344 info->svcapp_info->permission->type= strdup(coltxt[i]);
2346 info->svcapp_info->permission->type = NULL;
2347 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2349 info->svcapp_info->permission->value = strdup(coltxt[i]);
2351 info->svcapp_info->permission->value = NULL;
2352 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2354 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2355 info->svcapp_info->label->lang = strdup(coltxt[i]);
2358 info->svcapp_info->icon->lang = NULL;
2359 info->svcapp_info->label->lang = NULL;
2361 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2363 info->svcapp_info->permission_type = strdup(coltxt[i]);
2365 info->svcapp_info->permission_type = NULL;
2378 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2380 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2382 for(i = 0; i < ncols; i++)
2384 if (strcmp(colname[i], "app_component") == 0) {
2385 info->app_component = __appcomponent_convert(coltxt[i]);
2386 } else if (strcmp(colname[i], "package") == 0) {
2387 info->package = strdup(coltxt[i]);
2394 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2396 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2398 for(i = 0; i < ncols; i++)
2400 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2402 info->appid = strdup(coltxt[i]);
2405 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2407 info->access = strdup(coltxt[i]);
2409 info->access = NULL;
2416 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2418 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2421 for(i = 0; i < ncols; i++)
2423 if (strcmp(colname[i], "author_signer_cert") == 0) {
2425 info->cert_id = atoi(coltxt[i]);
2428 } else if (strcmp(colname[i], "package") == 0) {
2430 info->pkgid= strdup(coltxt[i]);
2439 /* get the first locale value*/
2440 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2442 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2445 info->locale = strdup(coltxt[0]);
2447 info->locale = NULL;
2452 static int __exec_pkginfo_query(char *query, void *data)
2454 char *error_message = NULL;
2456 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2457 _LOGE("Don't execute query = %s error message = %s\n", query,
2459 sqlite3_free(error_message);
2462 sqlite3_free(error_message);
2466 static int __exec_certinfo_query(char *query, void *data)
2468 char *error_message = NULL;
2470 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2471 _LOGE("Don't execute query = %s error message = %s\n", query,
2473 sqlite3_free(error_message);
2476 sqlite3_free(error_message);
2480 static int __exec_certindexinfo_query(char *query, void *data)
2482 char *error_message = NULL;
2484 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2485 _LOGE("Don't execute query = %s error message = %s\n", query,
2487 sqlite3_free(error_message);
2490 sqlite3_free(error_message);
2494 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2496 char *error_message = NULL;
2497 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2498 if (SQLITE_OK != ret) {
2499 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2500 error_message, ret);
2501 sqlite3_free(error_message);
2504 sqlite3_free(error_message);
2509 static int __child_element(xmlTextReaderPtr reader, int depth)
2511 int ret = xmlTextReaderRead(reader);
2512 int cur = xmlTextReaderDepth(reader);
2515 switch (xmlTextReaderNodeType(reader)) {
2516 case XML_READER_TYPE_ELEMENT:
2517 if (cur == depth + 1)
2520 case XML_READER_TYPE_TEXT:
2521 /*text is handled by each function separately*/
2522 if (cur == depth + 1)
2525 case XML_READER_TYPE_END_ELEMENT:
2534 ret = xmlTextReaderRead(reader);
2535 cur = xmlTextReaderDepth(reader);
2540 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2542 int *p = (int*)data;
2543 *p = atoi(coltxt[0]);
2547 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2549 int result_query = -1;
2551 char query[MAX_QUERY_LEN];
2553 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);
2554 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2555 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2556 return result_query;
2559 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2561 int result_query = -1;
2563 char wildcard[2] = {'%','\0'};
2564 char query[MAX_QUERY_LEN];
2565 char lang[3] = {'\0'};
2566 strncpy(lang, locale, LANGUAGE_LENGTH);
2568 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);
2569 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2570 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2571 return result_query;
2574 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2577 char wildcard[2] = {'%','\0'};
2578 char lang[3] = {'\0'};
2579 char query[MAX_QUERY_LEN];
2580 char *locale_new = NULL;
2581 pkgmgr_locale_x *info = NULL;
2583 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2585 _LOGE("Out of Memory!!!\n");
2588 memset(info, '\0', sizeof(*info));
2590 strncpy(lang, locale, 2);
2591 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);
2592 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2593 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2594 locale_new = info->locale;
2605 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2607 char *locale = malloc(6);
2609 _LOGE("Malloc Failed\n");
2613 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2617 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2622 char *locale = NULL;
2623 char *locale_new = NULL;
2624 int check_result = 0;
2626 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2628 /*check exact matching */
2629 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2632 if (check_result == 1) {
2633 _LOGD("%s find exact locale(%s)\n", appid, locale);
2637 /* fallback matching */
2638 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2639 if(check_result == 1) {
2640 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2642 if (locale_new == NULL)
2643 locale_new = strdup(DEFAULT_LOCALE);
2647 /* default locale */
2649 return strdup(DEFAULT_LOCALE);
2652 long long _pkgmgr_calculate_dir_size(char *dirname)
2654 long long total = 0;
2656 int q = 0; /*quotient*/
2657 int r = 0; /*remainder*/
2659 struct dirent *ep = NULL;
2660 struct stat fileinfo;
2661 char abs_filename[FILENAME_MAX] = { 0, };
2662 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2664 dp = opendir(dirname);
2666 while ((ep = readdir(dp)) != NULL) {
2667 if (!strcmp(ep->d_name, ".") ||
2668 !strcmp(ep->d_name, "..")) {
2671 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2673 if (lstat(abs_filename, &fileinfo) < 0)
2674 perror(abs_filename);
2676 if (S_ISDIR(fileinfo.st_mode)) {
2677 total += fileinfo.st_size;
2678 if (strcmp(ep->d_name, ".")
2679 && strcmp(ep->d_name, "..")) {
2680 ret = _pkgmgr_calculate_dir_size
2682 total = total + ret;
2684 } else if (S_ISLNK(fileinfo.st_mode)) {
2687 /*It is a file. Calculate the actual
2688 size occupied (in terms of 4096 blocks)*/
2689 q = (fileinfo.st_size / BLOCK_SIZE);
2690 r = (fileinfo.st_size % BLOCK_SIZE);
2694 total += q * BLOCK_SIZE;
2700 _LOGE("Couldn't open the directory\n");
2707 static int __delete_certinfo(const char *pkgid)
2713 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2714 char *error_message = NULL;
2715 char query[MAX_QUERY_LEN] = {'\0'};
2716 pkgmgr_certinfo_x *certinfo = NULL;
2717 pkgmgr_certindexinfo_x *indexinfo = NULL;
2718 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2719 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2720 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2721 if (indexinfo == NULL) {
2722 _LOGE("Out of Memory!!!");
2723 ret = PMINFO_R_ERROR;
2726 /*populate certinfo from DB*/
2727 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2728 ret = __exec_certinfo_query(query, (void *)certinfo);
2730 _LOGE("Package Cert Info DB Information retrieval failed\n");
2731 ret = PMINFO_R_ERROR;
2734 /*Update cert index table*/
2735 for (i = 0; i < MAX_CERT_TYPE; i++) {
2736 if ((certinfo->cert_id)[i]) {
2737 for (j = 0; j < MAX_CERT_TYPE; j++) {
2738 if ((certinfo->cert_id)[i] == unique_id[j]) {
2739 /*Ref count has already been updated. Just continue*/
2743 if (j == MAX_CERT_TYPE)
2744 unique_id[c++] = (certinfo->cert_id)[i];
2747 memset(query, '\0', MAX_QUERY_LEN);
2748 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2749 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2751 _LOGE("Cert Info DB Information retrieval failed\n");
2752 ret = PMINFO_R_ERROR;
2755 memset(query, '\0', MAX_QUERY_LEN);
2756 if (indexinfo->cert_ref_count > 1) {
2757 /*decrease ref count*/
2758 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2759 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2761 /*delete this certificate as ref count is 1 and it will become 0*/
2762 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2765 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2766 _LOGE("Don't execute query = %s error message = %s\n", query,
2768 sqlite3_free(error_message);
2769 ret = PMINFO_R_ERROR;
2774 /*Now delete the entry from db*/
2775 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2777 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2778 _LOGE("Don't execute query = %s error message = %s\n", query,
2780 sqlite3_free(error_message);
2781 ret = PMINFO_R_ERROR;
2790 if (certinfo->pkgid) {
2791 free(certinfo->pkgid);
2792 certinfo->pkgid = NULL;
2794 for (i = 0; i < MAX_CERT_TYPE; i++) {
2795 if ((certinfo->cert_info)[i]) {
2796 free((certinfo->cert_info)[i]);
2797 (certinfo->cert_info)[i] = NULL;
2805 static int __get_pkg_location(const char *pkgid)
2807 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2810 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2811 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2813 /*check whether application is in external memory or not */
2814 fp = fopen(pkg_mmc_path, "r");
2818 return PMINFO_EXTERNAL_STORAGE;
2821 return PMINFO_INTERNAL_STORAGE;
2824 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2826 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2827 char *error_message = NULL;
2828 int ret = PMINFO_R_OK;
2831 char query[MAX_QUERY_LEN] = {'\0'};
2832 char *syslocale = NULL;
2833 char *locale = NULL;
2834 pkgmgr_pkginfo_x *pkginfo = NULL;
2835 label_x *tmp1 = NULL;
2836 icon_x *tmp2 = NULL;
2837 description_x *tmp3 = NULL;
2838 author_x *tmp4 = NULL;
2839 privilege_x *tmp5 = NULL;
2841 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2842 if (syslocale == NULL) {
2843 _LOGE("current locale is NULL\n");
2844 return PMINFO_R_ERROR;
2846 locale = __convert_system_locale_to_manifest_locale(syslocale);
2847 if (locale == NULL) {
2848 _LOGE("manifest locale is NULL\n");
2850 return PMINFO_R_ERROR;
2853 ret_db = __open_manifest_db(uid);
2855 _LOGE("Fail to open manifest DB\n");
2858 return PMINFO_R_ERROR;
2860 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2861 pkgmgr_pkginfo_x *node = NULL;
2862 pkgmgr_pkginfo_x *temp_node = NULL;
2864 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2866 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2867 _LOGE("Don't execute query = %s error message = %s\n", query,
2869 sqlite3_free(error_message);
2870 ret = PMINFO_R_ERROR;
2874 LISTHEAD(tmphead, node);
2876 for(node = node->next; node ; node = node->next) {
2878 pkginfo->locale = strdup(locale);
2879 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2880 if (pkginfo->manifest_info->privileges == NULL) {
2881 _LOGE("Failed to allocate memory for privileges info\n");
2882 ret = PMINFO_R_ERROR;
2885 /*populate manifest_info from DB*/
2886 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2887 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2889 _LOGE("Package Info DB Information retrieval failed\n");
2890 ret = PMINFO_R_ERROR;
2893 memset(query, '\0', MAX_QUERY_LEN);
2894 /*populate privilege_info from DB*/
2895 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2896 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2898 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2899 ret = PMINFO_R_ERROR;
2902 memset(query, '\0', MAX_QUERY_LEN);
2903 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2904 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2905 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2907 _LOGE("Package Info DB Information retrieval failed\n");
2908 ret = PMINFO_R_ERROR;
2911 /*Also store the values corresponding to default locales*/
2912 memset(query, '\0', MAX_QUERY_LEN);
2913 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2914 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2915 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2917 _LOGE("Package Info DB Information retrieval failed\n");
2918 ret = PMINFO_R_ERROR;
2921 if (pkginfo->manifest_info->label) {
2922 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2923 pkginfo->manifest_info->label = tmp1;
2925 if (pkginfo->manifest_info->icon) {
2926 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2927 pkginfo->manifest_info->icon = tmp2;
2929 if (pkginfo->manifest_info->description) {
2930 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2931 pkginfo->manifest_info->description = tmp3;
2933 if (pkginfo->manifest_info->author) {
2934 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2935 pkginfo->manifest_info->author = tmp4;
2937 if (pkginfo->manifest_info->privileges->privilege) {
2938 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2939 pkginfo->manifest_info->privileges->privilege = tmp5;
2943 LISTHEAD(tmphead, node);
2945 for(node = node->next; node ; node = node->next) {
2948 ret = pkg_list_cb( (void *)pkginfo, user_data);
2956 __close_manifest_db();
2965 LISTHEAD(tmphead, node);
2966 temp_node = node->next;
2969 temp_node = node->next;
2970 __cleanup_pkginfo(node);
2973 __cleanup_pkginfo(tmphead);
2977 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2979 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2982 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2984 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2985 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2986 pkgmgr_pkginfo_x *pkginfo = NULL;
2987 int ret = PMINFO_R_OK;
2988 char query[MAX_QUERY_LEN] = {'\0'};
2989 char *syslocale = NULL;
2990 char *locale = NULL;
2992 label_x *tmp1 = NULL;
2993 icon_x *tmp2 = NULL;
2994 description_x *tmp3 = NULL;
2995 author_x *tmp4 = NULL;
2996 privilege_x *tmp5 = NULL;
2997 const char* user_pkg_parser = NULL;
3002 user_pkg_parser = getUserPkgParserDBPathUID(uid);
3003 ret = __open_manifest_db(uid);
3004 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
3006 /*check pkgid exist on db*/
3007 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
3008 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
3009 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
3010 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
3012 /*get system locale*/
3013 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3014 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3016 /*get locale on db*/
3017 locale = __convert_system_locale_to_manifest_locale(syslocale);
3018 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3020 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3021 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
3023 pkginfo->locale = strdup(locale);
3025 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3026 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
3028 pkginfo->manifest_info->package = strdup(pkgid);
3029 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3030 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
3032 /*populate manifest_info from DB*/
3033 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
3034 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3035 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3037 memset(query, '\0', MAX_QUERY_LEN);
3038 /*populate privilege_info from DB*/
3039 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
3040 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3041 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
3043 memset(query, '\0', MAX_QUERY_LEN);
3044 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3045 " package='%s' and package_locale='%s'", pkgid, locale);
3046 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3047 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3049 /*Also store the values corresponding to default locales*/
3050 memset(query, '\0', MAX_QUERY_LEN);
3051 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3052 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
3053 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3054 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3056 if (pkginfo->manifest_info->label) {
3057 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3058 pkginfo->manifest_info->label = tmp1;
3060 if (pkginfo->manifest_info->icon) {
3061 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3062 pkginfo->manifest_info->icon = tmp2;
3064 if (pkginfo->manifest_info->description) {
3065 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3066 pkginfo->manifest_info->description = tmp3;
3068 if (pkginfo->manifest_info->author) {
3069 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3070 pkginfo->manifest_info->author = tmp4;
3072 if (pkginfo->manifest_info->privileges->privilege) {
3073 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3074 pkginfo->manifest_info->privileges->privilege = tmp5;
3078 if (ret == PMINFO_R_OK)
3079 *handle = (void*)pkginfo;
3082 __cleanup_pkginfo(pkginfo);
3084 __close_manifest_db();
3096 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3098 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3101 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3103 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3104 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3105 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3106 if (info->manifest_info->package)
3107 *pkg_name = (char *)info->manifest_info->package;
3109 return PMINFO_R_ERROR;
3114 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3116 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3117 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3118 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3119 if (info->manifest_info->package)
3120 *pkgid = (char *)info->manifest_info->package;
3122 return PMINFO_R_ERROR;
3127 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3130 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3131 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3132 if (info->manifest_info->type)
3133 *type = (char *)info->manifest_info->type;
3139 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3142 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3143 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3144 *version = (char *)info->manifest_info->version;
3148 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3151 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3153 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3154 val = (char *)info->manifest_info->installlocation;
3156 if (strcmp(val, "internal-only") == 0)
3157 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3158 else if (strcmp(val, "prefer-external") == 0)
3159 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3161 *location = PMINFO_INSTALL_LOCATION_AUTO;
3166 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3168 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3169 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3171 char *location = NULL;
3172 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3173 location = (char *)info->manifest_info->installlocation;
3174 val = (char *)info->manifest_info->package_size;
3179 _LOGE("package size is not specified\n");
3180 return PMINFO_R_ERROR;
3185 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3187 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3188 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3191 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3192 long long rw_size = 0;
3193 long long ro_size= 0;
3194 long long tmp_size= 0;
3195 long long total_size= 0;
3196 struct stat fileinfo;
3199 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3201 return PMINFO_R_ERROR;
3204 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3205 if (lstat(device_path, &fileinfo) == 0) {
3206 if (!S_ISLNK(fileinfo.st_mode)) {
3207 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3209 rw_size += tmp_size;
3213 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3214 if (lstat(device_path, &fileinfo) == 0) {
3215 if (!S_ISLNK(fileinfo.st_mode)) {
3216 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3218 rw_size += tmp_size;
3222 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3223 if (lstat(device_path, &fileinfo) == 0) {
3224 if (!S_ISLNK(fileinfo.st_mode)) {
3225 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3227 rw_size += tmp_size;
3231 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3232 if (lstat(device_path, &fileinfo) == 0) {
3233 if (!S_ISLNK(fileinfo.st_mode)) {
3234 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3236 rw_size += tmp_size;
3240 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3241 if (lstat(device_path, &fileinfo) == 0) {
3242 if (!S_ISLNK(fileinfo.st_mode)) {
3243 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3245 rw_size += tmp_size;
3249 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3250 if (lstat(device_path, &fileinfo) == 0) {
3251 if (!S_ISLNK(fileinfo.st_mode)) {
3252 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3254 rw_size += tmp_size;
3259 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3260 if (lstat(device_path, &fileinfo) == 0) {
3261 if (!S_ISLNK(fileinfo.st_mode)) {
3262 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3264 ro_size += tmp_size;
3268 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3269 if (lstat(device_path, &fileinfo) == 0) {
3270 if (!S_ISLNK(fileinfo.st_mode)) {
3271 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3273 ro_size += tmp_size;
3277 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3278 if (lstat(device_path, &fileinfo) == 0) {
3279 if (!S_ISLNK(fileinfo.st_mode)) {
3280 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3282 ro_size += tmp_size;
3286 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3287 if (lstat(device_path, &fileinfo) == 0) {
3288 if (!S_ISLNK(fileinfo.st_mode)) {
3289 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3291 ro_size += tmp_size;
3295 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3296 if (lstat(device_path, &fileinfo) == 0) {
3297 if (!S_ISLNK(fileinfo.st_mode)) {
3298 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3300 ro_size += tmp_size;
3304 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3305 if (lstat(device_path, &fileinfo) == 0) {
3306 if (!S_ISLNK(fileinfo.st_mode)) {
3307 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3309 ro_size += tmp_size;
3314 total_size = rw_size + ro_size;
3315 *size = (int)total_size;
3320 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3322 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3323 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3326 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3327 long long total_size= 0;
3330 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3332 return PMINFO_R_ERROR;
3334 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3335 if (access(device_path, R_OK) == 0)
3336 total_size = _pkgmgr_calculate_dir_size(device_path);
3338 return PMINFO_R_ERROR;
3340 *size = (int)total_size;
3345 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3347 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3348 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3349 int ret = PMINFO_R_OK;
3350 char *locale = NULL;
3354 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3356 locale = info->locale;
3357 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3359 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3362 if (strcmp(ptr->lang, locale) == 0) {
3363 *icon = (char *)ptr->text;
3364 if (strcasecmp(*icon, "(null)") == 0) {
3365 locale = DEFAULT_LOCALE;
3369 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3370 *icon = (char *)ptr->text;
3379 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3381 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3382 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3383 int ret = PMINFO_R_OK;
3384 char *locale = NULL;
3385 label_x *ptr = NULL;
3388 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3389 locale = info->locale;
3390 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3392 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3395 if (strcmp(ptr->lang, locale) == 0) {
3396 *label = (char *)ptr->text;
3397 if (strcasecmp(*label, "(null)") == 0) {
3398 locale = DEFAULT_LOCALE;
3402 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3403 *label = (char *)ptr->text;
3412 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3415 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3416 char *locale = NULL;
3417 description_x *ptr = NULL;
3418 *description = NULL;
3420 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3421 locale = info->locale;
3422 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3424 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3427 if (strcmp(ptr->lang, locale) == 0) {
3428 *description = (char *)ptr->text;
3429 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3430 locale = DEFAULT_LOCALE;
3434 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3435 *description = (char *)ptr->text;
3443 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3445 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3446 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3447 char *locale = NULL;
3448 author_x *ptr = NULL;
3449 *author_name = NULL;
3451 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3452 locale = info->locale;
3453 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3455 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3458 if (strcmp(ptr->lang, locale) == 0) {
3459 *author_name = (char *)ptr->text;
3460 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3461 locale = DEFAULT_LOCALE;
3465 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3466 *author_name = (char *)ptr->text;
3474 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3476 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3477 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3478 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3479 *author_email = (char *)info->manifest_info->author->email;
3483 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3485 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3486 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3487 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3488 *author_href = (char *)info->manifest_info->author->href;
3492 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3494 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3495 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3497 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3499 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3500 *storage = PMINFO_INTERNAL_STORAGE;
3501 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3502 *storage = PMINFO_EXTERNAL_STORAGE;
3504 return PMINFO_R_ERROR;
3509 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3512 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3513 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3514 if (info->manifest_info->installed_time)
3515 *installed_time = atoi(info->manifest_info->installed_time);
3517 return PMINFO_R_ERROR;
3522 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3524 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3525 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3526 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3527 *storeclientid = (char *)info->manifest_info->storeclient_id;
3531 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3533 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3534 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3535 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3536 *mainappid = (char *)info->manifest_info->mainapp_id;
3540 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3542 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3543 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3544 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3545 *url = (char *)info->manifest_info->package_url;
3549 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3551 const char *val = NULL;
3552 const xmlChar *node;
3553 xmlTextReaderPtr reader;
3554 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3555 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3558 reader = xmlReaderForFile(manifest, NULL, 0);
3561 if (__child_element(reader, -1)) {
3562 node = xmlTextReaderConstName(reader);
3564 _LOGE("xmlTextReaderConstName value is NULL\n");
3565 xmlFreeTextReader(reader);
3567 return PMINFO_R_ERROR;
3570 if (!strcmp(ASC_CHAR(node), "manifest")) {
3571 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3572 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3578 _LOGE("package size is not specified\n");
3579 xmlFreeTextReader(reader);
3581 return PMINFO_R_ERROR;
3584 _LOGE("Unable to create xml reader\n");
3585 xmlFreeTextReader(reader);
3587 return PMINFO_R_ERROR;
3591 _LOGE("xmlReaderForFile value is NULL\n");
3593 return PMINFO_R_ERROR;
3596 xmlFreeTextReader(reader);
3602 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3604 const char *val = NULL;
3605 const xmlChar *node;
3606 xmlTextReaderPtr reader;
3607 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3608 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3611 reader = xmlReaderForFile(manifest, NULL, 0);
3614 if ( __child_element(reader, -1)) {
3615 node = xmlTextReaderConstName(reader);
3617 _LOGE("xmlTextReaderConstName value is NULL\n");
3618 xmlFreeTextReader(reader);
3620 return PMINFO_R_ERROR;
3623 if (!strcmp(ASC_CHAR(node), "manifest")) {
3624 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3625 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3628 if (strcmp(val, "internal-only") == 0)
3629 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3630 else if (strcmp(val, "prefer-external") == 0)
3631 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3633 *location = PMINFO_INSTALL_LOCATION_AUTO;
3636 _LOGE("Unable to create xml reader\n");
3637 xmlFreeTextReader(reader);
3639 return PMINFO_R_ERROR;
3643 _LOGE("xmlReaderForFile value is NULL\n");
3645 return PMINFO_R_ERROR;
3648 xmlFreeTextReader(reader);
3655 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3657 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3658 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3660 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3661 if (info->manifest_info->root_path)
3662 *path = (char *)info->manifest_info->root_path;
3664 return PMINFO_R_ERROR;
3669 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3671 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3672 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3674 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3675 if (info->manifest_info->csc_path)
3676 *path = (char *)info->manifest_info->csc_path;
3678 *path = (char *)info->manifest_info->csc_path;
3683 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)
3685 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3686 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3687 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3689 int ret = PMINFO_R_OK;
3690 char query[MAX_QUERY_LEN] = {'\0'};
3691 char *error_message = NULL;
3692 pkgmgr_cert_x *info= NULL;
3696 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3697 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3698 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3700 ret = __open_cert_db(uid);
3702 ret = PMINFO_R_ERROR;
3705 _check_create_Cert_db(GET_DB(cert_db));
3706 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3708 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3709 _LOGE("Don't execute query = %s error message = %s\n", query,
3711 ret = PMINFO_R_ERROR;
3718 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3720 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3721 _LOGE("Don't execute query = %s error message = %s\n", query,
3723 ret = PMINFO_R_ERROR;
3726 lcert = info->cert_id;
3729 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3731 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3732 _LOGE("Don't execute query = %s error message = %s\n", query,
3734 ret = PMINFO_R_ERROR;
3741 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3743 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3744 _LOGE("Don't execute query = %s error message = %s\n", query,
3746 ret = PMINFO_R_ERROR;
3749 rcert = info->cert_id;
3752 if ((lcert == 0) || (rcert == 0))
3754 if ((lcert == 0) && (rcert == 0))
3755 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3756 else if (lcert == 0)
3757 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3758 else if (rcert == 0)
3759 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3762 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3764 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3768 sqlite3_free(error_message);
3781 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)
3783 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3786 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)
3788 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3789 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3790 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3792 int ret = PMINFO_R_OK;
3793 char query[MAX_QUERY_LEN] = {'\0'};
3794 char *error_message = NULL;
3795 pkgmgr_cert_x *info= NULL;
3797 char *lpkgid = NULL;
3798 char *rpkgid = NULL;
3799 const char* user_pkg_parser = getUserPkgParserDBPath();
3801 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3802 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3804 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3805 SQLITE_OPEN_READONLY, NULL);
3806 if (ret != SQLITE_OK) {
3807 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3808 ret = PMINFO_R_ERROR;
3812 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3814 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3815 _LOGE("Don't execute query = %s error message = %s\n", query,
3817 ret = PMINFO_R_ERROR;
3824 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3826 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3827 _LOGE("Don't execute query = %s error message = %s\n", query,
3829 ret = PMINFO_R_ERROR;
3832 lpkgid = strdup(info->pkgid);
3833 if (lpkgid == NULL) {
3834 _LOGE("Out of Memory\n");
3835 ret = PMINFO_R_ERROR;
3842 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3844 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3845 _LOGE("Don't execute query = %s error message = %s\n", query,
3847 ret = PMINFO_R_ERROR;
3854 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3856 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3857 _LOGE("Don't execute query = %s error message = %s\n", query,
3859 ret = PMINFO_R_ERROR;
3862 rpkgid = strdup(info->pkgid);
3863 if (rpkgid == NULL) {
3864 _LOGE("Out of Memory\n");
3865 ret = PMINFO_R_ERROR;
3871 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3873 sqlite3_free(error_message);
3874 __close_manifest_db();
3894 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)
3896 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3897 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3898 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3900 int ret = PMINFO_R_OK;
3901 char query[MAX_QUERY_LEN] = {'\0'};
3902 char *error_message = NULL;
3903 pkgmgr_cert_x *info= NULL;
3905 char *lpkgid = NULL;
3906 char *rpkgid = NULL;
3908 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3909 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3911 ret = __open_manifest_db(uid);
3912 if (ret != SQLITE_OK) {
3913 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3914 ret = PMINFO_R_ERROR;
3918 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3920 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3921 _LOGE("Don't execute query = %s error message = %s\n", query,
3923 ret = PMINFO_R_ERROR;
3930 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3932 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3933 _LOGE("Don't execute query = %s error message = %s\n", query,
3935 ret = PMINFO_R_ERROR;
3938 lpkgid = strdup(info->pkgid);
3939 if (lpkgid == NULL) {
3940 _LOGE("Out of Memory\n");
3941 ret = PMINFO_R_ERROR;
3948 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3950 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3951 _LOGE("Don't execute query = %s error message = %s\n", query,
3953 ret = PMINFO_R_ERROR;
3960 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3962 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3963 _LOGE("Don't execute query = %s error message = %s\n", query,
3965 ret = PMINFO_R_ERROR;
3968 rpkgid = strdup(info->pkgid);
3969 if (rpkgid == NULL) {
3970 _LOGE("Out of Memory\n");
3971 ret = PMINFO_R_ERROR;
3977 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3979 sqlite3_free(error_message);
3980 __close_manifest_db();
4000 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
4002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4003 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4005 #if 0 //smack issue occured, check later
4007 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
4009 _LOGD("invalid func parameters\n");
4010 return PMINFO_R_ERROR;
4012 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
4015 char app_mmc_path[FILENAME_MAX] = { 0, };
4016 char app_dir_path[FILENAME_MAX] = { 0, };
4017 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
4018 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
4019 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
4020 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
4022 /*check whether application is in external memory or not */
4023 fp = fopen(app_mmc_path, "r");
4025 _LOGD(" app path in external memory not accesible\n");
4030 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
4034 /*check whether application is in internal or not */
4035 fp = fopen(app_dir_path, "r");
4037 _LOGD(" app path in internal memory not accesible\n");
4039 return PMINFO_R_ERROR;
4042 /*check whether the application is installed in SD card
4043 but SD card is not present*/
4044 fp = fopen(app_mmc_internal_path, "r");
4047 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
4052 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
4057 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
4064 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
4066 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4067 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4069 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4070 val = (char *)info->manifest_info->removable;
4072 if (strcasecmp(val, "true") == 0)
4074 else if (strcasecmp(val, "false") == 0)
4082 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4084 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4085 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4088 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4090 val = (char *)info->manifest_info->installlocation;
4092 if (strcmp(val, "internal-only") == 0)
4094 else if (strcmp(val, "prefer-external") == 0)
4103 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4105 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4106 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4108 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4109 val = (char *)info->manifest_info->preload;
4111 if (strcasecmp(val, "true") == 0)
4113 else if (strcasecmp(val, "false") == 0)
4121 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4123 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4124 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4127 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4128 val = (char *)info->manifest_info->system;
4130 if (strcasecmp(val, "true") == 0)
4132 else if (strcasecmp(val, "false") == 0)
4141 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4143 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4144 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4146 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4147 val = (char *)info->manifest_info->readonly;
4149 if (strcasecmp(val, "true") == 0)
4151 else if (strcasecmp(val, "false") == 0)
4159 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4162 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4165 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4166 val = (char *)info->manifest_info->update;
4168 if (strcasecmp(val, "true") == 0)
4170 else if (strcasecmp(val, "false") == 0)
4178 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4181 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4184 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4185 val = (char *)info->manifest_info->for_all_users;
4187 if (strcasecmp(val, "1") == 0)
4189 else if (strcasecmp(val, "0") == 0)
4198 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4200 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4201 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4202 __cleanup_pkginfo(info);
4206 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4208 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4210 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4211 if (filter == NULL) {
4212 _LOGE("Out of Memory!!!");
4213 return PMINFO_R_ERROR;
4219 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4221 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4222 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4224 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4225 g_slist_free(filter->list);
4232 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4233 const char *property, const int value)
4235 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4236 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4237 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4239 GSList *link = NULL;
4241 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4242 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4243 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4244 _LOGE("Invalid Integer Property\n");
4245 return PMINFO_R_EINVAL;
4247 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4248 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4250 _LOGE("Out of Memory!!!\n");
4251 return PMINFO_R_ERROR;
4253 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4254 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4256 _LOGE("Out of Memory\n");
4259 return PMINFO_R_ERROR;
4263 /*If API is called multiple times for same property, we should override the previous values.
4264 Last value set will be used for filtering.*/
4265 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4267 filter->list = g_slist_delete_link(filter->list, link);
4268 filter->list = g_slist_append(filter->list, (gpointer)node);
4273 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4274 const char *property, const bool value)
4276 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4277 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4279 GSList *link = NULL;
4281 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4282 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4283 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4284 _LOGE("Invalid Boolean Property\n");
4285 return PMINFO_R_EINVAL;
4287 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4288 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4290 _LOGE("Out of Memory!!!\n");
4291 return PMINFO_R_ERROR;
4294 val = strndup("('true','True')", 15);
4296 val = strndup("('false','False')", 17);
4298 _LOGE("Out of Memory\n");
4301 return PMINFO_R_ERROR;
4305 /*If API is called multiple times for same property, we should override the previous values.
4306 Last value set will be used for filtering.*/
4307 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4309 filter->list = g_slist_delete_link(filter->list, link);
4310 filter->list = g_slist_append(filter->list, (gpointer)node);
4315 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4316 const char *property, const char *value)
4318 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4319 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4320 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4322 GSList *link = NULL;
4324 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4325 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4326 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4327 _LOGE("Invalid String Property\n");
4328 return PMINFO_R_EINVAL;
4330 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4331 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4333 _LOGE("Out of Memory!!!\n");
4334 return PMINFO_R_ERROR;
4336 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4337 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4338 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4339 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4340 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4341 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4342 else if (strcmp(value, "installed_internal") == 0)
4343 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4344 else if (strcmp(value, "installed_external") == 0)
4345 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4347 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4349 _LOGE("Out of Memory\n");
4352 return PMINFO_R_ERROR;
4356 /*If API is called multiple times for same property, we should override the previous values.
4357 Last value set will be used for filtering.*/
4358 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4360 filter->list = g_slist_delete_link(filter->list, link);
4361 filter->list = g_slist_append(filter->list, (gpointer)node);
4366 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4369 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4370 char *syslocale = NULL;
4371 char *locale = NULL;
4372 char *condition = NULL;
4373 char *error_message = NULL;
4374 char query[MAX_QUERY_LEN] = {'\0'};
4375 char where[MAX_QUERY_LEN] = {'\0'};
4379 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4381 /*Get current locale*/
4382 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4383 if (syslocale == NULL) {
4384 _LOGE("current locale is NULL\n");
4385 return PMINFO_R_ERROR;
4387 locale = __convert_system_locale_to_manifest_locale(syslocale);
4388 if (locale == NULL) {
4389 _LOGE("manifest locale is NULL\n");
4391 return PMINFO_R_ERROR;
4394 ret = __open_manifest_db(uid);
4396 _LOGE("Fail to open manifest DB\n");
4399 return PMINFO_R_ERROR;
4402 /*Start constructing query*/
4403 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4405 /*Get where clause*/
4406 for (list = filter->list; list; list = g_slist_next(list)) {
4407 __get_filter_condition(list->data, &condition);
4409 strncat(where, condition, sizeof(where) - strlen(where) -1);
4410 where[sizeof(where) - 1] = '\0';
4414 if (g_slist_next(list)) {
4415 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4416 where[sizeof(where) - 1] = '\0';
4419 _LOGE("where = %s\n", where);
4420 if (strlen(where) > 0) {
4421 strncat(query, where, sizeof(query) - strlen(query) - 1);
4422 query[sizeof(query) - 1] = '\0';
4424 _LOGE("query = %s\n", query);
4428 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4429 _LOGE("Don't execute query = %s error message = %s\n", query,
4431 sqlite3_free(error_message);
4432 ret = PMINFO_R_ERROR;
4446 __close_manifest_db();
4450 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4452 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4455 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4456 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4458 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4459 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4460 char *syslocale = NULL;
4461 char *locale = NULL;
4462 char *condition = NULL;
4463 char *error_message = NULL;
4464 char query[MAX_QUERY_LEN] = {'\0'};
4465 char where[MAX_QUERY_LEN] = {'\0'};
4468 label_x *tmp1 = NULL;
4469 icon_x *tmp2 = NULL;
4470 description_x *tmp3 = NULL;
4471 author_x *tmp4 = NULL;
4472 privilege_x *tmp5 = NULL;
4473 pkgmgr_pkginfo_x *node = NULL;
4474 pkgmgr_pkginfo_x *tmphead = NULL;
4475 pkgmgr_pkginfo_x *pkginfo = NULL;
4477 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4478 /*Get current locale*/
4479 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4480 if (syslocale == NULL) {
4481 _LOGE("current locale is NULL\n");
4482 return PMINFO_R_ERROR;
4484 locale = __convert_system_locale_to_manifest_locale(syslocale);
4485 if (locale == NULL) {
4486 _LOGE("manifest locale is NULL\n");
4488 return PMINFO_R_ERROR;
4491 ret = __open_manifest_db(uid);
4493 _LOGE("Fail to open manifest DB\n");
4496 return PMINFO_R_ERROR;
4498 /*Start constructing query*/
4499 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4501 /*Get where clause*/
4502 for (list = filter->list; list; list = g_slist_next(list)) {
4503 __get_filter_condition(list->data, &condition);
4505 strncat(where, condition, sizeof(where) - strlen(where) -1);
4506 where[sizeof(where) - 1] = '\0';
4510 if (g_slist_next(list)) {
4511 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4512 where[sizeof(where) - 1] = '\0';
4515 _LOGE("where = %s\n", where);
4516 if (strlen(where) > 0) {
4517 strncat(query, where, sizeof(query) - strlen(query) - 1);
4518 query[sizeof(query) - 1] = '\0';
4520 _LOGE("query = %s\n", query);
4521 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4522 if (tmphead == NULL) {
4523 _LOGE("Out of Memory!!!\n");
4524 ret = PMINFO_R_ERROR;
4530 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4531 _LOGE("Don't execute query = %s error message = %s\n", query,
4533 sqlite3_free(error_message);
4534 ret = PMINFO_R_ERROR;
4538 LISTHEAD(tmphead, node);
4539 for(node = node->next ; node ; node = node->next) {
4541 pkginfo->locale = strdup(locale);
4542 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4543 if (pkginfo->manifest_info->privileges == NULL) {
4544 _LOGE("Failed to allocate memory for privileges info\n");
4545 ret = PMINFO_R_ERROR;
4549 /*populate manifest_info from DB*/
4550 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4551 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4553 _LOGE("Package Info DB Information retrieval failed\n");
4554 ret = PMINFO_R_ERROR;
4557 memset(query, '\0', MAX_QUERY_LEN);
4558 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4559 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4560 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4562 _LOGE("Package Info DB Information retrieval failed\n");
4563 ret = PMINFO_R_ERROR;
4566 /*Also store the values corresponding to default locales*/
4567 memset(query, '\0', MAX_QUERY_LEN);
4568 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4569 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4570 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4572 _LOGE("Package Info DB Information retrieval failed\n");
4573 ret = PMINFO_R_ERROR;
4576 if (pkginfo->manifest_info->label) {
4577 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4578 pkginfo->manifest_info->label = tmp1;
4580 if (pkginfo->manifest_info->icon) {
4581 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4582 pkginfo->manifest_info->icon = tmp2;
4584 if (pkginfo->manifest_info->description) {
4585 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4586 pkginfo->manifest_info->description = tmp3;
4588 if (pkginfo->manifest_info->author) {
4589 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4590 pkginfo->manifest_info->author = tmp4;
4592 if (pkginfo->manifest_info->privileges->privilege) {
4593 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4594 pkginfo->manifest_info->privileges->privilege = tmp5;
4598 LISTHEAD(tmphead, node);
4600 for(node = node->next ; node ; node = node->next) {
4603 ret = pkg_cb( (void *)pkginfo, user_data);
4618 __close_manifest_db();
4619 __cleanup_pkginfo(tmphead);
4623 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4624 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4626 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4629 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4630 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4632 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4633 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4635 privilege_x *ptr = NULL;
4636 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4637 ptr = info->manifest_info->privileges->privilege;
4638 for (; ptr; ptr = ptr->next) {
4640 ret = privilege_func(ptr->text, user_data);
4648 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4649 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4651 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4652 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4653 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4655 char *syslocale = NULL;
4656 char *locale = NULL;
4658 char query[MAX_QUERY_LEN] = {'\0'};
4659 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4660 pkgmgr_pkginfo_x *allinfo = NULL;
4661 pkgmgr_appinfo_x *appinfo = NULL;
4662 icon_x *ptr1 = NULL;
4663 label_x *ptr2 = NULL;
4664 category_x *ptr3 = NULL;
4665 metadata_x *ptr4 = NULL;
4666 permission_x *ptr5 = NULL;
4667 image_x *ptr6 = NULL;
4668 const char* user_pkg_parser = NULL;
4670 /*get system locale*/
4671 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4672 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4674 /*get locale on db*/
4675 locale = __convert_system_locale_to_manifest_locale(syslocale);
4676 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4679 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4680 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4682 /*calloc manifest_info*/
4683 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4684 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4687 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4688 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4690 /*set component type*/
4691 if (component == PMINFO_UI_APP)
4692 appinfo->app_component = PMINFO_UI_APP;
4693 if (component == PMINFO_SVC_APP)
4694 appinfo->app_component = PMINFO_SVC_APP;
4695 if (component == PMINFO_ALL_APP)
4696 appinfo->app_component = PMINFO_ALL_APP;
4699 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4700 ret = __open_manifest_db(uid);
4701 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4703 appinfo->package = strdup(info->manifest_info->package);
4704 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4705 "from package_app_info where " \
4706 "package='%s' and app_component='%s'",
4707 info->manifest_info->package,
4708 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4712 /*Populate ui app info */
4713 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4714 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4716 uiapplication_x *tmp = NULL;
4717 if (info->manifest_info->uiapplication) {
4718 LISTHEAD(info->manifest_info->uiapplication, tmp);
4719 info->manifest_info->uiapplication = tmp;
4721 /*Populate localized info for default locales and call callback*/
4722 /*If the callback func return < 0 we break and no more call back is called*/
4725 appinfo->locale = strdup(locale);
4726 appinfo->uiapp_info = tmp;
4727 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4731 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4734 memset(query, '\0', MAX_QUERY_LEN);
4735 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4736 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4737 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4739 memset(query, '\0', MAX_QUERY_LEN);
4740 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);
4741 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4742 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4744 /*store setting notification icon section*/
4745 memset(query, '\0', MAX_QUERY_LEN);
4746 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4747 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4748 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4750 /*store app preview image info*/
4751 memset(query, '\0', MAX_QUERY_LEN);
4752 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4753 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4754 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4756 if (appinfo->uiapp_info->label) {
4757 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4758 appinfo->uiapp_info->label = ptr2;
4760 if (appinfo->uiapp_info->icon) {
4761 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4762 appinfo->uiapp_info->icon = ptr1;
4764 if (appinfo->uiapp_info->category) {
4765 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4766 appinfo->uiapp_info->category = ptr3;
4768 if (appinfo->uiapp_info->metadata) {
4769 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4770 appinfo->uiapp_info->metadata = ptr4;
4772 if (appinfo->uiapp_info->permission) {
4773 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4774 appinfo->uiapp_info->permission = ptr5;
4776 if (appinfo->uiapp_info->image) {
4777 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4778 appinfo->uiapp_info->image = ptr6;
4780 ret = app_func((void *)appinfo, user_data);
4786 case PMINFO_SVC_APP:
4787 /*Populate svc app info */
4788 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4789 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4791 serviceapplication_x *tmp1 = NULL;
4792 if (info->manifest_info->serviceapplication) {
4793 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4794 info->manifest_info->serviceapplication = tmp1;
4796 /*Populate localized info for default locales and call callback*/
4797 /*If the callback func return < 0 we break and no more call back is called*/
4800 appinfo->locale = strdup(locale);
4801 appinfo->svcapp_info = tmp1;
4802 memset(query, '\0', MAX_QUERY_LEN);
4803 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4804 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4805 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4807 memset(query, '\0', MAX_QUERY_LEN);
4808 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);
4809 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4810 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4812 if (appinfo->svcapp_info->label) {
4813 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4814 appinfo->svcapp_info->label = ptr2;
4816 if (appinfo->svcapp_info->icon) {
4817 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4818 appinfo->svcapp_info->icon = ptr1;
4820 if (appinfo->svcapp_info->category) {
4821 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4822 appinfo->svcapp_info->category = ptr3;
4824 if (appinfo->svcapp_info->metadata) {
4825 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4826 appinfo->svcapp_info->metadata = ptr4;
4828 if (appinfo->svcapp_info->permission) {
4829 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4830 appinfo->svcapp_info->permission = ptr5;
4832 ret = app_func((void *)appinfo, user_data);
4838 case PMINFO_ALL_APP:
4839 memset(query, '\0', MAX_QUERY_LEN);
4840 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4842 /*Populate all app info */
4843 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4844 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4847 appinfo->app_component = PMINFO_UI_APP;
4848 uiapplication_x *tmp2 = NULL;
4849 if (allinfo->manifest_info->uiapplication) {
4850 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4851 allinfo->manifest_info->uiapplication = tmp2;
4853 /*Populate localized info for default locales and call callback*/
4854 /*If the callback func return < 0 we break and no more call back is called*/
4857 appinfo->locale = strdup(locale);
4858 appinfo->uiapp_info = tmp2;
4859 memset(query, '\0', MAX_QUERY_LEN);
4860 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4861 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4862 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4864 memset(query, '\0', MAX_QUERY_LEN);
4865 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);
4866 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4867 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4869 /*store setting notification icon section*/
4870 memset(query, '\0', MAX_QUERY_LEN);
4871 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4872 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4873 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4875 /*store app preview image info*/
4876 memset(query, '\0', MAX_QUERY_LEN);
4877 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4878 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4879 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4881 if (appinfo->uiapp_info->label) {
4882 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4883 appinfo->uiapp_info->label = ptr2;
4885 if (appinfo->uiapp_info->icon) {
4886 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4887 appinfo->uiapp_info->icon = ptr1;
4889 if (appinfo->uiapp_info->category) {
4890 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4891 appinfo->uiapp_info->category = ptr3;
4893 if (appinfo->uiapp_info->metadata) {
4894 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4895 appinfo->uiapp_info->metadata = ptr4;
4897 if (appinfo->uiapp_info->permission) {
4898 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4899 appinfo->uiapp_info->permission = ptr5;
4901 if (appinfo->uiapp_info->image) {
4902 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4903 appinfo->uiapp_info->image = ptr6;
4905 ret = app_func((void *)appinfo, user_data);
4912 appinfo->app_component = PMINFO_SVC_APP;
4913 serviceapplication_x *tmp3 = NULL;
4914 if (allinfo->manifest_info->serviceapplication) {
4915 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4916 allinfo->manifest_info->serviceapplication = tmp3;
4918 /*Populate localized info for default locales and call callback*/
4919 /*If the callback func return < 0 we break and no more call back is called*/
4922 appinfo->locale = strdup(locale);
4923 appinfo->svcapp_info = tmp3;
4924 memset(query, '\0', MAX_QUERY_LEN);
4925 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4926 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4927 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4929 memset(query, '\0', MAX_QUERY_LEN);
4930 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);
4931 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4932 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4934 if (appinfo->svcapp_info->label) {
4935 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4936 appinfo->svcapp_info->label = ptr2;
4938 if (appinfo->svcapp_info->icon) {
4939 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4940 appinfo->svcapp_info->icon = ptr1;
4942 if (appinfo->svcapp_info->category) {
4943 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4944 appinfo->svcapp_info->category = ptr3;
4946 if (appinfo->svcapp_info->metadata) {
4947 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4948 appinfo->svcapp_info->metadata = ptr4;
4950 if (appinfo->svcapp_info->permission) {
4951 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4952 appinfo->svcapp_info->permission = ptr5;
4954 ret = app_func((void *)appinfo, user_data);
4959 appinfo->app_component = PMINFO_ALL_APP;
4975 if (appinfo->package) {
4976 free((void *)appinfo->package);
4977 appinfo->package = NULL;
4982 __cleanup_pkginfo(allinfo);
4984 __close_manifest_db();
4988 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4989 pkgmgrinfo_app_list_cb app_func, void *user_data)
4991 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4994 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4996 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4998 int ret = PMINFO_R_OK;
4999 char query[MAX_QUERY_LEN] = {'\0'};
5000 pkgmgr_appinfo_x *appinfo = NULL;
5001 uiapplication_x *ptr1 = NULL;
5002 serviceapplication_x *ptr2 = NULL;
5003 const char* user_pkg_parser = NULL;
5006 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5007 ret = __open_manifest_db(uid);
5008 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5011 pkgmgr_pkginfo_x *info = NULL;
5012 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5013 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5015 /*calloc manifest_info*/
5016 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5017 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5020 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5021 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5023 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5024 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
5025 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5027 if (info->manifest_info->uiapplication) {
5028 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5029 info->manifest_info->uiapplication = ptr1;
5031 if (info->manifest_info->serviceapplication) {
5032 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5033 info->manifest_info->serviceapplication = ptr2;
5037 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5039 appinfo->app_component = PMINFO_UI_APP;
5040 appinfo->package = strdup(ptr1->package);
5041 appinfo->uiapp_info = ptr1;
5043 ret = app_func((void *)appinfo, user_data);
5046 free((void *)appinfo->package);
5047 appinfo->package = NULL;
5050 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5052 appinfo->app_component = PMINFO_SVC_APP;
5053 appinfo->package = strdup(ptr2->package);
5054 appinfo->svcapp_info = ptr2;
5056 ret = app_func((void *)appinfo, user_data);
5059 free((void *)appinfo->package);
5060 appinfo->package = NULL;
5065 __close_manifest_db();
5070 __cleanup_pkginfo(info);
5074 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5076 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
5079 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5081 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5083 int ret = PMINFO_R_OK;
5084 char query[MAX_QUERY_LEN] = {'\0'};
5085 char *syslocale = NULL;
5086 char *locale = NULL;
5087 pkgmgr_appinfo_x *appinfo = NULL;
5088 uiapplication_x *ptr1 = NULL;
5089 serviceapplication_x *ptr2 = NULL;
5090 label_x *tmp1 = NULL;
5091 icon_x *tmp2 = NULL;
5092 category_x *tmp3 = NULL;
5093 metadata_x *tmp4 = NULL;
5094 permission_x *tmp5 = NULL;
5095 image_x *tmp6 = NULL;
5096 const char *user_pkg_parser = NULL;
5098 /*get system locale*/
5099 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5100 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5102 /*get locale on db*/
5103 locale = __convert_system_locale_to_manifest_locale(syslocale);
5104 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5107 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5108 ret = __open_manifest_db(uid);
5109 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5112 pkgmgr_pkginfo_x *info = NULL;
5113 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5114 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5116 /*calloc manifest_info*/
5117 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5118 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5121 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5122 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5124 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5125 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5126 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5128 if (info->manifest_info->uiapplication) {
5129 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5130 info->manifest_info->uiapplication = ptr1;
5132 if (info->manifest_info->serviceapplication) {
5133 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5134 info->manifest_info->serviceapplication = ptr2;
5138 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5140 appinfo->locale = strdup(locale);
5141 appinfo->app_component = PMINFO_UI_APP;
5142 appinfo->package = strdup(ptr1->package);
5143 appinfo->uiapp_info = ptr1;
5144 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5145 "from package_app_info where " \
5146 "app_id='%s'", ptr1->appid);
5147 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5148 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5150 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5154 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5157 memset(query, '\0', MAX_QUERY_LEN);
5158 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5159 "from package_app_localized_info where " \
5160 "app_id='%s' and app_locale='%s'",
5161 ptr1->appid, locale);
5162 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5163 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5165 memset(query, '\0', MAX_QUERY_LEN);
5166 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5167 "from package_app_localized_info where " \
5168 "app_id='%s' and app_locale='%s'",
5169 ptr1->appid, DEFAULT_LOCALE);
5171 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5172 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5174 /*store setting notification icon section*/
5175 memset(query, '\0', MAX_QUERY_LEN);
5176 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5177 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5178 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5180 /*store app preview image info*/
5181 memset(query, '\0', MAX_QUERY_LEN);
5182 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5183 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5184 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5186 if (appinfo->uiapp_info->label) {
5187 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5188 appinfo->uiapp_info->label = tmp1;
5190 if (appinfo->uiapp_info->icon) {
5191 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5192 appinfo->uiapp_info->icon= tmp2;
5194 if (appinfo->uiapp_info->category) {
5195 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5196 appinfo->uiapp_info->category = tmp3;
5198 if (appinfo->uiapp_info->metadata) {
5199 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5200 appinfo->uiapp_info->metadata = tmp4;
5202 if (appinfo->uiapp_info->permission) {
5203 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5204 appinfo->uiapp_info->permission = tmp5;
5206 if (appinfo->uiapp_info->image) {
5207 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5208 appinfo->uiapp_info->image = tmp6;
5210 ret = app_func((void *)appinfo, user_data);
5213 free((void *)appinfo->package);
5214 appinfo->package = NULL;
5217 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5219 appinfo->locale = strdup(locale);
5220 appinfo->app_component = PMINFO_SVC_APP;
5221 appinfo->package = strdup(ptr2->package);
5222 appinfo->svcapp_info = ptr2;
5223 memset(query, '\0', MAX_QUERY_LEN);
5224 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5225 "from package_app_info where " \
5226 "app_id='%s'", ptr2->appid);
5227 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5228 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5230 memset(query, '\0', MAX_QUERY_LEN);
5231 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5232 "from package_app_localized_info where " \
5233 "app_id='%s' and app_locale='%s'",
5234 ptr2->appid, locale);
5235 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5236 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5238 memset(query, '\0', MAX_QUERY_LEN);
5239 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5240 "from package_app_localized_info where " \
5241 "app_id='%s' and app_locale='%s'",
5242 ptr2->appid, DEFAULT_LOCALE);
5243 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5244 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5246 if (appinfo->svcapp_info->label) {
5247 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5248 appinfo->svcapp_info->label = tmp1;
5250 if (appinfo->svcapp_info->icon) {
5251 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5252 appinfo->svcapp_info->icon= tmp2;
5254 if (appinfo->svcapp_info->category) {
5255 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5256 appinfo->svcapp_info->category = tmp3;
5258 if (appinfo->svcapp_info->metadata) {
5259 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5260 appinfo->svcapp_info->metadata = tmp4;
5262 if (appinfo->svcapp_info->permission) {
5263 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5264 appinfo->svcapp_info->permission = tmp5;
5266 ret = app_func((void *)appinfo, user_data);
5269 free((void *)appinfo->package);
5270 appinfo->package = NULL;
5283 __close_manifest_db();
5288 __cleanup_pkginfo(info);
5292 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5294 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5297 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5299 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5300 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5302 pkgmgr_appinfo_x *appinfo = NULL;
5303 char *syslocale = NULL;
5304 char *locale = NULL;
5307 label_x *tmp1 = NULL;
5308 icon_x *tmp2 = NULL;
5309 category_x *tmp3 = NULL;
5310 metadata_x *tmp4 = NULL;
5311 permission_x *tmp5 = NULL;
5312 image_x *tmp6 = NULL;
5313 char query[MAX_QUERY_LEN] = {'\0'};
5314 const char* user_pkg_parser = NULL;
5319 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5320 ret = __open_manifest_db(uid);
5321 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5323 /*check appid exist on db*/
5324 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5325 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5326 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5327 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5329 /*get system locale*/
5330 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5331 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5333 /*get locale on db*/
5334 locale = __convert_system_locale_to_manifest_locale(syslocale);
5335 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5338 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5339 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5341 /*check app_component from DB*/
5342 memset(query, '\0', MAX_QUERY_LEN);
5343 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5344 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5345 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5347 /*calloc app_component*/
5348 if (appinfo->app_component == PMINFO_UI_APP) {
5349 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5350 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5352 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5353 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5355 appinfo->locale = strdup(locale);
5357 /*populate app_info from DB*/
5358 memset(query, '\0', MAX_QUERY_LEN);
5359 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5360 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5361 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5363 memset(query, '\0', MAX_QUERY_LEN);
5364 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5365 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5366 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5368 /*Also store the values corresponding to default locales*/
5369 memset(query, '\0', MAX_QUERY_LEN);
5370 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5371 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5372 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5374 /*Populate app category*/
5375 memset(query, '\0', MAX_QUERY_LEN);
5376 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5377 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5378 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5380 /*Populate app metadata*/
5381 memset(query, '\0', MAX_QUERY_LEN);
5382 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5383 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5384 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5386 /*Populate app permission*/
5387 memset(query, '\0', MAX_QUERY_LEN);
5388 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5389 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5390 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5392 /*store setting notification icon section*/
5393 memset(query, '\0', MAX_QUERY_LEN);
5394 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5395 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5396 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5398 /*store app preview image info*/
5399 memset(query, '\0', MAX_QUERY_LEN);
5400 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5401 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5402 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5404 switch (appinfo->app_component) {
5406 if (appinfo->uiapp_info->label) {
5407 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5408 appinfo->uiapp_info->label = tmp1;
5410 if (appinfo->uiapp_info->icon) {
5411 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5412 appinfo->uiapp_info->icon = tmp2;
5414 if (appinfo->uiapp_info->category) {
5415 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5416 appinfo->uiapp_info->category = tmp3;
5418 if (appinfo->uiapp_info->metadata) {
5419 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5420 appinfo->uiapp_info->metadata = tmp4;
5422 if (appinfo->uiapp_info->permission) {
5423 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5424 appinfo->uiapp_info->permission = tmp5;
5426 if (appinfo->uiapp_info->image) {
5427 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5428 appinfo->uiapp_info->image = tmp6;
5431 case PMINFO_SVC_APP:
5432 if (appinfo->svcapp_info->label) {
5433 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5434 appinfo->svcapp_info->label = tmp1;
5436 if (appinfo->svcapp_info->icon) {
5437 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5438 appinfo->svcapp_info->icon = tmp2;
5440 if (appinfo->svcapp_info->category) {
5441 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5442 appinfo->svcapp_info->category = tmp3;
5444 if (appinfo->svcapp_info->metadata) {
5445 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5446 appinfo->svcapp_info->metadata = tmp4;
5448 if (appinfo->svcapp_info->permission) {
5449 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5450 appinfo->svcapp_info->permission = tmp5;
5460 if (ret == PMINFO_R_OK)
5461 *handle = (void*)appinfo;
5464 __cleanup_appinfo(appinfo);
5467 __close_manifest_db();
5479 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5481 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5484 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5486 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5487 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5488 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5490 if (info->app_component == PMINFO_UI_APP)
5491 *appid = (char *)info->uiapp_info->appid;
5492 else if (info->app_component == PMINFO_SVC_APP)
5493 *appid = (char *)info->svcapp_info->appid;
5498 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5500 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5501 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5502 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5504 *pkg_name = (char *)info->package;
5509 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5512 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5513 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5515 *pkgid = (char *)info->package;
5520 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5523 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5524 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5526 if (info->app_component == PMINFO_UI_APP)
5527 *exec = (char *)info->uiapp_info->exec;
5528 if (info->app_component == PMINFO_SVC_APP)
5529 *exec = (char *)info->svcapp_info->exec;
5535 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5537 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5538 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5539 char *locale = NULL;
5541 icon_x *start = NULL;
5544 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5545 locale = info->locale;
5546 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5548 if (info->app_component == PMINFO_UI_APP)
5549 start = info->uiapp_info->icon;
5550 if (info->app_component == PMINFO_SVC_APP)
5551 start = info->svcapp_info->icon;
5552 for(ptr = start; ptr != NULL; ptr = ptr->next)
5555 if (strcmp(ptr->lang, locale) == 0) {
5556 *icon = (char *)ptr->text;
5557 if (strcasecmp(*icon, "(null)") == 0) {
5558 locale = DEFAULT_LOCALE;
5562 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5563 *icon = (char *)ptr->text;
5572 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5574 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5575 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5576 char *locale = NULL;
5577 label_x *ptr = NULL;
5578 label_x *start = NULL;
5581 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5582 locale = info->locale;
5583 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5585 if (info->app_component == PMINFO_UI_APP)
5586 start = info->uiapp_info->label;
5587 if (info->app_component == PMINFO_SVC_APP)
5588 start = info->svcapp_info->label;
5589 for(ptr = start; ptr != NULL; ptr = ptr->next)
5592 if (strcmp(ptr->lang, locale) == 0) {
5593 *label = (char *)ptr->text;
5594 if (strcasecmp(*label, "(null)") == 0) {
5595 locale = DEFAULT_LOCALE;
5599 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5600 *label = (char *)ptr->text;
5601 if (strcasecmp(*label, "(null)") == 0) {
5602 locale = DEFAULT_LOCALE;
5606 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5607 *label = (char *)ptr->text;
5616 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5618 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5619 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5620 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5622 if (info->app_component == PMINFO_UI_APP)
5623 *component = PMINFO_UI_APP;
5624 else if (info->app_component == PMINFO_SVC_APP)
5625 *component = PMINFO_SVC_APP;
5627 return PMINFO_R_ERROR;
5632 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5634 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5635 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5636 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5638 if (info->app_component == PMINFO_UI_APP)
5639 *app_type = (char *)info->uiapp_info->type;
5640 if (info->app_component == PMINFO_SVC_APP)
5641 *app_type = (char *)info->svcapp_info->type;
5646 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5647 int *operation_count, char ***operation)
5649 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5650 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5651 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5652 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5653 *operation_count = data->operation_count;
5654 *operation = data->operation;
5658 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5659 int *uri_count, char ***uri)
5661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5662 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5663 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5664 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5665 *uri_count = data->uri_count;
5670 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5671 int *mime_count, char ***mime)
5673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5674 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5675 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5676 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5677 *mime_count = data->mime_count;
5682 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5683 int *subapp_count, char ***subapp)
5685 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5686 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5687 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5688 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5689 *subapp_count = data->subapp_count;
5690 *subapp = data->subapp;
5694 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5696 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5697 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5701 icon_x *start = NULL;
5702 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5704 start = info->uiapp_info->icon;
5706 for(ptr = start; ptr != NULL; ptr = ptr->next)
5709 val = (char *)ptr->section;
5710 if (strcmp(val, "setting") == 0){
5711 *icon = (char *)ptr->text;
5720 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5722 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5723 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5727 icon_x *start = NULL;
5728 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5730 start = info->uiapp_info->icon;
5732 for(ptr = start; ptr != NULL; ptr = ptr->next)
5735 val = (char *)ptr->section;
5737 if (strcmp(val, "notification") == 0){
5738 *icon = (char *)ptr->text;
5747 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5749 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5750 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5752 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5753 val = (char *)info->uiapp_info->recentimage;
5755 if (strcasecmp(val, "capture") == 0)
5756 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5757 else if (strcasecmp(val, "icon") == 0)
5758 *type = PMINFO_RECENTIMAGE_USE_ICON;
5760 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5766 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5768 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5769 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5772 image_x *ptr = NULL;
5773 image_x *start = NULL;
5774 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5776 start = info->uiapp_info->image;
5778 for(ptr = start; ptr != NULL; ptr = ptr->next)
5781 val = (char *)ptr->section;
5783 if (strcmp(val, "preview") == 0)
5784 *preview_img = (char *)ptr->text;
5792 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5794 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5795 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5798 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5800 if (info->app_component == PMINFO_UI_APP)
5801 val = info->uiapp_info->permission_type;
5802 else if (info->app_component == PMINFO_SVC_APP)
5803 val = info->svcapp_info->permission_type;
5805 return PMINFO_R_ERROR;
5807 if (strcmp(val, "signature") == 0)
5808 *permission = PMINFO_PERMISSION_SIGNATURE;
5809 else if (strcmp(val, "privilege") == 0)
5810 *permission = PMINFO_PERMISSION_PRIVILEGE;
5812 *permission = PMINFO_PERMISSION_NORMAL;
5817 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5819 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5820 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5821 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5823 *component_type = (char *)info->uiapp_info->component_type;
5828 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5830 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5831 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5833 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5834 val = (char *)info->uiapp_info->hwacceleration;
5836 if (strcasecmp(val, "not-use-GL") == 0)
5837 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5838 else if (strcasecmp(val, "use-GL") == 0)
5839 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5841 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5846 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5848 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5849 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5851 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5852 val = (char *)info->uiapp_info->screenreader;
5854 if (strcasecmp(val, "screenreader-off") == 0)
5855 *screenreader = PMINFO_SCREENREADER_OFF;
5856 else if (strcasecmp(val, "screenreader-on") == 0)
5857 *screenreader = PMINFO_SCREENREADER_ON;
5859 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5864 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5866 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5867 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5868 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5869 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5871 if (info->app_component == PMINFO_UI_APP){
5872 *portrait_img = (char *)info->uiapp_info->portraitimg;
5873 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5879 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5881 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5882 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5883 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5885 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5890 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5891 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5894 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5896 permission_x *ptr = NULL;
5897 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5898 if (info->app_component == PMINFO_UI_APP)
5899 ptr = info->uiapp_info->permission;
5900 else if (info->app_component == PMINFO_SVC_APP)
5901 ptr = info->svcapp_info->permission;
5903 return PMINFO_R_EINVAL;
5904 for (; ptr; ptr = ptr->next) {
5906 ret = permission_func(ptr->value, user_data);
5914 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5915 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5918 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5920 category_x *ptr = NULL;
5921 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5922 if (info->app_component == PMINFO_UI_APP)
5923 ptr = info->uiapp_info->category;
5924 else if (info->app_component == PMINFO_SVC_APP)
5925 ptr = info->svcapp_info->category;
5927 return PMINFO_R_EINVAL;
5928 for (; ptr; ptr = ptr->next) {
5930 ret = category_func(ptr->name, user_data);
5938 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5939 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5942 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5944 metadata_x *ptr = NULL;
5945 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5946 if (info->app_component == PMINFO_UI_APP)
5947 ptr = info->uiapp_info->metadata;
5948 else if (info->app_component == PMINFO_SVC_APP)
5949 ptr = info->svcapp_info->metadata;
5951 return PMINFO_R_EINVAL;
5952 for (; ptr; ptr = ptr->next) {
5954 ret = metadata_func(ptr->key, ptr->value, user_data);
5962 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5963 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5966 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5974 char *manifest = NULL;
5975 char **operation = NULL;
5978 char **subapp = NULL;
5979 appcontrol_x *appcontrol = NULL;
5980 manifest_x *mfx = NULL;
5981 operation_x *op = NULL;
5984 subapp_x *sa = NULL;
5985 pkgmgrinfo_app_component component;
5986 pkgmgrinfo_appcontrol_x *ptr = NULL;
5987 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5989 _LOGE("Failed to get package name\n");
5990 return PMINFO_R_ERROR;
5992 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5994 _LOGE("Failed to get app component name\n");
5995 return PMINFO_R_ERROR;
5997 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
5998 if (manifest == NULL) {
5999 _LOGE("Failed to fetch package manifest file\n");
6000 return PMINFO_R_ERROR;
6002 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
6004 _LOGE("Failed to parse package manifest file\n");
6007 return PMINFO_R_ERROR;
6010 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6012 _LOGE("Out of Memory!!!\n");
6013 pkgmgr_parser_free_manifest_xml(mfx);
6014 return PMINFO_R_ERROR;
6016 /*Get Operation, Uri, Mime*/
6017 switch (component) {
6019 if (mfx->uiapplication) {
6020 if (mfx->uiapplication->appsvc) {
6021 appcontrol = mfx->uiapplication->appsvc;
6025 case PMINFO_SVC_APP:
6026 if (mfx->serviceapplication) {
6027 if (mfx->serviceapplication->appsvc) {
6028 appcontrol = mfx->serviceapplication->appsvc;
6035 for (; appcontrol; appcontrol = appcontrol->next) {
6036 op = appcontrol->operation;
6037 for (; op; op = op->next)
6039 op = appcontrol->operation;
6041 ui = appcontrol->uri;
6042 for (; ui; ui = ui->next)
6044 ui = appcontrol->uri;
6046 mi = appcontrol->mime;
6047 for (; mi; mi = mi->next)
6049 mi = appcontrol->mime;
6051 sa = appcontrol->subapp;
6052 for (; sa; sa = sa->next)
6054 sa = appcontrol->subapp;
6056 operation = (char **)calloc(oc, sizeof(char *));
6057 for (i = 0; i < oc; i++) {
6058 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6062 uri = (char **)calloc(uc, sizeof(char *));
6063 for (i = 0; i < uc; i++) {
6064 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6068 mime = (char **)calloc(mc, sizeof(char *));
6069 for (i = 0; i < mc; i++) {
6070 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6074 subapp = (char **)calloc(sc, sizeof(char *));
6075 for (i = 0; i < sc; i++) {
6076 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6080 /*populate appcontrol handle*/
6081 ptr->operation_count = oc;
6082 ptr->uri_count = uc;
6083 ptr->mime_count = mc;
6084 ptr->subapp_count = sc;
6085 ptr->operation = operation;
6088 ptr->subapp = subapp;
6090 ret = appcontrol_func((void *)ptr, user_data);
6091 for (i = 0; i < oc; i++) {
6094 operation[i] = NULL;
6101 for (i = 0; i < uc; i++) {
6111 for (i = 0; i < mc; i++) {
6121 for (i = 0; i < sc; i++) {
6138 pkgmgr_parser_free_manifest_xml(mfx);
6146 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6147 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6149 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6150 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6158 char *manifest = NULL;
6159 char **operation = NULL;
6162 char **subapp = NULL;
6163 appcontrol_x *appcontrol = NULL;
6164 manifest_x *mfx = NULL;
6165 operation_x *op = NULL;
6168 subapp_x *sa = NULL;
6169 pkgmgrinfo_app_component component;
6170 pkgmgrinfo_appcontrol_x *ptr = NULL;
6171 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6173 _LOGE("Failed to get package name\n");
6174 return PMINFO_R_ERROR;
6176 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6178 _LOGE("Failed to get app component name\n");
6179 return PMINFO_R_ERROR;
6181 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6182 if (manifest == NULL) {
6183 _LOGE("Failed to fetch package manifest file\n");
6184 return PMINFO_R_ERROR;
6186 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6188 _LOGE("Failed to parse package manifest file\n");
6191 return PMINFO_R_ERROR;
6194 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6196 _LOGE("Out of Memory!!!\n");
6197 pkgmgr_parser_free_manifest_xml(mfx);
6198 return PMINFO_R_ERROR;
6200 /*Get Operation, Uri, Mime*/
6201 switch (component) {
6203 if (mfx->uiapplication) {
6204 if (mfx->uiapplication->appsvc) {
6205 appcontrol = mfx->uiapplication->appsvc;
6209 case PMINFO_SVC_APP:
6210 if (mfx->serviceapplication) {
6211 if (mfx->serviceapplication->appsvc) {
6212 appcontrol = mfx->serviceapplication->appsvc;
6219 for (; appcontrol; appcontrol = appcontrol->next) {
6220 op = appcontrol->operation;
6221 for (; op; op = op->next)
6223 op = appcontrol->operation;
6225 ui = appcontrol->uri;
6226 for (; ui; ui = ui->next)
6228 ui = appcontrol->uri;
6230 mi = appcontrol->mime;
6231 for (; mi; mi = mi->next)
6233 mi = appcontrol->mime;
6235 sa = appcontrol->subapp;
6236 for (; sa; sa = sa->next)
6238 sa = appcontrol->subapp;
6240 operation = (char **)calloc(oc, sizeof(char *));
6241 for (i = 0; i < oc; i++) {
6242 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6246 uri = (char **)calloc(uc, sizeof(char *));
6247 for (i = 0; i < uc; i++) {
6248 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6252 mime = (char **)calloc(mc, sizeof(char *));
6253 for (i = 0; i < mc; i++) {
6254 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6258 subapp = (char **)calloc(sc, sizeof(char *));
6259 for (i = 0; i < sc; i++) {
6260 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6264 /*populate appcontrol handle*/
6265 ptr->operation_count = oc;
6266 ptr->uri_count = uc;
6267 ptr->mime_count = mc;
6268 ptr->subapp_count = sc;
6269 ptr->operation = operation;
6272 ptr->subapp = subapp;
6274 ret = appcontrol_func((void *)ptr, user_data);
6275 for (i = 0; i < oc; i++) {
6278 operation[i] = NULL;
6285 for (i = 0; i < uc; i++) {
6295 for (i = 0; i < mc; i++) {
6305 for (i = 0; i < sc; i++) {
6322 pkgmgr_parser_free_manifest_xml(mfx);
6330 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6332 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6333 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6335 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6336 val = (char *)info->uiapp_info->nodisplay;
6338 if (strcasecmp(val, "true") == 0)
6340 else if (strcasecmp(val, "false") == 0)
6348 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6350 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6351 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6353 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6354 val = (char *)info->uiapp_info->multiple;
6356 if (strcasecmp(val, "true") == 0)
6358 else if (strcasecmp(val, "false") == 0)
6366 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6368 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6369 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6371 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6372 val = (char *)info->uiapp_info->indicatordisplay;
6374 if (strcasecmp(val, "true") == 0){
6375 *indicator_disp = 1;
6376 }else if (strcasecmp(val, "false") == 0){
6377 *indicator_disp = 0;
6379 *indicator_disp = 0;
6385 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6387 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6388 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6390 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6391 val = (char *)info->uiapp_info->taskmanage;
6393 if (strcasecmp(val, "true") == 0)
6395 else if (strcasecmp(val, "false") == 0)
6403 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6405 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6406 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6408 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6409 if (info->app_component == PMINFO_UI_APP)
6410 val = (char *)info->uiapp_info->enabled;
6411 else if (info->app_component == PMINFO_SVC_APP)
6412 val = (char *)info->uiapp_info->enabled;
6414 _LOGE("invalid component type\n");
6415 return PMINFO_R_EINVAL;
6419 if (strcasecmp(val, "true") == 0)
6421 else if (strcasecmp(val, "false") == 0)
6430 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6432 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6433 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6435 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6436 val = (char *)info->svcapp_info->onboot;
6438 if (strcasecmp(val, "true") == 0)
6440 else if (strcasecmp(val, "false") == 0)
6448 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6450 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6451 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6453 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6454 val = (char *)info->svcapp_info->autorestart;
6456 if (strcasecmp(val, "true") == 0)
6458 else if (strcasecmp(val, "false") == 0)
6466 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6468 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6469 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6471 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6472 val = (char *)info->uiapp_info->mainapp;
6474 if (strcasecmp(val, "true") == 0)
6476 else if (strcasecmp(val, "false") == 0)
6484 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6486 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6487 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6489 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6490 val = (char *)info->uiapp_info->preload;
6492 if (strcasecmp(val, "true") == 0)
6494 else if (strcasecmp(val, "false") == 0)
6502 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6504 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6505 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6507 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6508 val = (char *)info->uiapp_info->submode;
6510 if (strcasecmp(val, "true") == 0)
6512 else if (strcasecmp(val, "false") == 0)
6520 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6522 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6523 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6524 __cleanup_appinfo(info);
6528 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6530 return (pkgmgrinfo_pkginfo_filter_create(handle));
6533 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6535 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6538 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6539 const char *property, const int value)
6541 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6542 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6543 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6545 GSList *link = NULL;
6547 prop = _pminfo_appinfo_convert_to_prop_int(property);
6548 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6549 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6550 _LOGE("Invalid Integer Property\n");
6551 return PMINFO_R_EINVAL;
6553 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6554 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6556 _LOGE("Out of Memory!!!\n");
6557 return PMINFO_R_ERROR;
6559 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6560 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6562 _LOGE("Out of Memory\n");
6565 return PMINFO_R_ERROR;
6569 /*If API is called multiple times for same property, we should override the previous values.
6570 Last value set will be used for filtering.*/
6571 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6573 filter->list = g_slist_delete_link(filter->list, link);
6574 filter->list = g_slist_append(filter->list, (gpointer)node);
6579 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6580 const char *property, const bool value)
6582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6583 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6585 GSList *link = NULL;
6587 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6588 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6589 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6590 _LOGE("Invalid Boolean Property\n");
6591 return PMINFO_R_EINVAL;
6593 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6594 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6596 _LOGE("Out of Memory!!!\n");
6597 return PMINFO_R_ERROR;
6600 val = strndup("('true','True')", 15);
6602 val = strndup("('false','False')", 17);
6604 _LOGE("Out of Memory\n");
6607 return PMINFO_R_ERROR;
6611 /*If API is called multiple times for same property, we should override the previous values.
6612 Last value set will be used for filtering.*/
6613 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6615 filter->list = g_slist_delete_link(filter->list, link);
6616 filter->list = g_slist_append(filter->list, (gpointer)node);
6621 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6622 const char *property, const char *value)
6624 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6625 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6626 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6628 pkgmgrinfo_node_x *ptr = NULL;
6629 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6630 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6631 GSList *link = NULL;
6633 prop = _pminfo_appinfo_convert_to_prop_str(property);
6634 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6635 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6636 _LOGE("Invalid String Property\n");
6637 return PMINFO_R_EINVAL;
6639 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6640 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6642 _LOGE("Out of Memory!!!\n");
6643 return PMINFO_R_ERROR;
6647 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6648 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6649 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6651 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6653 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6655 filter->list = g_slist_delete_link(filter->list, link);
6656 filter->list = g_slist_append(filter->list, (gpointer)node);
6658 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6659 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6660 case E_PMINFO_APPINFO_PROP_APP_URI:
6661 case E_PMINFO_APPINFO_PROP_APP_MIME:
6662 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6664 _LOGE("Out of Memory\n");
6667 return PMINFO_R_ERROR;
6669 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6671 ptr = (pkgmgrinfo_node_x *)link->data;
6672 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6673 _LOGE("Previous value is %s\n", prev);
6674 filter->list = g_slist_delete_link(filter->list, link);
6675 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6676 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6677 _LOGE("New value is %s\n", val);
6679 filter->list = g_slist_append(filter->list, (gpointer)node);
6680 memset(temp, '\0', PKG_STRING_LEN_MAX);
6682 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6683 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6684 _LOGE("First value is %s\n", val);
6686 filter->list = g_slist_append(filter->list, (gpointer)node);
6687 memset(temp, '\0', PKG_STRING_LEN_MAX);
6691 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6692 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6694 filter->list = g_slist_delete_link(filter->list, link);
6695 filter->list = g_slist_append(filter->list, (gpointer)node);
6701 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6703 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6704 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6705 char *syslocale = NULL;
6706 char *locale = NULL;
6707 char *condition = NULL;
6708 char *error_message = NULL;
6709 char query[MAX_QUERY_LEN] = {'\0'};
6710 char where[MAX_QUERY_LEN] = {'\0'};
6714 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6715 /*Get current locale*/
6716 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6717 if (syslocale == NULL) {
6718 _LOGE("current locale is NULL\n");
6719 return PMINFO_R_ERROR;
6721 locale = __convert_system_locale_to_manifest_locale(syslocale);
6722 if (locale == NULL) {
6723 _LOGE("manifest locale is NULL\n");
6725 return PMINFO_R_ERROR;
6728 ret = __open_manifest_db(uid);
6730 _LOGE("Fail to open manifest DB\n");
6733 return PMINFO_R_ERROR;
6736 /*Start constructing query*/
6737 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6739 /*Get where clause*/
6740 for (list = filter->list; list; list = g_slist_next(list)) {
6741 __get_filter_condition(list->data, &condition);
6743 strncat(where, condition, sizeof(where) - strlen(where) -1);
6744 where[sizeof(where) - 1] = '\0';
6748 if (g_slist_next(list)) {
6749 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6750 where[sizeof(where) - 1] = '\0';
6753 _LOGE("where = %s\n", where);
6754 if (strlen(where) > 0) {
6755 strncat(query, where, sizeof(query) - strlen(query) - 1);
6756 query[sizeof(query) - 1] = '\0';
6758 _LOGE("query = %s\n", query);
6762 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6763 _LOGE("Don't execute query = %s error message = %s\n", query,
6765 sqlite3_free(error_message);
6766 ret = PMINFO_R_ERROR;
6780 __close_manifest_db();
6784 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6786 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6789 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6790 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6792 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6793 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6794 char *syslocale = NULL;
6795 char *locale = NULL;
6796 char *condition = NULL;
6797 char *error_message = NULL;
6798 char query[MAX_QUERY_LEN] = {'\0'};
6799 char where[MAX_QUERY_LEN] = {'\0'};
6802 uiapplication_x *ptr1 = NULL;
6803 serviceapplication_x *ptr2 = NULL;
6804 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6805 /*Get current locale*/
6806 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6807 if (syslocale == NULL) {
6808 _LOGE("current locale is NULL\n");
6809 return PMINFO_R_ERROR;
6811 locale = __convert_system_locale_to_manifest_locale(syslocale);
6812 if (locale == NULL) {
6813 _LOGE("manifest locale is NULL\n");
6815 return PMINFO_R_ERROR;
6818 ret = __open_manifest_db(uid);
6820 _LOGE("Fail to open manifest DB\n");
6823 return PMINFO_R_ERROR;
6825 /*Start constructing query*/
6826 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6827 /*Get where clause*/
6828 for (list = filter->list; list; list = g_slist_next(list)) {
6829 __get_filter_condition(list->data, &condition);
6831 strncat(where, condition, sizeof(where) - strlen(where) -1);
6832 where[sizeof(where) - 1] = '\0';
6836 if (g_slist_next(list)) {
6837 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6838 where[sizeof(where) - 1] = '\0';
6841 _LOGE("where = %s\n", where);
6842 if (strlen(where) > 0) {
6843 strncat(query, where, sizeof(query) - strlen(query) - 1);
6844 query[sizeof(query) - 1] = '\0';
6846 _LOGE("query = %s\n", query);
6847 /*To get filtered list*/
6848 pkgmgr_pkginfo_x *info = NULL;
6849 pkgmgr_pkginfo_x *filtinfo = NULL;
6850 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6852 _LOGE("Out of Memory!!!\n");
6853 ret = PMINFO_R_ERROR;
6856 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6857 if (info->manifest_info == NULL) {
6858 _LOGE("Out of Memory!!!\n");
6859 ret = PMINFO_R_ERROR;
6862 /*To get detail app info for each member of filtered list*/
6863 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6864 if (filtinfo == NULL) {
6865 _LOGE("Out of Memory!!!\n");
6866 ret = PMINFO_R_ERROR;
6869 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6870 if (filtinfo->manifest_info == NULL) {
6871 _LOGE("Out of Memory!!!\n");
6872 ret = PMINFO_R_ERROR;
6875 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6876 if (appinfo == NULL) {
6877 _LOGE("Out of Memory!!!\n");
6878 ret = PMINFO_R_ERROR;
6882 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6883 _LOGE("Don't execute query = %s error message = %s\n", query,
6885 sqlite3_free(error_message);
6886 ret = PMINFO_R_ERROR;
6889 memset(query, '\0', MAX_QUERY_LEN);
6890 if (info->manifest_info->uiapplication) {
6891 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6892 info->manifest_info->uiapplication = ptr1;
6894 if (info->manifest_info->serviceapplication) {
6895 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6896 info->manifest_info->serviceapplication = ptr2;
6898 /*Filtered UI Apps*/
6899 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6901 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6902 ptr1->appid, "uiapp");
6904 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6905 _LOGE("Don't execute query = %s error message = %s\n", query,
6907 sqlite3_free(error_message);
6908 ret = PMINFO_R_ERROR;
6912 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6914 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6915 ptr2->appid, "svcapp");
6917 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6918 _LOGE("Don't execute query = %s error message = %s\n", query,
6920 sqlite3_free(error_message);
6921 ret = PMINFO_R_ERROR;
6925 if (filtinfo->manifest_info->uiapplication) {
6926 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6927 filtinfo->manifest_info->uiapplication = ptr1;
6929 /*If the callback func return < 0 we break and no more call back is called*/
6932 appinfo->locale = strdup(locale);
6933 appinfo->uiapp_info = ptr1;
6934 appinfo->app_component = PMINFO_UI_APP;
6935 ret = app_cb((void *)appinfo, user_data);
6940 /*Filtered Service Apps*/
6941 if (filtinfo->manifest_info->serviceapplication) {
6942 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6943 filtinfo->manifest_info->serviceapplication = ptr2;
6945 /*If the callback func return < 0 we break and no more call back is called*/
6948 appinfo->locale = strdup(locale);
6949 appinfo->svcapp_info = ptr2;
6950 appinfo->app_component = PMINFO_SVC_APP;
6951 ret = app_cb((void *)appinfo, user_data);
6966 __close_manifest_db();
6971 __cleanup_pkginfo(info);
6972 __cleanup_pkginfo(filtinfo);
6976 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6977 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6979 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6982 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6984 return (pkgmgrinfo_pkginfo_filter_create(handle));
6987 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6989 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6992 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6993 const char *key, const char *value)
6995 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6996 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6997 /*value can be NULL. In that case all apps with specified key should be displayed*/
7001 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7002 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7003 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7005 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7009 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7012 /*If API is called multiple times, we should OR all conditions.*/
7013 filter->list = g_slist_append(filter->list, (gpointer)node);
7014 /*All memory will be freed in destroy API*/
7032 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7033 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7036 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7037 char *syslocale = NULL;
7038 char *locale = NULL;
7039 char *condition = NULL;
7040 char *error_message = NULL;
7041 char query[MAX_QUERY_LEN] = {'\0'};
7042 char where[MAX_QUERY_LEN] = {'\0'};
7045 pkgmgr_pkginfo_x *info = NULL;
7046 pkgmgr_pkginfo_x *filtinfo = NULL;
7047 pkgmgr_appinfo_x *appinfo = NULL;
7048 uiapplication_x *ptr1 = NULL;
7049 serviceapplication_x *ptr2 = NULL;
7050 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7052 /*Get current locale*/
7053 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7054 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7055 locale = __convert_system_locale_to_manifest_locale(syslocale);
7056 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7058 ret = __open_manifest_db(uid);
7060 _LOGE("Fail to open manifest DB\n");
7063 return PMINFO_R_ERROR;
7065 /*Start constructing query*/
7066 memset(where, '\0', MAX_QUERY_LEN);
7067 memset(query, '\0', MAX_QUERY_LEN);
7068 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7069 /*Get where clause*/
7070 for (list = filter->list; list; list = g_slist_next(list)) {
7071 __get_metadata_filter_condition(list->data, &condition);
7073 strncat(where, condition, sizeof(where) - strlen(where) -1);
7077 if (g_slist_next(list)) {
7078 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7081 _LOGE("where = %s (%d)\n", where, strlen(where));
7082 if (strlen(where) > 0) {
7083 strncat(query, where, sizeof(query) - strlen(query) - 1);
7085 _LOGE("query = %s (%d)\n", query, strlen(query));
7086 /*To get filtered list*/
7087 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7088 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7090 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7091 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7093 /*To get detail app info for each member of filtered list*/
7094 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7095 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7097 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7098 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7100 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7101 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7103 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7104 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7105 memset(query, '\0', MAX_QUERY_LEN);
7107 if (info->manifest_info->uiapplication) {
7108 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7109 info->manifest_info->uiapplication = ptr1;
7111 if (info->manifest_info->serviceapplication) {
7112 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7113 info->manifest_info->serviceapplication = ptr2;
7117 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7119 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7120 ptr1->appid, "uiapp");
7121 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7122 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7123 memset(query, '\0', MAX_QUERY_LEN);
7126 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7128 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7129 ptr2->appid, "svcapp");
7130 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7131 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7132 memset(query, '\0', MAX_QUERY_LEN);
7134 /*Filtered UI Apps*/
7135 if (filtinfo->manifest_info->uiapplication) {
7136 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7137 filtinfo->manifest_info->uiapplication = ptr1;
7139 /*If the callback func return < 0 we break and no more call back is called*/
7142 appinfo->locale = strdup(locale);
7143 appinfo->uiapp_info = ptr1;
7144 appinfo->app_component = PMINFO_UI_APP;
7145 ret = app_cb((void *)appinfo, user_data);
7150 /*Filtered Service Apps*/
7151 if (filtinfo->manifest_info->serviceapplication) {
7152 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7153 filtinfo->manifest_info->serviceapplication = ptr2;
7155 /*If the callback func return < 0 we break and no more call back is called*/
7158 appinfo->locale = strdup(locale);
7159 appinfo->svcapp_info = ptr2;
7160 appinfo->app_component = PMINFO_SVC_APP;
7161 ret = app_cb((void *)appinfo, user_data);
7176 sqlite3_free(error_message);
7177 __close_manifest_db();
7182 __cleanup_pkginfo(info);
7183 __cleanup_pkginfo(filtinfo);
7187 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7188 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7190 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7193 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7195 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7196 pkgmgr_certinfo_x *certinfo = NULL;
7197 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7199 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7200 *handle = (void *)certinfo;
7204 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
7206 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7207 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7208 pkgmgr_certinfo_x *certinfo = NULL;
7209 char *error_message = NULL;
7210 int ret = PMINFO_R_OK;
7211 char query[MAX_QUERY_LEN] = {'\0'};
7214 const char* user_pkg_cert = NULL;
7217 user_pkg_cert = getUserPkgCertDBPath();
7218 ret = db_util_open_with_options(user_pkg_cert, &GET_DB(cert_db),
7219 SQLITE_OPEN_READWRITE, NULL);
7220 if (ret != SQLITE_OK) {
7221 _LOGE("connect db [%s] failed!\n", user_pkg_cert);
7222 return PMINFO_R_ERROR;
7224 _check_create_Cert_db(GET_DB(cert_db));
7226 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7228 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7229 _LOGE("Don't execute query = %s error message = %s\n", query,
7231 sqlite3_free(error_message);
7232 ret = PMINFO_R_ERROR;
7236 _LOGE("Package not found in DB\n");
7237 ret = PMINFO_R_ERROR;
7240 certinfo = (pkgmgr_certinfo_x *)handle;
7241 /*populate certinfo from DB*/
7242 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7243 ret = __exec_certinfo_query(query, (void *)certinfo);
7245 _LOGE("Package Cert Info DB Information retrieval failed\n");
7246 ret = PMINFO_R_ERROR;
7249 for (i = 0; i < MAX_CERT_TYPE; i++) {
7250 memset(query, '\0', MAX_QUERY_LEN);
7251 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7252 ret = __exec_certinfo_query(query, (void *)certinfo);
7254 _LOGE("Cert Info DB Information retrieval failed\n");
7255 ret = PMINFO_R_ERROR;
7258 if (certinfo->cert_value) {
7259 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7260 free(certinfo->cert_value);
7261 certinfo->cert_value = NULL;
7269 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7271 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7272 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7273 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7274 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7275 pkgmgr_certinfo_x *certinfo = NULL;
7276 certinfo = (pkgmgr_certinfo_x *)handle;
7277 if ((certinfo->cert_info)[cert_type])
7278 *cert_value = (certinfo->cert_info)[cert_type];
7284 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7286 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7288 pkgmgr_certinfo_x *certinfo = NULL;
7289 certinfo = (pkgmgr_certinfo_x *)handle;
7290 if (certinfo->pkgid) {
7291 free(certinfo->pkgid);
7292 certinfo->pkgid = NULL;
7294 for (i = 0; i < MAX_CERT_TYPE; i++) {
7295 if ((certinfo->cert_info)[i]) {
7296 free((certinfo->cert_info)[i]);
7297 (certinfo->cert_info)[i] = NULL;
7305 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7307 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7308 pkgmgr_instcertinfo_x *certinfo = NULL;
7310 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7311 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7312 *handle = (void *)certinfo;
7316 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7318 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7319 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7320 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7321 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7322 pkgmgr_instcertinfo_x *certinfo = NULL;
7323 certinfo = (pkgmgr_instcertinfo_x *)handle;
7324 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7328 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
7330 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7331 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7332 char *error_message = NULL;
7333 char query[MAX_QUERY_LEN] = {'\0'};
7334 char *vquery = NULL;
7339 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7346 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7347 pkgmgr_certindexinfo_x *indexinfo = NULL;
7348 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7349 if (indexinfo == NULL) {
7350 _LOGE("Out of Memory!!!");
7351 return PMINFO_R_ERROR;
7353 info->pkgid = strdup(pkgid);
7356 ret = db_util_open_with_options(getUserPkgCertDBPath(), &GET_DB(cert_db),
7357 SQLITE_OPEN_READWRITE, NULL);
7358 if (ret != SQLITE_OK) {
7359 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7360 ret = PMINFO_R_ERROR;
7363 _check_create_Cert_db(GET_DB(cert_db));
7364 /*Begin Transaction*/
7365 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7366 if (ret != SQLITE_OK) {
7367 _LOGE("Failed to begin transaction\n");
7368 ret = PMINFO_R_ERROR;
7371 _LOGE("Transaction Begin\n");
7372 /*Check if request is to insert/update*/
7373 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7375 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7376 _LOGE("Don't execute query = %s error message = %s\n", query,
7378 sqlite3_free(error_message);
7379 ret = PMINFO_R_ERROR;
7384 We cant just issue update query directly. We need to manage index table also.
7385 Hence it is better to delete and insert again in case of update*/
7386 ret = __delete_certinfo(pkgid);
7388 _LOGE("Certificate Deletion Failed\n");
7390 for (i = 0; i < MAX_CERT_TYPE; i++) {
7391 if ((info->cert_info)[i]) {
7392 for (j = 0; j < i; j++) {
7393 if ( (info->cert_info)[j]) {
7394 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7395 (info->cert_id)[i] = (info->cert_id)[j];
7396 (info->is_new)[i] = 0;
7397 (info->ref_count)[i] = (info->ref_count)[j];
7404 memset(query, '\0', MAX_QUERY_LEN);
7405 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7406 "where cert_info='%s'",(info->cert_info)[i]);
7407 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7409 _LOGE("Cert Info DB Information retrieval failed\n");
7410 ret = PMINFO_R_ERROR;
7413 if (indexinfo->cert_id == 0) {
7414 /*New certificate. Get newid*/
7415 memset(query, '\0', MAX_QUERY_LEN);
7416 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7418 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7419 _LOGE("Don't execute query = %s error message = %s\n", query,
7421 sqlite3_free(error_message);
7422 ret = PMINFO_R_ERROR;
7430 indexinfo->cert_id = maxid;
7431 indexinfo->cert_ref_count = 1;
7435 (info->cert_id)[i] = indexinfo->cert_id;
7436 (info->is_new)[i] = is_new;
7437 (info->ref_count)[i] = indexinfo->cert_ref_count;
7438 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
7439 indexinfo->cert_id = 0;
7440 indexinfo->cert_ref_count = 0;
7444 len = MAX_QUERY_LEN;
7445 for (i = 0; i < MAX_CERT_TYPE; i++) {
7446 if ((info->cert_info)[i])
7447 len+= strlen((info->cert_info)[i]);
7449 vquery = (char *)calloc(1, len);
7451 snprintf(vquery, len,
7452 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7453 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7454 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7455 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7456 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7457 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7458 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7459 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7461 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7462 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7464 sqlite3_free(error_message);
7465 ret = PMINFO_R_ERROR;
7468 /*Update index table info*/
7469 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7470 for (i = 0; i < MAX_CERT_TYPE; i++) {
7471 if ((info->cert_info)[i]) {
7472 memset(vquery, '\0', len);
7473 if ((info->is_new)[i]) {
7474 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7475 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7476 unique_id[c++] = (info->cert_id)[i];
7479 for (j = 0; j < MAX_CERT_TYPE; j++) {
7480 if ((info->cert_id)[i] == unique_id[j]) {
7481 /*Ref count has already been increased. Just continue*/
7485 if (j == MAX_CERT_TYPE)
7486 unique_id[c++] = (info->cert_id)[i];
7489 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7490 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7493 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7494 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7496 sqlite3_free(error_message);
7497 ret = PMINFO_R_ERROR;
7502 /*Commit transaction*/
7503 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7504 if (ret != SQLITE_OK) {
7505 _LOGE("Failed to commit transaction, Rollback now\n");
7506 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7507 ret = PMINFO_R_ERROR;
7510 _LOGE("Transaction Commit and End\n");
7525 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7527 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7529 pkgmgr_instcertinfo_x *certinfo = NULL;
7530 certinfo = (pkgmgr_instcertinfo_x *)handle;
7531 if (certinfo->pkgid) {
7532 free(certinfo->pkgid);
7533 certinfo->pkgid = NULL;
7535 for (i = 0; i < MAX_CERT_TYPE; i++) {
7536 if ((certinfo->cert_info)[i]) {
7537 free((certinfo->cert_info)[i]);
7538 (certinfo->cert_info)[i] = NULL;
7546 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7548 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7551 ret = __open_cert_db(uid);
7553 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7554 ret = PMINFO_R_ERROR;
7557 _check_create_Cert_db(GET_DB(cert_db));
7558 /*Begin Transaction*/
7559 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7560 if (ret != SQLITE_OK) {
7561 _LOGE("Failed to begin transaction\n");
7562 ret = PMINFO_R_ERROR;
7565 _LOGE("Transaction Begin\n");
7566 ret = __delete_certinfo(pkgid);
7568 _LOGE("Certificate Deletion Failed\n");
7570 _LOGE("Certificate Deletion Success\n");
7572 /*Commit transaction*/
7573 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7574 if (ret != SQLITE_OK) {
7575 _LOGE("Failed to commit transaction, Rollback now\n");
7576 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7577 ret = PMINFO_R_ERROR;
7580 _LOGE("Transaction Commit and End\n");
7588 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7590 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7593 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7595 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7596 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7598 char *manifest = NULL;
7599 manifest_x *mfx = NULL;
7601 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7602 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7604 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7609 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7611 *handle = (void *)mfx;
7616 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7618 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7619 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7621 char *manifest = NULL;
7622 manifest_x *mfx = NULL;
7624 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7625 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7627 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7632 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7634 *handle = (void *)mfx;
7639 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7641 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7642 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7644 int len = strlen(type);
7645 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7647 manifest_x *mfx = (manifest_x *)handle;
7649 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7653 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7655 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7656 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7658 int len = strlen(version);
7659 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7661 manifest_x *mfx = (manifest_x *)handle;
7663 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7667 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7669 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7670 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7672 manifest_x *mfx = (manifest_x *)handle;
7674 if (location == INSTALL_INTERNAL)
7675 strcpy(mfx->installlocation, "internal-only");
7676 else if (location == INSTALL_EXTERNAL)
7677 strcpy(mfx->installlocation, "prefer-external");
7682 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7684 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7685 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7687 manifest_x *mfx = (manifest_x *)handle;
7689 mfx->package_size = strdup(size);
7694 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7696 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7697 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7699 int len = strlen(label_txt);
7700 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7702 manifest_x *mfx = (manifest_x *)handle;
7704 label_x *label = calloc(1, sizeof(label_x));
7705 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7707 LISTADD(mfx->label, label);
7709 mfx->label->lang = strdup(locale);
7711 mfx->label->lang = strdup(DEFAULT_LOCALE);
7712 mfx->label->text = strdup(label_txt);
7717 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7719 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7720 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7722 int len = strlen(icon_txt);
7723 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7725 manifest_x *mfx = (manifest_x *)handle;
7727 icon_x *icon = calloc(1, sizeof(icon_x));
7728 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7730 LISTADD(mfx->icon, icon);
7732 mfx->icon->lang = strdup(locale);
7734 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7735 mfx->icon->text = strdup(icon_txt);
7740 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7742 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7743 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7745 int len = strlen(desc_txt);
7746 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7748 manifest_x *mfx = (manifest_x *)handle;
7750 description_x *description = calloc(1, sizeof(description_x));
7751 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7753 LISTADD(mfx->description, description);
7755 mfx->description->lang = strdup(locale);
7757 mfx->description->lang = strdup(DEFAULT_LOCALE);
7758 mfx->description->text = strdup(desc_txt);
7763 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7764 const char *author_email, const char *author_href, const char *locale)
7766 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7767 manifest_x *mfx = (manifest_x *)handle;
7768 author_x *author = calloc(1, sizeof(author_x));
7769 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7771 LISTADD(mfx->author, author);
7773 mfx->author->text = strdup(author_name);
7775 mfx->author->email = strdup(author_email);
7777 mfx->author->href = strdup(author_href);
7779 mfx->author->lang = strdup(locale);
7781 mfx->author->lang = strdup(DEFAULT_LOCALE);
7785 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7787 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7788 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7790 manifest_x *mfx = (manifest_x *)handle;
7793 strcpy(mfx->removable, "false");
7794 else if (removable == 1)
7795 strcpy(mfx->removable, "true");
7800 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7802 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7803 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7805 manifest_x *mfx = (manifest_x *)handle;
7808 strcpy(mfx->preload, "false");
7809 else if (preload == 1)
7810 strcpy(mfx->preload, "true");
7815 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7817 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7818 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7820 manifest_x *mfx = (manifest_x *)handle;
7822 if (location == INSTALL_INTERNAL)
7823 strcpy(mfx->installed_storage, "installed_internal");
7824 else if (location == INSTALL_EXTERNAL)
7825 strcpy(mfx->installed_storage, "installed_external");
7830 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7832 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7835 manifest_x *mfx = NULL;
7836 mfx = (manifest_x *)handle;
7838 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7840 _LOGE("Successfully stored info in DB\n");
7843 _LOGE("Failed to store info in DB\n");
7844 return PMINFO_R_ERROR;
7848 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7850 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7853 manifest_x *mfx = NULL;
7854 mfx = (manifest_x *)handle;
7856 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7858 _LOGE("Successfully stored info in DB\n");
7861 _LOGE("Failed to store info in DB\n");
7862 return PMINFO_R_ERROR;
7866 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7868 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7870 manifest_x *mfx = NULL;
7871 mfx = (manifest_x *)handle;
7872 pkgmgr_parser_free_manifest_xml(mfx);
7876 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7878 /* Should be implemented later */
7882 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7884 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7886 char query[MAX_QUERY_LEN] = {'\0'};
7889 ret = __open_manifest_db(uid);
7890 if (ret != SQLITE_OK) {
7891 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7892 return PMINFO_R_ERROR;
7895 /*Begin transaction*/
7896 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7897 if (ret != SQLITE_OK) {
7898 _LOGE("Failed to begin transaction\n");
7899 __close_manifest_db();
7900 return PMINFO_R_ERROR;
7902 _LOGD("Transaction Begin\n");
7904 memset(query, '\0', MAX_QUERY_LEN);
7905 snprintf(query, MAX_QUERY_LEN,
7906 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7908 char *error_message = NULL;
7910 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7911 _LOGE("Don't execute query = %s error message = %s\n", query,
7913 sqlite3_free(error_message);
7914 return PMINFO_R_ERROR;
7916 sqlite3_free(error_message);
7918 /*Commit transaction*/
7919 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7920 if (ret != SQLITE_OK) {
7921 _LOGE("Failed to commit transaction. Rollback now\n");
7922 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7923 __close_manifest_db();
7924 return PMINFO_R_ERROR;
7926 _LOGD("Transaction Commit and End\n");
7927 __close_manifest_db();
7931 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7933 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7936 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7938 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7939 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7940 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7941 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7942 int ret = PMINFO_R_OK;
7943 char query[MAX_QUERY_LEN] = {'\0'};
7944 char *error_message = NULL;
7945 pkgmgr_datacontrol_x *data = NULL;
7947 ret = __open_datacontrol_db();
7949 _LOGE("Fail to open datacontrol DB\n");
7950 return PMINFO_R_ERROR;
7953 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7955 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7956 __close_datacontrol_db();
7957 return PMINFO_R_ERROR;
7960 snprintf(query, MAX_QUERY_LEN,
7961 "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",
7965 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7966 _LOGE("Don't execute query = %s error message = %s\n", query,
7968 sqlite3_free(error_message);
7969 __close_datacontrol_db();
7970 return PMINFO_R_ERROR;
7973 *appid = (char *)data->appid;
7974 *access = (char *)data->access;
7976 __close_datacontrol_db();
7981 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7983 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7985 char query[MAX_QUERY_LEN] = {'\0'};
7986 char *error_message = NULL;
7987 ret = __open_manifest_db(uid);
7990 /*Begin transaction*/
7991 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7992 if (ret != SQLITE_OK) {
7993 _LOGE("Failed to begin transaction\n");
7994 __close_manifest_db();
7995 return PMINFO_R_ERROR;
7997 _LOGD("Transaction Begin\n");
7999 memset(query, '\0', MAX_QUERY_LEN);
8000 snprintf(query, MAX_QUERY_LEN,
8001 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8004 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
8005 _LOGE("Don't execute query = %s error message = %s\n", query,
8007 sqlite3_free(error_message);
8008 return PMINFO_R_ERROR;
8011 /*Commit transaction*/
8012 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
8013 if (ret != SQLITE_OK) {
8014 _LOGE("Failed to commit transaction. Rollback now\n");
8015 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8016 __close_manifest_db();
8017 return PMINFO_R_ERROR;
8019 _LOGD("Transaction Commit and End\n");
8020 __close_manifest_db();
8024 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8026 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8029 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8031 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8032 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8034 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8035 val = (char *)info->uiapp_info->guestmode_visibility;
8037 if (strcasecmp(val, "true") == 0){
8039 }else if (strcasecmp(val, "false") == 0){
8048 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8050 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8053 char *noti_string = NULL;
8055 char query[MAX_QUERY_LEN] = {'\0'};
8056 char *errmsg = NULL;
8057 sqlite3 *pkgmgr_parser_db;
8059 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8060 val = (char *)info->uiapp_info->guestmode_visibility;
8063 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8064 SQLITE_OPEN_READWRITE, NULL);
8066 if (ret != SQLITE_OK) {
8067 _LOGE("DB Open Failed\n");
8068 return PMINFO_R_ERROR;
8071 /*TODO: Write to DB here*/
8073 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8075 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8077 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8078 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8080 sqlite3_close(pkgmgr_parser_db);
8081 return PMINFO_R_ERROR;
8083 sqlite3_close(pkgmgr_parser_db);
8084 len = strlen((char *)info->uiapp_info->appid) + 8;
8085 noti_string = calloc(1, len);
8086 if (noti_string == NULL){
8087 return PMINFO_R_ERROR;
8089 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8090 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8091 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8098 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8100 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8103 /* pkgmgrinfo client start*/
8104 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8107 char *errmsg = NULL;
8109 void *handle = NULL;
8110 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8112 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8113 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8115 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8117 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8119 pc = __pkgmgr_client_new(ctype);
8120 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8124 return (pkgmgrinfo_client *) pc;
8127 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8130 char *errmsg = NULL;
8131 void *handle = NULL;
8132 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8134 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8135 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8137 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8139 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8141 ret = __pkgmgr_client_set_status_type(pc, status_type);
8142 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8146 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8148 * The lib dependency chain like below
8149 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8151 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8152 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8153 * on libpkgmgr-installer-client.
8155 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8158 * However, when the libdbus call into the callback function, it suddenly fond that the
8159 * function address is gone (unmapped), then we receive a SIGSEGV.
8161 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8162 * robust if we just link to the well-known lib.
8164 * See https://bugs.tizen.org/jira/browse/PTREL-591
8170 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8173 char *errmsg = NULL;
8174 void *handle = NULL;
8175 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8177 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8178 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8180 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8182 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8184 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8185 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8188 /* same as pkgmgrinfo_client_new */
8192 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8195 char *errmsg = NULL;
8196 void *handle = NULL;
8197 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8199 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8200 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8202 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8204 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8206 ret = __pkgmgr_client_free(pc);
8207 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8210 /* same as pkgmgrinfo_client_new */
8214 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8217 DBusConnection *bus;
8218 DBusMessage *message;
8220 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8222 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8225 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8226 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8228 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8229 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8231 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8233 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8234 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8236 dbus_connection_flush(bus);
8237 dbus_message_unref(message);
8242 /* pkgmgrinfo client end*/