4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
37 #include <sys/smack.h>
39 #include <libxml/parser.h>
40 #include <libxml/xmlreader.h>
41 #include <libxml/xmlschemas.h>
43 #include <dbus/dbus.h>
44 #include <dbus/dbus-glib-lowlevel.h>
46 /* For multi-user support */
47 #include <tzplatform_config.h>
49 #include "pkgmgr_parser.h"
50 #include "pkgmgr-info-internal.h"
51 #include "pkgmgr-info-debug.h"
52 #include "pkgmgr-info.h"
53 #include "pkgmgr_parser_db.h"
60 #define LOG_TAG "PKGMGR_INFO"
62 #define ASC_CHAR(s) (const char *)s
63 #define XML_CHAR(s) (const xmlChar *)s
65 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
66 #define MAX_QUERY_LEN 4096
67 #define MAX_CERT_TYPE 9
68 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
69 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
70 #define PKG_TYPE_STRING_LEN_MAX 128
71 #define PKG_VERSION_STRING_LEN_MAX 128
72 #define PKG_VALUE_STRING_LEN_MAX 512
73 #define PKG_LOCALE_STRING_LEN_MAX 8
74 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
75 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
76 #define BLOCK_SIZE 4096 /*in bytes*/
80 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
81 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
82 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
84 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
85 "from package_info LEFT OUTER JOIN package_localized_info " \
86 "ON package_info.package=package_localized_info.package " \
87 "and package_localized_info.package_locale='%s' where "
89 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
90 "from package_info LEFT OUTER JOIN package_localized_info " \
91 "ON package_info.package=package_localized_info.package " \
92 "and package_localized_info.package_locale='%s' where "
94 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
95 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
96 "ON package_app_info.app_id=package_app_localized_info.app_id " \
97 "and package_app_localized_info.app_locale='%s' " \
98 "LEFT OUTER JOIN package_app_app_svc " \
99 "ON package_app_info.app_id=package_app_app_svc.app_id " \
100 "LEFT OUTER JOIN package_app_app_category " \
101 "ON package_app_info.app_id=package_app_app_category.app_id where "
103 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
104 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
105 "ON package_app_info.app_id=package_app_localized_info.app_id " \
106 "and package_app_localized_info.app_locale='%s' " \
107 "LEFT OUTER JOIN package_app_app_svc " \
108 "ON package_app_info.app_id=package_app_app_svc.app_id " \
109 "LEFT OUTER JOIN package_app_app_category " \
110 "ON package_app_info.app_id=package_app_app_category.app_id where "
112 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
113 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
114 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
116 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
118 #define LANGUAGE_LENGTH 2
119 #define LIBAIL_PATH "/usr/lib/libail.so.0"
121 #define SERVICE_NAME "org.tizen.system.deviced"
122 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
123 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
124 #define METHOD_NAME "RequestMountApp2ext"
128 typedef struct _pkgmgr_instcertinfo_x {
130 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
131 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
132 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
133 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
134 } pkgmgr_instcertinfo_x;
136 typedef struct _pkgmgr_certindexinfo_x {
139 } pkgmgr_certindexinfo_x;
141 typedef struct _pkgmgr_pkginfo_x {
143 manifest_x *manifest_info;
146 struct _pkgmgr_pkginfo_x *prev;
147 struct _pkgmgr_pkginfo_x *next;
150 typedef struct _pkgmgr_cert_x {
155 typedef struct _pkgmgr_datacontrol_x {
158 } pkgmgr_datacontrol_x;
160 typedef struct _pkgmgr_iconpath_x {
165 typedef struct _pkgmgr_image_x {
169 typedef struct _pkgmgr_locale_x {
173 typedef struct _pkgmgr_appinfo_x {
176 pkgmgrinfo_app_component app_component;
178 uiapplication_x *uiapp_info;
179 serviceapplication_x *svcapp_info;
183 typedef struct _pkgmgr_certinfo_x {
186 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
187 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
191 typedef struct _pkgmgrinfo_filter_x {
194 } pkgmgrinfo_filter_x;
196 typedef struct _pkgmgrinfo_node_x {
202 typedef struct _pkgmgrinfo_appcontrol_x {
211 } pkgmgrinfo_appcontrol_x;
214 typedef struct _db_handle {
220 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
222 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
223 const char *pkgid, const char *key,
224 const char *val, const void *pmsg, void *data);
226 typedef void pkgmgr_client;
227 typedef void pkgmgr_info;
232 PM_REQUEST_GET_SIZE = 2,
233 PM_REQUEST_KILL_APP = 3,
234 PM_REQUEST_CHECK_APP = 4,
236 }pkgmgr_request_service_type;
239 PM_GET_TOTAL_SIZE= 0,
240 PM_GET_DATA_SIZE = 1,
242 PM_GET_SIZE_INFO = 3,
243 PM_GET_TOTAL_AND_DATA = 4,
244 PM_GET_SIZE_FILE = 5,
246 }pkgmgr_getsize_type;
254 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
255 #define MAX_PKG_BUF_LEN 1024
256 #define MAX_PKG_INFO_LEN 10
258 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
259 "(cert_info text not null, " \
260 "cert_id integer, " \
261 "cert_ref_count integer, " \
262 "PRIMARY KEY(cert_id)) "
264 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
265 "(package text not null, " \
266 "author_root_cert integer, " \
267 "author_im_cert integer, " \
268 "author_signer_cert integer, " \
269 "dist_root_cert integer, " \
270 "dist_im_cert integer, " \
271 "dist_signer_cert integer, " \
272 "dist2_root_cert integer, " \
273 "dist2_im_cert integer, " \
274 "dist2_signer_cert integer, " \
275 "PRIMARY KEY(package)) "
278 #define QUERY_ATTACH "attach database '%s' as Global"
279 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select * " \
280 "from (select *,0 as for_all_users from main.package_app_app_category union select *,1 as for_all_users from Global.package_app_app_category)"
281 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\
282 "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)"
283 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select * "\
284 "from (select *,0 as for_all_users from main.package_app_app_control union select *,1 as for_all_users from Global.package_app_app_control)"
285 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select * "\
286 "from (select *,0 as for_all_users from main.package_app_localized_info union select *,1 as for_all_users from Global.package_app_localized_info)"
287 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select * "\
288 "from (select *,0 as for_all_users from main.package_app_app_metadata union select *,1 as for_all_users from Global.package_app_app_metadata)"
289 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select * "\
290 "from (select *,0 as for_all_users from main.package_app_share_allowed union select *,1 as for_all_users from Global.package_app_share_allowed)"
291 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select * "\
292 "from (select *,0 as for_all_users from main.package_app_app_permission union select *,1 as for_all_users from Global.package_app_app_permission)"
293 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select * "\
294 "from (select *,0 as for_all_users from main.package_app_share_request union select *,1 as for_all_users from Global.package_app_share_request)"
295 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select * "\
296 "from (select *,0 as for_all_users from main.package_app_app_svc union select *,1 as for_all_users from Global.package_app_app_svc)"
297 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select * "\
298 "from (select *,0 as for_all_users from main.package_info union select *,1 as for_all_users from Global.package_info)"
299 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select * "\
300 "from (select *,0 as for_all_users from main.package_app_icon_section_info union select *,1 as for_all_users from Global.package_app_icon_section_info)"
301 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select * "\
302 "from (select *,0 as for_all_users from main.package_localized_info union select *,1 as for_all_users from Global.package_localized_info)"
303 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select * "\
304 "from (select *,0 as for_all_users from main.package_app_image_info union select *,1 as for_all_users from Global.package_app_image_info )"
305 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select * "\
306 "from (select *,0 as for_all_users from main.package_privilege_info union select *,1 as for_all_users from Global.package_privilege_info)"
308 #define GET_DB(X) (X).dbHandle
309 char *pkgtype = "rpm";
310 __thread db_handle manifest_db;
311 __thread db_handle datacontrol_db;
312 __thread db_handle cert_db;
314 static int __open_manifest_db(uid_t uid);
315 static int __close_manifest_db(void);
316 static int __open_cert_db(uid_t uid, char* mode);
317 static int __close_cert_db(void);
318 static int __exec_pkginfo_query(char *query, void *data);
319 static int __exec_certinfo_query(char *query, void *data);
320 static int __exec_certindexinfo_query(char *query, void *data);
321 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
322 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
323 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
324 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
325 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
326 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
327 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
328 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
329 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
330 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
331 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
332 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
333 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
334 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
335 static void __destroy_each_node(gpointer data, gpointer user_data);
336 static void __get_filter_condition(gpointer data, char **condition);
337 static void __get_metadata_filter_condition(gpointer data, char **condition);
338 static gint __compare_func(gconstpointer data1, gconstpointer data2);
339 static int __delete_certinfo(const char *pkgid, uid_t uid);
340 static int _check_create_Cert_db( sqlite3 *certdb);
341 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
343 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
345 char *error_message = NULL;
346 char query_attach[MAX_QUERY_LEN] = {'\0'};
347 char query_view[MAX_QUERY_LEN] = {'\0'};
349 if(uid != GLOBAL_USER){
350 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
352 sqlite3_exec(handle, query_attach,
353 NULL, NULL, &error_message)) {
354 _LOGD("Don't execute query = %s error message = %s\n",
355 query_attach, error_message);
356 sqlite3_free(error_message);
359 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");
361 sqlite3_exec(handle, query_view,
362 NULL, NULL, &error_message)) {
363 _LOGD("Don't execute query = %s error message = %s\n",
364 query_view, error_message);
365 sqlite3_free(error_message);
367 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");
369 sqlite3_exec(handle, query_view,
370 NULL, NULL, &error_message)) {
371 _LOGD("Don't execute query = %s error message = %s\n",
372 query_view, error_message);
373 sqlite3_free(error_message);
380 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
382 char *error_message = NULL;
383 char query_attach[MAX_QUERY_LEN] = {'\0'};
384 if(uid != GLOBAL_USER){
385 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
387 sqlite3_exec(handle, query_attach,
388 NULL, NULL, &error_message)) {
389 _LOGD("Don't execute query = %s error message = %s\n",
390 query_attach, error_message);
391 sqlite3_free(error_message);
394 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
395 NULL, NULL, &error_message)) {
396 _LOGD("Don't execute query = %s error message = %s\n",
397 QUERY_CREATE_VIEW_1, error_message);
398 sqlite3_free(error_message);
401 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
402 NULL, NULL, &error_message)) {
403 _LOGD("Don't execute query = %s error message = %s\n",
404 QUERY_CREATE_VIEW_2, error_message);
405 sqlite3_free(error_message);
408 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
409 NULL, NULL, &error_message)) {
410 _LOGD("Don't execute query = %s error message = %s\n",
411 QUERY_CREATE_VIEW_3, error_message);
412 sqlite3_free(error_message);
415 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
416 NULL, NULL, &error_message)) {
417 _LOGD("Don't execute query = %s error message = %s\n",
418 QUERY_CREATE_VIEW_4, error_message);
419 sqlite3_free(error_message);
422 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
423 NULL, NULL, &error_message)) {
424 _LOGD("Don't execute query = %s error message = %s\n",
425 QUERY_CREATE_VIEW_5, error_message);
426 sqlite3_free(error_message);
429 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
430 NULL, NULL, &error_message)) {
431 _LOGD("Don't execute query = %s error message = %s\n",
432 QUERY_CREATE_VIEW_6, error_message);
433 sqlite3_free(error_message);
436 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
437 NULL, NULL, &error_message)) {
438 _LOGD("Don't execute query = %s error message = %s\n",
439 QUERY_CREATE_VIEW_7, error_message);
440 sqlite3_free(error_message);
443 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
444 NULL, NULL, &error_message)) {
445 _LOGD("Don't execute query = %s error message = %s\n",
446 QUERY_CREATE_VIEW_8, error_message);
447 sqlite3_free(error_message);
450 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
451 NULL, NULL, &error_message)) {
452 _LOGD("Don't execute query = %s error message = %s\n",
453 QUERY_CREATE_VIEW_9, error_message);
454 sqlite3_free(error_message);
457 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
458 NULL, NULL, &error_message)) {
459 _LOGD("Don't execute query = %s error message = %s\n",
460 QUERY_CREATE_VIEW_10, error_message);
461 sqlite3_free(error_message);
464 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
465 NULL, NULL, &error_message)) {
466 _LOGD("Don't execute query = %s error message = %s\n",
467 QUERY_CREATE_VIEW_11, error_message);
468 sqlite3_free(error_message);
471 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
472 NULL, NULL, &error_message)) {
473 _LOGD("Don't execute query = %s error message = %s\n",
474 QUERY_CREATE_VIEW_12, error_message);
475 sqlite3_free(error_message);
478 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
479 NULL, NULL, &error_message)) {
480 _LOGD("Don't execute query = %s error message = %s\n",
481 QUERY_CREATE_VIEW_13, error_message);
482 sqlite3_free(error_message);
485 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
486 NULL, NULL, &error_message)) {
487 _LOGD("Don't execute query = %s error message = %s\n",
488 QUERY_CREATE_VIEW_14, error_message);
489 sqlite3_free(error_message);
497 static int _check_create_Cert_db( sqlite3 *certdb)
500 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
503 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
509 API char *getIconPath(uid_t uid)
512 struct group *grpinfo = NULL;
513 struct passwd *userinfo = getpwuid(uid);
516 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
519 if (uid != GLOBAL_USER) {
520 if (userinfo == NULL) {
521 _LOGE("getpwuid(%d) returns NULL !", uid);
524 grpinfo = getgrnam("users");
525 if (grpinfo == NULL) {
526 _LOGE("getgrnam(users) returns NULL !");
529 // Compare git_t type and not group name
530 if (grpinfo->gr_gid != userinfo->pw_gid) {
531 _LOGE("UID [%d] does not belong to 'users' group!", uid);
534 ret = asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir);
536 _LOGE("asprintf fails");
541 result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
544 ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
545 if (ret == -1 && errno != EEXIST) {
546 _LOGE("FAIL : to create directory %s %d", result, errno);
547 } else if (getuid() == OWNER_ROOT) {
548 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
551 strerror_r(errno, buf, sizeof(buf));
552 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
558 API char *getUserPkgParserDBPath(void)
560 return getUserPkgParserDBPathUID(GLOBAL_USER);
563 API char *getUserPkgParserDBPathUID(uid_t uid)
565 const char *result = NULL;
566 const char *journal = NULL;
567 struct group *grpinfo = NULL;
569 struct passwd *userinfo = getpwuid(uid);
572 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
575 if (uid != GLOBAL_USER) {
576 if (userinfo == NULL) {
577 _LOGE("getpwuid(%d) returns NULL !", uid);
580 grpinfo = getgrnam("users");
581 if (grpinfo == NULL) {
582 _LOGE("getgrnam(users) returns NULL !");
585 // Compare git_t type and not group name
586 if (grpinfo->gr_gid != userinfo->pw_gid) {
587 _LOGE("UID [%d] does not belong to 'users' group!", uid);
590 ret = asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
592 _LOGE("asprintf fails");
595 ret = asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir);
597 _LOGE("asprintf fails");
601 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
602 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
604 char *temp = strdup(result);
605 dir = strrchr(temp, '/');
613 ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
614 if (ret == -1 && errno != EEXIST) {
615 _LOGE("FAIL : to create directory %s %d", temp, errno);
616 } else if (getuid() == OWNER_ROOT) {
617 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
620 strerror_r(errno, buf, sizeof(buf));
621 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
628 API char *getUserPkgCertDBPath(void)
630 return getUserPkgCertDBPathUID(GLOBAL_USER);
633 API char *getUserPkgCertDBPathUID(uid_t uid)
636 char *journal = NULL;
637 struct group *grpinfo = NULL;
639 struct passwd *userinfo = getpwuid(uid);
642 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
645 if (uid != GLOBAL_USER) {
646 if (userinfo == NULL) {
647 _LOGE("getpwuid(%d) returns NULL !", uid);
650 grpinfo = getgrnam("users");
651 if (grpinfo == NULL) {
652 _LOGE("getgrnam(users) returns NULL !");
655 // Compare git_t type and not group name
656 if (grpinfo->gr_gid != userinfo->pw_gid) {
657 _LOGE("UID [%d] does not belong to 'users' group!", uid);
660 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
661 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_cert.db-journal", userinfo->pw_dir);
663 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
664 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db-journal");
666 char *temp = strdup(result);
667 dir = strrchr(temp, '/');
675 int ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
676 if (ret == -1 && errno != EEXIST) {
677 _LOGE("FAIL : to create directory %s %d", temp, errno);
678 } else if (getuid() == OWNER_ROOT) {
679 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
682 strerror_r(errno, buf, sizeof(buf));
683 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
690 API const char* getUserDesktopPath(uid_t uid)
693 struct group *grpinfo = NULL;
695 struct passwd *userinfo = getpwuid(uid);
698 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
701 if (uid != GLOBAL_USER) {
702 if (userinfo == NULL) {
703 _LOGE("getpwuid(%d) returns NULL !", uid);
706 grpinfo = getgrnam("users");
707 if (grpinfo == NULL) {
708 _LOGE("getgrnam(users) returns NULL !");
711 // Compare git_t type and not group name
712 if (grpinfo->gr_gid != userinfo->pw_gid) {
713 _LOGE("UID [%d] does not belong to 'users' group!", uid);
716 asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir);
718 result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
721 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
722 if (ret == -1 && errno != EEXIST) {
723 _LOGE("FAIL : to create directory %s %d", result, errno);
724 } else if (getuid() == OWNER_ROOT) {
725 ret = chown(result, uid,((grpinfo)?grpinfo->gr_gid:0));
728 strerror_r(errno, buf, sizeof(buf));
729 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
735 API const char* getUserManifestPath(uid_t uid)
738 struct group *grpinfo = NULL;
740 struct passwd *userinfo = getpwuid(uid);
743 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
746 if (uid != GLOBAL_USER) {
747 if (userinfo == NULL) {
748 _LOGE("getpwuid(%d) returns NULL !", uid);
751 grpinfo = getgrnam("users");
752 if (grpinfo == NULL) {
753 _LOGE("getgrnam(users) returns NULL !");
756 // Compare git_t type and not group name
757 if (grpinfo->gr_gid != userinfo->pw_gid) {
758 _LOGE("UID [%d] does not belong to 'users' group!", uid);
761 asprintf(&result, "%s/.applications/manifest/", userinfo->pw_dir);
763 result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
766 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
767 if (ret == -1 && errno != EEXIST) {
768 _LOGE("FAIL : to create directory %s %d", result, errno);
769 } else if (getuid() == OWNER_ROOT) {
770 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
773 strerror_r(errno, buf, sizeof(buf));
774 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
781 static gint __compare_func(gconstpointer data1, gconstpointer data2)
783 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
784 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
785 if (node1->prop == node2->prop)
787 else if (node1->prop > node2->prop)
793 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
796 *p = atoi(coltxt[0]);
797 _LOGE("count value is %d\n", *p);
801 static void __destroy_each_node(gpointer data, gpointer user_data)
803 ret_if(data == NULL);
804 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
817 static void __get_metadata_filter_condition(gpointer data, char **condition)
819 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
820 char key[MAX_QUERY_LEN] = {'\0'};
821 char value[MAX_QUERY_LEN] = {'\0'};
823 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
826 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
831 *condition = strdup(key);
835 static void __get_filter_condition(gpointer data, char **condition)
837 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
838 char buf[MAX_QUERY_LEN + 1] = {'\0'};
839 char temp[PKG_STRING_LEN_MAX] = {'\0'};
840 switch (node->prop) {
841 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
842 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
844 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
845 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
847 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
848 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
850 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
851 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
853 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
854 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
856 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
857 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
859 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
860 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
862 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
863 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
865 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
866 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
868 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
869 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
871 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
872 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
874 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
875 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
877 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
878 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
880 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
881 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
883 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
884 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
887 case E_PMINFO_APPINFO_PROP_APP_ID:
888 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
890 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
891 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
893 case E_PMINFO_APPINFO_PROP_APP_EXEC:
894 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
896 case E_PMINFO_APPINFO_PROP_APP_ICON:
897 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
899 case E_PMINFO_APPINFO_PROP_APP_TYPE:
900 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
902 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
903 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
904 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
906 case E_PMINFO_APPINFO_PROP_APP_URI:
907 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
908 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
910 case E_PMINFO_APPINFO_PROP_APP_MIME:
911 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
912 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
914 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
915 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
916 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
918 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
919 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
921 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
922 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
924 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
925 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
927 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
928 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
930 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
931 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
933 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
934 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
936 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
937 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
939 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
940 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
943 _LOGE("Invalid Property Type\n");
947 *condition = strdup(buf);
951 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
953 if (syslocale == NULL)
954 return strdup(DEFAULT_LOCALE);
956 locale = (char *)calloc(1, 6);
957 retvm_if(!locale, NULL, "Malloc Failed\n");
959 strncpy(locale, syslocale, 2);
960 strncat(locale, "-", 1);
961 locale[3] = syslocale[3] + 32;
962 locale[4] = syslocale[4] + 32;
966 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
968 ret_if(data == NULL);
970 free((void *)data->locale);
974 pkgmgr_parser_free_manifest_xml(data->manifest_info);
980 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
982 ret_if(data == NULL);
984 free((void *)data->package);
985 data->package = NULL;
988 free((void *)data->locale);
992 manifest_x *mfx = calloc(1, sizeof(manifest_x));
993 if (data->app_component == PMINFO_UI_APP)
994 mfx->uiapplication = data->uiapp_info;
995 else if (data->app_component == PMINFO_SVC_APP)
996 mfx->serviceapplication = data->svcapp_info;
997 pkgmgr_parser_free_manifest_xml(mfx);
1003 static int __close_manifest_db(void)
1006 if(manifest_db.ref) {
1007 if(--manifest_db.ref == 0)
1008 sqlite3_close(GET_DB(manifest_db));
1015 static int __open_manifest_db(uid_t uid)
1018 if(manifest_db.ref) {
1022 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
1023 if (access(user_pkg_parser, F_OK) == 0) {
1025 db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
1026 SQLITE_OPEN_READONLY, NULL);
1027 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
1029 ret = _pkgmgr_parser_attach_create_view_parserdb(GET_DB(manifest_db),uid);
1030 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
1034 _LOGE("Manifest DB does not exists !!\n");
1038 static int __close_cert_db(void)
1042 if(--cert_db.ref == 0)
1043 sqlite3_close(GET_DB(cert_db));
1046 _LOGE("Certificate DB is already closed !!\n");
1051 static int __open_cert_db(uid_t uid, char* mode)
1059 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
1060 if (access(user_cert_parser, F_OK) == 0) {
1062 db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
1063 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
1064 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
1066 if ((strcmp(mode, "w") != 0)) {
1067 ret = _pkgmgr_parser_attach_create_view_certdb(GET_DB(cert_db),uid);
1068 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
1072 _LOGE("Cert DB does not exists !!\n");
1076 static int __close_datacontrol_db(void)
1079 if(datacontrol_db.ref) {
1080 if(--datacontrol_db.ref == 0)
1081 sqlite3_close(GET_DB(datacontrol_db));
1084 _LOGE("Certificate DB is already closed !!\n");
1088 static int __open_datacontrol_db()
1091 if(datacontrol_db.ref) {
1092 datacontrol_db.ref ++;
1095 if (access(DATACONTROL_DB, F_OK) == 0) {
1097 db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
1098 SQLITE_OPEN_READONLY, NULL);
1099 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1100 datacontrol_db.ref ++;
1103 _LOGE("Datacontrol DB does not exists !!\n");
1107 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1109 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1111 pkgmgr_pkginfo_x *info = NULL;
1112 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1113 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1115 LISTADD(udata, info);
1117 for(i = 0; i < ncols; i++)
1119 if (strcmp(colname[i], "package") == 0) {
1121 info->manifest_info->package = strdup(coltxt[i]);
1123 info->manifest_info->package = NULL;
1124 } else if (strcmp(colname[i], "for_all_users") == 0) {
1126 info->manifest_info->for_all_users = strdup(coltxt[i]);
1128 info->manifest_info->for_all_users = NULL;
1133 //by default if views are not set , the column for_all_users doesn't exist,
1134 // in this case we assume we retreive information about app avaible for all users
1135 if (!info->manifest_info->for_all_users)
1136 info->manifest_info->for_all_users = strdup("1");
1141 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1143 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1146 uiapplication_x *uiapp = NULL;
1147 serviceapplication_x *svcapp = NULL;
1148 for(i = 0; i < ncols; i++)
1150 if ((strcmp(colname[i], "app_component") == 0) ||
1151 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1153 if (strcmp(coltxt[i], "uiapp") == 0) {
1154 uiapp = calloc(1, sizeof(uiapplication_x));
1155 if (uiapp == NULL) {
1156 _LOGE("Out of Memory!!!\n");
1159 LISTADD(info->manifest_info->uiapplication, uiapp);
1160 for(j = 0; j < ncols; j++)
1162 if ((strcmp(colname[j], "app_id") == 0) ||
1163 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1165 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1166 } else if (strcmp(colname[j], "package") == 0) {
1168 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1173 svcapp = calloc(1, sizeof(serviceapplication_x));
1174 if (svcapp == NULL) {
1175 _LOGE("Out of Memory!!!\n");
1178 LISTADD(info->manifest_info->serviceapplication, svcapp);
1179 for(j = 0; j < ncols; j++)
1181 if ((strcmp(colname[j], "app_id") == 0) ||
1182 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1184 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1185 } else if (strcmp(colname[j], "package") == 0) {
1187 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1201 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1203 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1205 uiapplication_x *uiapp = NULL;
1206 icon_x *icon = NULL;
1207 label_x *label = NULL;
1209 uiapp = calloc(1, sizeof(uiapplication_x));
1210 LISTADD(info->manifest_info->uiapplication, uiapp);
1211 icon = calloc(1, sizeof(icon_x));
1212 LISTADD(info->manifest_info->uiapplication->icon, icon);
1213 label = calloc(1, sizeof(label_x));
1214 LISTADD(info->manifest_info->uiapplication->label, label);
1216 for(i = 0; i < ncols; i++)
1218 if (strcmp(colname[i], "app_id") == 0) {
1220 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1222 info->manifest_info->uiapplication->appid = NULL;
1223 } else if (strcmp(colname[i], "app_exec") == 0) {
1225 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1227 info->manifest_info->uiapplication->exec = NULL;
1228 } else if (strcmp(colname[i], "app_type") == 0 ){
1230 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1232 info->manifest_info->uiapplication->type = NULL;
1233 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1235 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1237 info->manifest_info->uiapplication->nodisplay = NULL;
1238 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1240 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1242 info->manifest_info->uiapplication->multiple = NULL;
1243 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1245 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1247 info->manifest_info->uiapplication->taskmanage = NULL;
1248 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1250 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1252 info->manifest_info->uiapplication->hwacceleration = NULL;
1253 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1255 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1257 info->manifest_info->uiapplication->screenreader = NULL;
1258 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1260 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1262 info->manifest_info->uiapplication->indicatordisplay = NULL;
1263 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1265 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1267 info->manifest_info->uiapplication->portraitimg = NULL;
1268 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1270 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1272 info->manifest_info->uiapplication->landscapeimg = NULL;
1273 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1275 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1277 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1278 } else if (strcmp(colname[i], "package") == 0 ){
1280 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1282 info->manifest_info->uiapplication->package = NULL;
1283 } else if (strcmp(colname[i], "app_icon") == 0) {
1285 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1287 info->manifest_info->uiapplication->icon->text = NULL;
1288 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1290 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1292 info->manifest_info->uiapplication->enabled = NULL;
1293 } else if (strcmp(colname[i], "app_label") == 0 ) {
1295 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1297 info->manifest_info->uiapplication->label->text = NULL;
1298 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1300 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1302 info->manifest_info->uiapplication->recentimage = NULL;
1303 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1305 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1307 info->manifest_info->uiapplication->mainapp = NULL;
1308 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1310 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1311 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1314 info->manifest_info->uiapplication->icon->lang = NULL;
1315 info->manifest_info->uiapplication->label->lang = NULL;
1317 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1319 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1321 info->manifest_info->uiapplication->permission_type = NULL;
1322 } else if (strcmp(colname[i], "component_type") == 0 ) {
1324 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1326 info->manifest_info->uiapplication->component_type = NULL;
1327 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1329 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1331 info->manifest_info->uiapplication->preload = NULL;
1332 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1334 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1336 info->manifest_info->uiapplication->submode = NULL;
1337 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1339 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1341 info->manifest_info->uiapplication->submode_mainid = NULL;
1348 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1350 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1352 serviceapplication_x *svcapp = NULL;
1353 icon_x *icon = NULL;
1354 label_x *label = NULL;
1356 svcapp = calloc(1, sizeof(serviceapplication_x));
1357 LISTADD(info->manifest_info->serviceapplication, svcapp);
1358 icon = calloc(1, sizeof(icon_x));
1359 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1360 label = calloc(1, sizeof(label_x));
1361 LISTADD(info->manifest_info->serviceapplication->label, label);
1362 for(i = 0; i < ncols; i++)
1364 if (strcmp(colname[i], "app_id") == 0) {
1366 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1368 info->manifest_info->serviceapplication->appid = NULL;
1369 } else if (strcmp(colname[i], "app_exec") == 0) {
1371 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1373 info->manifest_info->serviceapplication->exec = NULL;
1374 } else if (strcmp(colname[i], "app_type") == 0 ){
1376 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1378 info->manifest_info->serviceapplication->type = NULL;
1379 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1381 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1383 info->manifest_info->serviceapplication->onboot = NULL;
1384 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1386 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1388 info->manifest_info->serviceapplication->autorestart = NULL;
1389 } else if (strcmp(colname[i], "package") == 0 ){
1391 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1393 info->manifest_info->serviceapplication->package = NULL;
1394 } else if (strcmp(colname[i], "app_icon") == 0) {
1396 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1398 info->manifest_info->serviceapplication->icon->text = NULL;
1399 } else if (strcmp(colname[i], "app_label") == 0 ) {
1401 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1403 info->manifest_info->serviceapplication->label->text = NULL;
1404 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1406 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1407 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1410 info->manifest_info->serviceapplication->icon->lang = NULL;
1411 info->manifest_info->serviceapplication->label->lang = NULL;
1413 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1415 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1417 info->manifest_info->serviceapplication->permission_type = NULL;
1424 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1426 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1429 uiapplication_x *uiapp = NULL;
1430 serviceapplication_x *svcapp = NULL;
1431 for(j = 0; j < ncols; j++)
1433 if (strcmp(colname[j], "app_component") == 0) {
1435 if (strcmp(coltxt[j], "uiapp") == 0) {
1436 uiapp = calloc(1, sizeof(uiapplication_x));
1437 if (uiapp == NULL) {
1438 _LOGE("Out of Memory!!!\n");
1441 LISTADD(info->manifest_info->uiapplication, uiapp);
1442 for(i = 0; i < ncols; i++)
1444 if (strcmp(colname[i], "app_id") == 0) {
1446 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1448 info->manifest_info->uiapplication->appid = NULL;
1449 } else if (strcmp(colname[i], "app_exec") == 0) {
1451 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1453 info->manifest_info->uiapplication->exec = NULL;
1454 } else if (strcmp(colname[i], "app_type") == 0 ){
1456 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1458 info->manifest_info->uiapplication->type = NULL;
1459 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1461 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1463 info->manifest_info->uiapplication->nodisplay = NULL;
1464 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1466 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1468 info->manifest_info->uiapplication->multiple = NULL;
1469 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1471 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1473 info->manifest_info->uiapplication->taskmanage = NULL;
1474 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1476 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1478 info->manifest_info->uiapplication->hwacceleration = NULL;
1479 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1481 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1483 info->manifest_info->uiapplication->screenreader = NULL;
1484 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1486 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1488 info->manifest_info->uiapplication->indicatordisplay = NULL;
1489 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1491 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1493 info->manifest_info->uiapplication->portraitimg = NULL;
1494 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1496 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1498 info->manifest_info->uiapplication->landscapeimg = NULL;
1499 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1501 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1503 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1504 } else if (strcmp(colname[i], "package") == 0 ){
1506 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1508 info->manifest_info->uiapplication->package = NULL;
1509 } else if (strcmp(colname[i], "app_icon") == 0) {
1511 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1513 info->manifest_info->uiapplication->icon->text = NULL;
1514 } else if (strcmp(colname[i], "app_label") == 0 ) {
1516 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1518 info->manifest_info->uiapplication->label->text = NULL;
1519 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1521 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1523 info->manifest_info->uiapplication->recentimage = NULL;
1524 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1526 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1528 info->manifest_info->uiapplication->mainapp = NULL;
1529 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1531 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1532 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1535 info->manifest_info->uiapplication->icon->lang = NULL;
1536 info->manifest_info->uiapplication->label->lang = NULL;
1538 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1540 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1542 info->manifest_info->uiapplication->permission_type = NULL;
1547 svcapp = calloc(1, sizeof(serviceapplication_x));
1548 if (svcapp == NULL) {
1549 _LOGE("Out of Memory!!!\n");
1552 LISTADD(info->manifest_info->serviceapplication, svcapp);
1553 for(i = 0; i < ncols; i++)
1555 if (strcmp(colname[i], "app_id") == 0) {
1557 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1559 info->manifest_info->serviceapplication->appid = NULL;
1560 } else if (strcmp(colname[i], "app_exec") == 0) {
1562 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1564 info->manifest_info->serviceapplication->exec = NULL;
1565 } else if (strcmp(colname[i], "app_type") == 0 ){
1567 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1569 info->manifest_info->serviceapplication->type = NULL;
1570 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1572 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1574 info->manifest_info->serviceapplication->onboot = NULL;
1575 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1577 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1579 info->manifest_info->serviceapplication->autorestart = NULL;
1580 } else if (strcmp(colname[i], "package") == 0 ){
1582 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1584 info->manifest_info->serviceapplication->package = NULL;
1585 } else if (strcmp(colname[i], "app_icon") == 0) {
1587 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1589 info->manifest_info->serviceapplication->icon->text = NULL;
1590 } else if (strcmp(colname[i], "app_label") == 0 ) {
1592 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1594 info->manifest_info->serviceapplication->label->text = NULL;
1595 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1597 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1598 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1601 info->manifest_info->serviceapplication->icon->lang = NULL;
1602 info->manifest_info->serviceapplication->label->lang = NULL;
1604 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1606 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1608 info->manifest_info->serviceapplication->permission_type = NULL;
1623 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1625 int *p = (int*)data;
1626 *p = atoi(coltxt[0]);
1630 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1632 int *p = (int*)data;
1634 *p = atoi(coltxt[0]);
1638 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1640 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1642 author_x *author = NULL;
1643 icon_x *icon = NULL;
1644 label_x *label = NULL;
1645 description_x *description = NULL;
1646 privilege_x *privilege = NULL;
1648 author = calloc(1, sizeof(author_x));
1649 LISTADD(info->manifest_info->author, author);
1650 icon = calloc(1, sizeof(icon_x));
1651 LISTADD(info->manifest_info->icon, icon);
1652 label = calloc(1, sizeof(label_x));
1653 LISTADD(info->manifest_info->label, label);
1654 description = calloc(1, sizeof(description_x));
1655 LISTADD(info->manifest_info->description, description);
1656 privilege = calloc(1, sizeof(privilege_x));
1657 LISTADD(info->manifest_info->privileges->privilege, privilege);
1658 for(i = 0; i < ncols; i++)
1660 if (strcmp(colname[i], "package_version") == 0) {
1662 info->manifest_info->version = strdup(coltxt[i]);
1664 info->manifest_info->version = NULL;
1665 } else if (strcmp(colname[i], "package_type") == 0) {
1667 info->manifest_info->type = strdup(coltxt[i]);
1669 info->manifest_info->type = NULL;
1670 } else if (strcmp(colname[i], "install_location") == 0) {
1672 info->manifest_info->installlocation = strdup(coltxt[i]);
1674 info->manifest_info->installlocation = NULL;
1675 } else if (strcmp(colname[i], "package_size") == 0) {
1677 info->manifest_info->package_size = strdup(coltxt[i]);
1679 info->manifest_info->package_size = NULL;
1680 } else if (strcmp(colname[i], "author_email") == 0 ){
1682 info->manifest_info->author->email = strdup(coltxt[i]);
1684 info->manifest_info->author->email = NULL;
1685 } else if (strcmp(colname[i], "author_href") == 0 ){
1687 info->manifest_info->author->href = strdup(coltxt[i]);
1689 info->manifest_info->author->href = NULL;
1690 } else if (strcmp(colname[i], "package_label") == 0 ){
1692 info->manifest_info->label->text = strdup(coltxt[i]);
1694 info->manifest_info->label->text = NULL;
1695 } else if (strcmp(colname[i], "package_icon") == 0 ){
1697 info->manifest_info->icon->text = strdup(coltxt[i]);
1699 info->manifest_info->icon->text = NULL;
1700 } else if (strcmp(colname[i], "package_description") == 0 ){
1702 info->manifest_info->description->text = strdup(coltxt[i]);
1704 info->manifest_info->description->text = NULL;
1705 } else if (strcmp(colname[i], "package_author") == 0 ){
1707 info->manifest_info->author->text = strdup(coltxt[i]);
1709 info->manifest_info->author->text = NULL;
1710 } else if (strcmp(colname[i], "package_removable") == 0 ){
1712 info->manifest_info->removable = strdup(coltxt[i]);
1714 info->manifest_info->removable = NULL;
1715 } else if (strcmp(colname[i], "package_preload") == 0 ){
1717 info->manifest_info->preload = strdup(coltxt[i]);
1719 info->manifest_info->preload = NULL;
1720 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1722 info->manifest_info->readonly = strdup(coltxt[i]);
1724 info->manifest_info->readonly = NULL;
1725 } else if (strcmp(colname[i], "package_update") == 0 ){
1727 info->manifest_info->update= strdup(coltxt[i]);
1729 info->manifest_info->update = NULL;
1730 } else if (strcmp(colname[i], "package_system") == 0 ){
1732 info->manifest_info->system= strdup(coltxt[i]);
1734 info->manifest_info->system = NULL;
1735 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1737 info->manifest_info->appsetting = strdup(coltxt[i]);
1739 info->manifest_info->appsetting = NULL;
1740 } else if (strcmp(colname[i], "installed_time") == 0 ){
1742 info->manifest_info->installed_time = strdup(coltxt[i]);
1744 info->manifest_info->installed_time = NULL;
1745 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1747 info->manifest_info->installed_storage = strdup(coltxt[i]);
1749 info->manifest_info->installed_storage = NULL;
1750 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1752 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1754 info->manifest_info->mainapp_id = NULL;
1755 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1757 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1759 info->manifest_info->storeclient_id = NULL;
1760 } else if (strcmp(colname[i], "root_path") == 0 ){
1762 info->manifest_info->root_path = strdup(coltxt[i]);
1764 info->manifest_info->root_path = NULL;
1765 } else if (strcmp(colname[i], "csc_path") == 0 ){
1767 info->manifest_info->csc_path = strdup(coltxt[i]);
1769 info->manifest_info->csc_path = NULL;
1770 } else if (strcmp(colname[i], "privilege") == 0 ){
1772 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1774 info->manifest_info->privileges->privilege->text = NULL;
1775 } else if (strcmp(colname[i], "package_locale") == 0 ){
1777 info->manifest_info->author->lang = strdup(coltxt[i]);
1778 info->manifest_info->icon->lang = strdup(coltxt[i]);
1779 info->manifest_info->label->lang = strdup(coltxt[i]);
1780 info->manifest_info->description->lang = strdup(coltxt[i]);
1783 info->manifest_info->author->lang = NULL;
1784 info->manifest_info->icon->lang = NULL;
1785 info->manifest_info->label->lang = NULL;
1786 info->manifest_info->description->lang = NULL;
1788 } else if (strcmp(colname[i], "package_url") == 0 ){
1790 info->manifest_info->package_url = strdup(coltxt[i]);
1792 info->manifest_info->package_url = NULL;
1800 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1802 if ( strcasecmp(comp, "uiapp") == 0)
1803 return PMINFO_UI_APP;
1804 else if ( strcasecmp(comp, "svcapp") == 0)
1805 return PMINFO_SVC_APP;
1810 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1812 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1814 for(i = 0; i < ncols; i++) {
1815 if (strcmp(colname[i], "cert_id") == 0) {
1817 info->cert_id = atoi(coltxt[i]);
1820 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1822 info->cert_ref_count = atoi(coltxt[i]);
1824 info->cert_ref_count = 0;
1830 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1832 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1834 for(i = 0; i < ncols; i++)
1836 if (strcmp(colname[i], "package") == 0) {
1838 info->pkgid = strdup(coltxt[i]);
1841 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1843 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1845 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1846 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1848 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1850 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1851 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1853 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1855 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1856 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1858 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1860 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1861 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1863 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1865 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1866 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1868 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1870 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1871 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1873 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1875 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1876 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1878 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1880 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1881 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1883 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1885 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1886 } else if (strcmp(colname[i], "cert_info") == 0 ){
1888 info->cert_value = strdup(coltxt[i]);
1890 info->cert_value = NULL;
1897 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1899 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1902 uiapplication_x *uiapp = NULL;
1903 serviceapplication_x *svcapp = NULL;
1904 for(i = 0; i < ncols; i++)
1906 if (strcmp(colname[i], "app_component") == 0) {
1908 if (strcmp(coltxt[i], "uiapp") == 0) {
1909 uiapp = calloc(1, sizeof(uiapplication_x));
1910 if (uiapp == NULL) {
1911 _LOGE("Out of Memory!!!\n");
1914 LISTADD(info->manifest_info->uiapplication, uiapp);
1915 for(j = 0; j < ncols; j++)
1917 if (strcmp(colname[j], "app_id") == 0) {
1919 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1920 } else if (strcmp(colname[j], "app_exec") == 0) {
1922 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1924 info->manifest_info->uiapplication->exec = NULL;
1925 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1927 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1929 info->manifest_info->uiapplication->nodisplay = NULL;
1930 } else if (strcmp(colname[j], "app_type") == 0 ) {
1932 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1934 info->manifest_info->uiapplication->type = NULL;
1935 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1937 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1939 info->manifest_info->uiapplication->multiple = NULL;
1940 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1942 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1944 info->manifest_info->uiapplication->taskmanage = NULL;
1945 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1947 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1949 info->manifest_info->uiapplication->hwacceleration = NULL;
1950 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1952 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1954 info->manifest_info->uiapplication->screenreader = NULL;
1955 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1957 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1959 info->manifest_info->uiapplication->enabled = NULL;
1960 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1962 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1964 info->manifest_info->uiapplication->indicatordisplay = NULL;
1965 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1967 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1969 info->manifest_info->uiapplication->portraitimg = NULL;
1970 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1972 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1974 info->manifest_info->uiapplication->landscapeimg = NULL;
1975 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1977 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1979 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1980 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1982 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1984 info->manifest_info->uiapplication->recentimage = NULL;
1985 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1987 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1989 info->manifest_info->uiapplication->mainapp = NULL;
1990 } else if (strcmp(colname[j], "package") == 0 ) {
1992 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1994 info->manifest_info->uiapplication->package = NULL;
1995 } else if (strcmp(colname[j], "app_component") == 0) {
1997 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1999 info->manifest_info->uiapplication->app_component = NULL;
2000 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
2002 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
2004 info->manifest_info->uiapplication->permission_type = NULL;
2005 } else if (strcmp(colname[j], "component_type") == 0 ) {
2007 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
2009 info->manifest_info->uiapplication->component_type = NULL;
2010 } else if (strcmp(colname[j], "app_preload") == 0 ) {
2012 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
2014 info->manifest_info->uiapplication->preload = NULL;
2015 } else if (strcmp(colname[j], "app_submode") == 0 ) {
2017 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
2019 info->manifest_info->uiapplication->submode = NULL;
2020 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
2022 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
2024 info->manifest_info->uiapplication->submode_mainid = NULL;
2029 svcapp = calloc(1, sizeof(serviceapplication_x));
2030 if (svcapp == NULL) {
2031 _LOGE("Out of Memory!!!\n");
2034 LISTADD(info->manifest_info->serviceapplication, svcapp);
2035 for(j = 0; j < ncols; j++)
2037 if (strcmp(colname[j], "app_id") == 0) {
2039 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
2040 } else if (strcmp(colname[j], "app_exec") == 0) {
2042 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
2044 info->manifest_info->serviceapplication->exec = NULL;
2045 } else if (strcmp(colname[j], "app_type") == 0 ){
2047 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
2049 info->manifest_info->serviceapplication->type = NULL;
2050 } else if (strcmp(colname[j], "app_onboot") == 0 ){
2052 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
2054 info->manifest_info->serviceapplication->onboot = NULL;
2055 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
2057 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
2059 info->manifest_info->serviceapplication->autorestart = NULL;
2060 } else if (strcmp(colname[j], "package") == 0 ){
2062 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
2064 info->manifest_info->serviceapplication->package = NULL;
2065 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
2067 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
2069 info->manifest_info->serviceapplication->permission_type = NULL;
2082 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
2084 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2086 icon_x *icon = NULL;
2087 label_x *label = NULL;
2088 category_x *category = NULL;
2089 metadata_x *metadata = NULL;
2090 permission_x *permission = NULL;
2091 image_x *image = NULL;
2093 switch (info->app_component) {
2095 icon = calloc(1, sizeof(icon_x));
2096 LISTADD(info->uiapp_info->icon, icon);
2097 label = calloc(1, sizeof(label_x));
2098 LISTADD(info->uiapp_info->label, label);
2099 category = calloc(1, sizeof(category_x));
2100 LISTADD(info->uiapp_info->category, category);
2101 metadata = calloc(1, sizeof(metadata_x));
2102 LISTADD(info->uiapp_info->metadata, metadata);
2103 permission = calloc(1, sizeof(permission_x));
2104 LISTADD(info->uiapp_info->permission, permission);
2105 image = calloc(1, sizeof(image_x));
2106 LISTADD(info->uiapp_info->image, image);
2108 for(i = 0; i < ncols; i++)
2110 if (strcmp(colname[i], "app_id") == 0) {
2111 /*appid being foreign key, is column in every table
2112 Hence appid gets strduped every time leading to memory leak.
2113 If appid is already set, just continue.*/
2114 if (info->uiapp_info->appid)
2117 info->uiapp_info->appid = strdup(coltxt[i]);
2119 info->uiapp_info->appid = NULL;
2120 } else if (strcmp(colname[i], "app_exec") == 0) {
2122 info->uiapp_info->exec = strdup(coltxt[i]);
2124 info->uiapp_info->exec = NULL;
2125 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2127 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2129 info->uiapp_info->nodisplay = NULL;
2130 } else if (strcmp(colname[i], "app_type") == 0 ) {
2132 info->uiapp_info->type = strdup(coltxt[i]);
2134 info->uiapp_info->type = NULL;
2135 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2137 info->uiapp_info->icon->section= strdup(coltxt[i]);
2139 info->uiapp_info->icon->section = NULL;
2140 } else if (strcmp(colname[i], "app_icon") == 0) {
2142 info->uiapp_info->icon->text = strdup(coltxt[i]);
2144 info->uiapp_info->icon->text = NULL;
2145 } else if (strcmp(colname[i], "app_label") == 0 ) {
2147 info->uiapp_info->label->text = strdup(coltxt[i]);
2149 info->uiapp_info->label->text = NULL;
2150 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2152 info->uiapp_info->multiple = strdup(coltxt[i]);
2154 info->uiapp_info->multiple = NULL;
2155 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2157 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2159 info->uiapp_info->taskmanage = NULL;
2160 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2162 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2164 info->uiapp_info->hwacceleration = NULL;
2165 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2167 info->uiapp_info->screenreader = strdup(coltxt[i]);
2169 info->uiapp_info->screenreader = NULL;
2170 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2172 info->uiapp_info->enabled= strdup(coltxt[i]);
2174 info->uiapp_info->enabled = NULL;
2175 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2177 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2179 info->uiapp_info->indicatordisplay = NULL;
2180 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2182 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2184 info->uiapp_info->portraitimg = NULL;
2185 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2187 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2189 info->uiapp_info->landscapeimg = NULL;
2190 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2192 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2194 info->uiapp_info->guestmode_visibility = NULL;
2195 } else if (strcmp(colname[i], "category") == 0 ) {
2197 info->uiapp_info->category->name = strdup(coltxt[i]);
2199 info->uiapp_info->category->name = NULL;
2200 } else if (strcmp(colname[i], "md_key") == 0 ) {
2202 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2204 info->uiapp_info->metadata->key = NULL;
2205 } else if (strcmp(colname[i], "md_value") == 0 ) {
2207 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2209 info->uiapp_info->metadata->value = NULL;
2210 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2212 info->uiapp_info->permission->type= strdup(coltxt[i]);
2214 info->uiapp_info->permission->type = NULL;
2215 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2217 info->uiapp_info->permission->value = strdup(coltxt[i]);
2219 info->uiapp_info->permission->value = NULL;
2220 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2222 info->uiapp_info->recentimage = strdup(coltxt[i]);
2224 info->uiapp_info->recentimage = NULL;
2225 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2227 info->uiapp_info->mainapp = strdup(coltxt[i]);
2229 info->uiapp_info->mainapp = NULL;
2230 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2232 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2233 info->uiapp_info->label->lang = strdup(coltxt[i]);
2236 info->uiapp_info->icon->lang = NULL;
2237 info->uiapp_info->label->lang = NULL;
2239 } else if (strcmp(colname[i], "app_image") == 0) {
2241 info->uiapp_info->image->text= strdup(coltxt[i]);
2243 info->uiapp_info->image->text = NULL;
2244 } else if (strcmp(colname[i], "app_image_section") == 0) {
2246 info->uiapp_info->image->section= strdup(coltxt[i]);
2248 info->uiapp_info->image->section = NULL;
2249 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2251 info->uiapp_info->permission_type = strdup(coltxt[i]);
2253 info->uiapp_info->permission_type = NULL;
2254 } else if (strcmp(colname[i], "component_type") == 0 ) {
2256 info->uiapp_info->component_type = strdup(coltxt[i]);
2258 info->uiapp_info->component_type = NULL;
2259 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2261 info->uiapp_info->preload = strdup(coltxt[i]);
2263 info->uiapp_info->preload = NULL;
2264 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2266 info->uiapp_info->submode = strdup(coltxt[i]);
2268 info->uiapp_info->submode = NULL;
2269 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2271 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2273 info->uiapp_info->submode_mainid = NULL;
2278 case PMINFO_SVC_APP:
2279 icon = calloc(1, sizeof(icon_x));
2280 LISTADD(info->svcapp_info->icon, icon);
2281 label = calloc(1, sizeof(label_x));
2282 LISTADD(info->svcapp_info->label, label);
2283 category = calloc(1, sizeof(category_x));
2284 LISTADD(info->svcapp_info->category, category);
2285 metadata = calloc(1, sizeof(metadata_x));
2286 LISTADD(info->svcapp_info->metadata, metadata);
2287 permission = calloc(1, sizeof(permission_x));
2288 LISTADD(info->svcapp_info->permission, permission);
2289 for(i = 0; i < ncols; i++)
2291 if (strcmp(colname[i], "app_id") == 0) {
2292 /*appid being foreign key, is column in every table
2293 Hence appid gets strduped every time leading to memory leak.
2294 If appid is already set, just continue.*/
2295 if (info->svcapp_info->appid)
2298 info->svcapp_info->appid = strdup(coltxt[i]);
2300 info->svcapp_info->appid = NULL;
2301 } else if (strcmp(colname[i], "app_exec") == 0) {
2303 info->svcapp_info->exec = strdup(coltxt[i]);
2305 info->svcapp_info->exec = NULL;
2306 } else if (strcmp(colname[i], "app_icon") == 0) {
2308 info->svcapp_info->icon->text = strdup(coltxt[i]);
2310 info->svcapp_info->icon->text = NULL;
2311 } else if (strcmp(colname[i], "app_label") == 0 ) {
2313 info->svcapp_info->label->text = strdup(coltxt[i]);
2315 info->svcapp_info->label->text = NULL;
2316 } else if (strcmp(colname[i], "app_type") == 0 ) {
2318 info->svcapp_info->type = strdup(coltxt[i]);
2320 info->svcapp_info->type = NULL;
2321 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2323 info->svcapp_info->onboot = strdup(coltxt[i]);
2325 info->svcapp_info->onboot = NULL;
2326 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2328 info->svcapp_info->autorestart = strdup(coltxt[i]);
2330 info->svcapp_info->autorestart = NULL;
2331 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2333 info->svcapp_info->enabled= strdup(coltxt[i]);
2335 info->svcapp_info->enabled = NULL;
2336 } else if (strcmp(colname[i], "category") == 0 ) {
2338 info->svcapp_info->category->name = strdup(coltxt[i]);
2340 info->svcapp_info->category->name = NULL;
2341 } else if (strcmp(colname[i], "md_key") == 0 ) {
2343 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2345 info->svcapp_info->metadata->key = NULL;
2346 } else if (strcmp(colname[i], "md_value") == 0 ) {
2348 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2350 info->svcapp_info->metadata->value = NULL;
2351 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2353 info->svcapp_info->permission->type= strdup(coltxt[i]);
2355 info->svcapp_info->permission->type = NULL;
2356 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2358 info->svcapp_info->permission->value = strdup(coltxt[i]);
2360 info->svcapp_info->permission->value = NULL;
2361 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2363 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2364 info->svcapp_info->label->lang = strdup(coltxt[i]);
2367 info->svcapp_info->icon->lang = NULL;
2368 info->svcapp_info->label->lang = NULL;
2370 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2372 info->svcapp_info->permission_type = strdup(coltxt[i]);
2374 info->svcapp_info->permission_type = NULL;
2387 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2389 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2391 for(i = 0; i < ncols; i++)
2393 if (strcmp(colname[i], "app_component") == 0) {
2394 info->app_component = __appcomponent_convert(coltxt[i]);
2395 } else if (strcmp(colname[i], "package") == 0) {
2396 info->package = strdup(coltxt[i]);
2403 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2405 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2407 for(i = 0; i < ncols; i++)
2409 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2411 info->appid = strdup(coltxt[i]);
2414 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2416 info->access = strdup(coltxt[i]);
2418 info->access = NULL;
2425 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2427 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2430 for(i = 0; i < ncols; i++)
2432 if (strcmp(colname[i], "author_signer_cert") == 0) {
2434 info->cert_id = atoi(coltxt[i]);
2437 } else if (strcmp(colname[i], "package") == 0) {
2439 info->pkgid= strdup(coltxt[i]);
2448 /* get the first locale value*/
2449 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2451 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2454 info->locale = strdup(coltxt[0]);
2456 info->locale = NULL;
2461 static int __exec_pkginfo_query(char *query, void *data)
2463 char *error_message = NULL;
2465 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2466 _LOGE("Don't execute query = %s error message = %s\n", query,
2468 sqlite3_free(error_message);
2471 sqlite3_free(error_message);
2475 static int __exec_certinfo_query(char *query, void *data)
2477 char *error_message = NULL;
2479 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2480 _LOGE("Don't execute query = %s error message = %s\n", query,
2482 sqlite3_free(error_message);
2485 sqlite3_free(error_message);
2489 static int __exec_certindexinfo_query(char *query, void *data)
2491 char *error_message = NULL;
2493 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2494 _LOGE("Don't execute query = %s error message = %s\n", query,
2496 sqlite3_free(error_message);
2499 sqlite3_free(error_message);
2503 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2505 char *error_message = NULL;
2506 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2507 if (SQLITE_OK != ret) {
2508 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2509 error_message, ret);
2510 sqlite3_free(error_message);
2513 sqlite3_free(error_message);
2518 static int __child_element(xmlTextReaderPtr reader, int depth)
2520 int ret = xmlTextReaderRead(reader);
2521 int cur = xmlTextReaderDepth(reader);
2524 switch (xmlTextReaderNodeType(reader)) {
2525 case XML_READER_TYPE_ELEMENT:
2526 if (cur == depth + 1)
2529 case XML_READER_TYPE_TEXT:
2530 /*text is handled by each function separately*/
2531 if (cur == depth + 1)
2534 case XML_READER_TYPE_END_ELEMENT:
2543 ret = xmlTextReaderRead(reader);
2544 cur = xmlTextReaderDepth(reader);
2549 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2551 int *p = (int*)data;
2552 *p = atoi(coltxt[0]);
2556 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2558 int result_query = -1;
2560 char query[MAX_QUERY_LEN];
2562 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);
2563 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2564 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2565 return result_query;
2568 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2570 int result_query = -1;
2572 char wildcard[2] = {'%','\0'};
2573 char query[MAX_QUERY_LEN];
2574 char lang[3] = {'\0'};
2575 strncpy(lang, locale, LANGUAGE_LENGTH);
2577 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);
2578 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2579 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2580 return result_query;
2583 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2586 char wildcard[2] = {'%','\0'};
2587 char lang[3] = {'\0'};
2588 char query[MAX_QUERY_LEN];
2589 char *locale_new = NULL;
2590 pkgmgr_locale_x *info = NULL;
2592 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2594 _LOGE("Out of Memory!!!\n");
2597 memset(info, '\0', sizeof(*info));
2599 strncpy(lang, locale, 2);
2600 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);
2601 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2602 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2603 locale_new = info->locale;
2614 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2616 char *locale = malloc(6);
2618 _LOGE("Malloc Failed\n");
2622 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2626 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2631 char *locale = NULL;
2632 char *locale_new = NULL;
2633 int check_result = 0;
2635 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2637 /*check exact matching */
2638 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2641 if (check_result == 1) {
2642 _LOGD("%s find exact locale(%s)\n", appid, locale);
2646 /* fallback matching */
2647 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2648 if(check_result == 1) {
2649 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2651 if (locale_new == NULL)
2652 locale_new = strdup(DEFAULT_LOCALE);
2656 /* default locale */
2658 return strdup(DEFAULT_LOCALE);
2661 long long _pkgmgr_calculate_dir_size(char *dirname)
2663 long long total = 0;
2665 int q = 0; /*quotient*/
2666 int r = 0; /*remainder*/
2668 struct dirent *ep = NULL;
2669 struct stat fileinfo;
2670 char abs_filename[FILENAME_MAX] = { 0, };
2671 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2673 dp = opendir(dirname);
2675 while ((ep = readdir(dp)) != NULL) {
2676 if (!strcmp(ep->d_name, ".") ||
2677 !strcmp(ep->d_name, "..")) {
2680 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2682 if (lstat(abs_filename, &fileinfo) < 0)
2683 perror(abs_filename);
2685 if (S_ISDIR(fileinfo.st_mode)) {
2686 total += fileinfo.st_size;
2687 if (strcmp(ep->d_name, ".")
2688 && strcmp(ep->d_name, "..")) {
2689 ret = _pkgmgr_calculate_dir_size
2691 total = total + ret;
2693 } else if (S_ISLNK(fileinfo.st_mode)) {
2696 /*It is a file. Calculate the actual
2697 size occupied (in terms of 4096 blocks)*/
2698 q = (fileinfo.st_size / BLOCK_SIZE);
2699 r = (fileinfo.st_size % BLOCK_SIZE);
2703 total += q * BLOCK_SIZE;
2709 _LOGE("Couldn't open the directory\n");
2716 static int __delete_certinfo(const char *pkgid, uid_t uid)
2722 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2723 char *error_message = NULL;
2724 char query[MAX_QUERY_LEN] = {'\0'};
2725 pkgmgr_certinfo_x *certinfo = NULL;
2726 pkgmgr_certindexinfo_x *indexinfo = NULL;
2727 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2728 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2729 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2730 if (indexinfo == NULL) {
2731 _LOGE("Out of Memory!!!");
2732 ret = PMINFO_R_ERROR;
2736 __open_cert_db(uid, "w");
2737 /*populate certinfo from DB*/
2738 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2739 ret = __exec_certinfo_query(query, (void *)certinfo);
2741 _LOGE("Package Cert Info DB Information retrieval failed\n");
2742 ret = PMINFO_R_ERROR;
2745 /*Update cert index table*/
2746 for (i = 0; i < MAX_CERT_TYPE; i++) {
2747 if ((certinfo->cert_id)[i]) {
2748 for (j = 0; j < MAX_CERT_TYPE; j++) {
2749 if ((certinfo->cert_id)[i] == unique_id[j]) {
2750 /*Ref count has already been updated. Just continue*/
2754 if (j == MAX_CERT_TYPE)
2755 unique_id[c++] = (certinfo->cert_id)[i];
2758 memset(query, '\0', MAX_QUERY_LEN);
2759 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2760 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2762 _LOGE("Cert Info DB Information retrieval failed\n");
2763 ret = PMINFO_R_ERROR;
2766 memset(query, '\0', MAX_QUERY_LEN);
2767 if (indexinfo->cert_ref_count > 1) {
2768 /*decrease ref count*/
2769 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2770 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2772 /*delete this certificate as ref count is 1 and it will become 0*/
2773 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2776 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2777 _LOGE("Don't execute query = %s error message = %s\n", query,
2779 sqlite3_free(error_message);
2780 ret = PMINFO_R_ERROR;
2785 /*Now delete the entry from db*/
2786 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2788 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2789 _LOGE("Don't execute query = %s error message = %s\n", query,
2791 sqlite3_free(error_message);
2792 ret = PMINFO_R_ERROR;
2801 if (certinfo->pkgid) {
2802 free(certinfo->pkgid);
2803 certinfo->pkgid = NULL;
2805 for (i = 0; i < MAX_CERT_TYPE; i++) {
2806 if ((certinfo->cert_info)[i]) {
2807 free((certinfo->cert_info)[i]);
2808 (certinfo->cert_info)[i] = NULL;
2817 static int __get_pkg_location(const char *pkgid)
2819 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2822 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2823 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2825 /*check whether application is in external memory or not */
2826 fp = fopen(pkg_mmc_path, "r");
2830 return PMINFO_EXTERNAL_STORAGE;
2833 return PMINFO_INTERNAL_STORAGE;
2836 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2838 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2839 char *error_message = NULL;
2840 int ret = PMINFO_R_OK;
2843 char query[MAX_QUERY_LEN] = {'\0'};
2844 char *syslocale = NULL;
2845 char *locale = NULL;
2846 pkgmgr_pkginfo_x *pkginfo = NULL;
2847 label_x *tmp1 = NULL;
2848 icon_x *tmp2 = NULL;
2849 description_x *tmp3 = NULL;
2850 author_x *tmp4 = NULL;
2851 privilege_x *tmp5 = NULL;
2853 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2854 if (syslocale == NULL) {
2855 _LOGE("current locale is NULL\n");
2856 return PMINFO_R_ERROR;
2858 locale = __convert_system_locale_to_manifest_locale(syslocale);
2859 if (locale == NULL) {
2860 _LOGE("manifest locale is NULL\n");
2862 return PMINFO_R_ERROR;
2865 ret_db = __open_manifest_db(uid);
2867 _LOGE("Fail to open manifest DB\n");
2870 return PMINFO_R_ERROR;
2872 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2873 pkgmgr_pkginfo_x *node = NULL;
2874 pkgmgr_pkginfo_x *temp_node = NULL;
2876 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2878 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2879 _LOGE("Don't execute query = %s error message = %s\n", query,
2881 sqlite3_free(error_message);
2882 ret = PMINFO_R_ERROR;
2886 LISTHEAD(tmphead, node);
2888 for(node = node->next; node ; node = node->next) {
2890 pkginfo->locale = strdup(locale);
2891 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2892 if (pkginfo->manifest_info->privileges == NULL) {
2893 _LOGE("Failed to allocate memory for privileges info\n");
2894 ret = PMINFO_R_ERROR;
2897 /*populate manifest_info from DB*/
2898 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2899 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2901 _LOGE("Package Info DB Information retrieval failed\n");
2902 ret = PMINFO_R_ERROR;
2905 memset(query, '\0', MAX_QUERY_LEN);
2906 /*populate privilege_info from DB*/
2907 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2908 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2910 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2911 ret = PMINFO_R_ERROR;
2914 memset(query, '\0', MAX_QUERY_LEN);
2915 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2916 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2917 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2919 _LOGE("Package Info DB Information retrieval failed\n");
2920 ret = PMINFO_R_ERROR;
2923 /*Also store the values corresponding to default locales*/
2924 memset(query, '\0', MAX_QUERY_LEN);
2925 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2926 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2927 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2929 _LOGE("Package Info DB Information retrieval failed\n");
2930 ret = PMINFO_R_ERROR;
2933 if (pkginfo->manifest_info->label) {
2934 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2935 pkginfo->manifest_info->label = tmp1;
2937 if (pkginfo->manifest_info->icon) {
2938 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2939 pkginfo->manifest_info->icon = tmp2;
2941 if (pkginfo->manifest_info->description) {
2942 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2943 pkginfo->manifest_info->description = tmp3;
2945 if (pkginfo->manifest_info->author) {
2946 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2947 pkginfo->manifest_info->author = tmp4;
2949 if (pkginfo->manifest_info->privileges->privilege) {
2950 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2951 pkginfo->manifest_info->privileges->privilege = tmp5;
2955 LISTHEAD(tmphead, node);
2957 for(node = node->next; node ; node = node->next) {
2960 ret = pkg_list_cb( (void *)pkginfo, user_data);
2968 __close_manifest_db();
2977 LISTHEAD(tmphead, node);
2978 temp_node = node->next;
2981 temp_node = node->next;
2982 __cleanup_pkginfo(node);
2985 __cleanup_pkginfo(tmphead);
2989 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2991 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2994 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2996 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2998 pkgmgr_pkginfo_x *pkginfo = NULL;
2999 int ret = PMINFO_R_OK;
3000 char query[MAX_QUERY_LEN] = {'\0'};
3001 char *syslocale = NULL;
3002 char *locale = NULL;
3004 label_x *tmp1 = NULL;
3005 icon_x *tmp2 = NULL;
3006 description_x *tmp3 = NULL;
3007 author_x *tmp4 = NULL;
3008 privilege_x *tmp5 = NULL;
3009 const char* user_pkg_parser = NULL;
3014 user_pkg_parser = getUserPkgParserDBPathUID(uid);
3015 ret = __open_manifest_db(uid);
3016 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
3018 /*check pkgid exist on db*/
3019 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
3020 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
3021 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
3022 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
3024 /*get system locale*/
3025 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3026 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3028 /*get locale on db*/
3029 locale = __convert_system_locale_to_manifest_locale(syslocale);
3030 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3032 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3033 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
3035 pkginfo->locale = strdup(locale);
3037 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3038 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
3040 pkginfo->manifest_info->package = strdup(pkgid);
3041 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3042 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
3044 /*populate manifest_info from DB*/
3045 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
3046 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3047 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3049 memset(query, '\0', MAX_QUERY_LEN);
3050 /*populate privilege_info from DB*/
3051 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
3052 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3053 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
3055 memset(query, '\0', MAX_QUERY_LEN);
3056 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3057 " package='%s' and package_locale='%s'", pkgid, locale);
3058 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3059 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3061 /*Also store the values corresponding to default locales*/
3062 memset(query, '\0', MAX_QUERY_LEN);
3063 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3064 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
3065 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3066 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3068 if (pkginfo->manifest_info->label) {
3069 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3070 pkginfo->manifest_info->label = tmp1;
3072 if (pkginfo->manifest_info->icon) {
3073 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3074 pkginfo->manifest_info->icon = tmp2;
3076 if (pkginfo->manifest_info->description) {
3077 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3078 pkginfo->manifest_info->description = tmp3;
3080 if (pkginfo->manifest_info->author) {
3081 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3082 pkginfo->manifest_info->author = tmp4;
3084 if (pkginfo->manifest_info->privileges->privilege) {
3085 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3086 pkginfo->manifest_info->privileges->privilege = tmp5;
3090 if (ret == PMINFO_R_OK)
3091 *handle = (void*)pkginfo;
3094 __cleanup_pkginfo(pkginfo);
3096 __close_manifest_db();
3108 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3110 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3113 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3115 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3116 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3117 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3118 if (info->manifest_info->package)
3119 *pkg_name = (char *)info->manifest_info->package;
3121 return PMINFO_R_ERROR;
3126 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3128 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3129 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3130 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3131 if (info->manifest_info->package)
3132 *pkgid = (char *)info->manifest_info->package;
3134 return PMINFO_R_ERROR;
3139 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3141 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3142 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3143 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3144 if (info->manifest_info->type)
3145 *type = (char *)info->manifest_info->type;
3151 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3153 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3154 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3155 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3156 *version = (char *)info->manifest_info->version;
3160 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3162 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3163 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3165 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3166 val = (char *)info->manifest_info->installlocation;
3168 if (strcmp(val, "internal-only") == 0)
3169 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3170 else if (strcmp(val, "prefer-external") == 0)
3171 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3173 *location = PMINFO_INSTALL_LOCATION_AUTO;
3178 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3181 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3183 char *location = NULL;
3184 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3185 location = (char *)info->manifest_info->installlocation;
3186 val = (char *)info->manifest_info->package_size;
3191 _LOGE("package size is not specified\n");
3192 return PMINFO_R_ERROR;
3197 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3199 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3200 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3203 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3204 long long rw_size = 0;
3205 long long ro_size= 0;
3206 long long tmp_size= 0;
3207 long long total_size= 0;
3208 struct stat fileinfo;
3211 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3213 return PMINFO_R_ERROR;
3216 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3217 if (lstat(device_path, &fileinfo) == 0) {
3218 if (!S_ISLNK(fileinfo.st_mode)) {
3219 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3221 rw_size += tmp_size;
3225 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3226 if (lstat(device_path, &fileinfo) == 0) {
3227 if (!S_ISLNK(fileinfo.st_mode)) {
3228 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3230 rw_size += tmp_size;
3234 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3235 if (lstat(device_path, &fileinfo) == 0) {
3236 if (!S_ISLNK(fileinfo.st_mode)) {
3237 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3239 rw_size += tmp_size;
3243 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3244 if (lstat(device_path, &fileinfo) == 0) {
3245 if (!S_ISLNK(fileinfo.st_mode)) {
3246 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3248 rw_size += tmp_size;
3252 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3253 if (lstat(device_path, &fileinfo) == 0) {
3254 if (!S_ISLNK(fileinfo.st_mode)) {
3255 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3257 rw_size += tmp_size;
3261 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3262 if (lstat(device_path, &fileinfo) == 0) {
3263 if (!S_ISLNK(fileinfo.st_mode)) {
3264 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3266 rw_size += tmp_size;
3271 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3272 if (lstat(device_path, &fileinfo) == 0) {
3273 if (!S_ISLNK(fileinfo.st_mode)) {
3274 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3276 ro_size += tmp_size;
3280 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3281 if (lstat(device_path, &fileinfo) == 0) {
3282 if (!S_ISLNK(fileinfo.st_mode)) {
3283 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3285 ro_size += tmp_size;
3289 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3290 if (lstat(device_path, &fileinfo) == 0) {
3291 if (!S_ISLNK(fileinfo.st_mode)) {
3292 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3294 ro_size += tmp_size;
3298 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3299 if (lstat(device_path, &fileinfo) == 0) {
3300 if (!S_ISLNK(fileinfo.st_mode)) {
3301 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3303 ro_size += tmp_size;
3307 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3308 if (lstat(device_path, &fileinfo) == 0) {
3309 if (!S_ISLNK(fileinfo.st_mode)) {
3310 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3312 ro_size += tmp_size;
3316 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3317 if (lstat(device_path, &fileinfo) == 0) {
3318 if (!S_ISLNK(fileinfo.st_mode)) {
3319 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3321 ro_size += tmp_size;
3326 total_size = rw_size + ro_size;
3327 *size = (int)total_size;
3332 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3334 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3335 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3338 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3339 long long total_size= 0;
3342 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3344 return PMINFO_R_ERROR;
3346 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3347 if (access(device_path, R_OK) == 0)
3348 total_size = _pkgmgr_calculate_dir_size(device_path);
3350 return PMINFO_R_ERROR;
3352 *size = (int)total_size;
3357 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3359 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3360 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3361 int ret = PMINFO_R_OK;
3362 char *locale = NULL;
3366 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3368 locale = info->locale;
3369 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3371 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3374 if (strcmp(ptr->lang, locale) == 0) {
3375 *icon = (char *)ptr->text;
3376 if (strcasecmp(*icon, "(null)") == 0) {
3377 locale = DEFAULT_LOCALE;
3381 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3382 *icon = (char *)ptr->text;
3391 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3393 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3394 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3395 int ret = PMINFO_R_OK;
3396 char *locale = NULL;
3397 label_x *ptr = 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->label; ptr != NULL; ptr = ptr->next)
3407 if (strcmp(ptr->lang, locale) == 0) {
3408 *label = (char *)ptr->text;
3409 if (strcasecmp(*label, "(null)") == 0) {
3410 locale = DEFAULT_LOCALE;
3414 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3415 *label = (char *)ptr->text;
3424 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3427 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3428 char *locale = NULL;
3429 description_x *ptr = NULL;
3430 *description = NULL;
3432 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3433 locale = info->locale;
3434 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3436 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3439 if (strcmp(ptr->lang, locale) == 0) {
3440 *description = (char *)ptr->text;
3441 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3442 locale = DEFAULT_LOCALE;
3446 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3447 *description = (char *)ptr->text;
3455 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3457 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3458 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3459 char *locale = NULL;
3460 author_x *ptr = NULL;
3461 *author_name = NULL;
3463 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3464 locale = info->locale;
3465 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3467 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3470 if (strcmp(ptr->lang, locale) == 0) {
3471 *author_name = (char *)ptr->text;
3472 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3473 locale = DEFAULT_LOCALE;
3477 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3478 *author_name = (char *)ptr->text;
3486 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3488 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3489 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3490 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3491 *author_email = (char *)info->manifest_info->author->email;
3495 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3497 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3498 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3499 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3500 *author_href = (char *)info->manifest_info->author->href;
3504 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3506 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3507 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3509 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3511 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3512 *storage = PMINFO_INTERNAL_STORAGE;
3513 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3514 *storage = PMINFO_EXTERNAL_STORAGE;
3516 return PMINFO_R_ERROR;
3521 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3523 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3524 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3525 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3526 if (info->manifest_info->installed_time)
3527 *installed_time = atoi(info->manifest_info->installed_time);
3529 return PMINFO_R_ERROR;
3534 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3536 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3537 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3538 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3539 *storeclientid = (char *)info->manifest_info->storeclient_id;
3543 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3545 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3546 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3547 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3548 *mainappid = (char *)info->manifest_info->mainapp_id;
3552 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3554 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3555 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3556 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3557 *url = (char *)info->manifest_info->package_url;
3561 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3563 const char *val = NULL;
3564 const xmlChar *node;
3565 xmlTextReaderPtr reader;
3566 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3567 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3570 reader = xmlReaderForFile(manifest, NULL, 0);
3573 if (__child_element(reader, -1)) {
3574 node = xmlTextReaderConstName(reader);
3576 _LOGE("xmlTextReaderConstName value is NULL\n");
3577 xmlFreeTextReader(reader);
3579 return PMINFO_R_ERROR;
3582 if (!strcmp(ASC_CHAR(node), "manifest")) {
3583 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3584 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3590 _LOGE("package size is not specified\n");
3591 xmlFreeTextReader(reader);
3593 return PMINFO_R_ERROR;
3596 _LOGE("Unable to create xml reader\n");
3597 xmlFreeTextReader(reader);
3599 return PMINFO_R_ERROR;
3603 _LOGE("xmlReaderForFile value is NULL\n");
3605 return PMINFO_R_ERROR;
3608 xmlFreeTextReader(reader);
3614 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3616 const char *val = NULL;
3617 const xmlChar *node;
3618 xmlTextReaderPtr reader;
3619 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3620 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3623 reader = xmlReaderForFile(manifest, NULL, 0);
3626 if ( __child_element(reader, -1)) {
3627 node = xmlTextReaderConstName(reader);
3629 _LOGE("xmlTextReaderConstName value is NULL\n");
3630 xmlFreeTextReader(reader);
3632 return PMINFO_R_ERROR;
3635 if (!strcmp(ASC_CHAR(node), "manifest")) {
3636 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3637 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3640 if (strcmp(val, "internal-only") == 0)
3641 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3642 else if (strcmp(val, "prefer-external") == 0)
3643 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3645 *location = PMINFO_INSTALL_LOCATION_AUTO;
3648 _LOGE("Unable to create xml reader\n");
3649 xmlFreeTextReader(reader);
3651 return PMINFO_R_ERROR;
3655 _LOGE("xmlReaderForFile value is NULL\n");
3657 return PMINFO_R_ERROR;
3660 xmlFreeTextReader(reader);
3667 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3669 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3670 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3672 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3673 if (info->manifest_info->root_path)
3674 *path = (char *)info->manifest_info->root_path;
3676 return PMINFO_R_ERROR;
3681 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3683 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3684 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3686 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3687 if (info->manifest_info->csc_path)
3688 *path = (char *)info->manifest_info->csc_path;
3690 *path = (char *)info->manifest_info->csc_path;
3695 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)
3697 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3698 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3699 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3701 int ret = PMINFO_R_OK;
3702 char query[MAX_QUERY_LEN] = {'\0'};
3703 char *error_message = NULL;
3704 pkgmgr_cert_x *info= NULL;
3708 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3709 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3710 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3712 ret = __open_cert_db(uid, "r");
3714 ret = PMINFO_R_ERROR;
3717 _check_create_Cert_db(GET_DB(cert_db));
3718 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3720 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3721 _LOGE("Don't execute query = %s error message = %s\n", query,
3723 ret = PMINFO_R_ERROR;
3730 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3732 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3733 _LOGE("Don't execute query = %s error message = %s\n", query,
3735 ret = PMINFO_R_ERROR;
3738 lcert = info->cert_id;
3741 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3743 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3744 _LOGE("Don't execute query = %s error message = %s\n", query,
3746 ret = PMINFO_R_ERROR;
3753 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3755 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3756 _LOGE("Don't execute query = %s error message = %s\n", query,
3758 ret = PMINFO_R_ERROR;
3761 rcert = info->cert_id;
3764 if ((lcert == 0) || (rcert == 0))
3766 if ((lcert == 0) && (rcert == 0))
3767 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3768 else if (lcert == 0)
3769 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3770 else if (rcert == 0)
3771 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3774 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3776 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3780 sqlite3_free(error_message);
3793 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)
3795 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3798 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)
3800 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3801 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3802 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3804 int ret = PMINFO_R_OK;
3805 char query[MAX_QUERY_LEN] = {'\0'};
3806 char *error_message = NULL;
3807 pkgmgr_cert_x *info= NULL;
3809 char *lpkgid = NULL;
3810 char *rpkgid = NULL;
3811 const char* user_pkg_parser = getUserPkgParserDBPath();
3813 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3814 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3816 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3817 SQLITE_OPEN_READONLY, NULL);
3818 if (ret != SQLITE_OK) {
3819 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3820 ret = PMINFO_R_ERROR;
3824 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3826 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3827 _LOGE("Don't execute query = %s error message = %s\n", query,
3829 ret = PMINFO_R_ERROR;
3836 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3838 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3839 _LOGE("Don't execute query = %s error message = %s\n", query,
3841 ret = PMINFO_R_ERROR;
3844 lpkgid = strdup(info->pkgid);
3845 if (lpkgid == NULL) {
3846 _LOGE("Out of Memory\n");
3847 ret = PMINFO_R_ERROR;
3854 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3856 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3857 _LOGE("Don't execute query = %s error message = %s\n", query,
3859 ret = PMINFO_R_ERROR;
3866 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3868 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3869 _LOGE("Don't execute query = %s error message = %s\n", query,
3871 ret = PMINFO_R_ERROR;
3874 rpkgid = strdup(info->pkgid);
3875 if (rpkgid == NULL) {
3876 _LOGE("Out of Memory\n");
3877 ret = PMINFO_R_ERROR;
3883 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3885 sqlite3_free(error_message);
3886 __close_manifest_db();
3906 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)
3908 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3909 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3910 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3912 int ret = PMINFO_R_OK;
3913 char query[MAX_QUERY_LEN] = {'\0'};
3914 char *error_message = NULL;
3915 pkgmgr_cert_x *info= NULL;
3917 char *lpkgid = NULL;
3918 char *rpkgid = NULL;
3920 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3921 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3923 ret = __open_manifest_db(uid);
3924 if (ret != SQLITE_OK) {
3925 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3926 ret = PMINFO_R_ERROR;
3930 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3932 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3933 _LOGE("Don't execute query = %s error message = %s\n", query,
3935 ret = PMINFO_R_ERROR;
3942 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3944 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3945 _LOGE("Don't execute query = %s error message = %s\n", query,
3947 ret = PMINFO_R_ERROR;
3950 lpkgid = strdup(info->pkgid);
3951 if (lpkgid == NULL) {
3952 _LOGE("Out of Memory\n");
3953 ret = PMINFO_R_ERROR;
3960 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3962 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3963 _LOGE("Don't execute query = %s error message = %s\n", query,
3965 ret = PMINFO_R_ERROR;
3972 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3974 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3975 _LOGE("Don't execute query = %s error message = %s\n", query,
3977 ret = PMINFO_R_ERROR;
3980 rpkgid = strdup(info->pkgid);
3981 if (rpkgid == NULL) {
3982 _LOGE("Out of Memory\n");
3983 ret = PMINFO_R_ERROR;
3989 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3991 sqlite3_free(error_message);
3992 __close_manifest_db();
4012 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
4014 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4015 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4017 #if 0 //smack issue occured, check later
4019 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
4021 _LOGD("invalid func parameters\n");
4022 return PMINFO_R_ERROR;
4024 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
4027 char app_mmc_path[FILENAME_MAX] = { 0, };
4028 char app_dir_path[FILENAME_MAX] = { 0, };
4029 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
4030 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
4031 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
4032 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
4034 /*check whether application is in external memory or not */
4035 fp = fopen(app_mmc_path, "r");
4037 _LOGD(" app path in external memory not accesible\n");
4042 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
4046 /*check whether application is in internal or not */
4047 fp = fopen(app_dir_path, "r");
4049 _LOGD(" app path in internal memory not accesible\n");
4051 return PMINFO_R_ERROR;
4054 /*check whether the application is installed in SD card
4055 but SD card is not present*/
4056 fp = fopen(app_mmc_internal_path, "r");
4059 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
4064 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
4069 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
4076 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
4078 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4079 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4081 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4082 val = (char *)info->manifest_info->removable;
4084 if (strcasecmp(val, "true") == 0)
4086 else if (strcasecmp(val, "false") == 0)
4094 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4096 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4097 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4100 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4102 val = (char *)info->manifest_info->installlocation;
4104 if (strcmp(val, "internal-only") == 0)
4106 else if (strcmp(val, "prefer-external") == 0)
4115 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4117 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4118 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4120 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4121 val = (char *)info->manifest_info->preload;
4123 if (strcasecmp(val, "true") == 0)
4125 else if (strcasecmp(val, "false") == 0)
4133 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4135 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4136 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4139 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4140 val = (char *)info->manifest_info->system;
4142 if (strcasecmp(val, "true") == 0)
4144 else if (strcasecmp(val, "false") == 0)
4153 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4155 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4156 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4158 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4159 val = (char *)info->manifest_info->readonly;
4161 if (strcasecmp(val, "true") == 0)
4163 else if (strcasecmp(val, "false") == 0)
4171 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4173 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4174 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4177 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4178 val = (char *)info->manifest_info->update;
4180 if (strcasecmp(val, "true") == 0)
4182 else if (strcasecmp(val, "false") == 0)
4190 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4192 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4193 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4196 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4197 val = (char *)info->manifest_info->for_all_users;
4199 if (strcasecmp(val, "1") == 0)
4201 else if (strcasecmp(val, "0") == 0)
4210 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4212 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4213 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4214 __cleanup_pkginfo(info);
4218 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4222 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4223 if (filter == NULL) {
4224 _LOGE("Out of Memory!!!");
4225 return PMINFO_R_ERROR;
4231 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4233 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4234 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4236 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4237 g_slist_free(filter->list);
4244 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4245 const char *property, const int value)
4247 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4248 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4249 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4251 GSList *link = NULL;
4253 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4254 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4255 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4256 _LOGE("Invalid Integer Property\n");
4257 return PMINFO_R_EINVAL;
4259 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4260 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4262 _LOGE("Out of Memory!!!\n");
4263 return PMINFO_R_ERROR;
4265 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4266 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4268 _LOGE("Out of Memory\n");
4271 return PMINFO_R_ERROR;
4275 /*If API is called multiple times for same property, we should override the previous values.
4276 Last value set will be used for filtering.*/
4277 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4279 filter->list = g_slist_delete_link(filter->list, link);
4280 filter->list = g_slist_append(filter->list, (gpointer)node);
4285 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4286 const char *property, const bool value)
4288 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4289 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4291 GSList *link = NULL;
4293 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4294 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4295 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4296 _LOGE("Invalid Boolean Property\n");
4297 return PMINFO_R_EINVAL;
4299 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4300 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4302 _LOGE("Out of Memory!!!\n");
4303 return PMINFO_R_ERROR;
4306 val = strndup("('true','True')", 15);
4308 val = strndup("('false','False')", 17);
4310 _LOGE("Out of Memory\n");
4313 return PMINFO_R_ERROR;
4317 /*If API is called multiple times for same property, we should override the previous values.
4318 Last value set will be used for filtering.*/
4319 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4321 filter->list = g_slist_delete_link(filter->list, link);
4322 filter->list = g_slist_append(filter->list, (gpointer)node);
4327 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4328 const char *property, const char *value)
4330 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4331 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4332 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4334 GSList *link = NULL;
4336 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4337 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4338 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4339 _LOGE("Invalid String Property\n");
4340 return PMINFO_R_EINVAL;
4342 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4343 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4345 _LOGE("Out of Memory!!!\n");
4346 return PMINFO_R_ERROR;
4348 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4349 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4350 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4351 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4352 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4353 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4354 else if (strcmp(value, "installed_internal") == 0)
4355 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4356 else if (strcmp(value, "installed_external") == 0)
4357 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4359 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4361 _LOGE("Out of Memory\n");
4364 return PMINFO_R_ERROR;
4368 /*If API is called multiple times for same property, we should override the previous values.
4369 Last value set will be used for filtering.*/
4370 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4372 filter->list = g_slist_delete_link(filter->list, link);
4373 filter->list = g_slist_append(filter->list, (gpointer)node);
4378 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4380 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4381 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4382 char *syslocale = NULL;
4383 char *locale = NULL;
4384 char *condition = NULL;
4385 char *error_message = NULL;
4386 char query[MAX_QUERY_LEN] = {'\0'};
4387 char where[MAX_QUERY_LEN] = {'\0'};
4391 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4393 /*Get current locale*/
4394 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4395 if (syslocale == NULL) {
4396 _LOGE("current locale is NULL\n");
4397 return PMINFO_R_ERROR;
4399 locale = __convert_system_locale_to_manifest_locale(syslocale);
4400 if (locale == NULL) {
4401 _LOGE("manifest locale is NULL\n");
4403 return PMINFO_R_ERROR;
4406 ret = __open_manifest_db(uid);
4408 _LOGE("Fail to open manifest DB\n");
4411 return PMINFO_R_ERROR;
4414 /*Start constructing query*/
4415 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4417 /*Get where clause*/
4418 for (list = filter->list; list; list = g_slist_next(list)) {
4419 __get_filter_condition(list->data, &condition);
4421 strncat(where, condition, sizeof(where) - strlen(where) -1);
4422 where[sizeof(where) - 1] = '\0';
4426 if (g_slist_next(list)) {
4427 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4428 where[sizeof(where) - 1] = '\0';
4431 _LOGE("where = %s\n", where);
4432 if (strlen(where) > 0) {
4433 strncat(query, where, sizeof(query) - strlen(query) - 1);
4434 query[sizeof(query) - 1] = '\0';
4436 _LOGE("query = %s\n", query);
4440 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4441 _LOGE("Don't execute query = %s error message = %s\n", query,
4443 sqlite3_free(error_message);
4444 ret = PMINFO_R_ERROR;
4458 __close_manifest_db();
4462 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4464 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4467 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4468 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4470 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4471 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4472 char *syslocale = NULL;
4473 char *locale = NULL;
4474 char *condition = NULL;
4475 char *error_message = NULL;
4476 char query[MAX_QUERY_LEN] = {'\0'};
4477 char where[MAX_QUERY_LEN] = {'\0'};
4480 label_x *tmp1 = NULL;
4481 icon_x *tmp2 = NULL;
4482 description_x *tmp3 = NULL;
4483 author_x *tmp4 = NULL;
4484 privilege_x *tmp5 = NULL;
4485 pkgmgr_pkginfo_x *node = NULL;
4486 pkgmgr_pkginfo_x *tmphead = NULL;
4487 pkgmgr_pkginfo_x *pkginfo = NULL;
4489 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4490 /*Get current locale*/
4491 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4492 if (syslocale == NULL) {
4493 _LOGE("current locale is NULL\n");
4494 return PMINFO_R_ERROR;
4496 locale = __convert_system_locale_to_manifest_locale(syslocale);
4497 if (locale == NULL) {
4498 _LOGE("manifest locale is NULL\n");
4500 return PMINFO_R_ERROR;
4503 ret = __open_manifest_db(uid);
4505 _LOGE("Fail to open manifest DB\n");
4508 return PMINFO_R_ERROR;
4510 /*Start constructing query*/
4511 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4513 /*Get where clause*/
4514 for (list = filter->list; list; list = g_slist_next(list)) {
4515 __get_filter_condition(list->data, &condition);
4517 strncat(where, condition, sizeof(where) - strlen(where) -1);
4518 where[sizeof(where) - 1] = '\0';
4522 if (g_slist_next(list)) {
4523 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4524 where[sizeof(where) - 1] = '\0';
4527 _LOGE("where = %s\n", where);
4528 if (strlen(where) > 0) {
4529 strncat(query, where, sizeof(query) - strlen(query) - 1);
4530 query[sizeof(query) - 1] = '\0';
4532 _LOGE("query = %s\n", query);
4533 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4534 if (tmphead == NULL) {
4535 _LOGE("Out of Memory!!!\n");
4536 ret = PMINFO_R_ERROR;
4542 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4543 _LOGE("Don't execute query = %s error message = %s\n", query,
4545 sqlite3_free(error_message);
4546 ret = PMINFO_R_ERROR;
4550 LISTHEAD(tmphead, node);
4551 for(node = node->next ; node ; node = node->next) {
4553 pkginfo->locale = strdup(locale);
4554 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4555 if (pkginfo->manifest_info->privileges == NULL) {
4556 _LOGE("Failed to allocate memory for privileges info\n");
4557 ret = PMINFO_R_ERROR;
4561 /*populate manifest_info from DB*/
4562 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4563 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4565 _LOGE("Package Info DB Information retrieval failed\n");
4566 ret = PMINFO_R_ERROR;
4569 memset(query, '\0', MAX_QUERY_LEN);
4570 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4571 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4572 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4574 _LOGE("Package Info DB Information retrieval failed\n");
4575 ret = PMINFO_R_ERROR;
4578 /*Also store the values corresponding to default locales*/
4579 memset(query, '\0', MAX_QUERY_LEN);
4580 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4581 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4582 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4584 _LOGE("Package Info DB Information retrieval failed\n");
4585 ret = PMINFO_R_ERROR;
4588 if (pkginfo->manifest_info->label) {
4589 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4590 pkginfo->manifest_info->label = tmp1;
4592 if (pkginfo->manifest_info->icon) {
4593 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4594 pkginfo->manifest_info->icon = tmp2;
4596 if (pkginfo->manifest_info->description) {
4597 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4598 pkginfo->manifest_info->description = tmp3;
4600 if (pkginfo->manifest_info->author) {
4601 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4602 pkginfo->manifest_info->author = tmp4;
4604 if (pkginfo->manifest_info->privileges->privilege) {
4605 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4606 pkginfo->manifest_info->privileges->privilege = tmp5;
4610 LISTHEAD(tmphead, node);
4612 for(node = node->next ; node ; node = node->next) {
4615 ret = pkg_cb( (void *)pkginfo, user_data);
4630 __close_manifest_db();
4631 __cleanup_pkginfo(tmphead);
4635 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4636 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4638 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4641 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4642 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4644 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4645 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4647 privilege_x *ptr = NULL;
4648 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4649 ptr = info->manifest_info->privileges->privilege;
4650 for (; ptr; ptr = ptr->next) {
4652 ret = privilege_func(ptr->text, user_data);
4660 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4661 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4663 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4664 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4665 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4667 char *syslocale = NULL;
4668 char *locale = NULL;
4670 char query[MAX_QUERY_LEN] = {'\0'};
4671 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4672 pkgmgr_pkginfo_x *allinfo = NULL;
4673 pkgmgr_appinfo_x *appinfo = NULL;
4674 icon_x *ptr1 = NULL;
4675 label_x *ptr2 = NULL;
4676 category_x *ptr3 = NULL;
4677 metadata_x *ptr4 = NULL;
4678 permission_x *ptr5 = NULL;
4679 image_x *ptr6 = NULL;
4680 const char* user_pkg_parser = NULL;
4682 /*get system locale*/
4683 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4684 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4686 /*get locale on db*/
4687 locale = __convert_system_locale_to_manifest_locale(syslocale);
4688 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4691 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4692 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4694 /*calloc manifest_info*/
4695 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4696 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4699 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4700 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4702 /*set component type*/
4703 if (component == PMINFO_UI_APP)
4704 appinfo->app_component = PMINFO_UI_APP;
4705 if (component == PMINFO_SVC_APP)
4706 appinfo->app_component = PMINFO_SVC_APP;
4707 if (component == PMINFO_ALL_APP)
4708 appinfo->app_component = PMINFO_ALL_APP;
4711 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4712 ret = __open_manifest_db(uid);
4713 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4715 appinfo->package = strdup(info->manifest_info->package);
4716 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4717 "from package_app_info where " \
4718 "package='%s' and app_component='%s'",
4719 info->manifest_info->package,
4720 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4724 /*Populate ui app info */
4725 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4726 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4728 uiapplication_x *tmp = NULL;
4729 if (info->manifest_info->uiapplication) {
4730 LISTHEAD(info->manifest_info->uiapplication, tmp);
4731 info->manifest_info->uiapplication = tmp;
4733 /*Populate localized info for default locales and call callback*/
4734 /*If the callback func return < 0 we break and no more call back is called*/
4737 appinfo->locale = strdup(locale);
4738 appinfo->uiapp_info = tmp;
4739 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4743 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4746 memset(query, '\0', MAX_QUERY_LEN);
4747 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4748 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4749 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4751 memset(query, '\0', MAX_QUERY_LEN);
4752 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);
4753 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4754 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4756 /*store setting notification icon section*/
4757 memset(query, '\0', MAX_QUERY_LEN);
4758 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4759 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4760 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4762 /*store app preview image info*/
4763 memset(query, '\0', MAX_QUERY_LEN);
4764 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4765 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4766 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4768 if (appinfo->uiapp_info->label) {
4769 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4770 appinfo->uiapp_info->label = ptr2;
4772 if (appinfo->uiapp_info->icon) {
4773 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4774 appinfo->uiapp_info->icon = ptr1;
4776 if (appinfo->uiapp_info->category) {
4777 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4778 appinfo->uiapp_info->category = ptr3;
4780 if (appinfo->uiapp_info->metadata) {
4781 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4782 appinfo->uiapp_info->metadata = ptr4;
4784 if (appinfo->uiapp_info->permission) {
4785 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4786 appinfo->uiapp_info->permission = ptr5;
4788 if (appinfo->uiapp_info->image) {
4789 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4790 appinfo->uiapp_info->image = ptr6;
4792 ret = app_func((void *)appinfo, user_data);
4798 case PMINFO_SVC_APP:
4799 /*Populate svc app info */
4800 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4801 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4803 serviceapplication_x *tmp1 = NULL;
4804 if (info->manifest_info->serviceapplication) {
4805 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4806 info->manifest_info->serviceapplication = tmp1;
4808 /*Populate localized info for default locales and call callback*/
4809 /*If the callback func return < 0 we break and no more call back is called*/
4812 appinfo->locale = strdup(locale);
4813 appinfo->svcapp_info = tmp1;
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->svcapp_info->appid, locale);
4816 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4817 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4819 memset(query, '\0', MAX_QUERY_LEN);
4820 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);
4821 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4822 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4824 if (appinfo->svcapp_info->label) {
4825 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4826 appinfo->svcapp_info->label = ptr2;
4828 if (appinfo->svcapp_info->icon) {
4829 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4830 appinfo->svcapp_info->icon = ptr1;
4832 if (appinfo->svcapp_info->category) {
4833 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4834 appinfo->svcapp_info->category = ptr3;
4836 if (appinfo->svcapp_info->metadata) {
4837 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4838 appinfo->svcapp_info->metadata = ptr4;
4840 if (appinfo->svcapp_info->permission) {
4841 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4842 appinfo->svcapp_info->permission = ptr5;
4844 ret = app_func((void *)appinfo, user_data);
4850 case PMINFO_ALL_APP:
4851 memset(query, '\0', MAX_QUERY_LEN);
4852 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4854 /*Populate all app info */
4855 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4856 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4859 appinfo->app_component = PMINFO_UI_APP;
4860 uiapplication_x *tmp2 = NULL;
4861 if (allinfo->manifest_info->uiapplication) {
4862 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4863 allinfo->manifest_info->uiapplication = tmp2;
4865 /*Populate localized info for default locales and call callback*/
4866 /*If the callback func return < 0 we break and no more call back is called*/
4869 appinfo->locale = strdup(locale);
4870 appinfo->uiapp_info = tmp2;
4871 memset(query, '\0', MAX_QUERY_LEN);
4872 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4873 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4874 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4876 memset(query, '\0', MAX_QUERY_LEN);
4877 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);
4878 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4879 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4881 /*store setting notification icon section*/
4882 memset(query, '\0', MAX_QUERY_LEN);
4883 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4884 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4885 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4887 /*store app preview image info*/
4888 memset(query, '\0', MAX_QUERY_LEN);
4889 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4890 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4891 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4893 if (appinfo->uiapp_info->label) {
4894 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4895 appinfo->uiapp_info->label = ptr2;
4897 if (appinfo->uiapp_info->icon) {
4898 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4899 appinfo->uiapp_info->icon = ptr1;
4901 if (appinfo->uiapp_info->category) {
4902 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4903 appinfo->uiapp_info->category = ptr3;
4905 if (appinfo->uiapp_info->metadata) {
4906 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4907 appinfo->uiapp_info->metadata = ptr4;
4909 if (appinfo->uiapp_info->permission) {
4910 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4911 appinfo->uiapp_info->permission = ptr5;
4913 if (appinfo->uiapp_info->image) {
4914 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4915 appinfo->uiapp_info->image = ptr6;
4917 ret = app_func((void *)appinfo, user_data);
4924 appinfo->app_component = PMINFO_SVC_APP;
4925 serviceapplication_x *tmp3 = NULL;
4926 if (allinfo->manifest_info->serviceapplication) {
4927 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4928 allinfo->manifest_info->serviceapplication = tmp3;
4930 /*Populate localized info for default locales and call callback*/
4931 /*If the callback func return < 0 we break and no more call back is called*/
4934 appinfo->locale = strdup(locale);
4935 appinfo->svcapp_info = tmp3;
4936 memset(query, '\0', MAX_QUERY_LEN);
4937 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4938 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4939 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4941 memset(query, '\0', MAX_QUERY_LEN);
4942 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);
4943 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4944 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4946 if (appinfo->svcapp_info->label) {
4947 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4948 appinfo->svcapp_info->label = ptr2;
4950 if (appinfo->svcapp_info->icon) {
4951 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4952 appinfo->svcapp_info->icon = ptr1;
4954 if (appinfo->svcapp_info->category) {
4955 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4956 appinfo->svcapp_info->category = ptr3;
4958 if (appinfo->svcapp_info->metadata) {
4959 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4960 appinfo->svcapp_info->metadata = ptr4;
4962 if (appinfo->svcapp_info->permission) {
4963 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4964 appinfo->svcapp_info->permission = ptr5;
4966 ret = app_func((void *)appinfo, user_data);
4971 appinfo->app_component = PMINFO_ALL_APP;
4987 if (appinfo->package) {
4988 free((void *)appinfo->package);
4989 appinfo->package = NULL;
4994 __cleanup_pkginfo(allinfo);
4996 __close_manifest_db();
5000 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
5001 pkgmgrinfo_app_list_cb app_func, void *user_data)
5003 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
5006 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5008 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5010 int ret = PMINFO_R_OK;
5011 char query[MAX_QUERY_LEN] = {'\0'};
5012 pkgmgr_appinfo_x *appinfo = NULL;
5013 uiapplication_x *ptr1 = NULL;
5014 serviceapplication_x *ptr2 = NULL;
5015 const char* user_pkg_parser = NULL;
5018 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5019 ret = __open_manifest_db(uid);
5020 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5023 pkgmgr_pkginfo_x *info = NULL;
5024 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5025 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5027 /*calloc manifest_info*/
5028 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5029 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5032 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5033 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5035 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5036 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
5037 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5039 if (info->manifest_info->uiapplication) {
5040 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5041 info->manifest_info->uiapplication = ptr1;
5043 if (info->manifest_info->serviceapplication) {
5044 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5045 info->manifest_info->serviceapplication = ptr2;
5049 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5051 appinfo->app_component = PMINFO_UI_APP;
5052 appinfo->package = strdup(ptr1->package);
5053 appinfo->uiapp_info = ptr1;
5055 ret = app_func((void *)appinfo, user_data);
5058 free((void *)appinfo->package);
5059 appinfo->package = NULL;
5062 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5064 appinfo->app_component = PMINFO_SVC_APP;
5065 appinfo->package = strdup(ptr2->package);
5066 appinfo->svcapp_info = ptr2;
5068 ret = app_func((void *)appinfo, user_data);
5071 free((void *)appinfo->package);
5072 appinfo->package = NULL;
5077 __close_manifest_db();
5082 __cleanup_pkginfo(info);
5086 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5088 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
5091 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5093 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5095 int ret = PMINFO_R_OK;
5096 char query[MAX_QUERY_LEN] = {'\0'};
5097 char *syslocale = NULL;
5098 char *locale = NULL;
5099 pkgmgr_appinfo_x *appinfo = NULL;
5100 uiapplication_x *ptr1 = NULL;
5101 serviceapplication_x *ptr2 = NULL;
5102 label_x *tmp1 = NULL;
5103 icon_x *tmp2 = NULL;
5104 category_x *tmp3 = NULL;
5105 metadata_x *tmp4 = NULL;
5106 permission_x *tmp5 = NULL;
5107 image_x *tmp6 = NULL;
5108 const char *user_pkg_parser = NULL;
5110 /*get system locale*/
5111 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5112 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5114 /*get locale on db*/
5115 locale = __convert_system_locale_to_manifest_locale(syslocale);
5116 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5119 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5120 ret = __open_manifest_db(uid);
5121 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5124 pkgmgr_pkginfo_x *info = NULL;
5125 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5126 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5128 /*calloc manifest_info*/
5129 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5130 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5133 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5134 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5136 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5137 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5138 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5140 if (info->manifest_info->uiapplication) {
5141 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5142 info->manifest_info->uiapplication = ptr1;
5144 if (info->manifest_info->serviceapplication) {
5145 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5146 info->manifest_info->serviceapplication = ptr2;
5150 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5152 appinfo->locale = strdup(locale);
5153 appinfo->app_component = PMINFO_UI_APP;
5154 appinfo->package = strdup(ptr1->package);
5155 appinfo->uiapp_info = ptr1;
5156 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5157 "from package_app_info where " \
5158 "app_id='%s'", ptr1->appid);
5159 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5160 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5162 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5166 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5169 memset(query, '\0', MAX_QUERY_LEN);
5170 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5171 "from package_app_localized_info where " \
5172 "app_id='%s' and app_locale='%s'",
5173 ptr1->appid, locale);
5174 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5175 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5177 memset(query, '\0', MAX_QUERY_LEN);
5178 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5179 "from package_app_localized_info where " \
5180 "app_id='%s' and app_locale='%s'",
5181 ptr1->appid, DEFAULT_LOCALE);
5183 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5184 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5186 /*store setting notification icon section*/
5187 memset(query, '\0', MAX_QUERY_LEN);
5188 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5189 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5190 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5192 /*store app preview image info*/
5193 memset(query, '\0', MAX_QUERY_LEN);
5194 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5195 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5196 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5198 if (appinfo->uiapp_info->label) {
5199 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5200 appinfo->uiapp_info->label = tmp1;
5202 if (appinfo->uiapp_info->icon) {
5203 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5204 appinfo->uiapp_info->icon= tmp2;
5206 if (appinfo->uiapp_info->category) {
5207 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5208 appinfo->uiapp_info->category = tmp3;
5210 if (appinfo->uiapp_info->metadata) {
5211 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5212 appinfo->uiapp_info->metadata = tmp4;
5214 if (appinfo->uiapp_info->permission) {
5215 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5216 appinfo->uiapp_info->permission = tmp5;
5218 if (appinfo->uiapp_info->image) {
5219 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5220 appinfo->uiapp_info->image = tmp6;
5222 ret = app_func((void *)appinfo, user_data);
5225 free((void *)appinfo->package);
5226 appinfo->package = NULL;
5229 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5231 appinfo->locale = strdup(locale);
5232 appinfo->app_component = PMINFO_SVC_APP;
5233 appinfo->package = strdup(ptr2->package);
5234 appinfo->svcapp_info = ptr2;
5235 memset(query, '\0', MAX_QUERY_LEN);
5236 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5237 "from package_app_info where " \
5238 "app_id='%s'", ptr2->appid);
5239 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5240 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5242 memset(query, '\0', MAX_QUERY_LEN);
5243 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5244 "from package_app_localized_info where " \
5245 "app_id='%s' and app_locale='%s'",
5246 ptr2->appid, locale);
5247 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5248 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5250 memset(query, '\0', MAX_QUERY_LEN);
5251 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5252 "from package_app_localized_info where " \
5253 "app_id='%s' and app_locale='%s'",
5254 ptr2->appid, DEFAULT_LOCALE);
5255 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5256 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5258 if (appinfo->svcapp_info->label) {
5259 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5260 appinfo->svcapp_info->label = tmp1;
5262 if (appinfo->svcapp_info->icon) {
5263 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5264 appinfo->svcapp_info->icon= tmp2;
5266 if (appinfo->svcapp_info->category) {
5267 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5268 appinfo->svcapp_info->category = tmp3;
5270 if (appinfo->svcapp_info->metadata) {
5271 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5272 appinfo->svcapp_info->metadata = tmp4;
5274 if (appinfo->svcapp_info->permission) {
5275 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5276 appinfo->svcapp_info->permission = tmp5;
5278 ret = app_func((void *)appinfo, user_data);
5281 free((void *)appinfo->package);
5282 appinfo->package = NULL;
5295 __close_manifest_db();
5300 __cleanup_pkginfo(info);
5304 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5306 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5309 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5311 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5312 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5314 pkgmgr_appinfo_x *appinfo = NULL;
5315 char *syslocale = NULL;
5316 char *locale = NULL;
5319 label_x *tmp1 = NULL;
5320 icon_x *tmp2 = NULL;
5321 category_x *tmp3 = NULL;
5322 metadata_x *tmp4 = NULL;
5323 permission_x *tmp5 = NULL;
5324 image_x *tmp6 = NULL;
5325 char query[MAX_QUERY_LEN] = {'\0'};
5326 const char* user_pkg_parser = NULL;
5331 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5332 ret = __open_manifest_db(uid);
5333 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5335 /*check appid exist on db*/
5336 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5337 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5338 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5339 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5341 /*get system locale*/
5342 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5343 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5345 /*get locale on db*/
5346 locale = __convert_system_locale_to_manifest_locale(syslocale);
5347 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5350 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5351 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5353 /*check app_component from DB*/
5354 memset(query, '\0', MAX_QUERY_LEN);
5355 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5356 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5357 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5359 /*calloc app_component*/
5360 if (appinfo->app_component == PMINFO_UI_APP) {
5361 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5362 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5364 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5365 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5367 appinfo->locale = strdup(locale);
5369 /*populate app_info from DB*/
5370 memset(query, '\0', MAX_QUERY_LEN);
5371 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5372 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5373 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5375 memset(query, '\0', MAX_QUERY_LEN);
5376 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5377 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5378 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5380 /*Also store the values corresponding to default locales*/
5381 memset(query, '\0', MAX_QUERY_LEN);
5382 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5383 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5384 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5386 /*Populate app category*/
5387 memset(query, '\0', MAX_QUERY_LEN);
5388 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5389 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5390 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5392 /*Populate app metadata*/
5393 memset(query, '\0', MAX_QUERY_LEN);
5394 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5395 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5396 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5398 /*Populate app permission*/
5399 memset(query, '\0', MAX_QUERY_LEN);
5400 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5401 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5402 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5404 /*store setting notification icon section*/
5405 memset(query, '\0', MAX_QUERY_LEN);
5406 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5407 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5408 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5410 /*store app preview image info*/
5411 memset(query, '\0', MAX_QUERY_LEN);
5412 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5413 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5414 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5416 switch (appinfo->app_component) {
5418 if (appinfo->uiapp_info->label) {
5419 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5420 appinfo->uiapp_info->label = tmp1;
5422 if (appinfo->uiapp_info->icon) {
5423 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5424 appinfo->uiapp_info->icon = tmp2;
5426 if (appinfo->uiapp_info->category) {
5427 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5428 appinfo->uiapp_info->category = tmp3;
5430 if (appinfo->uiapp_info->metadata) {
5431 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5432 appinfo->uiapp_info->metadata = tmp4;
5434 if (appinfo->uiapp_info->permission) {
5435 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5436 appinfo->uiapp_info->permission = tmp5;
5438 if (appinfo->uiapp_info->image) {
5439 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5440 appinfo->uiapp_info->image = tmp6;
5443 case PMINFO_SVC_APP:
5444 if (appinfo->svcapp_info->label) {
5445 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5446 appinfo->svcapp_info->label = tmp1;
5448 if (appinfo->svcapp_info->icon) {
5449 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5450 appinfo->svcapp_info->icon = tmp2;
5452 if (appinfo->svcapp_info->category) {
5453 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5454 appinfo->svcapp_info->category = tmp3;
5456 if (appinfo->svcapp_info->metadata) {
5457 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5458 appinfo->svcapp_info->metadata = tmp4;
5460 if (appinfo->svcapp_info->permission) {
5461 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5462 appinfo->svcapp_info->permission = tmp5;
5472 if (ret == PMINFO_R_OK)
5473 *handle = (void*)appinfo;
5476 __cleanup_appinfo(appinfo);
5479 __close_manifest_db();
5491 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5493 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5496 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5499 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5500 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5502 if (info->app_component == PMINFO_UI_APP)
5503 *appid = (char *)info->uiapp_info->appid;
5504 else if (info->app_component == PMINFO_SVC_APP)
5505 *appid = (char *)info->svcapp_info->appid;
5510 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5512 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5513 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5514 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5516 *pkg_name = (char *)info->package;
5521 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5523 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5524 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5525 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5527 *pkgid = (char *)info->package;
5532 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5534 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5535 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5536 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5538 if (info->app_component == PMINFO_UI_APP)
5539 *exec = (char *)info->uiapp_info->exec;
5540 if (info->app_component == PMINFO_SVC_APP)
5541 *exec = (char *)info->svcapp_info->exec;
5547 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5549 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5550 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5551 char *locale = NULL;
5553 icon_x *start = NULL;
5556 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5557 locale = info->locale;
5558 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5560 if (info->app_component == PMINFO_UI_APP)
5561 start = info->uiapp_info->icon;
5562 if (info->app_component == PMINFO_SVC_APP)
5563 start = info->svcapp_info->icon;
5564 for(ptr = start; ptr != NULL; ptr = ptr->next)
5567 if (strcmp(ptr->lang, locale) == 0) {
5568 *icon = (char *)ptr->text;
5569 if (strcasecmp(*icon, "(null)") == 0) {
5570 locale = DEFAULT_LOCALE;
5574 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5575 *icon = (char *)ptr->text;
5584 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5586 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5587 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5588 char *locale = NULL;
5589 label_x *ptr = NULL;
5590 label_x *start = NULL;
5593 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5594 locale = info->locale;
5595 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5597 if (info->app_component == PMINFO_UI_APP)
5598 start = info->uiapp_info->label;
5599 if (info->app_component == PMINFO_SVC_APP)
5600 start = info->svcapp_info->label;
5601 for(ptr = start; ptr != NULL; ptr = ptr->next)
5604 if (strcmp(ptr->lang, locale) == 0) {
5605 *label = (char *)ptr->text;
5606 if (strcasecmp(*label, "(null)") == 0) {
5607 locale = DEFAULT_LOCALE;
5611 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5612 *label = (char *)ptr->text;
5613 if (strcasecmp(*label, "(null)") == 0) {
5614 locale = DEFAULT_LOCALE;
5618 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5619 *label = (char *)ptr->text;
5628 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5630 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5631 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5632 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5634 if (info->app_component == PMINFO_UI_APP)
5635 *component = PMINFO_UI_APP;
5636 else if (info->app_component == PMINFO_SVC_APP)
5637 *component = PMINFO_SVC_APP;
5639 return PMINFO_R_ERROR;
5644 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5646 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5647 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5648 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5650 if (info->app_component == PMINFO_UI_APP)
5651 *app_type = (char *)info->uiapp_info->type;
5652 if (info->app_component == PMINFO_SVC_APP)
5653 *app_type = (char *)info->svcapp_info->type;
5658 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5659 int *operation_count, char ***operation)
5661 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5662 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5663 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5664 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5665 *operation_count = data->operation_count;
5666 *operation = data->operation;
5670 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5671 int *uri_count, char ***uri)
5673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5674 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5675 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5676 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5677 *uri_count = data->uri_count;
5682 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5683 int *mime_count, char ***mime)
5685 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5686 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5687 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5688 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5689 *mime_count = data->mime_count;
5694 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5695 int *subapp_count, char ***subapp)
5697 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5698 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5699 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5700 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5701 *subapp_count = data->subapp_count;
5702 *subapp = data->subapp;
5706 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5708 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5709 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5713 icon_x *start = NULL;
5714 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5716 start = info->uiapp_info->icon;
5718 for(ptr = start; ptr != NULL; ptr = ptr->next)
5721 val = (char *)ptr->section;
5722 if (strcmp(val, "setting") == 0){
5723 *icon = (char *)ptr->text;
5732 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5734 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5735 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5739 icon_x *start = NULL;
5740 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5742 start = info->uiapp_info->icon;
5744 for(ptr = start; ptr != NULL; ptr = ptr->next)
5747 val = (char *)ptr->section;
5749 if (strcmp(val, "notification") == 0){
5750 *icon = (char *)ptr->text;
5759 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5761 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5762 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5764 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5765 val = (char *)info->uiapp_info->recentimage;
5767 if (strcasecmp(val, "capture") == 0)
5768 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5769 else if (strcasecmp(val, "icon") == 0)
5770 *type = PMINFO_RECENTIMAGE_USE_ICON;
5772 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5778 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5780 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5781 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5784 image_x *ptr = NULL;
5785 image_x *start = NULL;
5786 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5788 start = info->uiapp_info->image;
5790 for(ptr = start; ptr != NULL; ptr = ptr->next)
5793 val = (char *)ptr->section;
5795 if (strcmp(val, "preview") == 0)
5796 *preview_img = (char *)ptr->text;
5804 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5806 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5807 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5810 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5812 if (info->app_component == PMINFO_UI_APP)
5813 val = info->uiapp_info->permission_type;
5814 else if (info->app_component == PMINFO_SVC_APP)
5815 val = info->svcapp_info->permission_type;
5817 return PMINFO_R_ERROR;
5819 if (strcmp(val, "signature") == 0)
5820 *permission = PMINFO_PERMISSION_SIGNATURE;
5821 else if (strcmp(val, "privilege") == 0)
5822 *permission = PMINFO_PERMISSION_PRIVILEGE;
5824 *permission = PMINFO_PERMISSION_NORMAL;
5829 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5831 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5832 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5833 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5835 *component_type = (char *)info->uiapp_info->component_type;
5840 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5842 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5843 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5845 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5846 val = (char *)info->uiapp_info->hwacceleration;
5848 if (strcasecmp(val, "not-use-GL") == 0)
5849 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5850 else if (strcasecmp(val, "use-GL") == 0)
5851 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5853 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5858 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5860 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5861 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5863 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5864 val = (char *)info->uiapp_info->screenreader;
5866 if (strcasecmp(val, "screenreader-off") == 0)
5867 *screenreader = PMINFO_SCREENREADER_OFF;
5868 else if (strcasecmp(val, "screenreader-on") == 0)
5869 *screenreader = PMINFO_SCREENREADER_ON;
5871 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5876 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5878 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5879 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5880 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5881 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5883 if (info->app_component == PMINFO_UI_APP){
5884 *portrait_img = (char *)info->uiapp_info->portraitimg;
5885 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5891 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5894 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5895 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5897 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5902 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5903 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5905 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5906 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5908 permission_x *ptr = NULL;
5909 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5910 if (info->app_component == PMINFO_UI_APP)
5911 ptr = info->uiapp_info->permission;
5912 else if (info->app_component == PMINFO_SVC_APP)
5913 ptr = info->svcapp_info->permission;
5915 return PMINFO_R_EINVAL;
5916 for (; ptr; ptr = ptr->next) {
5918 ret = permission_func(ptr->value, user_data);
5926 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5927 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5929 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5930 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5932 category_x *ptr = NULL;
5933 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5934 if (info->app_component == PMINFO_UI_APP)
5935 ptr = info->uiapp_info->category;
5936 else if (info->app_component == PMINFO_SVC_APP)
5937 ptr = info->svcapp_info->category;
5939 return PMINFO_R_EINVAL;
5940 for (; ptr; ptr = ptr->next) {
5942 ret = category_func(ptr->name, user_data);
5950 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5951 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5953 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5954 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5956 metadata_x *ptr = NULL;
5957 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5958 if (info->app_component == PMINFO_UI_APP)
5959 ptr = info->uiapp_info->metadata;
5960 else if (info->app_component == PMINFO_SVC_APP)
5961 ptr = info->svcapp_info->metadata;
5963 return PMINFO_R_EINVAL;
5964 for (; ptr; ptr = ptr->next) {
5966 ret = metadata_func(ptr->key, ptr->value, user_data);
5974 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5975 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5977 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5978 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5986 char *manifest = NULL;
5987 char **operation = NULL;
5990 char **subapp = NULL;
5991 appcontrol_x *appcontrol = NULL;
5992 manifest_x *mfx = NULL;
5993 operation_x *op = NULL;
5996 subapp_x *sa = NULL;
5997 pkgmgrinfo_app_component component;
5998 pkgmgrinfo_appcontrol_x *ptr = NULL;
5999 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6001 _LOGE("Failed to get package name\n");
6002 return PMINFO_R_ERROR;
6004 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6006 _LOGE("Failed to get app component name\n");
6007 return PMINFO_R_ERROR;
6009 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
6010 if (manifest == NULL) {
6011 _LOGE("Failed to fetch package manifest file\n");
6012 return PMINFO_R_ERROR;
6014 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
6016 _LOGE("Failed to parse package manifest file\n");
6019 return PMINFO_R_ERROR;
6022 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6024 _LOGE("Out of Memory!!!\n");
6025 pkgmgr_parser_free_manifest_xml(mfx);
6026 return PMINFO_R_ERROR;
6028 /*Get Operation, Uri, Mime*/
6029 switch (component) {
6031 if (mfx->uiapplication) {
6032 if (mfx->uiapplication->appsvc) {
6033 appcontrol = mfx->uiapplication->appsvc;
6037 case PMINFO_SVC_APP:
6038 if (mfx->serviceapplication) {
6039 if (mfx->serviceapplication->appsvc) {
6040 appcontrol = mfx->serviceapplication->appsvc;
6047 for (; appcontrol; appcontrol = appcontrol->next) {
6048 op = appcontrol->operation;
6049 for (; op; op = op->next)
6051 op = appcontrol->operation;
6053 ui = appcontrol->uri;
6054 for (; ui; ui = ui->next)
6056 ui = appcontrol->uri;
6058 mi = appcontrol->mime;
6059 for (; mi; mi = mi->next)
6061 mi = appcontrol->mime;
6063 sa = appcontrol->subapp;
6064 for (; sa; sa = sa->next)
6066 sa = appcontrol->subapp;
6068 operation = (char **)calloc(oc, sizeof(char *));
6069 for (i = 0; i < oc; i++) {
6070 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6074 uri = (char **)calloc(uc, sizeof(char *));
6075 for (i = 0; i < uc; i++) {
6076 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6080 mime = (char **)calloc(mc, sizeof(char *));
6081 for (i = 0; i < mc; i++) {
6082 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6086 subapp = (char **)calloc(sc, sizeof(char *));
6087 for (i = 0; i < sc; i++) {
6088 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6092 /*populate appcontrol handle*/
6093 ptr->operation_count = oc;
6094 ptr->uri_count = uc;
6095 ptr->mime_count = mc;
6096 ptr->subapp_count = sc;
6097 ptr->operation = operation;
6100 ptr->subapp = subapp;
6102 ret = appcontrol_func((void *)ptr, user_data);
6103 for (i = 0; i < oc; i++) {
6106 operation[i] = NULL;
6113 for (i = 0; i < uc; i++) {
6123 for (i = 0; i < mc; i++) {
6133 for (i = 0; i < sc; i++) {
6150 pkgmgr_parser_free_manifest_xml(mfx);
6158 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6159 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6161 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6162 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6170 char *manifest = NULL;
6171 char **operation = NULL;
6174 char **subapp = NULL;
6175 appcontrol_x *appcontrol = NULL;
6176 manifest_x *mfx = NULL;
6177 operation_x *op = NULL;
6180 subapp_x *sa = NULL;
6181 pkgmgrinfo_app_component component;
6182 pkgmgrinfo_appcontrol_x *ptr = NULL;
6183 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6185 _LOGE("Failed to get package name\n");
6186 return PMINFO_R_ERROR;
6188 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6190 _LOGE("Failed to get app component name\n");
6191 return PMINFO_R_ERROR;
6193 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6194 if (manifest == NULL) {
6195 _LOGE("Failed to fetch package manifest file\n");
6196 return PMINFO_R_ERROR;
6198 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6200 _LOGE("Failed to parse package manifest file\n");
6203 return PMINFO_R_ERROR;
6206 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6208 _LOGE("Out of Memory!!!\n");
6209 pkgmgr_parser_free_manifest_xml(mfx);
6210 return PMINFO_R_ERROR;
6212 /*Get Operation, Uri, Mime*/
6213 switch (component) {
6215 if (mfx->uiapplication) {
6216 if (mfx->uiapplication->appsvc) {
6217 appcontrol = mfx->uiapplication->appsvc;
6221 case PMINFO_SVC_APP:
6222 if (mfx->serviceapplication) {
6223 if (mfx->serviceapplication->appsvc) {
6224 appcontrol = mfx->serviceapplication->appsvc;
6231 for (; appcontrol; appcontrol = appcontrol->next) {
6232 op = appcontrol->operation;
6233 for (; op; op = op->next)
6235 op = appcontrol->operation;
6237 ui = appcontrol->uri;
6238 for (; ui; ui = ui->next)
6240 ui = appcontrol->uri;
6242 mi = appcontrol->mime;
6243 for (; mi; mi = mi->next)
6245 mi = appcontrol->mime;
6247 sa = appcontrol->subapp;
6248 for (; sa; sa = sa->next)
6250 sa = appcontrol->subapp;
6252 operation = (char **)calloc(oc, sizeof(char *));
6253 for (i = 0; i < oc; i++) {
6254 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6258 uri = (char **)calloc(uc, sizeof(char *));
6259 for (i = 0; i < uc; i++) {
6260 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6264 mime = (char **)calloc(mc, sizeof(char *));
6265 for (i = 0; i < mc; i++) {
6266 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6270 subapp = (char **)calloc(sc, sizeof(char *));
6271 for (i = 0; i < sc; i++) {
6272 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6276 /*populate appcontrol handle*/
6277 ptr->operation_count = oc;
6278 ptr->uri_count = uc;
6279 ptr->mime_count = mc;
6280 ptr->subapp_count = sc;
6281 ptr->operation = operation;
6284 ptr->subapp = subapp;
6286 ret = appcontrol_func((void *)ptr, user_data);
6287 for (i = 0; i < oc; i++) {
6290 operation[i] = NULL;
6297 for (i = 0; i < uc; i++) {
6307 for (i = 0; i < mc; i++) {
6317 for (i = 0; i < sc; i++) {
6334 pkgmgr_parser_free_manifest_xml(mfx);
6342 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6344 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6345 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6347 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6348 val = (char *)info->uiapp_info->nodisplay;
6350 if (strcasecmp(val, "true") == 0)
6352 else if (strcasecmp(val, "false") == 0)
6360 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6362 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6363 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6365 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6366 val = (char *)info->uiapp_info->multiple;
6368 if (strcasecmp(val, "true") == 0)
6370 else if (strcasecmp(val, "false") == 0)
6378 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6380 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6381 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6383 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6384 val = (char *)info->uiapp_info->indicatordisplay;
6386 if (strcasecmp(val, "true") == 0){
6387 *indicator_disp = 1;
6388 }else if (strcasecmp(val, "false") == 0){
6389 *indicator_disp = 0;
6391 *indicator_disp = 0;
6397 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6399 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6400 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6402 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6403 val = (char *)info->uiapp_info->taskmanage;
6405 if (strcasecmp(val, "true") == 0)
6407 else if (strcasecmp(val, "false") == 0)
6415 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6417 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6418 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6420 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6421 if (info->app_component == PMINFO_UI_APP)
6422 val = (char *)info->uiapp_info->enabled;
6423 else if (info->app_component == PMINFO_SVC_APP)
6424 val = (char *)info->uiapp_info->enabled;
6426 _LOGE("invalid component type\n");
6427 return PMINFO_R_EINVAL;
6431 if (strcasecmp(val, "true") == 0)
6433 else if (strcasecmp(val, "false") == 0)
6442 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6444 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6445 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6447 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6448 val = (char *)info->svcapp_info->onboot;
6450 if (strcasecmp(val, "true") == 0)
6452 else if (strcasecmp(val, "false") == 0)
6460 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6462 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6463 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6465 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6466 val = (char *)info->svcapp_info->autorestart;
6468 if (strcasecmp(val, "true") == 0)
6470 else if (strcasecmp(val, "false") == 0)
6478 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6480 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6481 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6483 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6484 val = (char *)info->uiapp_info->mainapp;
6486 if (strcasecmp(val, "true") == 0)
6488 else if (strcasecmp(val, "false") == 0)
6496 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6498 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6499 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6501 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6502 val = (char *)info->uiapp_info->preload;
6504 if (strcasecmp(val, "true") == 0)
6506 else if (strcasecmp(val, "false") == 0)
6514 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6517 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6519 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6520 val = (char *)info->uiapp_info->submode;
6522 if (strcasecmp(val, "true") == 0)
6524 else if (strcasecmp(val, "false") == 0)
6532 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6534 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6535 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6536 __cleanup_appinfo(info);
6540 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6542 return (pkgmgrinfo_pkginfo_filter_create(handle));
6545 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6547 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6550 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6551 const char *property, const int value)
6553 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6554 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6555 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6557 GSList *link = NULL;
6559 prop = _pminfo_appinfo_convert_to_prop_int(property);
6560 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6561 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6562 _LOGE("Invalid Integer Property\n");
6563 return PMINFO_R_EINVAL;
6565 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6566 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6568 _LOGE("Out of Memory!!!\n");
6569 return PMINFO_R_ERROR;
6571 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6572 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6574 _LOGE("Out of Memory\n");
6577 return PMINFO_R_ERROR;
6581 /*If API is called multiple times for same property, we should override the previous values.
6582 Last value set will be used for filtering.*/
6583 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6585 filter->list = g_slist_delete_link(filter->list, link);
6586 filter->list = g_slist_append(filter->list, (gpointer)node);
6591 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6592 const char *property, const bool value)
6594 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6595 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6597 GSList *link = NULL;
6599 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6600 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6601 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6602 _LOGE("Invalid Boolean Property\n");
6603 return PMINFO_R_EINVAL;
6605 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6606 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6608 _LOGE("Out of Memory!!!\n");
6609 return PMINFO_R_ERROR;
6612 val = strndup("('true','True')", 15);
6614 val = strndup("('false','False')", 17);
6616 _LOGE("Out of Memory\n");
6619 return PMINFO_R_ERROR;
6623 /*If API is called multiple times for same property, we should override the previous values.
6624 Last value set will be used for filtering.*/
6625 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6627 filter->list = g_slist_delete_link(filter->list, link);
6628 filter->list = g_slist_append(filter->list, (gpointer)node);
6633 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6634 const char *property, const char *value)
6636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6637 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6638 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6640 pkgmgrinfo_node_x *ptr = NULL;
6641 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6642 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6643 GSList *link = NULL;
6645 prop = _pminfo_appinfo_convert_to_prop_str(property);
6646 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6647 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6648 _LOGE("Invalid String Property\n");
6649 return PMINFO_R_EINVAL;
6651 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6652 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6654 _LOGE("Out of Memory!!!\n");
6655 return PMINFO_R_ERROR;
6659 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6660 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6661 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6663 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6665 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6667 filter->list = g_slist_delete_link(filter->list, link);
6668 filter->list = g_slist_append(filter->list, (gpointer)node);
6670 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6671 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6672 case E_PMINFO_APPINFO_PROP_APP_URI:
6673 case E_PMINFO_APPINFO_PROP_APP_MIME:
6674 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6676 _LOGE("Out of Memory\n");
6679 return PMINFO_R_ERROR;
6681 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6683 ptr = (pkgmgrinfo_node_x *)link->data;
6684 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6685 _LOGE("Previous value is %s\n", prev);
6686 filter->list = g_slist_delete_link(filter->list, link);
6687 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6688 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6689 _LOGE("New value is %s\n", val);
6691 filter->list = g_slist_append(filter->list, (gpointer)node);
6692 memset(temp, '\0', PKG_STRING_LEN_MAX);
6694 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6695 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6696 _LOGE("First value is %s\n", val);
6698 filter->list = g_slist_append(filter->list, (gpointer)node);
6699 memset(temp, '\0', PKG_STRING_LEN_MAX);
6703 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6704 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6706 filter->list = g_slist_delete_link(filter->list, link);
6707 filter->list = g_slist_append(filter->list, (gpointer)node);
6713 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6715 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6716 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6717 char *syslocale = NULL;
6718 char *locale = NULL;
6719 char *condition = NULL;
6720 char *error_message = NULL;
6721 char query[MAX_QUERY_LEN] = {'\0'};
6722 char where[MAX_QUERY_LEN] = {'\0'};
6726 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6727 /*Get current locale*/
6728 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6729 if (syslocale == NULL) {
6730 _LOGE("current locale is NULL\n");
6731 return PMINFO_R_ERROR;
6733 locale = __convert_system_locale_to_manifest_locale(syslocale);
6734 if (locale == NULL) {
6735 _LOGE("manifest locale is NULL\n");
6737 return PMINFO_R_ERROR;
6740 ret = __open_manifest_db(uid);
6742 _LOGE("Fail to open manifest DB\n");
6745 return PMINFO_R_ERROR;
6748 /*Start constructing query*/
6749 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6751 /*Get where clause*/
6752 for (list = filter->list; list; list = g_slist_next(list)) {
6753 __get_filter_condition(list->data, &condition);
6755 strncat(where, condition, sizeof(where) - strlen(where) -1);
6756 where[sizeof(where) - 1] = '\0';
6760 if (g_slist_next(list)) {
6761 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6762 where[sizeof(where) - 1] = '\0';
6765 _LOGE("where = %s\n", where);
6766 if (strlen(where) > 0) {
6767 strncat(query, where, sizeof(query) - strlen(query) - 1);
6768 query[sizeof(query) - 1] = '\0';
6770 _LOGE("query = %s\n", query);
6774 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6775 _LOGE("Don't execute query = %s error message = %s\n", query,
6777 sqlite3_free(error_message);
6778 ret = PMINFO_R_ERROR;
6792 __close_manifest_db();
6796 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6798 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6801 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6802 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6804 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6805 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6806 char *syslocale = NULL;
6807 char *locale = NULL;
6808 char *condition = NULL;
6809 char *error_message = NULL;
6810 char query[MAX_QUERY_LEN] = {'\0'};
6811 char where[MAX_QUERY_LEN] = {'\0'};
6814 uiapplication_x *ptr1 = NULL;
6815 serviceapplication_x *ptr2 = NULL;
6816 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6817 /*Get current locale*/
6818 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6819 if (syslocale == NULL) {
6820 _LOGE("current locale is NULL\n");
6821 return PMINFO_R_ERROR;
6823 locale = __convert_system_locale_to_manifest_locale(syslocale);
6824 if (locale == NULL) {
6825 _LOGE("manifest locale is NULL\n");
6827 return PMINFO_R_ERROR;
6830 ret = __open_manifest_db(uid);
6832 _LOGE("Fail to open manifest DB\n");
6835 return PMINFO_R_ERROR;
6837 /*Start constructing query*/
6838 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6839 /*Get where clause*/
6840 for (list = filter->list; list; list = g_slist_next(list)) {
6841 __get_filter_condition(list->data, &condition);
6843 strncat(where, condition, sizeof(where) - strlen(where) -1);
6844 where[sizeof(where) - 1] = '\0';
6848 if (g_slist_next(list)) {
6849 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6850 where[sizeof(where) - 1] = '\0';
6853 _LOGE("where = %s\n", where);
6854 if (strlen(where) > 0) {
6855 strncat(query, where, sizeof(query) - strlen(query) - 1);
6856 query[sizeof(query) - 1] = '\0';
6858 _LOGE("query = %s\n", query);
6859 /*To get filtered list*/
6860 pkgmgr_pkginfo_x *info = NULL;
6861 pkgmgr_pkginfo_x *filtinfo = NULL;
6862 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6864 _LOGE("Out of Memory!!!\n");
6865 ret = PMINFO_R_ERROR;
6868 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6869 if (info->manifest_info == NULL) {
6870 _LOGE("Out of Memory!!!\n");
6871 ret = PMINFO_R_ERROR;
6874 /*To get detail app info for each member of filtered list*/
6875 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6876 if (filtinfo == NULL) {
6877 _LOGE("Out of Memory!!!\n");
6878 ret = PMINFO_R_ERROR;
6881 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6882 if (filtinfo->manifest_info == NULL) {
6883 _LOGE("Out of Memory!!!\n");
6884 ret = PMINFO_R_ERROR;
6887 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6888 if (appinfo == NULL) {
6889 _LOGE("Out of Memory!!!\n");
6890 ret = PMINFO_R_ERROR;
6894 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6895 _LOGE("Don't execute query = %s error message = %s\n", query,
6897 sqlite3_free(error_message);
6898 ret = PMINFO_R_ERROR;
6901 memset(query, '\0', MAX_QUERY_LEN);
6902 if (info->manifest_info->uiapplication) {
6903 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6904 info->manifest_info->uiapplication = ptr1;
6906 if (info->manifest_info->serviceapplication) {
6907 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6908 info->manifest_info->serviceapplication = ptr2;
6910 /*Filtered UI Apps*/
6911 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6913 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6914 ptr1->appid, "uiapp");
6916 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6917 _LOGE("Don't execute query = %s error message = %s\n", query,
6919 sqlite3_free(error_message);
6920 ret = PMINFO_R_ERROR;
6924 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6926 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6927 ptr2->appid, "svcapp");
6929 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6930 _LOGE("Don't execute query = %s error message = %s\n", query,
6932 sqlite3_free(error_message);
6933 ret = PMINFO_R_ERROR;
6937 if (filtinfo->manifest_info->uiapplication) {
6938 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6939 filtinfo->manifest_info->uiapplication = ptr1;
6941 /*If the callback func return < 0 we break and no more call back is called*/
6944 appinfo->locale = strdup(locale);
6945 appinfo->uiapp_info = ptr1;
6946 appinfo->app_component = PMINFO_UI_APP;
6947 ret = app_cb((void *)appinfo, user_data);
6952 /*Filtered Service Apps*/
6953 if (filtinfo->manifest_info->serviceapplication) {
6954 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6955 filtinfo->manifest_info->serviceapplication = ptr2;
6957 /*If the callback func return < 0 we break and no more call back is called*/
6960 appinfo->locale = strdup(locale);
6961 appinfo->svcapp_info = ptr2;
6962 appinfo->app_component = PMINFO_SVC_APP;
6963 ret = app_cb((void *)appinfo, user_data);
6978 __close_manifest_db();
6983 __cleanup_pkginfo(info);
6984 __cleanup_pkginfo(filtinfo);
6988 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6989 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6991 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6994 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6996 return (pkgmgrinfo_pkginfo_filter_create(handle));
6999 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
7001 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
7004 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
7005 const char *key, const char *value)
7007 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7008 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
7009 /*value can be NULL. In that case all apps with specified key should be displayed*/
7013 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7014 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7015 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7017 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7021 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7024 /*If API is called multiple times, we should OR all conditions.*/
7025 filter->list = g_slist_append(filter->list, (gpointer)node);
7026 /*All memory will be freed in destroy API*/
7044 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7045 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7047 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7048 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7049 char *syslocale = NULL;
7050 char *locale = NULL;
7051 char *condition = NULL;
7052 char *error_message = NULL;
7053 char query[MAX_QUERY_LEN] = {'\0'};
7054 char where[MAX_QUERY_LEN] = {'\0'};
7057 pkgmgr_pkginfo_x *info = NULL;
7058 pkgmgr_pkginfo_x *filtinfo = NULL;
7059 pkgmgr_appinfo_x *appinfo = NULL;
7060 uiapplication_x *ptr1 = NULL;
7061 serviceapplication_x *ptr2 = NULL;
7062 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7064 /*Get current locale*/
7065 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7066 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7067 locale = __convert_system_locale_to_manifest_locale(syslocale);
7068 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7070 ret = __open_manifest_db(uid);
7072 _LOGE("Fail to open manifest DB\n");
7075 return PMINFO_R_ERROR;
7077 /*Start constructing query*/
7078 memset(where, '\0', MAX_QUERY_LEN);
7079 memset(query, '\0', MAX_QUERY_LEN);
7080 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7081 /*Get where clause*/
7082 for (list = filter->list; list; list = g_slist_next(list)) {
7083 __get_metadata_filter_condition(list->data, &condition);
7085 strncat(where, condition, sizeof(where) - strlen(where) -1);
7089 if (g_slist_next(list)) {
7090 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7093 _LOGE("where = %s (%d)\n", where, strlen(where));
7094 if (strlen(where) > 0) {
7095 strncat(query, where, sizeof(query) - strlen(query) - 1);
7097 _LOGE("query = %s (%d)\n", query, strlen(query));
7098 /*To get filtered list*/
7099 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7100 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7102 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7103 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7105 /*To get detail app info for each member of filtered list*/
7106 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7107 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7109 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7110 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7112 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7113 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7115 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7116 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7117 memset(query, '\0', MAX_QUERY_LEN);
7119 if (info->manifest_info->uiapplication) {
7120 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7121 info->manifest_info->uiapplication = ptr1;
7123 if (info->manifest_info->serviceapplication) {
7124 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7125 info->manifest_info->serviceapplication = ptr2;
7129 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7131 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7132 ptr1->appid, "uiapp");
7133 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7134 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7135 memset(query, '\0', MAX_QUERY_LEN);
7138 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7140 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7141 ptr2->appid, "svcapp");
7142 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7143 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7144 memset(query, '\0', MAX_QUERY_LEN);
7146 /*Filtered UI Apps*/
7147 if (filtinfo->manifest_info->uiapplication) {
7148 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7149 filtinfo->manifest_info->uiapplication = ptr1;
7151 /*If the callback func return < 0 we break and no more call back is called*/
7154 appinfo->locale = strdup(locale);
7155 appinfo->uiapp_info = ptr1;
7156 appinfo->app_component = PMINFO_UI_APP;
7157 ret = app_cb((void *)appinfo, user_data);
7162 /*Filtered Service Apps*/
7163 if (filtinfo->manifest_info->serviceapplication) {
7164 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7165 filtinfo->manifest_info->serviceapplication = ptr2;
7167 /*If the callback func return < 0 we break and no more call back is called*/
7170 appinfo->locale = strdup(locale);
7171 appinfo->svcapp_info = ptr2;
7172 appinfo->app_component = PMINFO_SVC_APP;
7173 ret = app_cb((void *)appinfo, user_data);
7188 sqlite3_free(error_message);
7189 __close_manifest_db();
7194 __cleanup_pkginfo(info);
7195 __cleanup_pkginfo(filtinfo);
7199 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7200 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7202 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7205 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7207 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7208 pkgmgr_certinfo_x *certinfo = NULL;
7209 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7211 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7212 *handle = (void *)certinfo;
7216 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle, uid_t uid)
7218 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7220 pkgmgr_certinfo_x *certinfo = NULL;
7221 char *error_message = NULL;
7222 int ret = PMINFO_R_OK;
7223 char query[MAX_QUERY_LEN] = {'\0'};
7228 ret = __open_cert_db(uid,"r");
7229 if (ret != SQLITE_OK) {
7230 _LOGE("connect db [%s] failed!\n");
7231 ret = PMINFO_R_ERROR;
7234 _check_create_Cert_db(GET_DB(cert_db));
7236 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7238 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7239 _LOGE("Don't execute query = %s error message = %s\n", query,
7241 sqlite3_free(error_message);
7242 ret = PMINFO_R_ERROR;
7246 _LOGE("Package not found in DB\n");
7247 ret = PMINFO_R_ERROR;
7250 certinfo = (pkgmgr_certinfo_x *)handle;
7251 /*populate certinfo from DB*/
7252 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7253 ret = __exec_certinfo_query(query, (void *)certinfo);
7255 _LOGE("Package Cert Info DB Information retrieval failed\n");
7256 ret = PMINFO_R_ERROR;
7259 for (i = 0; i < MAX_CERT_TYPE; i++) {
7260 memset(query, '\0', MAX_QUERY_LEN);
7261 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7262 ret = __exec_certinfo_query(query, (void *)certinfo);
7264 _LOGE("Cert Info DB Information retrieval failed\n");
7265 ret = PMINFO_R_ERROR;
7268 if (certinfo->cert_value) {
7269 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7270 free(certinfo->cert_value);
7271 certinfo->cert_value = NULL;
7279 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7281 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7282 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7283 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7284 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7285 pkgmgr_certinfo_x *certinfo = NULL;
7286 certinfo = (pkgmgr_certinfo_x *)handle;
7287 if ((certinfo->cert_info)[cert_type])
7288 *cert_value = (certinfo->cert_info)[cert_type];
7294 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7296 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7298 pkgmgr_certinfo_x *certinfo = NULL;
7299 certinfo = (pkgmgr_certinfo_x *)handle;
7300 if (certinfo->pkgid) {
7301 free(certinfo->pkgid);
7302 certinfo->pkgid = NULL;
7304 for (i = 0; i < MAX_CERT_TYPE; i++) {
7305 if ((certinfo->cert_info)[i]) {
7306 free((certinfo->cert_info)[i]);
7307 (certinfo->cert_info)[i] = NULL;
7315 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7317 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7318 pkgmgr_instcertinfo_x *certinfo = NULL;
7320 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7321 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7322 *handle = (void *)certinfo;
7326 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7328 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7329 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7330 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7331 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7332 pkgmgr_instcertinfo_x *certinfo = NULL;
7333 certinfo = (pkgmgr_instcertinfo_x *)handle;
7334 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7338 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle, uid_t uid)
7340 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7341 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7342 char *error_message = NULL;
7343 char query[MAX_QUERY_LEN] = {'\0'};
7344 char *vquery = NULL;
7349 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7356 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7357 pkgmgr_certindexinfo_x *indexinfo = NULL;
7358 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7359 if (indexinfo == NULL) {
7360 _LOGE("Out of Memory!!!");
7361 return PMINFO_R_ERROR;
7363 info->pkgid = strdup(pkgid);
7366 ret =__open_cert_db(uid, "w");
7368 ret = PMINFO_R_ERROR;
7369 _LOGE("Failed to open cert db \n");
7372 _check_create_Cert_db(GET_DB(cert_db));
7373 /*Begin Transaction*/
7374 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7376 _LOGE("Failed to begin transaction %s\n");
7377 ret = PMINFO_R_ERROR;
7381 /*Check if request is to insert/update*/
7382 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7384 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7385 _LOGE("Don't execute query = %s error message = %s\n", query,
7387 sqlite3_free(error_message);
7388 ret = PMINFO_R_ERROR;
7393 We cant just issue update query directly. We need to manage index table also.
7394 Hence it is better to delete and insert again in case of update*/
7395 ret = __delete_certinfo(pkgid, uid);
7397 _LOGE("Certificate Deletion Failed\n");
7399 for (i = 0; i < MAX_CERT_TYPE; i++) {
7400 if ((info->cert_info)[i]) {
7401 for (j = 0; j < i; j++) {
7402 if ( (info->cert_info)[j]) {
7403 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7404 (info->cert_id)[i] = (info->cert_id)[j];
7405 (info->is_new)[i] = 0;
7406 (info->ref_count)[i] = (info->ref_count)[j];
7413 memset(query, '\0', MAX_QUERY_LEN);
7414 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7415 "where cert_info='%s'",(info->cert_info)[i]);
7416 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7418 _LOGE("Cert Info DB Information retrieval failed\n");
7419 ret = PMINFO_R_ERROR;
7422 if (indexinfo->cert_id == 0) {
7423 /*New certificate. Get newid*/
7424 memset(query, '\0', MAX_QUERY_LEN);
7425 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7427 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7428 _LOGE("Don't execute query = %s error message = %s\n", query,
7430 sqlite3_free(error_message);
7431 ret = PMINFO_R_ERROR;
7439 indexinfo->cert_id = maxid;
7440 indexinfo->cert_ref_count = 1;
7444 (info->cert_id)[i] = indexinfo->cert_id;
7445 (info->is_new)[i] = is_new;
7446 (info->ref_count)[i] = indexinfo->cert_ref_count;
7447 indexinfo->cert_id = 0;
7448 indexinfo->cert_ref_count = 0;
7452 len = MAX_QUERY_LEN;
7453 for (i = 0; i < MAX_CERT_TYPE; i++) {
7454 if ((info->cert_info)[i])
7455 len+= strlen((info->cert_info)[i]);
7457 vquery = (char *)calloc(1, len);
7459 snprintf(vquery, len,
7460 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7461 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7462 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7463 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7464 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7465 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7466 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7467 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7469 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7470 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7472 sqlite3_free(error_message);
7473 ret = PMINFO_R_ERROR;
7476 /*Update index table info*/
7477 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7478 for (i = 0; i < MAX_CERT_TYPE; i++) {
7479 if ((info->cert_info)[i]) {
7480 memset(vquery, '\0', len);
7481 if ((info->is_new)[i]) {
7482 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7483 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7484 unique_id[c++] = (info->cert_id)[i];
7487 for (j = 0; j < MAX_CERT_TYPE; j++) {
7488 if ((info->cert_id)[i] == unique_id[j]) {
7489 /*Ref count has already been increased. Just continue*/
7493 if (j == MAX_CERT_TYPE)
7494 unique_id[c++] = (info->cert_id)[i];
7497 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7498 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7501 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7502 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7504 sqlite3_free(error_message);
7505 ret = PMINFO_R_ERROR;
7510 /*Commit transaction*/
7511 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7512 if (ret != SQLITE_OK) {
7513 _LOGE("Failed to commit transaction, Rollback now\n");
7514 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7515 ret = PMINFO_R_ERROR;
7533 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7535 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7537 pkgmgr_instcertinfo_x *certinfo = NULL;
7538 certinfo = (pkgmgr_instcertinfo_x *)handle;
7539 if (certinfo->pkgid) {
7540 free(certinfo->pkgid);
7541 certinfo->pkgid = NULL;
7543 for (i = 0; i < MAX_CERT_TYPE; i++) {
7544 if ((certinfo->cert_info)[i]) {
7545 free((certinfo->cert_info)[i]);
7546 (certinfo->cert_info)[i] = NULL;
7554 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7556 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7559 ret = __open_cert_db(uid, "w");
7561 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7562 ret = PMINFO_R_ERROR;
7565 _check_create_Cert_db(GET_DB(cert_db));
7566 /*Begin Transaction*/
7567 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7568 if (ret != SQLITE_OK) {
7569 _LOGE("Failed to begin transaction\n");
7570 ret = PMINFO_R_ERROR;
7573 _LOGE("Transaction Begin\n");
7574 ret = __delete_certinfo(pkgid, uid);
7576 _LOGE("Certificate Deletion Failed\n");
7578 _LOGE("Certificate Deletion Success\n");
7580 /*Commit transaction*/
7581 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7582 if (ret != SQLITE_OK) {
7583 _LOGE("Failed to commit transaction, Rollback now\n");
7584 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7585 ret = PMINFO_R_ERROR;
7588 _LOGE("Transaction Commit and End\n");
7596 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7598 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7601 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7603 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7604 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7606 char *manifest = NULL;
7607 manifest_x *mfx = NULL;
7609 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7610 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7612 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7617 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7619 *handle = (void *)mfx;
7624 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7626 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7627 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7629 char *manifest = NULL;
7630 manifest_x *mfx = NULL;
7632 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7633 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7635 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7640 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7642 *handle = (void *)mfx;
7647 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7649 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7650 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7652 int len = strlen(type);
7653 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7655 manifest_x *mfx = (manifest_x *)handle;
7657 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7661 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7663 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7664 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7666 int len = strlen(version);
7667 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7669 manifest_x *mfx = (manifest_x *)handle;
7671 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7675 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7677 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7678 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7680 manifest_x *mfx = (manifest_x *)handle;
7682 if (location == INSTALL_INTERNAL)
7683 strcpy(mfx->installlocation, "internal-only");
7684 else if (location == INSTALL_EXTERNAL)
7685 strcpy(mfx->installlocation, "prefer-external");
7690 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7692 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7693 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7695 manifest_x *mfx = (manifest_x *)handle;
7697 mfx->package_size = strdup(size);
7702 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7704 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7705 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7707 int len = strlen(label_txt);
7708 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7710 manifest_x *mfx = (manifest_x *)handle;
7712 label_x *label = calloc(1, sizeof(label_x));
7713 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7715 LISTADD(mfx->label, label);
7717 mfx->label->lang = strdup(locale);
7719 mfx->label->lang = strdup(DEFAULT_LOCALE);
7720 mfx->label->text = strdup(label_txt);
7725 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7727 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7728 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7730 int len = strlen(icon_txt);
7731 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7733 manifest_x *mfx = (manifest_x *)handle;
7735 icon_x *icon = calloc(1, sizeof(icon_x));
7736 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7738 LISTADD(mfx->icon, icon);
7740 mfx->icon->lang = strdup(locale);
7742 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7743 mfx->icon->text = strdup(icon_txt);
7748 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7750 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7751 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7753 int len = strlen(desc_txt);
7754 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7756 manifest_x *mfx = (manifest_x *)handle;
7758 description_x *description = calloc(1, sizeof(description_x));
7759 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7761 LISTADD(mfx->description, description);
7763 mfx->description->lang = strdup(locale);
7765 mfx->description->lang = strdup(DEFAULT_LOCALE);
7766 mfx->description->text = strdup(desc_txt);
7771 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7772 const char *author_email, const char *author_href, const char *locale)
7774 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7775 manifest_x *mfx = (manifest_x *)handle;
7776 author_x *author = calloc(1, sizeof(author_x));
7777 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7779 LISTADD(mfx->author, author);
7781 mfx->author->text = strdup(author_name);
7783 mfx->author->email = strdup(author_email);
7785 mfx->author->href = strdup(author_href);
7787 mfx->author->lang = strdup(locale);
7789 mfx->author->lang = strdup(DEFAULT_LOCALE);
7793 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7795 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7796 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7798 manifest_x *mfx = (manifest_x *)handle;
7801 strcpy(mfx->removable, "false");
7802 else if (removable == 1)
7803 strcpy(mfx->removable, "true");
7808 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7810 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7811 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7813 manifest_x *mfx = (manifest_x *)handle;
7816 strcpy(mfx->preload, "false");
7817 else if (preload == 1)
7818 strcpy(mfx->preload, "true");
7823 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7825 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7826 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7828 manifest_x *mfx = (manifest_x *)handle;
7830 if (location == INSTALL_INTERNAL)
7831 strcpy(mfx->installed_storage, "installed_internal");
7832 else if (location == INSTALL_EXTERNAL)
7833 strcpy(mfx->installed_storage, "installed_external");
7838 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7840 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7843 manifest_x *mfx = NULL;
7844 mfx = (manifest_x *)handle;
7846 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7848 _LOGE("Successfully stored info in DB\n");
7851 _LOGE("Failed to store info in DB\n");
7852 return PMINFO_R_ERROR;
7856 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7858 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7861 manifest_x *mfx = NULL;
7862 mfx = (manifest_x *)handle;
7864 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7866 _LOGE("Successfully stored info in DB\n");
7869 _LOGE("Failed to store info in DB\n");
7870 return PMINFO_R_ERROR;
7874 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7876 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7878 manifest_x *mfx = NULL;
7879 mfx = (manifest_x *)handle;
7880 pkgmgr_parser_free_manifest_xml(mfx);
7884 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7886 /* Should be implemented later */
7890 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7892 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7894 char query[MAX_QUERY_LEN] = {'\0'};
7897 ret = __open_manifest_db(uid);
7898 if (ret != SQLITE_OK) {
7899 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7900 return PMINFO_R_ERROR;
7903 /*Begin transaction*/
7904 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7905 if (ret != SQLITE_OK) {
7906 _LOGE("Failed to begin transaction\n");
7907 __close_manifest_db();
7908 return PMINFO_R_ERROR;
7910 _LOGD("Transaction Begin\n");
7912 memset(query, '\0', MAX_QUERY_LEN);
7913 snprintf(query, MAX_QUERY_LEN,
7914 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7916 char *error_message = NULL;
7918 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7919 _LOGE("Don't execute query = %s error message = %s\n", query,
7921 sqlite3_free(error_message);
7922 return PMINFO_R_ERROR;
7924 sqlite3_free(error_message);
7926 /*Commit transaction*/
7927 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7928 if (ret != SQLITE_OK) {
7929 _LOGE("Failed to commit transaction. Rollback now\n");
7930 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7931 __close_manifest_db();
7932 return PMINFO_R_ERROR;
7934 _LOGD("Transaction Commit and End\n");
7935 __close_manifest_db();
7939 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7941 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7944 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7946 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7947 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7948 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7949 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7950 int ret = PMINFO_R_OK;
7951 char query[MAX_QUERY_LEN] = {'\0'};
7952 char *error_message = NULL;
7953 pkgmgr_datacontrol_x *data = NULL;
7955 ret = __open_datacontrol_db();
7957 _LOGE("Fail to open datacontrol DB\n");
7958 return PMINFO_R_ERROR;
7961 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7963 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7964 __close_datacontrol_db();
7965 return PMINFO_R_ERROR;
7968 snprintf(query, MAX_QUERY_LEN,
7969 "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",
7973 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7974 _LOGE("Don't execute query = %s error message = %s\n", query,
7976 sqlite3_free(error_message);
7977 __close_datacontrol_db();
7978 return PMINFO_R_ERROR;
7981 *appid = (char *)data->appid;
7982 *access = (char *)data->access;
7984 __close_datacontrol_db();
7989 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7991 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7993 char query[MAX_QUERY_LEN] = {'\0'};
7994 char *error_message = NULL;
7995 ret = __open_manifest_db(uid);
7998 /*Begin transaction*/
7999 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8000 if (ret != SQLITE_OK) {
8001 _LOGE("Failed to begin transaction\n");
8002 __close_manifest_db();
8003 return PMINFO_R_ERROR;
8005 _LOGD("Transaction Begin\n");
8007 memset(query, '\0', MAX_QUERY_LEN);
8008 snprintf(query, MAX_QUERY_LEN,
8009 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8012 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
8013 _LOGE("Don't execute query = %s error message = %s\n", query,
8015 sqlite3_free(error_message);
8016 return PMINFO_R_ERROR;
8019 /*Commit transaction*/
8020 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
8021 if (ret != SQLITE_OK) {
8022 _LOGE("Failed to commit transaction. Rollback now\n");
8023 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8024 __close_manifest_db();
8025 return PMINFO_R_ERROR;
8027 _LOGD("Transaction Commit and End\n");
8028 __close_manifest_db();
8032 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8034 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8037 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8039 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8040 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8042 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8043 val = (char *)info->uiapp_info->guestmode_visibility;
8045 if (strcasecmp(val, "true") == 0){
8047 }else if (strcasecmp(val, "false") == 0){
8056 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8058 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8061 char *noti_string = NULL;
8063 char query[MAX_QUERY_LEN] = {'\0'};
8064 char *errmsg = NULL;
8065 sqlite3 *pkgmgr_parser_db;
8067 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8068 val = (char *)info->uiapp_info->guestmode_visibility;
8071 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8072 SQLITE_OPEN_READWRITE, NULL);
8074 if (ret != SQLITE_OK) {
8075 _LOGE("DB Open Failed\n");
8076 return PMINFO_R_ERROR;
8079 /*TODO: Write to DB here*/
8081 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8083 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8085 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8086 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8088 sqlite3_close(pkgmgr_parser_db);
8089 return PMINFO_R_ERROR;
8091 sqlite3_close(pkgmgr_parser_db);
8092 len = strlen((char *)info->uiapp_info->appid) + 8;
8093 noti_string = calloc(1, len);
8094 if (noti_string == NULL){
8095 return PMINFO_R_ERROR;
8097 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8098 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8099 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8106 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8108 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8111 /* pkgmgrinfo client start*/
8112 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8115 char *errmsg = NULL;
8117 void *handle = NULL;
8118 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8120 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8121 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8123 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8125 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8127 pc = __pkgmgr_client_new(ctype);
8128 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8132 return (pkgmgrinfo_client *) pc;
8135 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8138 char *errmsg = NULL;
8139 void *handle = NULL;
8140 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8142 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8143 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8145 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8147 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8149 ret = __pkgmgr_client_set_status_type(pc, status_type);
8150 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8154 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8156 * The lib dependency chain like below
8157 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8159 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8160 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8161 * on libpkgmgr-installer-client.
8163 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8166 * However, when the libdbus call into the callback function, it suddenly fond that the
8167 * function address is gone (unmapped), then we receive a SIGSEGV.
8169 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8170 * robust if we just link to the well-known lib.
8172 * See https://bugs.tizen.org/jira/browse/PTREL-591
8178 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8181 char *errmsg = NULL;
8182 void *handle = NULL;
8183 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8185 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8186 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8188 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8190 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8192 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8193 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8196 /* same as pkgmgrinfo_client_new */
8200 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8203 char *errmsg = NULL;
8204 void *handle = NULL;
8205 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8207 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8208 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8210 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8212 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8214 ret = __pkgmgr_client_free(pc);
8215 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8218 /* same as pkgmgrinfo_client_new */
8222 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8225 DBusConnection *bus;
8226 DBusMessage *message;
8228 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8230 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8233 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8234 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8236 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8237 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8239 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8241 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8242 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8244 dbus_connection_flush(bus);
8245 dbus_message_unref(message);
8250 /* pkgmgrinfo client end*/