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;
213 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
215 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
216 const char *pkgid, const char *key,
217 const char *val, const void *pmsg, void *data);
219 typedef void pkgmgr_client;
220 typedef void pkgmgr_info;
225 PM_REQUEST_GET_SIZE = 2,
226 PM_REQUEST_KILL_APP = 3,
227 PM_REQUEST_CHECK_APP = 4,
229 }pkgmgr_request_service_type;
232 PM_GET_TOTAL_SIZE= 0,
233 PM_GET_DATA_SIZE = 1,
235 PM_GET_SIZE_INFO = 3,
236 PM_GET_TOTAL_AND_DATA = 4,
237 PM_GET_SIZE_FILE = 5,
239 }pkgmgr_getsize_type;
247 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
248 #define MAX_PKG_BUF_LEN 1024
249 #define MAX_PKG_INFO_LEN 10
251 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
252 "(cert_info text not null, " \
253 "cert_id integer, " \
254 "cert_ref_count integer, " \
255 "PRIMARY KEY(cert_id)) "
257 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
258 "(package text not null, " \
259 "author_root_cert integer, " \
260 "author_im_cert integer, " \
261 "author_signer_cert integer, " \
262 "dist_root_cert integer, " \
263 "dist_im_cert integer, " \
264 "dist_signer_cert integer, " \
265 "dist2_root_cert integer, " \
266 "dist2_im_cert integer, " \
267 "dist2_signer_cert integer, " \
268 "PRIMARY KEY(package)) "
271 #define QUERY_ATTACH "attach database '%s' as Global"
272 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select * " \
273 "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)"
274 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\
275 "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)"
276 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select * "\
277 "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)"
278 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select * "\
279 "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)"
280 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select * "\
281 "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)"
282 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select * "\
283 "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)"
284 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select * "\
285 "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)"
286 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select * "\
287 "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)"
288 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select * "\
289 "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)"
290 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select * "\
291 "from (select *,0 as for_all_users from main.package_info union select *,1 as for_all_users from Global.package_info)"
292 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select * "\
293 "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)"
294 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select * "\
295 "from (select *,0 as for_all_users from main.package_localized_info union select *,1 as for_all_users from Global.package_localized_info)"
296 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select * "\
297 "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 )"
298 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select * "\
299 "from (select *,0 as for_all_users from main.package_privilege_info union select *,1 as for_all_users from Global.package_privilege_info)"
301 char *pkgtype = "rpm";
302 __thread sqlite3 *manifest_db = NULL;
303 __thread sqlite3 *datacontrol_db = NULL;
304 __thread sqlite3 *cert_db = NULL;
306 static int __open_manifest_db(uid_t uid);
307 static int __open_cert_db(uid_t uid);
308 static int __exec_pkginfo_query(char *query, void *data);
309 static int __exec_certinfo_query(char *query, void *data);
310 static int __exec_certindexinfo_query(char *query, void *data);
311 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
312 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
313 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
314 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
315 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
316 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
317 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
318 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
319 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
320 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
321 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
322 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
323 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
324 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
325 static void __destroy_each_node(gpointer data, gpointer user_data);
326 static void __get_filter_condition(gpointer data, char **condition);
327 static void __get_metadata_filter_condition(gpointer data, char **condition);
328 static gint __compare_func(gconstpointer data1, gconstpointer data2);
329 static int __delete_certinfo(const char *pkgid);
330 static int _check_create_Cert_db( sqlite3 *certdb);
331 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
333 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
335 char *error_message = NULL;
336 char query_attach[MAX_QUERY_LEN] = {'\0'};
337 char query_view[MAX_QUERY_LEN] = {'\0'};
339 if(uid != GLOBAL_USER){
340 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
342 sqlite3_exec(handle, query_attach,
343 NULL, NULL, &error_message)) {
344 _LOGD("Don't execute query = %s error message = %s\n",
345 query_attach, error_message);
346 sqlite3_free(error_message);
353 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");
355 sqlite3_exec(handle, query_view,
356 NULL, NULL, &error_message)) {
357 _LOGD("Don't execute query = %s error message = %s\n",
358 query_view, error_message);
359 sqlite3_free(error_message);
361 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");
363 sqlite3_exec(handle, query_view,
364 NULL, NULL, &error_message)) {
365 _LOGD("Don't execute query = %s error message = %s\n",
366 query_view, error_message);
367 sqlite3_free(error_message);
374 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
376 char *error_message = NULL;
377 char query_attach[MAX_QUERY_LEN] = {'\0'};
378 if(uid != GLOBAL_USER){
379 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
381 sqlite3_exec(handle, query_attach,
382 NULL, NULL, &error_message)) {
383 _LOGD("Don't execute query = %s error message = %s\n",
384 query_attach, error_message);
385 sqlite3_free(error_message);
388 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
389 NULL, NULL, &error_message)) {
390 _LOGD("Don't execute query = %s error message = %s\n",
391 QUERY_CREATE_VIEW_1, error_message);
392 sqlite3_free(error_message);
395 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
396 NULL, NULL, &error_message)) {
397 _LOGD("Don't execute query = %s error message = %s\n",
398 QUERY_CREATE_VIEW_2, error_message);
399 sqlite3_free(error_message);
402 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
403 NULL, NULL, &error_message)) {
404 _LOGD("Don't execute query = %s error message = %s\n",
405 QUERY_CREATE_VIEW_3, error_message);
406 sqlite3_free(error_message);
409 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
410 NULL, NULL, &error_message)) {
411 _LOGD("Don't execute query = %s error message = %s\n",
412 QUERY_CREATE_VIEW_4, error_message);
413 sqlite3_free(error_message);
416 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
417 NULL, NULL, &error_message)) {
418 _LOGD("Don't execute query = %s error message = %s\n",
419 QUERY_CREATE_VIEW_5, error_message);
420 sqlite3_free(error_message);
423 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
424 NULL, NULL, &error_message)) {
425 _LOGD("Don't execute query = %s error message = %s\n",
426 QUERY_CREATE_VIEW_6, error_message);
427 sqlite3_free(error_message);
430 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
431 NULL, NULL, &error_message)) {
432 _LOGD("Don't execute query = %s error message = %s\n",
433 QUERY_CREATE_VIEW_7, error_message);
434 sqlite3_free(error_message);
437 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
438 NULL, NULL, &error_message)) {
439 _LOGD("Don't execute query = %s error message = %s\n",
440 QUERY_CREATE_VIEW_8, error_message);
441 sqlite3_free(error_message);
444 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
445 NULL, NULL, &error_message)) {
446 _LOGD("Don't execute query = %s error message = %s\n",
447 QUERY_CREATE_VIEW_9, error_message);
448 sqlite3_free(error_message);
451 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
452 NULL, NULL, &error_message)) {
453 _LOGD("Don't execute query = %s error message = %s\n",
454 QUERY_CREATE_VIEW_10, error_message);
455 sqlite3_free(error_message);
458 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
459 NULL, NULL, &error_message)) {
460 _LOGD("Don't execute query = %s error message = %s\n",
461 QUERY_CREATE_VIEW_11, error_message);
462 sqlite3_free(error_message);
465 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
466 NULL, NULL, &error_message)) {
467 _LOGD("Don't execute query = %s error message = %s\n",
468 QUERY_CREATE_VIEW_12, error_message);
469 sqlite3_free(error_message);
472 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
473 NULL, NULL, &error_message)) {
474 _LOGD("Don't execute query = %s error message = %s\n",
475 QUERY_CREATE_VIEW_13, error_message);
476 sqlite3_free(error_message);
479 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
480 NULL, NULL, &error_message)) {
481 _LOGD("Don't execute query = %s error message = %s\n",
482 QUERY_CREATE_VIEW_14, error_message);
483 sqlite3_free(error_message);
491 static int _check_create_Cert_db( sqlite3 *certdb)
494 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
497 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
503 API char *getIconPath(uid_t uid)
506 struct group *grpinfo = NULL;
507 struct passwd *userinfo = getpwuid(uid);
510 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
513 if (uid != GLOBAL_USER) {
514 if (userinfo == NULL) {
515 _LOGE("getpwuid(%d) returns NULL !", uid);
518 grpinfo = getgrnam("users");
519 if (grpinfo == NULL) {
520 _LOGE("getgrnam(users) returns NULL !");
523 // Compare git_t type and not group name
524 if (grpinfo->gr_gid != userinfo->pw_gid) {
525 _LOGE("UID [%d] does not belong to 'users' group!", uid);
528 ret = asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir);
530 _LOGE("asprintf fails");
535 result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
538 ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
539 if (ret == -1 && errno != EEXIST) {
540 _LOGE("FAIL : to create directory %s %d", result, errno);
541 } else if (getuid() == OWNER_ROOT) {
542 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
545 strerror_r(errno, buf, sizeof(buf));
546 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
552 API char *getUserPkgParserDBPath(void)
554 return getUserPkgParserDBPathUID(GLOBAL_USER);
557 API char *getUserPkgParserDBPathUID(uid_t uid)
559 const char *result = NULL;
560 const char *journal = NULL;
561 struct group *grpinfo = NULL;
563 struct passwd *userinfo = getpwuid(uid);
566 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
569 if (uid != GLOBAL_USER) {
570 if (userinfo == NULL) {
571 _LOGE("getpwuid(%d) returns NULL !", uid);
574 grpinfo = getgrnam("users");
575 if (grpinfo == NULL) {
576 _LOGE("getgrnam(users) returns NULL !");
579 // Compare git_t type and not group name
580 if (grpinfo->gr_gid != userinfo->pw_gid) {
581 _LOGE("UID [%d] does not belong to 'users' group!", uid);
584 ret = asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
586 _LOGE("asprintf fails");
589 ret = asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir);
591 _LOGE("asprintf fails");
595 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
596 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
598 char *temp = strdup(result);
599 dir = strrchr(temp, '/');
607 ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
608 if (ret == -1 && errno != EEXIST) {
609 _LOGE("FAIL : to create directory %s %d", temp, errno);
610 } else if (getuid() == OWNER_ROOT) {
611 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
614 strerror_r(errno, buf, sizeof(buf));
615 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
622 API char *getUserPkgCertDBPath(void)
624 return getUserPkgCertDBPathUID(GLOBAL_USER);
627 API char *getUserPkgCertDBPathUID(uid_t uid)
630 char *journal = NULL;
631 struct group *grpinfo = NULL;
633 struct passwd *userinfo = getpwuid(uid);
636 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
639 if (uid != GLOBAL_USER) {
640 if (userinfo == NULL) {
641 _LOGE("getpwuid(%d) returns NULL !", uid);
644 grpinfo = getgrnam("users");
645 if (grpinfo == NULL) {
646 _LOGE("getgrnam(users) returns NULL !");
649 // Compare git_t type and not group name
650 if (grpinfo->gr_gid != userinfo->pw_gid) {
651 _LOGE("UID [%d] does not belong to 'users' group!", uid);
654 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
655 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_cert.db-journal", userinfo->pw_dir);
657 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
658 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db-journal");
660 char *temp = strdup(result);
661 dir = strrchr(temp, '/');
669 int ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
670 if (ret == -1 && errno != EEXIST) {
671 _LOGE("FAIL : to create directory %s %d", temp, errno);
672 } else if (getuid() == OWNER_ROOT) {
673 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
676 strerror_r(errno, buf, sizeof(buf));
677 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
684 API const char* getUserDesktopPath(uid_t uid)
687 struct group *grpinfo = NULL;
689 struct passwd *userinfo = getpwuid(uid);
692 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
695 if (uid != GLOBAL_USER) {
696 if (userinfo == NULL) {
697 _LOGE("getpwuid(%d) returns NULL !", uid);
700 grpinfo = getgrnam("users");
701 if (grpinfo == NULL) {
702 _LOGE("getgrnam(users) returns NULL !");
705 // Compare git_t type and not group name
706 if (grpinfo->gr_gid != userinfo->pw_gid) {
707 _LOGE("UID [%d] does not belong to 'users' group!", uid);
710 asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir);
712 result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
715 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
716 if (ret == -1 && errno != EEXIST) {
717 _LOGE("FAIL : to create directory %s %d", result, errno);
718 } else if (getuid() == OWNER_ROOT) {
719 ret = chown(result, uid,((grpinfo)?grpinfo->gr_gid:0));
722 strerror_r(errno, buf, sizeof(buf));
723 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
729 API const char* getUserManifestPath(uid_t uid)
732 struct group *grpinfo = NULL;
734 struct passwd *userinfo = getpwuid(uid);
737 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
740 if (uid != GLOBAL_USER) {
741 if (userinfo == NULL) {
742 _LOGE("getpwuid(%d) returns NULL !", uid);
745 grpinfo = getgrnam("users");
746 if (grpinfo == NULL) {
747 _LOGE("getgrnam(users) returns NULL !");
750 // Compare git_t type and not group name
751 if (grpinfo->gr_gid != userinfo->pw_gid) {
752 _LOGE("UID [%d] does not belong to 'users' group!", uid);
755 asprintf(&result, "%s/.applications/manifest/", userinfo->pw_dir);
757 result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
760 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
761 if (ret == -1 && errno != EEXIST) {
762 _LOGE("FAIL : to create directory %s %d", result, errno);
763 } else if (getuid() == OWNER_ROOT) {
764 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
767 strerror_r(errno, buf, sizeof(buf));
768 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
775 static gint __compare_func(gconstpointer data1, gconstpointer data2)
777 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
778 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
779 if (node1->prop == node2->prop)
781 else if (node1->prop > node2->prop)
787 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
790 *p = atoi(coltxt[0]);
791 _LOGE("count value is %d\n", *p);
795 static void __destroy_each_node(gpointer data, gpointer user_data)
797 ret_if(data == NULL);
798 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
811 static void __get_metadata_filter_condition(gpointer data, char **condition)
813 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
814 char key[MAX_QUERY_LEN] = {'\0'};
815 char value[MAX_QUERY_LEN] = {'\0'};
817 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
820 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
825 *condition = strdup(key);
829 static void __get_filter_condition(gpointer data, char **condition)
831 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
832 char buf[MAX_QUERY_LEN + 1] = {'\0'};
833 char temp[PKG_STRING_LEN_MAX] = {'\0'};
834 switch (node->prop) {
835 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
836 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
838 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
839 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
841 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
842 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
844 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
845 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
847 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
848 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
850 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
851 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
853 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
854 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
856 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
857 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
859 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
860 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
862 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
863 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
865 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
866 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
868 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
869 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
871 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
872 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
874 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
875 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
877 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
878 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
881 case E_PMINFO_APPINFO_PROP_APP_ID:
882 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
884 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
885 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
887 case E_PMINFO_APPINFO_PROP_APP_EXEC:
888 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
890 case E_PMINFO_APPINFO_PROP_APP_ICON:
891 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
893 case E_PMINFO_APPINFO_PROP_APP_TYPE:
894 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
896 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
897 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
898 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
900 case E_PMINFO_APPINFO_PROP_APP_URI:
901 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
902 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
904 case E_PMINFO_APPINFO_PROP_APP_MIME:
905 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
906 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
908 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
909 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
910 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
912 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
913 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
915 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
916 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
918 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
919 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
921 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
922 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
924 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
925 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
927 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
928 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
930 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
931 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
933 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
934 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
937 _LOGE("Invalid Property Type\n");
941 *condition = strdup(buf);
945 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
947 if (syslocale == NULL)
948 return strdup(DEFAULT_LOCALE);
950 locale = (char *)calloc(1, 6);
951 retvm_if(!locale, NULL, "Malloc Failed\n");
953 strncpy(locale, syslocale, 2);
954 strncat(locale, "-", 1);
955 locale[3] = syslocale[3] + 32;
956 locale[4] = syslocale[4] + 32;
960 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
962 ret_if(data == NULL);
964 free((void *)data->locale);
968 pkgmgr_parser_free_manifest_xml(data->manifest_info);
974 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
976 ret_if(data == NULL);
978 free((void *)data->package);
979 data->package = NULL;
982 free((void *)data->locale);
986 manifest_x *mfx = calloc(1, sizeof(manifest_x));
987 if (data->app_component == PMINFO_UI_APP)
988 mfx->uiapplication = data->uiapp_info;
989 else if (data->app_component == PMINFO_SVC_APP)
990 mfx->serviceapplication = data->svcapp_info;
991 pkgmgr_parser_free_manifest_xml(mfx);
997 static int __open_manifest_db(uid_t uid)
1000 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
1001 if (access(user_pkg_parser, F_OK) == 0) {
1003 db_util_open_with_options(user_pkg_parser, &manifest_db,
1004 SQLITE_OPEN_READONLY, NULL);
1005 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
1006 ret = _pkgmgr_parser_attach_create_view_parserdb(manifest_db,uid);
1007 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
1010 _LOGE("Manifest DB does not exists !!\n");
1014 static int __open_cert_db(uid_t uid)
1017 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
1018 if (access(user_cert_parser, F_OK) == 0) {
1020 db_util_open_with_options(user_cert_parser, &cert_db,
1021 SQLITE_OPEN_READWRITE, NULL);
1022 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
1024 ret = _pkgmgr_parser_attach_create_view_certdb(cert_db,uid);
1025 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
1029 _LOGE("Cert DB does not exists !!\n");
1033 static int __open_datacontrol_db()
1036 if (access(DATACONTROL_DB, F_OK) == 0) {
1038 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
1039 SQLITE_OPEN_READONLY, NULL);
1040 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1043 _LOGE("Datacontrol DB does not exists !!\n");
1047 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1049 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1051 pkgmgr_pkginfo_x *info = NULL;
1052 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1053 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1055 LISTADD(udata, info);
1057 for(i = 0; i < ncols; i++)
1059 if (strcmp(colname[i], "package") == 0) {
1061 info->manifest_info->package = strdup(coltxt[i]);
1063 info->manifest_info->package = NULL;
1064 } else if (strcmp(colname[i], "for_all_users") == 0) {
1066 info->manifest_info->for_all_users = strdup(coltxt[i]);
1068 info->manifest_info->for_all_users = NULL;
1073 //by default if views are not set , the column for_all_users doesn't exist,
1074 // in this case we assume we retreive information about app avaible for all users
1075 if (!info->manifest_info->for_all_users)
1076 info->manifest_info->for_all_users = strdup("1");
1081 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1083 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1086 uiapplication_x *uiapp = NULL;
1087 serviceapplication_x *svcapp = NULL;
1088 for(i = 0; i < ncols; i++)
1090 if ((strcmp(colname[i], "app_component") == 0) ||
1091 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1093 if (strcmp(coltxt[i], "uiapp") == 0) {
1094 uiapp = calloc(1, sizeof(uiapplication_x));
1095 if (uiapp == NULL) {
1096 _LOGE("Out of Memory!!!\n");
1099 LISTADD(info->manifest_info->uiapplication, uiapp);
1100 for(j = 0; j < ncols; j++)
1102 if ((strcmp(colname[j], "app_id") == 0) ||
1103 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1105 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1106 } else if (strcmp(colname[j], "package") == 0) {
1108 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1113 svcapp = calloc(1, sizeof(serviceapplication_x));
1114 if (svcapp == NULL) {
1115 _LOGE("Out of Memory!!!\n");
1118 LISTADD(info->manifest_info->serviceapplication, svcapp);
1119 for(j = 0; j < ncols; j++)
1121 if ((strcmp(colname[j], "app_id") == 0) ||
1122 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1124 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1125 } else if (strcmp(colname[j], "package") == 0) {
1127 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1141 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1143 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1145 uiapplication_x *uiapp = NULL;
1146 icon_x *icon = NULL;
1147 label_x *label = NULL;
1149 uiapp = calloc(1, sizeof(uiapplication_x));
1150 LISTADD(info->manifest_info->uiapplication, uiapp);
1151 icon = calloc(1, sizeof(icon_x));
1152 LISTADD(info->manifest_info->uiapplication->icon, icon);
1153 label = calloc(1, sizeof(label_x));
1154 LISTADD(info->manifest_info->uiapplication->label, label);
1156 for(i = 0; i < ncols; i++)
1158 if (strcmp(colname[i], "app_id") == 0) {
1160 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1162 info->manifest_info->uiapplication->appid = NULL;
1163 } else if (strcmp(colname[i], "app_exec") == 0) {
1165 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1167 info->manifest_info->uiapplication->exec = NULL;
1168 } else if (strcmp(colname[i], "app_type") == 0 ){
1170 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1172 info->manifest_info->uiapplication->type = NULL;
1173 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1175 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1177 info->manifest_info->uiapplication->nodisplay = NULL;
1178 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1180 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1182 info->manifest_info->uiapplication->multiple = NULL;
1183 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1185 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1187 info->manifest_info->uiapplication->taskmanage = NULL;
1188 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1190 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1192 info->manifest_info->uiapplication->hwacceleration = NULL;
1193 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1195 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1197 info->manifest_info->uiapplication->screenreader = NULL;
1198 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1200 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1202 info->manifest_info->uiapplication->indicatordisplay = NULL;
1203 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1205 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1207 info->manifest_info->uiapplication->portraitimg = NULL;
1208 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1210 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1212 info->manifest_info->uiapplication->landscapeimg = NULL;
1213 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1215 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1217 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1218 } else if (strcmp(colname[i], "package") == 0 ){
1220 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1222 info->manifest_info->uiapplication->package = NULL;
1223 } else if (strcmp(colname[i], "app_icon") == 0) {
1225 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1227 info->manifest_info->uiapplication->icon->text = NULL;
1228 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1230 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1232 info->manifest_info->uiapplication->enabled = NULL;
1233 } else if (strcmp(colname[i], "app_label") == 0 ) {
1235 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1237 info->manifest_info->uiapplication->label->text = NULL;
1238 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1240 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1242 info->manifest_info->uiapplication->recentimage = NULL;
1243 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1245 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1247 info->manifest_info->uiapplication->mainapp = NULL;
1248 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1250 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1251 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1254 info->manifest_info->uiapplication->icon->lang = NULL;
1255 info->manifest_info->uiapplication->label->lang = NULL;
1257 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1259 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1261 info->manifest_info->uiapplication->permission_type = NULL;
1262 } else if (strcmp(colname[i], "component_type") == 0 ) {
1264 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1266 info->manifest_info->uiapplication->component_type = NULL;
1267 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1269 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1271 info->manifest_info->uiapplication->preload = NULL;
1272 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1274 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1276 info->manifest_info->uiapplication->submode = NULL;
1277 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1279 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1281 info->manifest_info->uiapplication->submode_mainid = NULL;
1288 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1290 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1292 serviceapplication_x *svcapp = NULL;
1293 icon_x *icon = NULL;
1294 label_x *label = NULL;
1296 svcapp = calloc(1, sizeof(serviceapplication_x));
1297 LISTADD(info->manifest_info->serviceapplication, svcapp);
1298 icon = calloc(1, sizeof(icon_x));
1299 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1300 label = calloc(1, sizeof(label_x));
1301 LISTADD(info->manifest_info->serviceapplication->label, label);
1302 for(i = 0; i < ncols; i++)
1304 if (strcmp(colname[i], "app_id") == 0) {
1306 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1308 info->manifest_info->serviceapplication->appid = NULL;
1309 } else if (strcmp(colname[i], "app_exec") == 0) {
1311 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1313 info->manifest_info->serviceapplication->exec = NULL;
1314 } else if (strcmp(colname[i], "app_type") == 0 ){
1316 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1318 info->manifest_info->serviceapplication->type = NULL;
1319 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1321 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1323 info->manifest_info->serviceapplication->onboot = NULL;
1324 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1326 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1328 info->manifest_info->serviceapplication->autorestart = NULL;
1329 } else if (strcmp(colname[i], "package") == 0 ){
1331 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1333 info->manifest_info->serviceapplication->package = NULL;
1334 } else if (strcmp(colname[i], "app_icon") == 0) {
1336 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1338 info->manifest_info->serviceapplication->icon->text = NULL;
1339 } else if (strcmp(colname[i], "app_label") == 0 ) {
1341 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1343 info->manifest_info->serviceapplication->label->text = NULL;
1344 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1346 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1347 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1350 info->manifest_info->serviceapplication->icon->lang = NULL;
1351 info->manifest_info->serviceapplication->label->lang = NULL;
1353 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1355 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1357 info->manifest_info->serviceapplication->permission_type = NULL;
1364 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1366 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1369 uiapplication_x *uiapp = NULL;
1370 serviceapplication_x *svcapp = NULL;
1371 for(j = 0; j < ncols; j++)
1373 if (strcmp(colname[j], "app_component") == 0) {
1375 if (strcmp(coltxt[j], "uiapp") == 0) {
1376 uiapp = calloc(1, sizeof(uiapplication_x));
1377 if (uiapp == NULL) {
1378 _LOGE("Out of Memory!!!\n");
1381 LISTADD(info->manifest_info->uiapplication, uiapp);
1382 for(i = 0; i < ncols; i++)
1384 if (strcmp(colname[i], "app_id") == 0) {
1386 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1388 info->manifest_info->uiapplication->appid = NULL;
1389 } else if (strcmp(colname[i], "app_exec") == 0) {
1391 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1393 info->manifest_info->uiapplication->exec = NULL;
1394 } else if (strcmp(colname[i], "app_type") == 0 ){
1396 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1398 info->manifest_info->uiapplication->type = NULL;
1399 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1401 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1403 info->manifest_info->uiapplication->nodisplay = NULL;
1404 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1406 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1408 info->manifest_info->uiapplication->multiple = NULL;
1409 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1411 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1413 info->manifest_info->uiapplication->taskmanage = NULL;
1414 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1416 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1418 info->manifest_info->uiapplication->hwacceleration = NULL;
1419 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1421 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1423 info->manifest_info->uiapplication->screenreader = NULL;
1424 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1426 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1428 info->manifest_info->uiapplication->indicatordisplay = NULL;
1429 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1431 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1433 info->manifest_info->uiapplication->portraitimg = NULL;
1434 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1436 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1438 info->manifest_info->uiapplication->landscapeimg = NULL;
1439 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1441 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1443 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1444 } else if (strcmp(colname[i], "package") == 0 ){
1446 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1448 info->manifest_info->uiapplication->package = NULL;
1449 } else if (strcmp(colname[i], "app_icon") == 0) {
1451 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1453 info->manifest_info->uiapplication->icon->text = NULL;
1454 } else if (strcmp(colname[i], "app_label") == 0 ) {
1456 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1458 info->manifest_info->uiapplication->label->text = NULL;
1459 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1461 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1463 info->manifest_info->uiapplication->recentimage = NULL;
1464 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1466 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1468 info->manifest_info->uiapplication->mainapp = NULL;
1469 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1471 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1472 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1475 info->manifest_info->uiapplication->icon->lang = NULL;
1476 info->manifest_info->uiapplication->label->lang = NULL;
1478 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1480 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1482 info->manifest_info->uiapplication->permission_type = NULL;
1487 svcapp = calloc(1, sizeof(serviceapplication_x));
1488 if (svcapp == NULL) {
1489 _LOGE("Out of Memory!!!\n");
1492 LISTADD(info->manifest_info->serviceapplication, svcapp);
1493 for(i = 0; i < ncols; i++)
1495 if (strcmp(colname[i], "app_id") == 0) {
1497 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1499 info->manifest_info->serviceapplication->appid = NULL;
1500 } else if (strcmp(colname[i], "app_exec") == 0) {
1502 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1504 info->manifest_info->serviceapplication->exec = NULL;
1505 } else if (strcmp(colname[i], "app_type") == 0 ){
1507 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1509 info->manifest_info->serviceapplication->type = NULL;
1510 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1512 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1514 info->manifest_info->serviceapplication->onboot = NULL;
1515 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1517 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1519 info->manifest_info->serviceapplication->autorestart = NULL;
1520 } else if (strcmp(colname[i], "package") == 0 ){
1522 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1524 info->manifest_info->serviceapplication->package = NULL;
1525 } else if (strcmp(colname[i], "app_icon") == 0) {
1527 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1529 info->manifest_info->serviceapplication->icon->text = NULL;
1530 } else if (strcmp(colname[i], "app_label") == 0 ) {
1532 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1534 info->manifest_info->serviceapplication->label->text = NULL;
1535 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1537 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1538 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1541 info->manifest_info->serviceapplication->icon->lang = NULL;
1542 info->manifest_info->serviceapplication->label->lang = NULL;
1544 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1546 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1548 info->manifest_info->serviceapplication->permission_type = NULL;
1563 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1565 int *p = (int*)data;
1566 *p = atoi(coltxt[0]);
1570 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1572 int *p = (int*)data;
1574 *p = atoi(coltxt[0]);
1578 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1580 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1582 author_x *author = NULL;
1583 icon_x *icon = NULL;
1584 label_x *label = NULL;
1585 description_x *description = NULL;
1586 privilege_x *privilege = NULL;
1588 author = calloc(1, sizeof(author_x));
1589 LISTADD(info->manifest_info->author, author);
1590 icon = calloc(1, sizeof(icon_x));
1591 LISTADD(info->manifest_info->icon, icon);
1592 label = calloc(1, sizeof(label_x));
1593 LISTADD(info->manifest_info->label, label);
1594 description = calloc(1, sizeof(description_x));
1595 LISTADD(info->manifest_info->description, description);
1596 privilege = calloc(1, sizeof(privilege_x));
1597 LISTADD(info->manifest_info->privileges->privilege, privilege);
1598 for(i = 0; i < ncols; i++)
1600 if (strcmp(colname[i], "package_version") == 0) {
1602 info->manifest_info->version = strdup(coltxt[i]);
1604 info->manifest_info->version = NULL;
1605 } else if (strcmp(colname[i], "package_type") == 0) {
1607 info->manifest_info->type = strdup(coltxt[i]);
1609 info->manifest_info->type = NULL;
1610 } else if (strcmp(colname[i], "install_location") == 0) {
1612 info->manifest_info->installlocation = strdup(coltxt[i]);
1614 info->manifest_info->installlocation = NULL;
1615 } else if (strcmp(colname[i], "package_size") == 0) {
1617 info->manifest_info->package_size = strdup(coltxt[i]);
1619 info->manifest_info->package_size = NULL;
1620 } else if (strcmp(colname[i], "author_email") == 0 ){
1622 info->manifest_info->author->email = strdup(coltxt[i]);
1624 info->manifest_info->author->email = NULL;
1625 } else if (strcmp(colname[i], "author_href") == 0 ){
1627 info->manifest_info->author->href = strdup(coltxt[i]);
1629 info->manifest_info->author->href = NULL;
1630 } else if (strcmp(colname[i], "package_label") == 0 ){
1632 info->manifest_info->label->text = strdup(coltxt[i]);
1634 info->manifest_info->label->text = NULL;
1635 } else if (strcmp(colname[i], "package_icon") == 0 ){
1637 info->manifest_info->icon->text = strdup(coltxt[i]);
1639 info->manifest_info->icon->text = NULL;
1640 } else if (strcmp(colname[i], "package_description") == 0 ){
1642 info->manifest_info->description->text = strdup(coltxt[i]);
1644 info->manifest_info->description->text = NULL;
1645 } else if (strcmp(colname[i], "package_author") == 0 ){
1647 info->manifest_info->author->text = strdup(coltxt[i]);
1649 info->manifest_info->author->text = NULL;
1650 } else if (strcmp(colname[i], "package_removable") == 0 ){
1652 info->manifest_info->removable = strdup(coltxt[i]);
1654 info->manifest_info->removable = NULL;
1655 } else if (strcmp(colname[i], "package_preload") == 0 ){
1657 info->manifest_info->preload = strdup(coltxt[i]);
1659 info->manifest_info->preload = NULL;
1660 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1662 info->manifest_info->readonly = strdup(coltxt[i]);
1664 info->manifest_info->readonly = NULL;
1665 } else if (strcmp(colname[i], "package_update") == 0 ){
1667 info->manifest_info->update= strdup(coltxt[i]);
1669 info->manifest_info->update = NULL;
1670 } else if (strcmp(colname[i], "package_system") == 0 ){
1672 info->manifest_info->system= strdup(coltxt[i]);
1674 info->manifest_info->system = NULL;
1675 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1677 info->manifest_info->appsetting = strdup(coltxt[i]);
1679 info->manifest_info->appsetting = NULL;
1680 } else if (strcmp(colname[i], "installed_time") == 0 ){
1682 info->manifest_info->installed_time = strdup(coltxt[i]);
1684 info->manifest_info->installed_time = NULL;
1685 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1687 info->manifest_info->installed_storage = strdup(coltxt[i]);
1689 info->manifest_info->installed_storage = NULL;
1690 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1692 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1694 info->manifest_info->mainapp_id = NULL;
1695 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1697 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1699 info->manifest_info->storeclient_id = NULL;
1700 } else if (strcmp(colname[i], "root_path") == 0 ){
1702 info->manifest_info->root_path = strdup(coltxt[i]);
1704 info->manifest_info->root_path = NULL;
1705 } else if (strcmp(colname[i], "csc_path") == 0 ){
1707 info->manifest_info->csc_path = strdup(coltxt[i]);
1709 info->manifest_info->csc_path = NULL;
1710 } else if (strcmp(colname[i], "privilege") == 0 ){
1712 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1714 info->manifest_info->privileges->privilege->text = NULL;
1715 } else if (strcmp(colname[i], "package_locale") == 0 ){
1717 info->manifest_info->author->lang = strdup(coltxt[i]);
1718 info->manifest_info->icon->lang = strdup(coltxt[i]);
1719 info->manifest_info->label->lang = strdup(coltxt[i]);
1720 info->manifest_info->description->lang = strdup(coltxt[i]);
1723 info->manifest_info->author->lang = NULL;
1724 info->manifest_info->icon->lang = NULL;
1725 info->manifest_info->label->lang = NULL;
1726 info->manifest_info->description->lang = NULL;
1728 } else if (strcmp(colname[i], "package_url") == 0 ){
1730 info->manifest_info->package_url = strdup(coltxt[i]);
1732 info->manifest_info->package_url = NULL;
1740 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1742 if ( strcasecmp(comp, "uiapp") == 0)
1743 return PMINFO_UI_APP;
1744 else if ( strcasecmp(comp, "svcapp") == 0)
1745 return PMINFO_SVC_APP;
1750 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1752 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1754 for(i = 0; i < ncols; i++) {
1755 if (strcmp(colname[i], "cert_id") == 0) {
1757 info->cert_id = atoi(coltxt[i]);
1760 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1762 info->cert_ref_count = atoi(coltxt[i]);
1764 info->cert_ref_count = 0;
1770 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1772 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1774 for(i = 0; i < ncols; i++)
1776 if (strcmp(colname[i], "package") == 0) {
1778 info->pkgid = strdup(coltxt[i]);
1781 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1783 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1785 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1786 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1788 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1790 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1791 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1793 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1795 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1796 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1798 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1800 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1801 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1803 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1805 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1806 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1808 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1810 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1811 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1813 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1815 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1816 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1818 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1820 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1821 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1823 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1825 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1826 } else if (strcmp(colname[i], "cert_info") == 0 ){
1828 info->cert_value = strdup(coltxt[i]);
1830 info->cert_value = NULL;
1837 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1839 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1842 uiapplication_x *uiapp = NULL;
1843 serviceapplication_x *svcapp = NULL;
1844 for(i = 0; i < ncols; i++)
1846 if (strcmp(colname[i], "app_component") == 0) {
1848 if (strcmp(coltxt[i], "uiapp") == 0) {
1849 uiapp = calloc(1, sizeof(uiapplication_x));
1850 if (uiapp == NULL) {
1851 _LOGE("Out of Memory!!!\n");
1854 LISTADD(info->manifest_info->uiapplication, uiapp);
1855 for(j = 0; j < ncols; j++)
1857 if (strcmp(colname[j], "app_id") == 0) {
1859 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1860 } else if (strcmp(colname[j], "app_exec") == 0) {
1862 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1864 info->manifest_info->uiapplication->exec = NULL;
1865 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1867 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1869 info->manifest_info->uiapplication->nodisplay = NULL;
1870 } else if (strcmp(colname[j], "app_type") == 0 ) {
1872 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1874 info->manifest_info->uiapplication->type = NULL;
1875 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1877 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1879 info->manifest_info->uiapplication->multiple = NULL;
1880 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1882 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1884 info->manifest_info->uiapplication->taskmanage = NULL;
1885 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1887 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1889 info->manifest_info->uiapplication->hwacceleration = NULL;
1890 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1892 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1894 info->manifest_info->uiapplication->screenreader = NULL;
1895 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1897 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1899 info->manifest_info->uiapplication->enabled = NULL;
1900 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1902 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1904 info->manifest_info->uiapplication->indicatordisplay = NULL;
1905 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1907 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1909 info->manifest_info->uiapplication->portraitimg = NULL;
1910 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1912 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1914 info->manifest_info->uiapplication->landscapeimg = NULL;
1915 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1917 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1919 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1920 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1922 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1924 info->manifest_info->uiapplication->recentimage = NULL;
1925 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1927 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1929 info->manifest_info->uiapplication->mainapp = NULL;
1930 } else if (strcmp(colname[j], "package") == 0 ) {
1932 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1934 info->manifest_info->uiapplication->package = NULL;
1935 } else if (strcmp(colname[j], "app_component") == 0) {
1937 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1939 info->manifest_info->uiapplication->app_component = NULL;
1940 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1942 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1944 info->manifest_info->uiapplication->permission_type = NULL;
1945 } else if (strcmp(colname[j], "component_type") == 0 ) {
1947 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1949 info->manifest_info->uiapplication->component_type = NULL;
1950 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1952 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1954 info->manifest_info->uiapplication->preload = NULL;
1955 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1957 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1959 info->manifest_info->uiapplication->submode = NULL;
1960 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1962 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1964 info->manifest_info->uiapplication->submode_mainid = NULL;
1969 svcapp = calloc(1, sizeof(serviceapplication_x));
1970 if (svcapp == NULL) {
1971 _LOGE("Out of Memory!!!\n");
1974 LISTADD(info->manifest_info->serviceapplication, svcapp);
1975 for(j = 0; j < ncols; j++)
1977 if (strcmp(colname[j], "app_id") == 0) {
1979 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1980 } else if (strcmp(colname[j], "app_exec") == 0) {
1982 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1984 info->manifest_info->serviceapplication->exec = NULL;
1985 } else if (strcmp(colname[j], "app_type") == 0 ){
1987 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1989 info->manifest_info->serviceapplication->type = NULL;
1990 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1992 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1994 info->manifest_info->serviceapplication->onboot = NULL;
1995 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1997 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1999 info->manifest_info->serviceapplication->autorestart = NULL;
2000 } else if (strcmp(colname[j], "package") == 0 ){
2002 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
2004 info->manifest_info->serviceapplication->package = NULL;
2005 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
2007 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
2009 info->manifest_info->serviceapplication->permission_type = NULL;
2022 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
2024 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2026 icon_x *icon = NULL;
2027 label_x *label = NULL;
2028 category_x *category = NULL;
2029 metadata_x *metadata = NULL;
2030 permission_x *permission = NULL;
2031 image_x *image = NULL;
2033 switch (info->app_component) {
2035 icon = calloc(1, sizeof(icon_x));
2036 LISTADD(info->uiapp_info->icon, icon);
2037 label = calloc(1, sizeof(label_x));
2038 LISTADD(info->uiapp_info->label, label);
2039 category = calloc(1, sizeof(category_x));
2040 LISTADD(info->uiapp_info->category, category);
2041 metadata = calloc(1, sizeof(metadata_x));
2042 LISTADD(info->uiapp_info->metadata, metadata);
2043 permission = calloc(1, sizeof(permission_x));
2044 LISTADD(info->uiapp_info->permission, permission);
2045 image = calloc(1, sizeof(image_x));
2046 LISTADD(info->uiapp_info->image, image);
2048 for(i = 0; i < ncols; i++)
2050 if (strcmp(colname[i], "app_id") == 0) {
2051 /*appid being foreign key, is column in every table
2052 Hence appid gets strduped every time leading to memory leak.
2053 If appid is already set, just continue.*/
2054 if (info->uiapp_info->appid)
2057 info->uiapp_info->appid = strdup(coltxt[i]);
2059 info->uiapp_info->appid = NULL;
2060 } else if (strcmp(colname[i], "app_exec") == 0) {
2062 info->uiapp_info->exec = strdup(coltxt[i]);
2064 info->uiapp_info->exec = NULL;
2065 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2067 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2069 info->uiapp_info->nodisplay = NULL;
2070 } else if (strcmp(colname[i], "app_type") == 0 ) {
2072 info->uiapp_info->type = strdup(coltxt[i]);
2074 info->uiapp_info->type = NULL;
2075 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2077 info->uiapp_info->icon->section= strdup(coltxt[i]);
2079 info->uiapp_info->icon->section = NULL;
2080 } else if (strcmp(colname[i], "app_icon") == 0) {
2082 info->uiapp_info->icon->text = strdup(coltxt[i]);
2084 info->uiapp_info->icon->text = NULL;
2085 } else if (strcmp(colname[i], "app_label") == 0 ) {
2087 info->uiapp_info->label->text = strdup(coltxt[i]);
2089 info->uiapp_info->label->text = NULL;
2090 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2092 info->uiapp_info->multiple = strdup(coltxt[i]);
2094 info->uiapp_info->multiple = NULL;
2095 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2097 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2099 info->uiapp_info->taskmanage = NULL;
2100 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2102 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2104 info->uiapp_info->hwacceleration = NULL;
2105 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2107 info->uiapp_info->screenreader = strdup(coltxt[i]);
2109 info->uiapp_info->screenreader = NULL;
2110 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2112 info->uiapp_info->enabled= strdup(coltxt[i]);
2114 info->uiapp_info->enabled = NULL;
2115 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2117 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2119 info->uiapp_info->indicatordisplay = NULL;
2120 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2122 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2124 info->uiapp_info->portraitimg = NULL;
2125 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2127 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2129 info->uiapp_info->landscapeimg = NULL;
2130 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2132 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2134 info->uiapp_info->guestmode_visibility = NULL;
2135 } else if (strcmp(colname[i], "category") == 0 ) {
2137 info->uiapp_info->category->name = strdup(coltxt[i]);
2139 info->uiapp_info->category->name = NULL;
2140 } else if (strcmp(colname[i], "md_key") == 0 ) {
2142 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2144 info->uiapp_info->metadata->key = NULL;
2145 } else if (strcmp(colname[i], "md_value") == 0 ) {
2147 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2149 info->uiapp_info->metadata->value = NULL;
2150 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2152 info->uiapp_info->permission->type= strdup(coltxt[i]);
2154 info->uiapp_info->permission->type = NULL;
2155 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2157 info->uiapp_info->permission->value = strdup(coltxt[i]);
2159 info->uiapp_info->permission->value = NULL;
2160 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2162 info->uiapp_info->recentimage = strdup(coltxt[i]);
2164 info->uiapp_info->recentimage = NULL;
2165 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2167 info->uiapp_info->mainapp = strdup(coltxt[i]);
2169 info->uiapp_info->mainapp = NULL;
2170 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2172 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2173 info->uiapp_info->label->lang = strdup(coltxt[i]);
2176 info->uiapp_info->icon->lang = NULL;
2177 info->uiapp_info->label->lang = NULL;
2179 } else if (strcmp(colname[i], "app_image") == 0) {
2181 info->uiapp_info->image->text= strdup(coltxt[i]);
2183 info->uiapp_info->image->text = NULL;
2184 } else if (strcmp(colname[i], "app_image_section") == 0) {
2186 info->uiapp_info->image->section= strdup(coltxt[i]);
2188 info->uiapp_info->image->section = NULL;
2189 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2191 info->uiapp_info->permission_type = strdup(coltxt[i]);
2193 info->uiapp_info->permission_type = NULL;
2194 } else if (strcmp(colname[i], "component_type") == 0 ) {
2196 info->uiapp_info->component_type = strdup(coltxt[i]);
2198 info->uiapp_info->component_type = NULL;
2199 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2201 info->uiapp_info->preload = strdup(coltxt[i]);
2203 info->uiapp_info->preload = NULL;
2204 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2206 info->uiapp_info->submode = strdup(coltxt[i]);
2208 info->uiapp_info->submode = NULL;
2209 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2211 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2213 info->uiapp_info->submode_mainid = NULL;
2218 case PMINFO_SVC_APP:
2219 icon = calloc(1, sizeof(icon_x));
2220 LISTADD(info->svcapp_info->icon, icon);
2221 label = calloc(1, sizeof(label_x));
2222 LISTADD(info->svcapp_info->label, label);
2223 category = calloc(1, sizeof(category_x));
2224 LISTADD(info->svcapp_info->category, category);
2225 metadata = calloc(1, sizeof(metadata_x));
2226 LISTADD(info->svcapp_info->metadata, metadata);
2227 permission = calloc(1, sizeof(permission_x));
2228 LISTADD(info->svcapp_info->permission, permission);
2229 for(i = 0; i < ncols; i++)
2231 if (strcmp(colname[i], "app_id") == 0) {
2232 /*appid being foreign key, is column in every table
2233 Hence appid gets strduped every time leading to memory leak.
2234 If appid is already set, just continue.*/
2235 if (info->svcapp_info->appid)
2238 info->svcapp_info->appid = strdup(coltxt[i]);
2240 info->svcapp_info->appid = NULL;
2241 } else if (strcmp(colname[i], "app_exec") == 0) {
2243 info->svcapp_info->exec = strdup(coltxt[i]);
2245 info->svcapp_info->exec = NULL;
2246 } else if (strcmp(colname[i], "app_icon") == 0) {
2248 info->svcapp_info->icon->text = strdup(coltxt[i]);
2250 info->svcapp_info->icon->text = NULL;
2251 } else if (strcmp(colname[i], "app_label") == 0 ) {
2253 info->svcapp_info->label->text = strdup(coltxt[i]);
2255 info->svcapp_info->label->text = NULL;
2256 } else if (strcmp(colname[i], "app_type") == 0 ) {
2258 info->svcapp_info->type = strdup(coltxt[i]);
2260 info->svcapp_info->type = NULL;
2261 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2263 info->svcapp_info->onboot = strdup(coltxt[i]);
2265 info->svcapp_info->onboot = NULL;
2266 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2268 info->svcapp_info->autorestart = strdup(coltxt[i]);
2270 info->svcapp_info->autorestart = NULL;
2271 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2273 info->svcapp_info->enabled= strdup(coltxt[i]);
2275 info->svcapp_info->enabled = NULL;
2276 } else if (strcmp(colname[i], "category") == 0 ) {
2278 info->svcapp_info->category->name = strdup(coltxt[i]);
2280 info->svcapp_info->category->name = NULL;
2281 } else if (strcmp(colname[i], "md_key") == 0 ) {
2283 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2285 info->svcapp_info->metadata->key = NULL;
2286 } else if (strcmp(colname[i], "md_value") == 0 ) {
2288 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2290 info->svcapp_info->metadata->value = NULL;
2291 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2293 info->svcapp_info->permission->type= strdup(coltxt[i]);
2295 info->svcapp_info->permission->type = NULL;
2296 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2298 info->svcapp_info->permission->value = strdup(coltxt[i]);
2300 info->svcapp_info->permission->value = NULL;
2301 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2303 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2304 info->svcapp_info->label->lang = strdup(coltxt[i]);
2307 info->svcapp_info->icon->lang = NULL;
2308 info->svcapp_info->label->lang = NULL;
2310 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2312 info->svcapp_info->permission_type = strdup(coltxt[i]);
2314 info->svcapp_info->permission_type = NULL;
2327 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2329 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2331 for(i = 0; i < ncols; i++)
2333 if (strcmp(colname[i], "app_component") == 0) {
2334 info->app_component = __appcomponent_convert(coltxt[i]);
2335 } else if (strcmp(colname[i], "package") == 0) {
2336 info->package = strdup(coltxt[i]);
2343 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2345 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2347 for(i = 0; i < ncols; i++)
2349 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2351 info->appid = strdup(coltxt[i]);
2354 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2356 info->access = strdup(coltxt[i]);
2358 info->access = NULL;
2365 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2367 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2370 for(i = 0; i < ncols; i++)
2372 if (strcmp(colname[i], "author_signer_cert") == 0) {
2374 info->cert_id = atoi(coltxt[i]);
2377 } else if (strcmp(colname[i], "package") == 0) {
2379 info->pkgid= strdup(coltxt[i]);
2388 /* get the first locale value*/
2389 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2391 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2394 info->locale = strdup(coltxt[0]);
2396 info->locale = NULL;
2401 static int __exec_pkginfo_query(char *query, void *data)
2403 char *error_message = NULL;
2405 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
2406 _LOGE("Don't execute query = %s error message = %s\n", query,
2408 sqlite3_free(error_message);
2411 sqlite3_free(error_message);
2415 static int __exec_certinfo_query(char *query, void *data)
2417 char *error_message = NULL;
2419 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
2420 _LOGE("Don't execute query = %s error message = %s\n", query,
2422 sqlite3_free(error_message);
2425 sqlite3_free(error_message);
2429 static int __exec_certindexinfo_query(char *query, void *data)
2431 char *error_message = NULL;
2433 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
2434 _LOGE("Don't execute query = %s error message = %s\n", query,
2436 sqlite3_free(error_message);
2439 sqlite3_free(error_message);
2443 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2445 char *error_message = NULL;
2447 sqlite3_exec(db, query, callback, data, &error_message)) {
2448 _LOGE("Don't execute query = %s error message = %s\n", query,
2450 sqlite3_free(error_message);
2453 sqlite3_free(error_message);
2458 static int __child_element(xmlTextReaderPtr reader, int depth)
2460 int ret = xmlTextReaderRead(reader);
2461 int cur = xmlTextReaderDepth(reader);
2464 switch (xmlTextReaderNodeType(reader)) {
2465 case XML_READER_TYPE_ELEMENT:
2466 if (cur == depth + 1)
2469 case XML_READER_TYPE_TEXT:
2470 /*text is handled by each function separately*/
2471 if (cur == depth + 1)
2474 case XML_READER_TYPE_END_ELEMENT:
2483 ret = xmlTextReaderRead(reader);
2484 cur = xmlTextReaderDepth(reader);
2489 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2491 int *p = (int*)data;
2492 *p = atoi(coltxt[0]);
2496 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2498 int result_query = -1;
2500 char query[MAX_QUERY_LEN];
2502 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);
2503 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2504 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2505 return result_query;
2508 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2510 int result_query = -1;
2512 char wildcard[2] = {'%','\0'};
2513 char query[MAX_QUERY_LEN];
2514 char lang[3] = {'\0'};
2515 strncpy(lang, locale, LANGUAGE_LENGTH);
2517 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);
2518 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2519 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2520 return result_query;
2523 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2526 char wildcard[2] = {'%','\0'};
2527 char lang[3] = {'\0'};
2528 char query[MAX_QUERY_LEN];
2529 char *locale_new = NULL;
2530 pkgmgr_locale_x *info = NULL;
2532 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2534 _LOGE("Out of Memory!!!\n");
2537 memset(info, '\0', sizeof(*info));
2539 strncpy(lang, locale, 2);
2540 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);
2541 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2542 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2543 locale_new = info->locale;
2554 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2556 char *locale = malloc(6);
2558 _LOGE("Malloc Failed\n");
2562 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2566 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2571 char *locale = NULL;
2572 char *locale_new = NULL;
2573 int check_result = 0;
2575 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2577 /*check exact matching */
2578 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2581 if (check_result == 1) {
2582 _LOGD("%s find exact locale(%s)\n", appid, locale);
2586 /* fallback matching */
2587 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2588 if(check_result == 1) {
2589 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2591 if (locale_new == NULL)
2592 locale_new = strdup(DEFAULT_LOCALE);
2596 /* default locale */
2598 return strdup(DEFAULT_LOCALE);
2601 long long _pkgmgr_calculate_dir_size(char *dirname)
2603 long long total = 0;
2605 int q = 0; /*quotient*/
2606 int r = 0; /*remainder*/
2608 struct dirent *ep = NULL;
2609 struct stat fileinfo;
2610 char abs_filename[FILENAME_MAX] = { 0, };
2611 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2613 dp = opendir(dirname);
2615 while ((ep = readdir(dp)) != NULL) {
2616 if (!strcmp(ep->d_name, ".") ||
2617 !strcmp(ep->d_name, "..")) {
2620 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2622 if (lstat(abs_filename, &fileinfo) < 0)
2623 perror(abs_filename);
2625 if (S_ISDIR(fileinfo.st_mode)) {
2626 total += fileinfo.st_size;
2627 if (strcmp(ep->d_name, ".")
2628 && strcmp(ep->d_name, "..")) {
2629 ret = _pkgmgr_calculate_dir_size
2631 total = total + ret;
2633 } else if (S_ISLNK(fileinfo.st_mode)) {
2636 /*It is a file. Calculate the actual
2637 size occupied (in terms of 4096 blocks)*/
2638 q = (fileinfo.st_size / BLOCK_SIZE);
2639 r = (fileinfo.st_size % BLOCK_SIZE);
2643 total += q * BLOCK_SIZE;
2649 _LOGE("Couldn't open the directory\n");
2656 static int __delete_certinfo(const char *pkgid)
2662 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2663 char *error_message = NULL;
2664 char query[MAX_QUERY_LEN] = {'\0'};
2665 pkgmgr_certinfo_x *certinfo = NULL;
2666 pkgmgr_certindexinfo_x *indexinfo = NULL;
2667 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2668 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2669 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2670 if (indexinfo == NULL) {
2671 _LOGE("Out of Memory!!!");
2672 ret = PMINFO_R_ERROR;
2675 /*populate certinfo from DB*/
2676 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2677 ret = __exec_certinfo_query(query, (void *)certinfo);
2679 _LOGE("Package Cert Info DB Information retrieval failed\n");
2680 ret = PMINFO_R_ERROR;
2683 /*Update cert index table*/
2684 for (i = 0; i < MAX_CERT_TYPE; i++) {
2685 if ((certinfo->cert_id)[i]) {
2686 for (j = 0; j < MAX_CERT_TYPE; j++) {
2687 if ((certinfo->cert_id)[i] == unique_id[j]) {
2688 /*Ref count has already been updated. Just continue*/
2692 if (j == MAX_CERT_TYPE)
2693 unique_id[c++] = (certinfo->cert_id)[i];
2696 memset(query, '\0', MAX_QUERY_LEN);
2697 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2698 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2700 _LOGE("Cert Info DB Information retrieval failed\n");
2701 ret = PMINFO_R_ERROR;
2704 memset(query, '\0', MAX_QUERY_LEN);
2705 if (indexinfo->cert_ref_count > 1) {
2706 /*decrease ref count*/
2707 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2708 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2710 /*delete this certificate as ref count is 1 and it will become 0*/
2711 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2714 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2715 _LOGE("Don't execute query = %s error message = %s\n", query,
2717 sqlite3_free(error_message);
2718 ret = PMINFO_R_ERROR;
2723 /*Now delete the entry from db*/
2724 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2726 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2727 _LOGE("Don't execute query = %s error message = %s\n", query,
2729 sqlite3_free(error_message);
2730 ret = PMINFO_R_ERROR;
2739 if (certinfo->pkgid) {
2740 free(certinfo->pkgid);
2741 certinfo->pkgid = NULL;
2743 for (i = 0; i < MAX_CERT_TYPE; i++) {
2744 if ((certinfo->cert_info)[i]) {
2745 free((certinfo->cert_info)[i]);
2746 (certinfo->cert_info)[i] = NULL;
2754 static int __get_pkg_location(const char *pkgid)
2756 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2759 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2760 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2762 /*check whether application is in external memory or not */
2763 fp = fopen(pkg_mmc_path, "r");
2767 return PMINFO_EXTERNAL_STORAGE;
2770 return PMINFO_INTERNAL_STORAGE;
2773 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2775 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2776 char *error_message = NULL;
2777 int ret = PMINFO_R_OK;
2778 char query[MAX_QUERY_LEN] = {'\0'};
2779 char *syslocale = NULL;
2780 char *locale = NULL;
2781 pkgmgr_pkginfo_x *pkginfo = NULL;
2782 label_x *tmp1 = NULL;
2783 icon_x *tmp2 = NULL;
2784 description_x *tmp3 = NULL;
2785 author_x *tmp4 = NULL;
2786 privilege_x *tmp5 = NULL;
2788 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2789 if (syslocale == NULL) {
2790 _LOGE("current locale is NULL\n");
2791 return PMINFO_R_ERROR;
2793 locale = __convert_system_locale_to_manifest_locale(syslocale);
2794 if (locale == NULL) {
2795 _LOGE("manifest locale is NULL\n");
2797 return PMINFO_R_ERROR;
2800 ret = __open_manifest_db(uid);
2802 _LOGE("Fail to open manifest DB\n");
2805 return PMINFO_R_ERROR;
2807 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2808 pkgmgr_pkginfo_x *node = NULL;
2809 pkgmgr_pkginfo_x *temp_node = NULL;
2811 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2813 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2814 _LOGE("Don't execute query = %s error message = %s\n", query,
2816 sqlite3_free(error_message);
2817 sqlite3_close(manifest_db);
2818 ret = PMINFO_R_ERROR;
2822 LISTHEAD(tmphead, node);
2824 for(node = node->next; node ; node = node->next) {
2826 pkginfo->locale = strdup(locale);
2827 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2828 if (pkginfo->manifest_info->privileges == NULL) {
2829 _LOGE("Failed to allocate memory for privileges info\n");
2830 ret = PMINFO_R_ERROR;
2833 /*populate manifest_info from DB*/
2834 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2835 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2837 _LOGE("Package Info DB Information retrieval failed\n");
2838 ret = PMINFO_R_ERROR;
2841 memset(query, '\0', MAX_QUERY_LEN);
2842 /*populate privilege_info from DB*/
2843 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2844 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2846 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2847 ret = PMINFO_R_ERROR;
2850 memset(query, '\0', MAX_QUERY_LEN);
2851 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2852 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2853 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2855 _LOGE("Package Info DB Information retrieval failed\n");
2856 ret = PMINFO_R_ERROR;
2859 /*Also store the values corresponding to default locales*/
2860 memset(query, '\0', MAX_QUERY_LEN);
2861 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2862 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2863 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2865 _LOGE("Package Info DB Information retrieval failed\n");
2866 ret = PMINFO_R_ERROR;
2869 if (pkginfo->manifest_info->label) {
2870 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2871 pkginfo->manifest_info->label = tmp1;
2873 if (pkginfo->manifest_info->icon) {
2874 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2875 pkginfo->manifest_info->icon = tmp2;
2877 if (pkginfo->manifest_info->description) {
2878 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2879 pkginfo->manifest_info->description = tmp3;
2881 if (pkginfo->manifest_info->author) {
2882 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2883 pkginfo->manifest_info->author = tmp4;
2885 if (pkginfo->manifest_info->privileges->privilege) {
2886 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2887 pkginfo->manifest_info->privileges->privilege = tmp5;
2891 LISTHEAD(tmphead, node);
2893 for(node = node->next; node ; node = node->next) {
2896 ret = pkg_list_cb( (void *)pkginfo, user_data);
2904 sqlite3_close(manifest_db);
2913 LISTHEAD(tmphead, node);
2914 temp_node = node->next;
2917 temp_node = node->next;
2918 __cleanup_pkginfo(node);
2921 __cleanup_pkginfo(tmphead);
2925 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2927 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2930 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2932 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2933 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2934 pkgmgr_pkginfo_x *pkginfo = NULL;
2935 int ret = PMINFO_R_OK;
2936 char query[MAX_QUERY_LEN] = {'\0'};
2937 char *syslocale = NULL;
2938 char *locale = NULL;
2940 label_x *tmp1 = NULL;
2941 icon_x *tmp2 = NULL;
2942 description_x *tmp3 = NULL;
2943 author_x *tmp4 = NULL;
2944 privilege_x *tmp5 = NULL;
2945 const char* user_pkg_parser = NULL;
2950 user_pkg_parser = getUserPkgParserDBPathUID(uid);
2951 ret = __open_manifest_db(uid);
2952 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
2954 /*check pkgid exist on db*/
2955 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2956 ret = __exec_db_query(manifest_db, query, __validate_cb, (void *)&exist);
2957 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2958 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2960 /*get system locale*/
2961 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2962 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2964 /*get locale on db*/
2965 locale = __convert_system_locale_to_manifest_locale(syslocale);
2966 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2968 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2969 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2971 pkginfo->locale = strdup(locale);
2973 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2974 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2976 pkginfo->manifest_info->package = strdup(pkgid);
2977 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2978 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2980 /*populate manifest_info from DB*/
2981 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2982 ret = __exec_db_query(manifest_db, query, __pkginfo_cb, (void *)pkginfo);
2983 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2985 memset(query, '\0', MAX_QUERY_LEN);
2986 /*populate privilege_info from DB*/
2987 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2988 ret = __exec_db_query(manifest_db, query, __pkginfo_cb, (void *)pkginfo);
2989 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2991 memset(query, '\0', MAX_QUERY_LEN);
2992 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2993 " package='%s' and package_locale='%s'", pkgid, locale);
2994 ret = __exec_db_query(manifest_db, query, __pkginfo_cb, (void *)pkginfo);
2995 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2997 /*Also store the values corresponding to default locales*/
2998 memset(query, '\0', MAX_QUERY_LEN);
2999 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3000 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
3001 ret = __exec_db_query(manifest_db, query, __pkginfo_cb, (void *)pkginfo);
3002 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3004 if (pkginfo->manifest_info->label) {
3005 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3006 pkginfo->manifest_info->label = tmp1;
3008 if (pkginfo->manifest_info->icon) {
3009 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3010 pkginfo->manifest_info->icon = tmp2;
3012 if (pkginfo->manifest_info->description) {
3013 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3014 pkginfo->manifest_info->description = tmp3;
3016 if (pkginfo->manifest_info->author) {
3017 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3018 pkginfo->manifest_info->author = tmp4;
3020 if (pkginfo->manifest_info->privileges->privilege) {
3021 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3022 pkginfo->manifest_info->privileges->privilege = tmp5;
3026 if (ret == PMINFO_R_OK)
3027 *handle = (void*)pkginfo;
3030 __cleanup_pkginfo(pkginfo);
3032 sqlite3_close(manifest_db);
3045 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3047 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3050 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3052 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3053 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3054 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3055 if (info->manifest_info->package)
3056 *pkg_name = (char *)info->manifest_info->package;
3058 return PMINFO_R_ERROR;
3063 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3065 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3066 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3067 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3068 if (info->manifest_info->package)
3069 *pkgid = (char *)info->manifest_info->package;
3071 return PMINFO_R_ERROR;
3076 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3078 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3079 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3080 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3081 if (info->manifest_info->type)
3082 *type = (char *)info->manifest_info->type;
3088 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3090 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3091 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3092 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3093 *version = (char *)info->manifest_info->version;
3097 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3099 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3100 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3102 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3103 val = (char *)info->manifest_info->installlocation;
3105 if (strcmp(val, "internal-only") == 0)
3106 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3107 else if (strcmp(val, "prefer-external") == 0)
3108 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3110 *location = PMINFO_INSTALL_LOCATION_AUTO;
3115 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3117 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3118 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3120 char *location = NULL;
3121 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3122 location = (char *)info->manifest_info->installlocation;
3123 val = (char *)info->manifest_info->package_size;
3128 _LOGE("package size is not specified\n");
3129 return PMINFO_R_ERROR;
3134 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3136 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3137 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3140 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3141 long long rw_size = 0;
3142 long long ro_size= 0;
3143 long long tmp_size= 0;
3144 long long total_size= 0;
3145 struct stat fileinfo;
3148 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3150 return PMINFO_R_ERROR;
3153 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3154 if (lstat(device_path, &fileinfo) == 0) {
3155 if (!S_ISLNK(fileinfo.st_mode)) {
3156 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3158 rw_size += tmp_size;
3162 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3163 if (lstat(device_path, &fileinfo) == 0) {
3164 if (!S_ISLNK(fileinfo.st_mode)) {
3165 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3167 rw_size += tmp_size;
3171 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3172 if (lstat(device_path, &fileinfo) == 0) {
3173 if (!S_ISLNK(fileinfo.st_mode)) {
3174 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3176 rw_size += tmp_size;
3180 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3181 if (lstat(device_path, &fileinfo) == 0) {
3182 if (!S_ISLNK(fileinfo.st_mode)) {
3183 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3185 rw_size += tmp_size;
3189 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3190 if (lstat(device_path, &fileinfo) == 0) {
3191 if (!S_ISLNK(fileinfo.st_mode)) {
3192 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3194 rw_size += tmp_size;
3198 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3199 if (lstat(device_path, &fileinfo) == 0) {
3200 if (!S_ISLNK(fileinfo.st_mode)) {
3201 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3203 rw_size += tmp_size;
3208 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3209 if (lstat(device_path, &fileinfo) == 0) {
3210 if (!S_ISLNK(fileinfo.st_mode)) {
3211 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3213 ro_size += tmp_size;
3217 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3218 if (lstat(device_path, &fileinfo) == 0) {
3219 if (!S_ISLNK(fileinfo.st_mode)) {
3220 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3222 ro_size += tmp_size;
3226 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3227 if (lstat(device_path, &fileinfo) == 0) {
3228 if (!S_ISLNK(fileinfo.st_mode)) {
3229 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3231 ro_size += tmp_size;
3235 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3236 if (lstat(device_path, &fileinfo) == 0) {
3237 if (!S_ISLNK(fileinfo.st_mode)) {
3238 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3240 ro_size += tmp_size;
3244 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3245 if (lstat(device_path, &fileinfo) == 0) {
3246 if (!S_ISLNK(fileinfo.st_mode)) {
3247 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3249 ro_size += tmp_size;
3253 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3254 if (lstat(device_path, &fileinfo) == 0) {
3255 if (!S_ISLNK(fileinfo.st_mode)) {
3256 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3258 ro_size += tmp_size;
3263 total_size = rw_size + ro_size;
3264 *size = (int)total_size;
3269 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3271 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3272 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3275 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3276 long long total_size= 0;
3279 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3281 return PMINFO_R_ERROR;
3283 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3284 if (access(device_path, R_OK) == 0)
3285 total_size = _pkgmgr_calculate_dir_size(device_path);
3287 return PMINFO_R_ERROR;
3289 *size = (int)total_size;
3294 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3297 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3298 int ret = PMINFO_R_OK;
3299 char *locale = NULL;
3303 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3305 locale = info->locale;
3306 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3308 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3311 if (strcmp(ptr->lang, locale) == 0) {
3312 *icon = (char *)ptr->text;
3313 if (strcasecmp(*icon, "(null)") == 0) {
3314 locale = DEFAULT_LOCALE;
3318 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3319 *icon = (char *)ptr->text;
3328 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3330 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3331 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3332 int ret = PMINFO_R_OK;
3333 char *locale = NULL;
3334 label_x *ptr = NULL;
3337 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3338 locale = info->locale;
3339 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3341 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3344 if (strcmp(ptr->lang, locale) == 0) {
3345 *label = (char *)ptr->text;
3346 if (strcasecmp(*label, "(null)") == 0) {
3347 locale = DEFAULT_LOCALE;
3351 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3352 *label = (char *)ptr->text;
3361 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3363 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3364 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3365 char *locale = NULL;
3366 description_x *ptr = NULL;
3367 *description = NULL;
3369 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3370 locale = info->locale;
3371 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3373 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3376 if (strcmp(ptr->lang, locale) == 0) {
3377 *description = (char *)ptr->text;
3378 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3379 locale = DEFAULT_LOCALE;
3383 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3384 *description = (char *)ptr->text;
3392 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3394 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3395 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3396 char *locale = NULL;
3397 author_x *ptr = NULL;
3398 *author_name = NULL;
3400 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3401 locale = info->locale;
3402 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3404 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3407 if (strcmp(ptr->lang, locale) == 0) {
3408 *author_name = (char *)ptr->text;
3409 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3410 locale = DEFAULT_LOCALE;
3414 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3415 *author_name = (char *)ptr->text;
3423 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3425 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3426 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3427 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3428 *author_email = (char *)info->manifest_info->author->email;
3432 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3434 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3435 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3436 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3437 *author_href = (char *)info->manifest_info->author->href;
3441 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3443 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3444 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3446 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3448 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3449 *storage = PMINFO_INTERNAL_STORAGE;
3450 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3451 *storage = PMINFO_EXTERNAL_STORAGE;
3453 return PMINFO_R_ERROR;
3458 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3460 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3461 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3462 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3463 if (info->manifest_info->installed_time)
3464 *installed_time = atoi(info->manifest_info->installed_time);
3466 return PMINFO_R_ERROR;
3471 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3473 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3474 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3475 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3476 *storeclientid = (char *)info->manifest_info->storeclient_id;
3480 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3483 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3484 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3485 *mainappid = (char *)info->manifest_info->mainapp_id;
3489 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3491 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3492 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3493 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3494 *url = (char *)info->manifest_info->package_url;
3498 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3500 const char *val = NULL;
3501 const xmlChar *node;
3502 xmlTextReaderPtr reader;
3503 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3504 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3507 reader = xmlReaderForFile(manifest, NULL, 0);
3510 if (__child_element(reader, -1)) {
3511 node = xmlTextReaderConstName(reader);
3513 _LOGE("xmlTextReaderConstName value is NULL\n");
3514 xmlFreeTextReader(reader);
3516 return PMINFO_R_ERROR;
3519 if (!strcmp(ASC_CHAR(node), "manifest")) {
3520 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3521 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3527 _LOGE("package size is not specified\n");
3528 xmlFreeTextReader(reader);
3530 return PMINFO_R_ERROR;
3533 _LOGE("Unable to create xml reader\n");
3534 xmlFreeTextReader(reader);
3536 return PMINFO_R_ERROR;
3540 _LOGE("xmlReaderForFile value is NULL\n");
3542 return PMINFO_R_ERROR;
3545 xmlFreeTextReader(reader);
3551 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3553 const char *val = NULL;
3554 const xmlChar *node;
3555 xmlTextReaderPtr reader;
3556 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3557 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3560 reader = xmlReaderForFile(manifest, NULL, 0);
3563 if ( __child_element(reader, -1)) {
3564 node = xmlTextReaderConstName(reader);
3566 _LOGE("xmlTextReaderConstName value is NULL\n");
3567 xmlFreeTextReader(reader);
3569 return PMINFO_R_ERROR;
3572 if (!strcmp(ASC_CHAR(node), "manifest")) {
3573 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3574 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3577 if (strcmp(val, "internal-only") == 0)
3578 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3579 else if (strcmp(val, "prefer-external") == 0)
3580 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3582 *location = PMINFO_INSTALL_LOCATION_AUTO;
3585 _LOGE("Unable to create xml reader\n");
3586 xmlFreeTextReader(reader);
3588 return PMINFO_R_ERROR;
3592 _LOGE("xmlReaderForFile value is NULL\n");
3594 return PMINFO_R_ERROR;
3597 xmlFreeTextReader(reader);
3604 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3607 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3609 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3610 if (info->manifest_info->root_path)
3611 *path = (char *)info->manifest_info->root_path;
3613 return PMINFO_R_ERROR;
3618 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3620 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3621 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3623 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3624 if (info->manifest_info->csc_path)
3625 *path = (char *)info->manifest_info->csc_path;
3627 *path = (char *)info->manifest_info->csc_path;
3632 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)
3634 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3635 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3636 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3638 int ret = PMINFO_R_OK;
3639 char query[MAX_QUERY_LEN] = {'\0'};
3640 char *error_message = NULL;
3641 pkgmgr_cert_x *info= NULL;
3645 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3646 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3647 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3649 ret = __open_cert_db(uid);
3651 ret = PMINFO_R_ERROR;
3654 _check_create_Cert_db(cert_db);
3655 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3657 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3658 _LOGE("Don't execute query = %s error message = %s\n", query,
3660 ret = PMINFO_R_ERROR;
3667 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3669 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3670 _LOGE("Don't execute query = %s error message = %s\n", query,
3672 ret = PMINFO_R_ERROR;
3675 lcert = info->cert_id;
3678 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3680 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3681 _LOGE("Don't execute query = %s error message = %s\n", query,
3683 ret = PMINFO_R_ERROR;
3690 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3692 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3693 _LOGE("Don't execute query = %s error message = %s\n", query,
3695 ret = PMINFO_R_ERROR;
3698 rcert = info->cert_id;
3701 if ((lcert == 0) || (rcert == 0))
3703 if ((lcert == 0) && (rcert == 0))
3704 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3705 else if (lcert == 0)
3706 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3707 else if (rcert == 0)
3708 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3711 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3713 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3717 sqlite3_free(error_message);
3718 sqlite3_close(cert_db);
3730 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)
3732 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3735 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)
3737 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3738 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3739 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3741 int ret = PMINFO_R_OK;
3742 char query[MAX_QUERY_LEN] = {'\0'};
3743 char *error_message = NULL;
3744 pkgmgr_cert_x *info= NULL;
3746 char *lpkgid = NULL;
3747 char *rpkgid = NULL;
3748 const char* user_pkg_parser = getUserPkgParserDBPath();
3750 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3751 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3753 ret = db_util_open_with_options(user_pkg_parser, &manifest_db,
3754 SQLITE_OPEN_READONLY, NULL);
3755 if (ret != SQLITE_OK) {
3756 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3757 ret = PMINFO_R_ERROR;
3761 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3763 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3764 _LOGE("Don't execute query = %s error message = %s\n", query,
3766 ret = PMINFO_R_ERROR;
3773 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3775 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3776 _LOGE("Don't execute query = %s error message = %s\n", query,
3778 ret = PMINFO_R_ERROR;
3781 lpkgid = strdup(info->pkgid);
3782 if (lpkgid == NULL) {
3783 _LOGE("Out of Memory\n");
3784 ret = PMINFO_R_ERROR;
3791 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3793 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3794 _LOGE("Don't execute query = %s error message = %s\n", query,
3796 ret = PMINFO_R_ERROR;
3803 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3805 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3806 _LOGE("Don't execute query = %s error message = %s\n", query,
3808 ret = PMINFO_R_ERROR;
3811 rpkgid = strdup(info->pkgid);
3812 if (rpkgid == NULL) {
3813 _LOGE("Out of Memory\n");
3814 ret = PMINFO_R_ERROR;
3820 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3822 sqlite3_free(error_message);
3823 sqlite3_close(manifest_db);
3843 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)
3845 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3846 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3847 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3849 int ret = PMINFO_R_OK;
3850 char query[MAX_QUERY_LEN] = {'\0'};
3851 char *error_message = NULL;
3852 pkgmgr_cert_x *info= NULL;
3854 char *lpkgid = NULL;
3855 char *rpkgid = NULL;
3857 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3858 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3860 ret = __open_manifest_db(uid);
3861 if (ret != SQLITE_OK) {
3862 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3863 ret = PMINFO_R_ERROR;
3867 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3869 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3870 _LOGE("Don't execute query = %s error message = %s\n", query,
3872 ret = PMINFO_R_ERROR;
3879 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3881 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3882 _LOGE("Don't execute query = %s error message = %s\n", query,
3884 ret = PMINFO_R_ERROR;
3887 lpkgid = strdup(info->pkgid);
3888 if (lpkgid == NULL) {
3889 _LOGE("Out of Memory\n");
3890 ret = PMINFO_R_ERROR;
3897 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3899 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3900 _LOGE("Don't execute query = %s error message = %s\n", query,
3902 ret = PMINFO_R_ERROR;
3909 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3911 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3912 _LOGE("Don't execute query = %s error message = %s\n", query,
3914 ret = PMINFO_R_ERROR;
3917 rpkgid = strdup(info->pkgid);
3918 if (rpkgid == NULL) {
3919 _LOGE("Out of Memory\n");
3920 ret = PMINFO_R_ERROR;
3926 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3928 sqlite3_free(error_message);
3929 sqlite3_close(manifest_db);
3949 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3951 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3952 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3954 #if 0 //smack issue occured, check later
3956 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3958 _LOGD("invalid func parameters\n");
3959 return PMINFO_R_ERROR;
3961 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3964 char app_mmc_path[FILENAME_MAX] = { 0, };
3965 char app_dir_path[FILENAME_MAX] = { 0, };
3966 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3967 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3968 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3969 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3971 /*check whether application is in external memory or not */
3972 fp = fopen(app_mmc_path, "r");
3974 _LOGD(" app path in external memory not accesible\n");
3979 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3983 /*check whether application is in internal or not */
3984 fp = fopen(app_dir_path, "r");
3986 _LOGD(" app path in internal memory not accesible\n");
3988 return PMINFO_R_ERROR;
3991 /*check whether the application is installed in SD card
3992 but SD card is not present*/
3993 fp = fopen(app_mmc_internal_path, "r");
3996 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
4001 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
4006 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
4013 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
4015 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4016 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4018 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4019 val = (char *)info->manifest_info->removable;
4021 if (strcasecmp(val, "true") == 0)
4023 else if (strcasecmp(val, "false") == 0)
4031 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4033 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4034 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4037 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4039 val = (char *)info->manifest_info->installlocation;
4041 if (strcmp(val, "internal-only") == 0)
4043 else if (strcmp(val, "prefer-external") == 0)
4052 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4054 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4055 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4057 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4058 val = (char *)info->manifest_info->preload;
4060 if (strcasecmp(val, "true") == 0)
4062 else if (strcasecmp(val, "false") == 0)
4070 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4072 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4073 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4076 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4077 val = (char *)info->manifest_info->system;
4079 if (strcasecmp(val, "true") == 0)
4081 else if (strcasecmp(val, "false") == 0)
4090 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4092 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4093 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4095 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4096 val = (char *)info->manifest_info->readonly;
4098 if (strcasecmp(val, "true") == 0)
4100 else if (strcasecmp(val, "false") == 0)
4108 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4110 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4111 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4114 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4115 val = (char *)info->manifest_info->update;
4117 if (strcasecmp(val, "true") == 0)
4119 else if (strcasecmp(val, "false") == 0)
4127 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4130 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4133 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4134 val = (char *)info->manifest_info->for_all_users;
4136 if (strcasecmp(val, "1") == 0)
4138 else if (strcasecmp(val, "0") == 0)
4147 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4149 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4150 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4151 __cleanup_pkginfo(info);
4155 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4159 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4160 if (filter == NULL) {
4161 _LOGE("Out of Memory!!!");
4162 return PMINFO_R_ERROR;
4168 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4170 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4171 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4173 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4174 g_slist_free(filter->list);
4181 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4182 const char *property, const int value)
4184 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4185 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4186 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4188 GSList *link = NULL;
4190 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4191 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4192 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4193 _LOGE("Invalid Integer Property\n");
4194 return PMINFO_R_EINVAL;
4196 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4197 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4199 _LOGE("Out of Memory!!!\n");
4200 return PMINFO_R_ERROR;
4202 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4203 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4205 _LOGE("Out of Memory\n");
4208 return PMINFO_R_ERROR;
4212 /*If API is called multiple times for same property, we should override the previous values.
4213 Last value set will be used for filtering.*/
4214 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4216 filter->list = g_slist_delete_link(filter->list, link);
4217 filter->list = g_slist_append(filter->list, (gpointer)node);
4222 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4223 const char *property, const bool value)
4225 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4226 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4228 GSList *link = NULL;
4230 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4231 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4232 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4233 _LOGE("Invalid Boolean Property\n");
4234 return PMINFO_R_EINVAL;
4236 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4237 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4239 _LOGE("Out of Memory!!!\n");
4240 return PMINFO_R_ERROR;
4243 val = strndup("('true','True')", 15);
4245 val = strndup("('false','False')", 17);
4247 _LOGE("Out of Memory\n");
4250 return PMINFO_R_ERROR;
4254 /*If API is called multiple times for same property, we should override the previous values.
4255 Last value set will be used for filtering.*/
4256 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4258 filter->list = g_slist_delete_link(filter->list, link);
4259 filter->list = g_slist_append(filter->list, (gpointer)node);
4264 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4265 const char *property, const char *value)
4267 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4268 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4269 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4271 GSList *link = NULL;
4273 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4274 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4275 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4276 _LOGE("Invalid String Property\n");
4277 return PMINFO_R_EINVAL;
4279 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4280 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4282 _LOGE("Out of Memory!!!\n");
4283 return PMINFO_R_ERROR;
4285 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4286 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4287 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4288 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4289 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4290 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4291 else if (strcmp(value, "installed_internal") == 0)
4292 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4293 else if (strcmp(value, "installed_external") == 0)
4294 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4296 val = strndup(value, PKG_STRING_LEN_MAX - 1);
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_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4317 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4318 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4319 char *syslocale = NULL;
4320 char *locale = NULL;
4321 char *condition = NULL;
4322 char *error_message = NULL;
4323 char query[MAX_QUERY_LEN] = {'\0'};
4324 char where[MAX_QUERY_LEN] = {'\0'};
4328 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4330 /*Get current locale*/
4331 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4332 if (syslocale == NULL) {
4333 _LOGE("current locale is NULL\n");
4334 return PMINFO_R_ERROR;
4336 locale = __convert_system_locale_to_manifest_locale(syslocale);
4337 if (locale == NULL) {
4338 _LOGE("manifest locale is NULL\n");
4340 return PMINFO_R_ERROR;
4343 ret = __open_manifest_db(uid);
4345 _LOGE("Fail to open manifest DB\n");
4348 return PMINFO_R_ERROR;
4351 /*Start constructing query*/
4352 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4354 /*Get where clause*/
4355 for (list = filter->list; list; list = g_slist_next(list)) {
4356 __get_filter_condition(list->data, &condition);
4358 strncat(where, condition, sizeof(where) - strlen(where) -1);
4359 where[sizeof(where) - 1] = '\0';
4363 if (g_slist_next(list)) {
4364 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4365 where[sizeof(where) - 1] = '\0';
4368 _LOGE("where = %s\n", where);
4369 if (strlen(where) > 0) {
4370 strncat(query, where, sizeof(query) - strlen(query) - 1);
4371 query[sizeof(query) - 1] = '\0';
4373 _LOGE("query = %s\n", query);
4377 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
4378 _LOGE("Don't execute query = %s error message = %s\n", query,
4380 sqlite3_free(error_message);
4381 sqlite3_close(manifest_db);
4382 ret = PMINFO_R_ERROR;
4396 sqlite3_close(manifest_db);
4400 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4402 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4405 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4406 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4408 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4409 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4410 char *syslocale = NULL;
4411 char *locale = NULL;
4412 char *condition = NULL;
4413 char *error_message = NULL;
4414 char query[MAX_QUERY_LEN] = {'\0'};
4415 char where[MAX_QUERY_LEN] = {'\0'};
4418 label_x *tmp1 = NULL;
4419 icon_x *tmp2 = NULL;
4420 description_x *tmp3 = NULL;
4421 author_x *tmp4 = NULL;
4422 privilege_x *tmp5 = NULL;
4423 pkgmgr_pkginfo_x *node = NULL;
4424 pkgmgr_pkginfo_x *tmphead = NULL;
4425 pkgmgr_pkginfo_x *pkginfo = NULL;
4427 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4428 /*Get current locale*/
4429 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4430 if (syslocale == NULL) {
4431 _LOGE("current locale is NULL\n");
4432 return PMINFO_R_ERROR;
4434 locale = __convert_system_locale_to_manifest_locale(syslocale);
4435 if (locale == NULL) {
4436 _LOGE("manifest locale is NULL\n");
4438 return PMINFO_R_ERROR;
4441 ret = __open_manifest_db(uid);
4443 _LOGE("Fail to open manifest DB\n");
4446 return PMINFO_R_ERROR;
4448 /*Start constructing query*/
4449 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4451 /*Get where clause*/
4452 for (list = filter->list; list; list = g_slist_next(list)) {
4453 __get_filter_condition(list->data, &condition);
4455 strncat(where, condition, sizeof(where) - strlen(where) -1);
4456 where[sizeof(where) - 1] = '\0';
4460 if (g_slist_next(list)) {
4461 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4462 where[sizeof(where) - 1] = '\0';
4465 _LOGE("where = %s\n", where);
4466 if (strlen(where) > 0) {
4467 strncat(query, where, sizeof(query) - strlen(query) - 1);
4468 query[sizeof(query) - 1] = '\0';
4470 _LOGE("query = %s\n", query);
4471 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4472 if (tmphead == NULL) {
4473 _LOGE("Out of Memory!!!\n");
4474 ret = PMINFO_R_ERROR;
4480 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4481 _LOGE("Don't execute query = %s error message = %s\n", query,
4483 sqlite3_free(error_message);
4484 ret = PMINFO_R_ERROR;
4488 LISTHEAD(tmphead, node);
4489 for(node = node->next ; node ; node = node->next) {
4491 pkginfo->locale = strdup(locale);
4492 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4493 if (pkginfo->manifest_info->privileges == NULL) {
4494 _LOGE("Failed to allocate memory for privileges info\n");
4495 ret = PMINFO_R_ERROR;
4499 /*populate manifest_info from DB*/
4500 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4501 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4503 _LOGE("Package Info DB Information retrieval failed\n");
4504 ret = PMINFO_R_ERROR;
4507 memset(query, '\0', MAX_QUERY_LEN);
4508 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4509 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4510 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4512 _LOGE("Package Info DB Information retrieval failed\n");
4513 ret = PMINFO_R_ERROR;
4516 /*Also store the values corresponding to default locales*/
4517 memset(query, '\0', MAX_QUERY_LEN);
4518 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4519 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4520 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4522 _LOGE("Package Info DB Information retrieval failed\n");
4523 ret = PMINFO_R_ERROR;
4526 if (pkginfo->manifest_info->label) {
4527 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4528 pkginfo->manifest_info->label = tmp1;
4530 if (pkginfo->manifest_info->icon) {
4531 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4532 pkginfo->manifest_info->icon = tmp2;
4534 if (pkginfo->manifest_info->description) {
4535 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4536 pkginfo->manifest_info->description = tmp3;
4538 if (pkginfo->manifest_info->author) {
4539 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4540 pkginfo->manifest_info->author = tmp4;
4542 if (pkginfo->manifest_info->privileges->privilege) {
4543 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4544 pkginfo->manifest_info->privileges->privilege = tmp5;
4548 LISTHEAD(tmphead, node);
4550 for(node = node->next ; node ; node = node->next) {
4553 ret = pkg_cb( (void *)pkginfo, user_data);
4568 sqlite3_close(manifest_db);
4569 __cleanup_pkginfo(tmphead);
4573 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4574 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4576 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4579 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4580 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4582 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4583 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4585 privilege_x *ptr = NULL;
4586 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4587 ptr = info->manifest_info->privileges->privilege;
4588 for (; ptr; ptr = ptr->next) {
4590 ret = privilege_func(ptr->text, user_data);
4598 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4599 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4601 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4602 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4603 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4605 char *syslocale = NULL;
4606 char *locale = NULL;
4608 char query[MAX_QUERY_LEN] = {'\0'};
4609 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4610 pkgmgr_pkginfo_x *allinfo = NULL;
4611 pkgmgr_appinfo_x *appinfo = NULL;
4612 icon_x *ptr1 = NULL;
4613 label_x *ptr2 = NULL;
4614 category_x *ptr3 = NULL;
4615 metadata_x *ptr4 = NULL;
4616 permission_x *ptr5 = NULL;
4617 image_x *ptr6 = NULL;
4618 const char* user_pkg_parser = NULL;
4620 /*get system locale*/
4621 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4622 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4624 /*get locale on db*/
4625 locale = __convert_system_locale_to_manifest_locale(syslocale);
4626 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4629 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4630 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4632 /*calloc manifest_info*/
4633 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4634 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4637 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4638 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4640 /*set component type*/
4641 if (component == PMINFO_UI_APP)
4642 appinfo->app_component = PMINFO_UI_APP;
4643 if (component == PMINFO_SVC_APP)
4644 appinfo->app_component = PMINFO_SVC_APP;
4645 if (component == PMINFO_ALL_APP)
4646 appinfo->app_component = PMINFO_ALL_APP;
4649 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4650 ret = __open_manifest_db(uid);
4651 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4653 appinfo->package = strdup(info->manifest_info->package);
4654 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4655 "from package_app_info where " \
4656 "package='%s' and app_component='%s'",
4657 info->manifest_info->package,
4658 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4662 /*Populate ui app info */
4663 ret = __exec_db_query(manifest_db, query, __uiapp_list_cb, (void *)info);
4664 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4666 uiapplication_x *tmp = NULL;
4667 if (info->manifest_info->uiapplication) {
4668 LISTHEAD(info->manifest_info->uiapplication, tmp);
4669 info->manifest_info->uiapplication = tmp;
4671 /*Populate localized info for default locales and call callback*/
4672 /*If the callback func return < 0 we break and no more call back is called*/
4675 appinfo->locale = strdup(locale);
4676 appinfo->uiapp_info = tmp;
4677 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4681 locale = __get_app_locale_by_fallback(manifest_db, appinfo->uiapp_info->appid, syslocale);
4684 memset(query, '\0', MAX_QUERY_LEN);
4685 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4686 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4687 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4689 memset(query, '\0', MAX_QUERY_LEN);
4690 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);
4691 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4692 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4694 /*store setting notification icon section*/
4695 memset(query, '\0', MAX_QUERY_LEN);
4696 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4697 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4698 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4700 /*store app preview image info*/
4701 memset(query, '\0', MAX_QUERY_LEN);
4702 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4703 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4704 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4706 if (appinfo->uiapp_info->label) {
4707 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4708 appinfo->uiapp_info->label = ptr2;
4710 if (appinfo->uiapp_info->icon) {
4711 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4712 appinfo->uiapp_info->icon = ptr1;
4714 if (appinfo->uiapp_info->category) {
4715 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4716 appinfo->uiapp_info->category = ptr3;
4718 if (appinfo->uiapp_info->metadata) {
4719 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4720 appinfo->uiapp_info->metadata = ptr4;
4722 if (appinfo->uiapp_info->permission) {
4723 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4724 appinfo->uiapp_info->permission = ptr5;
4726 if (appinfo->uiapp_info->image) {
4727 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4728 appinfo->uiapp_info->image = ptr6;
4730 ret = app_func((void *)appinfo, user_data);
4736 case PMINFO_SVC_APP:
4737 /*Populate svc app info */
4738 ret = __exec_db_query(manifest_db, query, __svcapp_list_cb, (void *)info);
4739 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4741 serviceapplication_x *tmp1 = NULL;
4742 if (info->manifest_info->serviceapplication) {
4743 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4744 info->manifest_info->serviceapplication = tmp1;
4746 /*Populate localized info for default locales and call callback*/
4747 /*If the callback func return < 0 we break and no more call back is called*/
4750 appinfo->locale = strdup(locale);
4751 appinfo->svcapp_info = tmp1;
4752 memset(query, '\0', MAX_QUERY_LEN);
4753 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4754 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4755 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4757 memset(query, '\0', MAX_QUERY_LEN);
4758 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);
4759 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4760 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4762 if (appinfo->svcapp_info->label) {
4763 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4764 appinfo->svcapp_info->label = ptr2;
4766 if (appinfo->svcapp_info->icon) {
4767 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4768 appinfo->svcapp_info->icon = ptr1;
4770 if (appinfo->svcapp_info->category) {
4771 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4772 appinfo->svcapp_info->category = ptr3;
4774 if (appinfo->svcapp_info->metadata) {
4775 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4776 appinfo->svcapp_info->metadata = ptr4;
4778 if (appinfo->svcapp_info->permission) {
4779 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4780 appinfo->svcapp_info->permission = ptr5;
4782 ret = app_func((void *)appinfo, user_data);
4788 case PMINFO_ALL_APP:
4789 memset(query, '\0', MAX_QUERY_LEN);
4790 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4792 /*Populate all app info */
4793 ret = __exec_db_query(manifest_db, query, __allapp_list_cb, (void *)allinfo);
4794 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4797 appinfo->app_component = PMINFO_UI_APP;
4798 uiapplication_x *tmp2 = NULL;
4799 if (allinfo->manifest_info->uiapplication) {
4800 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4801 allinfo->manifest_info->uiapplication = tmp2;
4803 /*Populate localized info for default locales and call callback*/
4804 /*If the callback func return < 0 we break and no more call back is called*/
4807 appinfo->locale = strdup(locale);
4808 appinfo->uiapp_info = tmp2;
4809 memset(query, '\0', MAX_QUERY_LEN);
4810 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4811 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4812 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4814 memset(query, '\0', MAX_QUERY_LEN);
4815 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);
4816 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4817 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4819 /*store setting notification icon section*/
4820 memset(query, '\0', MAX_QUERY_LEN);
4821 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4822 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4823 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4825 /*store app preview image info*/
4826 memset(query, '\0', MAX_QUERY_LEN);
4827 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4828 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4829 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4831 if (appinfo->uiapp_info->label) {
4832 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4833 appinfo->uiapp_info->label = ptr2;
4835 if (appinfo->uiapp_info->icon) {
4836 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4837 appinfo->uiapp_info->icon = ptr1;
4839 if (appinfo->uiapp_info->category) {
4840 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4841 appinfo->uiapp_info->category = ptr3;
4843 if (appinfo->uiapp_info->metadata) {
4844 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4845 appinfo->uiapp_info->metadata = ptr4;
4847 if (appinfo->uiapp_info->permission) {
4848 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4849 appinfo->uiapp_info->permission = ptr5;
4851 if (appinfo->uiapp_info->image) {
4852 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4853 appinfo->uiapp_info->image = ptr6;
4855 ret = app_func((void *)appinfo, user_data);
4862 appinfo->app_component = PMINFO_SVC_APP;
4863 serviceapplication_x *tmp3 = NULL;
4864 if (allinfo->manifest_info->serviceapplication) {
4865 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4866 allinfo->manifest_info->serviceapplication = tmp3;
4868 /*Populate localized info for default locales and call callback*/
4869 /*If the callback func return < 0 we break and no more call back is called*/
4872 appinfo->locale = strdup(locale);
4873 appinfo->svcapp_info = tmp3;
4874 memset(query, '\0', MAX_QUERY_LEN);
4875 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4876 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4877 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4879 memset(query, '\0', MAX_QUERY_LEN);
4880 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);
4881 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
4882 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4884 if (appinfo->svcapp_info->label) {
4885 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4886 appinfo->svcapp_info->label = ptr2;
4888 if (appinfo->svcapp_info->icon) {
4889 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4890 appinfo->svcapp_info->icon = ptr1;
4892 if (appinfo->svcapp_info->category) {
4893 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4894 appinfo->svcapp_info->category = ptr3;
4896 if (appinfo->svcapp_info->metadata) {
4897 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4898 appinfo->svcapp_info->metadata = ptr4;
4900 if (appinfo->svcapp_info->permission) {
4901 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4902 appinfo->svcapp_info->permission = ptr5;
4904 ret = app_func((void *)appinfo, user_data);
4909 appinfo->app_component = PMINFO_ALL_APP;
4925 if (appinfo->package) {
4926 free((void *)appinfo->package);
4927 appinfo->package = NULL;
4932 __cleanup_pkginfo(allinfo);
4934 sqlite3_close(manifest_db);
4938 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4939 pkgmgrinfo_app_list_cb app_func, void *user_data)
4941 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4944 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4946 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4948 int ret = PMINFO_R_OK;
4949 char query[MAX_QUERY_LEN] = {'\0'};
4950 pkgmgr_appinfo_x *appinfo = NULL;
4951 uiapplication_x *ptr1 = NULL;
4952 serviceapplication_x *ptr2 = NULL;
4953 const char* user_pkg_parser = NULL;
4956 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4957 ret = __open_manifest_db(uid);
4958 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4961 pkgmgr_pkginfo_x *info = NULL;
4962 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4963 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4965 /*calloc manifest_info*/
4966 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4967 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4970 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4971 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4973 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4974 ret = __exec_db_query(manifest_db, query, __mini_appinfo_cb, (void *)info);
4975 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4977 if (info->manifest_info->uiapplication) {
4978 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4979 info->manifest_info->uiapplication = ptr1;
4981 if (info->manifest_info->serviceapplication) {
4982 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4983 info->manifest_info->serviceapplication = ptr2;
4987 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4989 appinfo->app_component = PMINFO_UI_APP;
4990 appinfo->package = strdup(ptr1->package);
4991 appinfo->uiapp_info = ptr1;
4993 ret = app_func((void *)appinfo, user_data);
4996 free((void *)appinfo->package);
4997 appinfo->package = NULL;
5000 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5002 appinfo->app_component = PMINFO_SVC_APP;
5003 appinfo->package = strdup(ptr2->package);
5004 appinfo->svcapp_info = ptr2;
5006 ret = app_func((void *)appinfo, user_data);
5009 free((void *)appinfo->package);
5010 appinfo->package = NULL;
5015 sqlite3_close(manifest_db);
5021 __cleanup_pkginfo(info);
5025 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5027 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
5030 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5032 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5034 int ret = PMINFO_R_OK;
5035 char query[MAX_QUERY_LEN] = {'\0'};
5036 char *syslocale = NULL;
5037 char *locale = NULL;
5038 pkgmgr_appinfo_x *appinfo = NULL;
5039 uiapplication_x *ptr1 = NULL;
5040 serviceapplication_x *ptr2 = NULL;
5041 label_x *tmp1 = NULL;
5042 icon_x *tmp2 = NULL;
5043 category_x *tmp3 = NULL;
5044 metadata_x *tmp4 = NULL;
5045 permission_x *tmp5 = NULL;
5046 image_x *tmp6 = NULL;
5047 const char *user_pkg_parser = NULL;
5049 /*get system locale*/
5050 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5051 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5053 /*get locale on db*/
5054 locale = __convert_system_locale_to_manifest_locale(syslocale);
5055 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5058 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5059 ret = __open_manifest_db(uid);
5060 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5063 pkgmgr_pkginfo_x *info = NULL;
5064 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5065 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5067 /*calloc manifest_info*/
5068 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5069 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5072 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5073 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5075 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5076 ret = __exec_db_query(manifest_db, query, __app_list_cb, (void *)info);
5077 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5079 if (info->manifest_info->uiapplication) {
5080 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5081 info->manifest_info->uiapplication = ptr1;
5083 if (info->manifest_info->serviceapplication) {
5084 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5085 info->manifest_info->serviceapplication = ptr2;
5089 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5091 appinfo->locale = strdup(locale);
5092 appinfo->app_component = PMINFO_UI_APP;
5093 appinfo->package = strdup(ptr1->package);
5094 appinfo->uiapp_info = ptr1;
5095 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5096 "from package_app_info where " \
5097 "app_id='%s'", ptr1->appid);
5098 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5099 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5101 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5105 locale = __get_app_locale_by_fallback(manifest_db, ptr1->appid, syslocale);
5108 memset(query, '\0', MAX_QUERY_LEN);
5109 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5110 "from package_app_localized_info where " \
5111 "app_id='%s' and app_locale='%s'",
5112 ptr1->appid, locale);
5113 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5114 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5116 memset(query, '\0', MAX_QUERY_LEN);
5117 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5118 "from package_app_localized_info where " \
5119 "app_id='%s' and app_locale='%s'",
5120 ptr1->appid, DEFAULT_LOCALE);
5122 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5123 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5125 /*store setting notification icon section*/
5126 memset(query, '\0', MAX_QUERY_LEN);
5127 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5128 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5129 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5131 /*store app preview image info*/
5132 memset(query, '\0', MAX_QUERY_LEN);
5133 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5134 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5135 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5137 if (appinfo->uiapp_info->label) {
5138 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5139 appinfo->uiapp_info->label = tmp1;
5141 if (appinfo->uiapp_info->icon) {
5142 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5143 appinfo->uiapp_info->icon= tmp2;
5145 if (appinfo->uiapp_info->category) {
5146 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5147 appinfo->uiapp_info->category = tmp3;
5149 if (appinfo->uiapp_info->metadata) {
5150 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5151 appinfo->uiapp_info->metadata = tmp4;
5153 if (appinfo->uiapp_info->permission) {
5154 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5155 appinfo->uiapp_info->permission = tmp5;
5157 if (appinfo->uiapp_info->image) {
5158 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5159 appinfo->uiapp_info->image = tmp6;
5161 ret = app_func((void *)appinfo, user_data);
5164 free((void *)appinfo->package);
5165 appinfo->package = NULL;
5168 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5170 appinfo->locale = strdup(locale);
5171 appinfo->app_component = PMINFO_SVC_APP;
5172 appinfo->package = strdup(ptr2->package);
5173 appinfo->svcapp_info = ptr2;
5174 memset(query, '\0', MAX_QUERY_LEN);
5175 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5176 "from package_app_info where " \
5177 "app_id='%s'", ptr2->appid);
5178 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5179 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5181 memset(query, '\0', MAX_QUERY_LEN);
5182 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5183 "from package_app_localized_info where " \
5184 "app_id='%s' and app_locale='%s'",
5185 ptr2->appid, locale);
5186 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5187 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5189 memset(query, '\0', MAX_QUERY_LEN);
5190 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5191 "from package_app_localized_info where " \
5192 "app_id='%s' and app_locale='%s'",
5193 ptr2->appid, DEFAULT_LOCALE);
5194 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5195 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5197 if (appinfo->svcapp_info->label) {
5198 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5199 appinfo->svcapp_info->label = tmp1;
5201 if (appinfo->svcapp_info->icon) {
5202 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5203 appinfo->svcapp_info->icon= tmp2;
5205 if (appinfo->svcapp_info->category) {
5206 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5207 appinfo->svcapp_info->category = tmp3;
5209 if (appinfo->svcapp_info->metadata) {
5210 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5211 appinfo->svcapp_info->metadata = tmp4;
5213 if (appinfo->svcapp_info->permission) {
5214 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5215 appinfo->svcapp_info->permission = tmp5;
5217 ret = app_func((void *)appinfo, user_data);
5220 free((void *)appinfo->package);
5221 appinfo->package = NULL;
5234 sqlite3_close(manifest_db);
5239 __cleanup_pkginfo(info);
5243 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5245 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5248 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5250 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5251 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5253 pkgmgr_appinfo_x *appinfo = NULL;
5254 char *syslocale = NULL;
5255 char *locale = NULL;
5258 label_x *tmp1 = NULL;
5259 icon_x *tmp2 = NULL;
5260 category_x *tmp3 = NULL;
5261 metadata_x *tmp4 = NULL;
5262 permission_x *tmp5 = NULL;
5263 image_x *tmp6 = NULL;
5264 char query[MAX_QUERY_LEN] = {'\0'};
5265 const char* user_pkg_parser = NULL;
5270 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5271 ret = __open_manifest_db(uid);
5272 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5274 /*check appid exist on db*/
5275 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5276 ret = __exec_db_query(manifest_db, query, __validate_cb, (void *)&exist);
5277 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5278 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5280 /*get system locale*/
5281 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5282 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5284 /*get locale on db*/
5285 locale = __convert_system_locale_to_manifest_locale(syslocale);
5286 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5289 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5290 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5292 /*check app_component from DB*/
5293 memset(query, '\0', MAX_QUERY_LEN);
5294 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5295 ret = __exec_db_query(manifest_db, query, __appcomponent_cb, (void *)appinfo);
5296 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5298 /*calloc app_component*/
5299 if (appinfo->app_component == PMINFO_UI_APP) {
5300 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5301 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5303 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5304 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5306 appinfo->locale = strdup(locale);
5308 /*populate app_info from DB*/
5309 memset(query, '\0', MAX_QUERY_LEN);
5310 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5311 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5312 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5314 memset(query, '\0', MAX_QUERY_LEN);
5315 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5316 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5317 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5319 /*Also store the values corresponding to default locales*/
5320 memset(query, '\0', MAX_QUERY_LEN);
5321 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5322 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5323 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5325 /*Populate app category*/
5326 memset(query, '\0', MAX_QUERY_LEN);
5327 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5328 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5329 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5331 /*Populate app metadata*/
5332 memset(query, '\0', MAX_QUERY_LEN);
5333 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5334 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5335 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5337 /*Populate app permission*/
5338 memset(query, '\0', MAX_QUERY_LEN);
5339 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5340 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5341 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5343 /*store setting notification icon section*/
5344 memset(query, '\0', MAX_QUERY_LEN);
5345 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5346 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5347 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5349 /*store app preview image info*/
5350 memset(query, '\0', MAX_QUERY_LEN);
5351 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5352 ret = __exec_db_query(manifest_db, query, __appinfo_cb, (void *)appinfo);
5353 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5355 switch (appinfo->app_component) {
5357 if (appinfo->uiapp_info->label) {
5358 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5359 appinfo->uiapp_info->label = tmp1;
5361 if (appinfo->uiapp_info->icon) {
5362 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5363 appinfo->uiapp_info->icon = tmp2;
5365 if (appinfo->uiapp_info->category) {
5366 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5367 appinfo->uiapp_info->category = tmp3;
5369 if (appinfo->uiapp_info->metadata) {
5370 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5371 appinfo->uiapp_info->metadata = tmp4;
5373 if (appinfo->uiapp_info->permission) {
5374 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5375 appinfo->uiapp_info->permission = tmp5;
5377 if (appinfo->uiapp_info->image) {
5378 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5379 appinfo->uiapp_info->image = tmp6;
5382 case PMINFO_SVC_APP:
5383 if (appinfo->svcapp_info->label) {
5384 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5385 appinfo->svcapp_info->label = tmp1;
5387 if (appinfo->svcapp_info->icon) {
5388 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5389 appinfo->svcapp_info->icon = tmp2;
5391 if (appinfo->svcapp_info->category) {
5392 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5393 appinfo->svcapp_info->category = tmp3;
5395 if (appinfo->svcapp_info->metadata) {
5396 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5397 appinfo->svcapp_info->metadata = tmp4;
5399 if (appinfo->svcapp_info->permission) {
5400 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5401 appinfo->svcapp_info->permission = tmp5;
5411 if (ret == PMINFO_R_OK)
5412 *handle = (void*)appinfo;
5415 __cleanup_appinfo(appinfo);
5418 sqlite3_close(manifest_db);
5430 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5432 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5435 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5437 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5438 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5439 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5441 if (info->app_component == PMINFO_UI_APP)
5442 *appid = (char *)info->uiapp_info->appid;
5443 else if (info->app_component == PMINFO_SVC_APP)
5444 *appid = (char *)info->svcapp_info->appid;
5449 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5451 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5452 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5453 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5455 *pkg_name = (char *)info->package;
5460 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5462 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5463 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5464 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5466 *pkgid = (char *)info->package;
5471 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5473 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5474 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5475 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5477 if (info->app_component == PMINFO_UI_APP)
5478 *exec = (char *)info->uiapp_info->exec;
5479 if (info->app_component == PMINFO_SVC_APP)
5480 *exec = (char *)info->svcapp_info->exec;
5486 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5488 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5489 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5490 char *locale = NULL;
5492 icon_x *start = NULL;
5495 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5496 locale = info->locale;
5497 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5499 if (info->app_component == PMINFO_UI_APP)
5500 start = info->uiapp_info->icon;
5501 if (info->app_component == PMINFO_SVC_APP)
5502 start = info->svcapp_info->icon;
5503 for(ptr = start; ptr != NULL; ptr = ptr->next)
5506 if (strcmp(ptr->lang, locale) == 0) {
5507 *icon = (char *)ptr->text;
5508 if (strcasecmp(*icon, "(null)") == 0) {
5509 locale = DEFAULT_LOCALE;
5513 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5514 *icon = (char *)ptr->text;
5523 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5525 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5526 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5527 char *locale = NULL;
5528 label_x *ptr = NULL;
5529 label_x *start = NULL;
5532 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5533 locale = info->locale;
5534 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5536 if (info->app_component == PMINFO_UI_APP)
5537 start = info->uiapp_info->label;
5538 if (info->app_component == PMINFO_SVC_APP)
5539 start = info->svcapp_info->label;
5540 for(ptr = start; ptr != NULL; ptr = ptr->next)
5543 if (strcmp(ptr->lang, locale) == 0) {
5544 *label = (char *)ptr->text;
5545 if (strcasecmp(*label, "(null)") == 0) {
5546 locale = DEFAULT_LOCALE;
5550 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5551 *label = (char *)ptr->text;
5552 if (strcasecmp(*label, "(null)") == 0) {
5553 locale = DEFAULT_LOCALE;
5557 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5558 *label = (char *)ptr->text;
5567 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5569 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5570 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5571 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5573 if (info->app_component == PMINFO_UI_APP)
5574 *component = PMINFO_UI_APP;
5575 else if (info->app_component == PMINFO_SVC_APP)
5576 *component = PMINFO_SVC_APP;
5578 return PMINFO_R_ERROR;
5583 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5585 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5586 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5587 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5589 if (info->app_component == PMINFO_UI_APP)
5590 *app_type = (char *)info->uiapp_info->type;
5591 if (info->app_component == PMINFO_SVC_APP)
5592 *app_type = (char *)info->svcapp_info->type;
5597 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5598 int *operation_count, char ***operation)
5600 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5601 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5602 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5603 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5604 *operation_count = data->operation_count;
5605 *operation = data->operation;
5609 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5610 int *uri_count, char ***uri)
5612 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5613 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5614 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5615 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5616 *uri_count = data->uri_count;
5621 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5622 int *mime_count, char ***mime)
5624 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5625 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5626 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5627 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5628 *mime_count = data->mime_count;
5633 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5634 int *subapp_count, char ***subapp)
5636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5637 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5638 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5639 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5640 *subapp_count = data->subapp_count;
5641 *subapp = data->subapp;
5645 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5647 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5648 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5652 icon_x *start = NULL;
5653 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5655 start = info->uiapp_info->icon;
5657 for(ptr = start; ptr != NULL; ptr = ptr->next)
5660 val = (char *)ptr->section;
5661 if (strcmp(val, "setting") == 0){
5662 *icon = (char *)ptr->text;
5671 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5674 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5678 icon_x *start = NULL;
5679 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5681 start = info->uiapp_info->icon;
5683 for(ptr = start; ptr != NULL; ptr = ptr->next)
5686 val = (char *)ptr->section;
5688 if (strcmp(val, "notification") == 0){
5689 *icon = (char *)ptr->text;
5698 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5700 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5701 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5703 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5704 val = (char *)info->uiapp_info->recentimage;
5706 if (strcasecmp(val, "capture") == 0)
5707 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5708 else if (strcasecmp(val, "icon") == 0)
5709 *type = PMINFO_RECENTIMAGE_USE_ICON;
5711 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5717 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5719 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5720 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5723 image_x *ptr = NULL;
5724 image_x *start = NULL;
5725 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5727 start = info->uiapp_info->image;
5729 for(ptr = start; ptr != NULL; ptr = ptr->next)
5732 val = (char *)ptr->section;
5734 if (strcmp(val, "preview") == 0)
5735 *preview_img = (char *)ptr->text;
5743 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5745 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5746 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5749 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5751 if (info->app_component == PMINFO_UI_APP)
5752 val = info->uiapp_info->permission_type;
5753 else if (info->app_component == PMINFO_SVC_APP)
5754 val = info->svcapp_info->permission_type;
5756 return PMINFO_R_ERROR;
5758 if (strcmp(val, "signature") == 0)
5759 *permission = PMINFO_PERMISSION_SIGNATURE;
5760 else if (strcmp(val, "privilege") == 0)
5761 *permission = PMINFO_PERMISSION_PRIVILEGE;
5763 *permission = PMINFO_PERMISSION_NORMAL;
5768 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5770 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5771 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5772 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5774 *component_type = (char *)info->uiapp_info->component_type;
5779 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5781 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5782 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5784 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5785 val = (char *)info->uiapp_info->hwacceleration;
5787 if (strcasecmp(val, "not-use-GL") == 0)
5788 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5789 else if (strcasecmp(val, "use-GL") == 0)
5790 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5792 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5797 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5799 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5800 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5802 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5803 val = (char *)info->uiapp_info->screenreader;
5805 if (strcasecmp(val, "screenreader-off") == 0)
5806 *screenreader = PMINFO_SCREENREADER_OFF;
5807 else if (strcasecmp(val, "screenreader-on") == 0)
5808 *screenreader = PMINFO_SCREENREADER_ON;
5810 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5815 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5817 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5818 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5819 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5820 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5822 if (info->app_component == PMINFO_UI_APP){
5823 *portrait_img = (char *)info->uiapp_info->portraitimg;
5824 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5830 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5832 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5833 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5834 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5836 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5841 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5842 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5844 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5845 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5847 permission_x *ptr = NULL;
5848 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5849 if (info->app_component == PMINFO_UI_APP)
5850 ptr = info->uiapp_info->permission;
5851 else if (info->app_component == PMINFO_SVC_APP)
5852 ptr = info->svcapp_info->permission;
5854 return PMINFO_R_EINVAL;
5855 for (; ptr; ptr = ptr->next) {
5857 ret = permission_func(ptr->value, user_data);
5865 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5866 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5868 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5869 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5871 category_x *ptr = NULL;
5872 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5873 if (info->app_component == PMINFO_UI_APP)
5874 ptr = info->uiapp_info->category;
5875 else if (info->app_component == PMINFO_SVC_APP)
5876 ptr = info->svcapp_info->category;
5878 return PMINFO_R_EINVAL;
5879 for (; ptr; ptr = ptr->next) {
5881 ret = category_func(ptr->name, user_data);
5889 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5890 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5892 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5893 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5895 metadata_x *ptr = NULL;
5896 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5897 if (info->app_component == PMINFO_UI_APP)
5898 ptr = info->uiapp_info->metadata;
5899 else if (info->app_component == PMINFO_SVC_APP)
5900 ptr = info->svcapp_info->metadata;
5902 return PMINFO_R_EINVAL;
5903 for (; ptr; ptr = ptr->next) {
5905 ret = metadata_func(ptr->key, ptr->value, user_data);
5913 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5914 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5916 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5917 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5925 char *manifest = NULL;
5926 char **operation = NULL;
5929 char **subapp = NULL;
5930 appcontrol_x *appcontrol = NULL;
5931 manifest_x *mfx = NULL;
5932 operation_x *op = NULL;
5935 subapp_x *sa = NULL;
5936 pkgmgrinfo_app_component component;
5937 pkgmgrinfo_appcontrol_x *ptr = NULL;
5938 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5940 _LOGE("Failed to get package name\n");
5941 return PMINFO_R_ERROR;
5943 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5945 _LOGE("Failed to get app component name\n");
5946 return PMINFO_R_ERROR;
5948 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
5949 if (manifest == NULL) {
5950 _LOGE("Failed to fetch package manifest file\n");
5951 return PMINFO_R_ERROR;
5953 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
5955 _LOGE("Failed to parse package manifest file\n");
5958 return PMINFO_R_ERROR;
5961 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5963 _LOGE("Out of Memory!!!\n");
5964 pkgmgr_parser_free_manifest_xml(mfx);
5965 return PMINFO_R_ERROR;
5967 /*Get Operation, Uri, Mime*/
5968 switch (component) {
5970 if (mfx->uiapplication) {
5971 if (mfx->uiapplication->appsvc) {
5972 appcontrol = mfx->uiapplication->appsvc;
5976 case PMINFO_SVC_APP:
5977 if (mfx->serviceapplication) {
5978 if (mfx->serviceapplication->appsvc) {
5979 appcontrol = mfx->serviceapplication->appsvc;
5986 for (; appcontrol; appcontrol = appcontrol->next) {
5987 op = appcontrol->operation;
5988 for (; op; op = op->next)
5990 op = appcontrol->operation;
5992 ui = appcontrol->uri;
5993 for (; ui; ui = ui->next)
5995 ui = appcontrol->uri;
5997 mi = appcontrol->mime;
5998 for (; mi; mi = mi->next)
6000 mi = appcontrol->mime;
6002 sa = appcontrol->subapp;
6003 for (; sa; sa = sa->next)
6005 sa = appcontrol->subapp;
6007 operation = (char **)calloc(oc, sizeof(char *));
6008 for (i = 0; i < oc; i++) {
6009 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6013 uri = (char **)calloc(uc, sizeof(char *));
6014 for (i = 0; i < uc; i++) {
6015 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6019 mime = (char **)calloc(mc, sizeof(char *));
6020 for (i = 0; i < mc; i++) {
6021 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6025 subapp = (char **)calloc(sc, sizeof(char *));
6026 for (i = 0; i < sc; i++) {
6027 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6031 /*populate appcontrol handle*/
6032 ptr->operation_count = oc;
6033 ptr->uri_count = uc;
6034 ptr->mime_count = mc;
6035 ptr->subapp_count = sc;
6036 ptr->operation = operation;
6039 ptr->subapp = subapp;
6041 ret = appcontrol_func((void *)ptr, user_data);
6042 for (i = 0; i < oc; i++) {
6045 operation[i] = NULL;
6052 for (i = 0; i < uc; i++) {
6062 for (i = 0; i < mc; i++) {
6072 for (i = 0; i < sc; i++) {
6089 pkgmgr_parser_free_manifest_xml(mfx);
6097 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6098 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6100 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6101 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6109 char *manifest = NULL;
6110 char **operation = NULL;
6113 char **subapp = NULL;
6114 appcontrol_x *appcontrol = NULL;
6115 manifest_x *mfx = NULL;
6116 operation_x *op = NULL;
6119 subapp_x *sa = NULL;
6120 pkgmgrinfo_app_component component;
6121 pkgmgrinfo_appcontrol_x *ptr = NULL;
6122 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6124 _LOGE("Failed to get package name\n");
6125 return PMINFO_R_ERROR;
6127 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6129 _LOGE("Failed to get app component name\n");
6130 return PMINFO_R_ERROR;
6132 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6133 if (manifest == NULL) {
6134 _LOGE("Failed to fetch package manifest file\n");
6135 return PMINFO_R_ERROR;
6137 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6139 _LOGE("Failed to parse package manifest file\n");
6142 return PMINFO_R_ERROR;
6145 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6147 _LOGE("Out of Memory!!!\n");
6148 pkgmgr_parser_free_manifest_xml(mfx);
6149 return PMINFO_R_ERROR;
6151 /*Get Operation, Uri, Mime*/
6152 switch (component) {
6154 if (mfx->uiapplication) {
6155 if (mfx->uiapplication->appsvc) {
6156 appcontrol = mfx->uiapplication->appsvc;
6160 case PMINFO_SVC_APP:
6161 if (mfx->serviceapplication) {
6162 if (mfx->serviceapplication->appsvc) {
6163 appcontrol = mfx->serviceapplication->appsvc;
6170 for (; appcontrol; appcontrol = appcontrol->next) {
6171 op = appcontrol->operation;
6172 for (; op; op = op->next)
6174 op = appcontrol->operation;
6176 ui = appcontrol->uri;
6177 for (; ui; ui = ui->next)
6179 ui = appcontrol->uri;
6181 mi = appcontrol->mime;
6182 for (; mi; mi = mi->next)
6184 mi = appcontrol->mime;
6186 sa = appcontrol->subapp;
6187 for (; sa; sa = sa->next)
6189 sa = appcontrol->subapp;
6191 operation = (char **)calloc(oc, sizeof(char *));
6192 for (i = 0; i < oc; i++) {
6193 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6197 uri = (char **)calloc(uc, sizeof(char *));
6198 for (i = 0; i < uc; i++) {
6199 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6203 mime = (char **)calloc(mc, sizeof(char *));
6204 for (i = 0; i < mc; i++) {
6205 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6209 subapp = (char **)calloc(sc, sizeof(char *));
6210 for (i = 0; i < sc; i++) {
6211 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6215 /*populate appcontrol handle*/
6216 ptr->operation_count = oc;
6217 ptr->uri_count = uc;
6218 ptr->mime_count = mc;
6219 ptr->subapp_count = sc;
6220 ptr->operation = operation;
6223 ptr->subapp = subapp;
6225 ret = appcontrol_func((void *)ptr, user_data);
6226 for (i = 0; i < oc; i++) {
6229 operation[i] = NULL;
6236 for (i = 0; i < uc; i++) {
6246 for (i = 0; i < mc; i++) {
6256 for (i = 0; i < sc; i++) {
6273 pkgmgr_parser_free_manifest_xml(mfx);
6281 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6283 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6284 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6286 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6287 val = (char *)info->uiapp_info->nodisplay;
6289 if (strcasecmp(val, "true") == 0)
6291 else if (strcasecmp(val, "false") == 0)
6299 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6301 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6302 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6304 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6305 val = (char *)info->uiapp_info->multiple;
6307 if (strcasecmp(val, "true") == 0)
6309 else if (strcasecmp(val, "false") == 0)
6317 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6319 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6320 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6322 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6323 val = (char *)info->uiapp_info->indicatordisplay;
6325 if (strcasecmp(val, "true") == 0){
6326 *indicator_disp = 1;
6327 }else if (strcasecmp(val, "false") == 0){
6328 *indicator_disp = 0;
6330 *indicator_disp = 0;
6336 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6338 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6339 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6341 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6342 val = (char *)info->uiapp_info->taskmanage;
6344 if (strcasecmp(val, "true") == 0)
6346 else if (strcasecmp(val, "false") == 0)
6354 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6356 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6357 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6359 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6360 if (info->app_component == PMINFO_UI_APP)
6361 val = (char *)info->uiapp_info->enabled;
6362 else if (info->app_component == PMINFO_SVC_APP)
6363 val = (char *)info->uiapp_info->enabled;
6365 _LOGE("invalid component type\n");
6366 return PMINFO_R_EINVAL;
6370 if (strcasecmp(val, "true") == 0)
6372 else if (strcasecmp(val, "false") == 0)
6381 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6383 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6384 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6386 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6387 val = (char *)info->svcapp_info->onboot;
6389 if (strcasecmp(val, "true") == 0)
6391 else if (strcasecmp(val, "false") == 0)
6399 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6401 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6402 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6404 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6405 val = (char *)info->svcapp_info->autorestart;
6407 if (strcasecmp(val, "true") == 0)
6409 else if (strcasecmp(val, "false") == 0)
6417 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6419 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6420 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6422 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6423 val = (char *)info->uiapp_info->mainapp;
6425 if (strcasecmp(val, "true") == 0)
6427 else if (strcasecmp(val, "false") == 0)
6435 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6437 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6438 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6440 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6441 val = (char *)info->uiapp_info->preload;
6443 if (strcasecmp(val, "true") == 0)
6445 else if (strcasecmp(val, "false") == 0)
6453 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6455 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6456 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6458 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6459 val = (char *)info->uiapp_info->submode;
6461 if (strcasecmp(val, "true") == 0)
6463 else if (strcasecmp(val, "false") == 0)
6471 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6473 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6474 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6475 __cleanup_appinfo(info);
6479 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6481 return (pkgmgrinfo_pkginfo_filter_create(handle));
6484 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6486 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6489 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6490 const char *property, const int value)
6492 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6493 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6494 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6496 GSList *link = NULL;
6498 prop = _pminfo_appinfo_convert_to_prop_int(property);
6499 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6500 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6501 _LOGE("Invalid Integer Property\n");
6502 return PMINFO_R_EINVAL;
6504 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6505 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6507 _LOGE("Out of Memory!!!\n");
6508 return PMINFO_R_ERROR;
6510 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6511 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6513 _LOGE("Out of Memory\n");
6516 return PMINFO_R_ERROR;
6520 /*If API is called multiple times for same property, we should override the previous values.
6521 Last value set will be used for filtering.*/
6522 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6524 filter->list = g_slist_delete_link(filter->list, link);
6525 filter->list = g_slist_append(filter->list, (gpointer)node);
6530 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6531 const char *property, const bool value)
6533 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6534 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6536 GSList *link = NULL;
6538 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6539 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6540 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6541 _LOGE("Invalid Boolean Property\n");
6542 return PMINFO_R_EINVAL;
6544 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6545 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6547 _LOGE("Out of Memory!!!\n");
6548 return PMINFO_R_ERROR;
6551 val = strndup("('true','True')", 15);
6553 val = strndup("('false','False')", 17);
6555 _LOGE("Out of Memory\n");
6558 return PMINFO_R_ERROR;
6562 /*If API is called multiple times for same property, we should override the previous values.
6563 Last value set will be used for filtering.*/
6564 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6566 filter->list = g_slist_delete_link(filter->list, link);
6567 filter->list = g_slist_append(filter->list, (gpointer)node);
6572 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6573 const char *property, const char *value)
6575 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6576 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6577 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6579 pkgmgrinfo_node_x *ptr = NULL;
6580 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6581 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6582 GSList *link = NULL;
6584 prop = _pminfo_appinfo_convert_to_prop_str(property);
6585 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6586 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6587 _LOGE("Invalid String Property\n");
6588 return PMINFO_R_EINVAL;
6590 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6591 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6593 _LOGE("Out of Memory!!!\n");
6594 return PMINFO_R_ERROR;
6598 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6599 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6600 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6602 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6604 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6606 filter->list = g_slist_delete_link(filter->list, link);
6607 filter->list = g_slist_append(filter->list, (gpointer)node);
6609 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6610 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6611 case E_PMINFO_APPINFO_PROP_APP_URI:
6612 case E_PMINFO_APPINFO_PROP_APP_MIME:
6613 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6615 _LOGE("Out of Memory\n");
6618 return PMINFO_R_ERROR;
6620 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6622 ptr = (pkgmgrinfo_node_x *)link->data;
6623 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6624 _LOGE("Previous value is %s\n", prev);
6625 filter->list = g_slist_delete_link(filter->list, link);
6626 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6627 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6628 _LOGE("New value is %s\n", val);
6630 filter->list = g_slist_append(filter->list, (gpointer)node);
6631 memset(temp, '\0', PKG_STRING_LEN_MAX);
6633 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6634 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6635 _LOGE("First value is %s\n", val);
6637 filter->list = g_slist_append(filter->list, (gpointer)node);
6638 memset(temp, '\0', PKG_STRING_LEN_MAX);
6642 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6643 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6645 filter->list = g_slist_delete_link(filter->list, link);
6646 filter->list = g_slist_append(filter->list, (gpointer)node);
6652 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6654 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6655 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6656 char *syslocale = NULL;
6657 char *locale = NULL;
6658 char *condition = NULL;
6659 char *error_message = NULL;
6660 char query[MAX_QUERY_LEN] = {'\0'};
6661 char where[MAX_QUERY_LEN] = {'\0'};
6665 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6666 /*Get current locale*/
6667 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6668 if (syslocale == NULL) {
6669 _LOGE("current locale is NULL\n");
6670 return PMINFO_R_ERROR;
6672 locale = __convert_system_locale_to_manifest_locale(syslocale);
6673 if (locale == NULL) {
6674 _LOGE("manifest locale is NULL\n");
6676 return PMINFO_R_ERROR;
6679 ret = __open_manifest_db(uid);
6681 _LOGE("Fail to open manifest DB\n");
6684 return PMINFO_R_ERROR;
6687 /*Start constructing query*/
6688 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6690 /*Get where clause*/
6691 for (list = filter->list; list; list = g_slist_next(list)) {
6692 __get_filter_condition(list->data, &condition);
6694 strncat(where, condition, sizeof(where) - strlen(where) -1);
6695 where[sizeof(where) - 1] = '\0';
6699 if (g_slist_next(list)) {
6700 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6701 where[sizeof(where) - 1] = '\0';
6704 _LOGE("where = %s\n", where);
6705 if (strlen(where) > 0) {
6706 strncat(query, where, sizeof(query) - strlen(query) - 1);
6707 query[sizeof(query) - 1] = '\0';
6709 _LOGE("query = %s\n", query);
6713 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
6714 _LOGE("Don't execute query = %s error message = %s\n", query,
6716 sqlite3_free(error_message);
6717 sqlite3_close(manifest_db);
6718 ret = PMINFO_R_ERROR;
6732 sqlite3_close(manifest_db);
6736 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6738 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6741 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6742 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6744 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6745 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6746 char *syslocale = NULL;
6747 char *locale = NULL;
6748 char *condition = NULL;
6749 char *error_message = NULL;
6750 char query[MAX_QUERY_LEN] = {'\0'};
6751 char where[MAX_QUERY_LEN] = {'\0'};
6754 uiapplication_x *ptr1 = NULL;
6755 serviceapplication_x *ptr2 = NULL;
6756 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6757 /*Get current locale*/
6758 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6759 if (syslocale == NULL) {
6760 _LOGE("current locale is NULL\n");
6761 return PMINFO_R_ERROR;
6763 locale = __convert_system_locale_to_manifest_locale(syslocale);
6764 if (locale == NULL) {
6765 _LOGE("manifest locale is NULL\n");
6767 return PMINFO_R_ERROR;
6770 ret = __open_manifest_db(uid);
6772 _LOGE("Fail to open manifest DB\n");
6775 return PMINFO_R_ERROR;
6777 /*Start constructing query*/
6778 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6779 /*Get where clause*/
6780 for (list = filter->list; list; list = g_slist_next(list)) {
6781 __get_filter_condition(list->data, &condition);
6783 strncat(where, condition, sizeof(where) - strlen(where) -1);
6784 where[sizeof(where) - 1] = '\0';
6788 if (g_slist_next(list)) {
6789 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6790 where[sizeof(where) - 1] = '\0';
6793 _LOGE("where = %s\n", where);
6794 if (strlen(where) > 0) {
6795 strncat(query, where, sizeof(query) - strlen(query) - 1);
6796 query[sizeof(query) - 1] = '\0';
6798 _LOGE("query = %s\n", query);
6799 /*To get filtered list*/
6800 pkgmgr_pkginfo_x *info = NULL;
6801 pkgmgr_pkginfo_x *filtinfo = NULL;
6802 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6804 _LOGE("Out of Memory!!!\n");
6805 ret = PMINFO_R_ERROR;
6808 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6809 if (info->manifest_info == NULL) {
6810 _LOGE("Out of Memory!!!\n");
6811 ret = PMINFO_R_ERROR;
6814 /*To get detail app info for each member of filtered list*/
6815 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6816 if (filtinfo == NULL) {
6817 _LOGE("Out of Memory!!!\n");
6818 ret = PMINFO_R_ERROR;
6821 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6822 if (filtinfo->manifest_info == NULL) {
6823 _LOGE("Out of Memory!!!\n");
6824 ret = PMINFO_R_ERROR;
6827 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6828 if (appinfo == NULL) {
6829 _LOGE("Out of Memory!!!\n");
6830 ret = PMINFO_R_ERROR;
6834 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
6835 _LOGE("Don't execute query = %s error message = %s\n", query,
6837 sqlite3_free(error_message);
6838 sqlite3_close(manifest_db);
6839 ret = PMINFO_R_ERROR;
6842 memset(query, '\0', MAX_QUERY_LEN);
6843 if (info->manifest_info->uiapplication) {
6844 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6845 info->manifest_info->uiapplication = ptr1;
6847 if (info->manifest_info->serviceapplication) {
6848 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6849 info->manifest_info->serviceapplication = ptr2;
6851 /*Filtered UI Apps*/
6852 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6854 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6855 ptr1->appid, "uiapp");
6857 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6858 _LOGE("Don't execute query = %s error message = %s\n", query,
6860 sqlite3_free(error_message);
6861 sqlite3_close(manifest_db);
6862 ret = PMINFO_R_ERROR;
6866 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6868 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6869 ptr2->appid, "svcapp");
6871 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6872 _LOGE("Don't execute query = %s error message = %s\n", query,
6874 sqlite3_free(error_message);
6875 sqlite3_close(manifest_db);
6876 ret = PMINFO_R_ERROR;
6880 if (filtinfo->manifest_info->uiapplication) {
6881 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6882 filtinfo->manifest_info->uiapplication = ptr1;
6884 /*If the callback func return < 0 we break and no more call back is called*/
6887 appinfo->locale = strdup(locale);
6888 appinfo->uiapp_info = ptr1;
6889 appinfo->app_component = PMINFO_UI_APP;
6890 ret = app_cb((void *)appinfo, user_data);
6895 /*Filtered Service Apps*/
6896 if (filtinfo->manifest_info->serviceapplication) {
6897 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6898 filtinfo->manifest_info->serviceapplication = ptr2;
6900 /*If the callback func return < 0 we break and no more call back is called*/
6903 appinfo->locale = strdup(locale);
6904 appinfo->svcapp_info = ptr2;
6905 appinfo->app_component = PMINFO_SVC_APP;
6906 ret = app_cb((void *)appinfo, user_data);
6921 sqlite3_close(manifest_db);
6926 __cleanup_pkginfo(info);
6927 __cleanup_pkginfo(filtinfo);
6931 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6932 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6934 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6937 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6939 return (pkgmgrinfo_pkginfo_filter_create(handle));
6942 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6944 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6947 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6948 const char *key, const char *value)
6950 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6951 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6952 /*value can be NULL. In that case all apps with specified key should be displayed*/
6956 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6957 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6958 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6960 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6964 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6967 /*If API is called multiple times, we should OR all conditions.*/
6968 filter->list = g_slist_append(filter->list, (gpointer)node);
6969 /*All memory will be freed in destroy API*/
6987 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6988 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6990 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6991 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6992 char *syslocale = NULL;
6993 char *locale = NULL;
6994 char *condition = NULL;
6995 char *error_message = NULL;
6996 char query[MAX_QUERY_LEN] = {'\0'};
6997 char where[MAX_QUERY_LEN] = {'\0'};
7000 pkgmgr_pkginfo_x *info = NULL;
7001 pkgmgr_pkginfo_x *filtinfo = NULL;
7002 pkgmgr_appinfo_x *appinfo = NULL;
7003 uiapplication_x *ptr1 = NULL;
7004 serviceapplication_x *ptr2 = NULL;
7005 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7007 /*Get current locale*/
7008 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7009 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7010 locale = __convert_system_locale_to_manifest_locale(syslocale);
7011 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7013 ret = __open_manifest_db(uid);
7015 _LOGE("Fail to open manifest DB\n");
7018 return PMINFO_R_ERROR;
7020 /*Start constructing query*/
7021 memset(where, '\0', MAX_QUERY_LEN);
7022 memset(query, '\0', MAX_QUERY_LEN);
7023 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7024 /*Get where clause*/
7025 for (list = filter->list; list; list = g_slist_next(list)) {
7026 __get_metadata_filter_condition(list->data, &condition);
7028 strncat(where, condition, sizeof(where) - strlen(where) -1);
7032 if (g_slist_next(list)) {
7033 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7036 _LOGE("where = %s (%d)\n", where, strlen(where));
7037 if (strlen(where) > 0) {
7038 strncat(query, where, sizeof(query) - strlen(query) - 1);
7040 _LOGE("query = %s (%d)\n", query, strlen(query));
7041 /*To get filtered list*/
7042 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7043 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7045 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7046 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7048 /*To get detail app info for each member of filtered list*/
7049 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7050 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7052 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7053 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7055 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7056 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7058 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
7059 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7060 memset(query, '\0', MAX_QUERY_LEN);
7062 if (info->manifest_info->uiapplication) {
7063 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7064 info->manifest_info->uiapplication = ptr1;
7066 if (info->manifest_info->serviceapplication) {
7067 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7068 info->manifest_info->serviceapplication = ptr2;
7072 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7074 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7075 ptr1->appid, "uiapp");
7076 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7077 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7078 memset(query, '\0', MAX_QUERY_LEN);
7081 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7083 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7084 ptr2->appid, "svcapp");
7085 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7086 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7087 memset(query, '\0', MAX_QUERY_LEN);
7089 /*Filtered UI Apps*/
7090 if (filtinfo->manifest_info->uiapplication) {
7091 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7092 filtinfo->manifest_info->uiapplication = ptr1;
7094 /*If the callback func return < 0 we break and no more call back is called*/
7097 appinfo->locale = strdup(locale);
7098 appinfo->uiapp_info = ptr1;
7099 appinfo->app_component = PMINFO_UI_APP;
7100 ret = app_cb((void *)appinfo, user_data);
7105 /*Filtered Service Apps*/
7106 if (filtinfo->manifest_info->serviceapplication) {
7107 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7108 filtinfo->manifest_info->serviceapplication = ptr2;
7110 /*If the callback func return < 0 we break and no more call back is called*/
7113 appinfo->locale = strdup(locale);
7114 appinfo->svcapp_info = ptr2;
7115 appinfo->app_component = PMINFO_SVC_APP;
7116 ret = app_cb((void *)appinfo, user_data);
7131 sqlite3_free(error_message);
7132 sqlite3_close(manifest_db);
7137 __cleanup_pkginfo(info);
7138 __cleanup_pkginfo(filtinfo);
7142 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7143 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7145 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7148 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7150 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7151 pkgmgr_certinfo_x *certinfo = NULL;
7152 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7154 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7155 *handle = (void *)certinfo;
7159 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
7161 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7162 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7163 pkgmgr_certinfo_x *certinfo = NULL;
7164 char *error_message = NULL;
7165 int ret = PMINFO_R_OK;
7166 char query[MAX_QUERY_LEN] = {'\0'};
7169 const char* user_pkg_cert = NULL;
7172 user_pkg_cert = getUserPkgCertDBPath();
7173 ret = db_util_open_with_options(user_pkg_cert, &cert_db,
7174 SQLITE_OPEN_READWRITE, NULL);
7175 if (ret != SQLITE_OK) {
7176 _LOGE("connect db [%s] failed!\n", user_pkg_cert);
7177 return PMINFO_R_ERROR;
7179 _check_create_Cert_db(cert_db);
7181 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7183 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7184 _LOGE("Don't execute query = %s error message = %s\n", query,
7186 sqlite3_free(error_message);
7187 ret = PMINFO_R_ERROR;
7191 _LOGE("Package not found in DB\n");
7192 ret = PMINFO_R_ERROR;
7195 certinfo = (pkgmgr_certinfo_x *)handle;
7196 /*populate certinfo from DB*/
7197 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7198 ret = __exec_certinfo_query(query, (void *)certinfo);
7200 _LOGE("Package Cert Info DB Information retrieval failed\n");
7201 ret = PMINFO_R_ERROR;
7204 for (i = 0; i < MAX_CERT_TYPE; i++) {
7205 memset(query, '\0', MAX_QUERY_LEN);
7206 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7207 ret = __exec_certinfo_query(query, (void *)certinfo);
7209 _LOGE("Cert Info DB Information retrieval failed\n");
7210 ret = PMINFO_R_ERROR;
7213 if (certinfo->cert_value) {
7214 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7215 free(certinfo->cert_value);
7216 certinfo->cert_value = NULL;
7220 sqlite3_close(cert_db);
7224 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7226 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7227 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7228 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7229 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7230 pkgmgr_certinfo_x *certinfo = NULL;
7231 certinfo = (pkgmgr_certinfo_x *)handle;
7232 if ((certinfo->cert_info)[cert_type])
7233 *cert_value = (certinfo->cert_info)[cert_type];
7239 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7241 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7243 pkgmgr_certinfo_x *certinfo = NULL;
7244 certinfo = (pkgmgr_certinfo_x *)handle;
7245 if (certinfo->pkgid) {
7246 free(certinfo->pkgid);
7247 certinfo->pkgid = NULL;
7249 for (i = 0; i < MAX_CERT_TYPE; i++) {
7250 if ((certinfo->cert_info)[i]) {
7251 free((certinfo->cert_info)[i]);
7252 (certinfo->cert_info)[i] = NULL;
7260 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7262 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7263 pkgmgr_instcertinfo_x *certinfo = NULL;
7265 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7266 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7267 *handle = (void *)certinfo;
7271 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7273 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7274 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7275 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7276 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7277 pkgmgr_instcertinfo_x *certinfo = NULL;
7278 certinfo = (pkgmgr_instcertinfo_x *)handle;
7279 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7283 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
7285 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7286 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7287 char *error_message = NULL;
7288 char query[MAX_QUERY_LEN] = {'\0'};
7289 char *vquery = NULL;
7294 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7301 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7302 pkgmgr_certindexinfo_x *indexinfo = NULL;
7303 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7304 if (indexinfo == NULL) {
7305 _LOGE("Out of Memory!!!");
7306 return PMINFO_R_ERROR;
7308 info->pkgid = strdup(pkgid);
7311 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7312 SQLITE_OPEN_READWRITE, NULL);
7313 if (ret != SQLITE_OK) {
7314 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7315 ret = PMINFO_R_ERROR;
7318 _check_create_Cert_db(cert_db);
7319 /*Begin Transaction*/
7320 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7321 if (ret != SQLITE_OK) {
7322 _LOGE("Failed to begin transaction\n");
7323 ret = PMINFO_R_ERROR;
7326 _LOGE("Transaction Begin\n");
7327 /*Check if request is to insert/update*/
7328 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7330 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7331 _LOGE("Don't execute query = %s error message = %s\n", query,
7333 sqlite3_free(error_message);
7334 ret = PMINFO_R_ERROR;
7339 We cant just issue update query directly. We need to manage index table also.
7340 Hence it is better to delete and insert again in case of update*/
7341 ret = __delete_certinfo(pkgid);
7343 _LOGE("Certificate Deletion Failed\n");
7345 for (i = 0; i < MAX_CERT_TYPE; i++) {
7346 if ((info->cert_info)[i]) {
7347 for (j = 0; j < i; j++) {
7348 if ( (info->cert_info)[j]) {
7349 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7350 (info->cert_id)[i] = (info->cert_id)[j];
7351 (info->is_new)[i] = 0;
7352 (info->ref_count)[i] = (info->ref_count)[j];
7359 memset(query, '\0', MAX_QUERY_LEN);
7360 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7361 "where cert_info='%s'",(info->cert_info)[i]);
7362 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7364 _LOGE("Cert Info DB Information retrieval failed\n");
7365 ret = PMINFO_R_ERROR;
7368 if (indexinfo->cert_id == 0) {
7369 /*New certificate. Get newid*/
7370 memset(query, '\0', MAX_QUERY_LEN);
7371 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7373 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
7374 _LOGE("Don't execute query = %s error message = %s\n", query,
7376 sqlite3_free(error_message);
7377 ret = PMINFO_R_ERROR;
7385 indexinfo->cert_id = maxid;
7386 indexinfo->cert_ref_count = 1;
7390 (info->cert_id)[i] = indexinfo->cert_id;
7391 (info->is_new)[i] = is_new;
7392 (info->ref_count)[i] = indexinfo->cert_ref_count;
7393 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
7394 indexinfo->cert_id = 0;
7395 indexinfo->cert_ref_count = 0;
7399 len = MAX_QUERY_LEN;
7400 for (i = 0; i < MAX_CERT_TYPE; i++) {
7401 if ((info->cert_info)[i])
7402 len+= strlen((info->cert_info)[i]);
7404 vquery = (char *)calloc(1, len);
7406 snprintf(vquery, len,
7407 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7408 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7409 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7410 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7411 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7412 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7413 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7414 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7416 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7417 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7419 sqlite3_free(error_message);
7420 ret = PMINFO_R_ERROR;
7423 /*Update index table info*/
7424 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7425 for (i = 0; i < MAX_CERT_TYPE; i++) {
7426 if ((info->cert_info)[i]) {
7427 memset(vquery, '\0', len);
7428 if ((info->is_new)[i]) {
7429 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7430 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7431 unique_id[c++] = (info->cert_id)[i];
7434 for (j = 0; j < MAX_CERT_TYPE; j++) {
7435 if ((info->cert_id)[i] == unique_id[j]) {
7436 /*Ref count has already been increased. Just continue*/
7440 if (j == MAX_CERT_TYPE)
7441 unique_id[c++] = (info->cert_id)[i];
7444 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7445 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7448 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7449 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7451 sqlite3_free(error_message);
7452 ret = PMINFO_R_ERROR;
7457 /*Commit transaction*/
7458 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7459 if (ret != SQLITE_OK) {
7460 _LOGE("Failed to commit transaction, Rollback now\n");
7461 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7462 ret = PMINFO_R_ERROR;
7465 _LOGE("Transaction Commit and End\n");
7468 sqlite3_close(cert_db);
7480 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7484 pkgmgr_instcertinfo_x *certinfo = NULL;
7485 certinfo = (pkgmgr_instcertinfo_x *)handle;
7486 if (certinfo->pkgid) {
7487 free(certinfo->pkgid);
7488 certinfo->pkgid = NULL;
7490 for (i = 0; i < MAX_CERT_TYPE; i++) {
7491 if ((certinfo->cert_info)[i]) {
7492 free((certinfo->cert_info)[i]);
7493 (certinfo->cert_info)[i] = NULL;
7501 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7503 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7506 ret = __open_cert_db(uid);
7508 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7509 ret = PMINFO_R_ERROR;
7512 _check_create_Cert_db(cert_db);
7513 /*Begin Transaction*/
7514 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7515 if (ret != SQLITE_OK) {
7516 _LOGE("Failed to begin transaction\n");
7517 ret = PMINFO_R_ERROR;
7520 _LOGE("Transaction Begin\n");
7521 ret = __delete_certinfo(pkgid);
7523 _LOGE("Certificate Deletion Failed\n");
7525 _LOGE("Certificate Deletion Success\n");
7527 /*Commit transaction*/
7528 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7529 if (ret != SQLITE_OK) {
7530 _LOGE("Failed to commit transaction, Rollback now\n");
7531 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7532 ret = PMINFO_R_ERROR;
7535 _LOGE("Transaction Commit and End\n");
7538 sqlite3_close(cert_db);
7543 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7545 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7548 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7550 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7551 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7553 char *manifest = NULL;
7554 manifest_x *mfx = NULL;
7556 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7557 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7559 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7564 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7566 *handle = (void *)mfx;
7571 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7573 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7574 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7576 char *manifest = NULL;
7577 manifest_x *mfx = NULL;
7579 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7580 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7582 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7587 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7589 *handle = (void *)mfx;
7594 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7596 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7597 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7599 int len = strlen(type);
7600 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7602 manifest_x *mfx = (manifest_x *)handle;
7604 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7608 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7610 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7611 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7613 int len = strlen(version);
7614 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7616 manifest_x *mfx = (manifest_x *)handle;
7618 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7622 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7624 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7625 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7627 manifest_x *mfx = (manifest_x *)handle;
7629 if (location == INSTALL_INTERNAL)
7630 strcpy(mfx->installlocation, "internal-only");
7631 else if (location == INSTALL_EXTERNAL)
7632 strcpy(mfx->installlocation, "prefer-external");
7637 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7639 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7640 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7642 manifest_x *mfx = (manifest_x *)handle;
7644 mfx->package_size = strdup(size);
7649 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7651 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7652 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7654 int len = strlen(label_txt);
7655 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7657 manifest_x *mfx = (manifest_x *)handle;
7659 label_x *label = calloc(1, sizeof(label_x));
7660 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7662 LISTADD(mfx->label, label);
7664 mfx->label->lang = strdup(locale);
7666 mfx->label->lang = strdup(DEFAULT_LOCALE);
7667 mfx->label->text = strdup(label_txt);
7672 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7674 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7675 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7677 int len = strlen(icon_txt);
7678 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7680 manifest_x *mfx = (manifest_x *)handle;
7682 icon_x *icon = calloc(1, sizeof(icon_x));
7683 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7685 LISTADD(mfx->icon, icon);
7687 mfx->icon->lang = strdup(locale);
7689 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7690 mfx->icon->text = strdup(icon_txt);
7695 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7697 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7698 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7700 int len = strlen(desc_txt);
7701 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7703 manifest_x *mfx = (manifest_x *)handle;
7705 description_x *description = calloc(1, sizeof(description_x));
7706 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7708 LISTADD(mfx->description, description);
7710 mfx->description->lang = strdup(locale);
7712 mfx->description->lang = strdup(DEFAULT_LOCALE);
7713 mfx->description->text = strdup(desc_txt);
7718 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7719 const char *author_email, const char *author_href, const char *locale)
7721 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7722 manifest_x *mfx = (manifest_x *)handle;
7723 author_x *author = calloc(1, sizeof(author_x));
7724 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7726 LISTADD(mfx->author, author);
7728 mfx->author->text = strdup(author_name);
7730 mfx->author->email = strdup(author_email);
7732 mfx->author->href = strdup(author_href);
7734 mfx->author->lang = strdup(locale);
7736 mfx->author->lang = strdup(DEFAULT_LOCALE);
7740 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7742 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7743 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7745 manifest_x *mfx = (manifest_x *)handle;
7748 strcpy(mfx->removable, "false");
7749 else if (removable == 1)
7750 strcpy(mfx->removable, "true");
7755 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7757 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7758 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7760 manifest_x *mfx = (manifest_x *)handle;
7763 strcpy(mfx->preload, "false");
7764 else if (preload == 1)
7765 strcpy(mfx->preload, "true");
7770 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7772 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7773 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7775 manifest_x *mfx = (manifest_x *)handle;
7777 if (location == INSTALL_INTERNAL)
7778 strcpy(mfx->installed_storage, "installed_internal");
7779 else if (location == INSTALL_EXTERNAL)
7780 strcpy(mfx->installed_storage, "installed_external");
7785 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7787 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7790 manifest_x *mfx = NULL;
7791 mfx = (manifest_x *)handle;
7793 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7795 _LOGE("Successfully stored info in DB\n");
7798 _LOGE("Failed to store info in DB\n");
7799 return PMINFO_R_ERROR;
7803 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7805 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7808 manifest_x *mfx = NULL;
7809 mfx = (manifest_x *)handle;
7811 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7813 _LOGE("Successfully stored info in DB\n");
7816 _LOGE("Failed to store info in DB\n");
7817 return PMINFO_R_ERROR;
7821 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7823 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7825 manifest_x *mfx = NULL;
7826 mfx = (manifest_x *)handle;
7827 pkgmgr_parser_free_manifest_xml(mfx);
7831 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7833 /* Should be implemented later */
7837 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7839 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7841 char query[MAX_QUERY_LEN] = {'\0'};
7844 ret = __open_manifest_db(uid);
7845 if (ret != SQLITE_OK) {
7846 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7847 sqlite3_close(manifest_db);
7848 return PMINFO_R_ERROR;
7851 /*Begin transaction*/
7852 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7853 if (ret != SQLITE_OK) {
7854 _LOGE("Failed to begin transaction\n");
7855 sqlite3_close(manifest_db);
7856 return PMINFO_R_ERROR;
7858 _LOGD("Transaction Begin\n");
7860 memset(query, '\0', MAX_QUERY_LEN);
7861 snprintf(query, MAX_QUERY_LEN,
7862 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7864 char *error_message = NULL;
7866 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7867 _LOGE("Don't execute query = %s error message = %s\n", query,
7869 sqlite3_free(error_message);
7870 return PMINFO_R_ERROR;
7872 sqlite3_free(error_message);
7874 /*Commit transaction*/
7875 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7876 if (ret != SQLITE_OK) {
7877 _LOGE("Failed to commit transaction. Rollback now\n");
7878 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7879 sqlite3_close(manifest_db);
7880 return PMINFO_R_ERROR;
7882 _LOGD("Transaction Commit and End\n");
7883 sqlite3_close(manifest_db);
7888 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7890 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7893 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7895 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7896 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7897 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7898 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7899 int ret = PMINFO_R_OK;
7900 char query[MAX_QUERY_LEN] = {'\0'};
7901 char *error_message = NULL;
7902 pkgmgr_datacontrol_x *data = NULL;
7904 ret = __open_datacontrol_db();
7906 _LOGE("Fail to open datacontrol DB\n");
7907 return PMINFO_R_ERROR;
7910 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7912 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7913 sqlite3_close(datacontrol_db);
7914 return PMINFO_R_ERROR;
7917 snprintf(query, MAX_QUERY_LEN,
7918 "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",
7922 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
7923 _LOGE("Don't execute query = %s error message = %s\n", query,
7925 sqlite3_free(error_message);
7926 sqlite3_close(datacontrol_db);
7927 return PMINFO_R_ERROR;
7930 *appid = (char *)data->appid;
7931 *access = (char *)data->access;
7933 sqlite3_close(datacontrol_db);
7938 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7940 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7942 char query[MAX_QUERY_LEN] = {'\0'};
7943 char *error_message = NULL;
7944 ret = __open_manifest_db(uid);
7947 /*Begin transaction*/
7948 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7949 if (ret != SQLITE_OK) {
7950 _LOGE("Failed to begin transaction\n");
7951 sqlite3_close(manifest_db);
7952 return PMINFO_R_ERROR;
7954 _LOGD("Transaction Begin\n");
7956 memset(query, '\0', MAX_QUERY_LEN);
7957 snprintf(query, MAX_QUERY_LEN,
7958 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7961 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7962 _LOGE("Don't execute query = %s error message = %s\n", query,
7964 sqlite3_free(error_message);
7965 return PMINFO_R_ERROR;
7968 /*Commit transaction*/
7969 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7970 if (ret != SQLITE_OK) {
7971 _LOGE("Failed to commit transaction. Rollback now\n");
7972 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7973 sqlite3_close(manifest_db);
7974 return PMINFO_R_ERROR;
7976 _LOGD("Transaction Commit and End\n");
7977 sqlite3_close(manifest_db);
7982 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7984 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7987 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7989 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7990 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7992 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7993 val = (char *)info->uiapp_info->guestmode_visibility;
7995 if (strcasecmp(val, "true") == 0){
7997 }else if (strcasecmp(val, "false") == 0){
8006 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8008 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8011 char *noti_string = NULL;
8013 char query[MAX_QUERY_LEN] = {'\0'};
8014 char *errmsg = NULL;
8015 sqlite3 *pkgmgr_parser_db;
8017 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8018 val = (char *)info->uiapp_info->guestmode_visibility;
8021 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8022 SQLITE_OPEN_READWRITE, NULL);
8024 if (ret != SQLITE_OK) {
8025 _LOGE("DB Open Failed\n");
8026 return PMINFO_R_ERROR;
8029 /*TODO: Write to DB here*/
8031 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8033 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8035 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8036 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8038 sqlite3_close(pkgmgr_parser_db);
8039 return PMINFO_R_ERROR;
8041 sqlite3_close(pkgmgr_parser_db);
8042 len = strlen((char *)info->uiapp_info->appid) + 8;
8043 noti_string = calloc(1, len);
8044 if (noti_string == NULL){
8045 return PMINFO_R_ERROR;
8047 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8048 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8049 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8056 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8058 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8061 /* pkgmgrinfo client start*/
8062 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8065 char *errmsg = NULL;
8067 void *handle = NULL;
8068 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8070 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8071 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8073 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8075 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8077 pc = __pkgmgr_client_new(ctype);
8078 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8082 return (pkgmgrinfo_client *) pc;
8085 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8088 char *errmsg = NULL;
8089 void *handle = NULL;
8090 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8092 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8093 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8095 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8097 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8099 ret = __pkgmgr_client_set_status_type(pc, status_type);
8100 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8104 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8106 * The lib dependency chain like below
8107 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8109 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8110 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8111 * on libpkgmgr-installer-client.
8113 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8116 * However, when the libdbus call into the callback function, it suddenly fond that the
8117 * function address is gone (unmapped), then we receive a SIGSEGV.
8119 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8120 * robust if we just link to the well-known lib.
8122 * See https://bugs.tizen.org/jira/browse/PTREL-591
8128 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8131 char *errmsg = NULL;
8132 void *handle = NULL;
8133 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8135 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8136 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8138 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8140 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8142 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8143 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8146 /* same as pkgmgrinfo_client_new */
8150 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8153 char *errmsg = NULL;
8154 void *handle = NULL;
8155 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8157 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8158 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8160 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8162 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8164 ret = __pkgmgr_client_free(pc);
8165 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8168 /* same as pkgmgrinfo_client_new */
8172 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8175 DBusConnection *bus;
8176 DBusMessage *message;
8178 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8180 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8183 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8184 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8186 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8187 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8189 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8191 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8192 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8194 dbus_connection_flush(bus);
8195 dbus_message_unref(message);
8200 /* pkgmgrinfo client end*/