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>
38 #include <linux/limits.h>
40 #include <libxml/parser.h>
41 #include <libxml/xmlreader.h>
42 #include <libxml/xmlschemas.h>
44 #include <dbus/dbus.h>
45 #include <dbus/dbus-glib-lowlevel.h>
47 /* For multi-user support */
48 #include <tzplatform_config.h>
50 #include "pkgmgr_parser.h"
51 #include "pkgmgr-info-internal.h"
52 #include "pkgmgr-info-debug.h"
53 #include "pkgmgr-info.h"
54 #include "pkgmgr_parser_db.h"
61 #define LOG_TAG "PKGMGR_INFO"
63 #define ASC_CHAR(s) (const char *)s
64 #define XML_CHAR(s) (const xmlChar *)s
66 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
67 #define MAX_QUERY_LEN 4096
68 #define MAX_CERT_TYPE 9
69 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
70 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
71 #define PKG_TYPE_STRING_LEN_MAX 128
72 #define PKG_VERSION_STRING_LEN_MAX 128
73 #define PKG_VALUE_STRING_LEN_MAX 512
74 #define PKG_LOCALE_STRING_LEN_MAX 8
75 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
76 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
77 #define BLOCK_SIZE 4096 /*in bytes*/
81 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
82 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
83 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
85 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
86 "from package_info LEFT OUTER JOIN package_localized_info " \
87 "ON package_info.package=package_localized_info.package " \
88 "and package_localized_info.package_locale='%s' where "
90 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
91 "from package_info LEFT OUTER JOIN package_localized_info " \
92 "ON package_info.package=package_localized_info.package " \
93 "and package_localized_info.package_locale='%s' where "
95 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
96 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
97 "ON package_app_info.app_id=package_app_localized_info.app_id " \
98 "and package_app_localized_info.app_locale='%s' " \
99 "LEFT OUTER JOIN package_app_app_svc " \
100 "ON package_app_info.app_id=package_app_app_svc.app_id " \
101 "LEFT OUTER JOIN package_app_app_category " \
102 "ON package_app_info.app_id=package_app_app_category.app_id where "
104 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
105 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
106 "ON package_app_info.app_id=package_app_localized_info.app_id " \
107 "and package_app_localized_info.app_locale='%s' " \
108 "LEFT OUTER JOIN package_app_app_svc " \
109 "ON package_app_info.app_id=package_app_app_svc.app_id " \
110 "LEFT OUTER JOIN package_app_app_category " \
111 "ON package_app_info.app_id=package_app_app_category.app_id where "
113 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
114 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
115 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
117 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
119 #define LANGUAGE_LENGTH 2
120 #define LIBAIL_PATH "/usr/lib/libail.so.0"
122 #define SERVICE_NAME "org.tizen.system.deviced"
123 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
124 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
125 #define METHOD_NAME "RequestMountApp2ext"
129 typedef struct _pkgmgr_instcertinfo_x {
131 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
132 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
133 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
134 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
135 } pkgmgr_instcertinfo_x;
137 typedef struct _pkgmgr_certindexinfo_x {
140 } pkgmgr_certindexinfo_x;
142 typedef struct _pkgmgr_pkginfo_x {
144 manifest_x *manifest_info;
147 struct _pkgmgr_pkginfo_x *prev;
148 struct _pkgmgr_pkginfo_x *next;
151 typedef struct _pkgmgr_cert_x {
156 typedef struct _pkgmgr_datacontrol_x {
159 } pkgmgr_datacontrol_x;
161 typedef struct _pkgmgr_iconpath_x {
166 typedef struct _pkgmgr_image_x {
170 typedef struct _pkgmgr_locale_x {
174 typedef struct _pkgmgr_appinfo_x {
177 pkgmgrinfo_app_component app_component;
179 uiapplication_x *uiapp_info;
180 serviceapplication_x *svcapp_info;
184 typedef struct _pkgmgr_certinfo_x {
187 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
188 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
192 typedef struct _pkgmgrinfo_filter_x {
195 } pkgmgrinfo_filter_x;
197 typedef struct _pkgmgrinfo_node_x {
203 typedef struct _pkgmgrinfo_appcontrol_x {
212 } pkgmgrinfo_appcontrol_x;
215 typedef struct _db_handle {
221 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
223 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
224 const char *pkgid, const char *key,
225 const char *val, const void *pmsg, void *data);
227 typedef void pkgmgr_client;
228 typedef void pkgmgr_info;
233 PM_REQUEST_GET_SIZE = 2,
234 PM_REQUEST_KILL_APP = 3,
235 PM_REQUEST_CHECK_APP = 4,
237 }pkgmgr_request_service_type;
240 PM_GET_TOTAL_SIZE= 0,
241 PM_GET_DATA_SIZE = 1,
243 PM_GET_SIZE_INFO = 3,
244 PM_GET_TOTAL_AND_DATA = 4,
245 PM_GET_SIZE_FILE = 5,
247 }pkgmgr_getsize_type;
255 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
256 #define MAX_PKG_BUF_LEN 1024
257 #define MAX_PKG_INFO_LEN 10
259 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
260 "(cert_info text not null, " \
261 "cert_id integer, " \
262 "cert_ref_count integer, " \
263 "PRIMARY KEY(cert_id)) "
265 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
266 "(package text not null, " \
267 "author_root_cert integer, " \
268 "author_im_cert integer, " \
269 "author_signer_cert integer, " \
270 "dist_root_cert integer, " \
271 "dist_im_cert integer, " \
272 "dist_signer_cert integer, " \
273 "dist2_root_cert integer, " \
274 "dist2_im_cert integer, " \
275 "dist2_signer_cert integer, " \
276 "PRIMARY KEY(package)) "
279 #define QUERY_ATTACH "attach database '%s' as Global"
280 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select * " \
281 "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)"
282 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\
283 "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)"
284 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select * "\
285 "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)"
286 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select * "\
287 "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)"
288 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select * "\
289 "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)"
290 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select * "\
291 "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)"
292 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select * "\
293 "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)"
294 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select * "\
295 "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)"
296 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select * "\
297 "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)"
298 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select * "\
299 "from (select *,0 as for_all_users from main.package_info union select *,1 as for_all_users from Global.package_info)"
300 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select * "\
301 "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)"
302 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select * "\
303 "from (select *,0 as for_all_users from main.package_localized_info union select *,1 as for_all_users from Global.package_localized_info)"
304 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select * "\
305 "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 )"
306 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select * "\
307 "from (select *,0 as for_all_users from main.package_privilege_info union select *,1 as for_all_users from Global.package_privilege_info)"
309 #define GET_DB(X) (X).dbHandle
310 char *pkgtype = "rpm";
311 __thread db_handle manifest_db;
312 __thread db_handle datacontrol_db;
313 __thread db_handle cert_db;
315 static int __open_manifest_db(uid_t uid);
316 static int __close_manifest_db(void);
317 static int __open_cert_db(uid_t uid);
318 static int __close_cert_db(void);
319 static int __exec_pkginfo_query(char *query, void *data);
320 static int __exec_certinfo_query(char *query, void *data);
321 static int __exec_certindexinfo_query(char *query, void *data);
322 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
323 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
324 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
325 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
326 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
327 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
328 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
329 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
330 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
331 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
332 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
333 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
334 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
335 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
336 static void __destroy_each_node(gpointer data, gpointer user_data);
337 static void __get_filter_condition(gpointer data, char **condition);
338 static void __get_metadata_filter_condition(gpointer data, char **condition);
339 static gint __compare_func(gconstpointer data1, gconstpointer data2);
340 static int __delete_certinfo(const char *pkgid);
341 static int _check_create_Cert_db( sqlite3 *certdb);
342 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
344 static int _mkdir(const char *dir, mode_t mode)
351 snprintf(tmp, sizeof(tmp), "%s", dir);
353 if(tmp[len - 1] == '/')
355 for(p = tmp + 1; *p; p++) {
358 ret = mkdir(tmp, mode);
359 if (ret && errno != EEXIST)
364 return mkdir(tmp, mode);
367 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
369 char *error_message = NULL;
370 char query_attach[MAX_QUERY_LEN] = {'\0'};
371 char query_view[MAX_QUERY_LEN] = {'\0'};
373 if(uid != GLOBAL_USER){
374 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
376 sqlite3_exec(handle, query_attach,
377 NULL, NULL, &error_message)) {
378 _LOGD("Don't execute query = %s error message = %s\n",
379 query_attach, error_message);
380 sqlite3_free(error_message);
387 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");
389 sqlite3_exec(handle, query_view,
390 NULL, NULL, &error_message)) {
391 _LOGD("Don't execute query = %s error message = %s\n",
392 query_view, error_message);
393 sqlite3_free(error_message);
395 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");
397 sqlite3_exec(handle, query_view,
398 NULL, NULL, &error_message)) {
399 _LOGD("Don't execute query = %s error message = %s\n",
400 query_view, error_message);
401 sqlite3_free(error_message);
408 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
410 char *error_message = NULL;
411 char query_attach[MAX_QUERY_LEN] = {'\0'};
412 if(uid != GLOBAL_USER){
413 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
415 sqlite3_exec(handle, query_attach,
416 NULL, NULL, &error_message)) {
417 _LOGD("Don't execute query = %s error message = %s\n",
418 query_attach, error_message);
419 sqlite3_free(error_message);
422 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
423 NULL, NULL, &error_message)) {
424 _LOGD("Don't execute query = %s error message = %s\n",
425 QUERY_CREATE_VIEW_1, error_message);
426 sqlite3_free(error_message);
429 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
430 NULL, NULL, &error_message)) {
431 _LOGD("Don't execute query = %s error message = %s\n",
432 QUERY_CREATE_VIEW_2, error_message);
433 sqlite3_free(error_message);
436 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
437 NULL, NULL, &error_message)) {
438 _LOGD("Don't execute query = %s error message = %s\n",
439 QUERY_CREATE_VIEW_3, error_message);
440 sqlite3_free(error_message);
443 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
444 NULL, NULL, &error_message)) {
445 _LOGD("Don't execute query = %s error message = %s\n",
446 QUERY_CREATE_VIEW_4, error_message);
447 sqlite3_free(error_message);
450 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
451 NULL, NULL, &error_message)) {
452 _LOGD("Don't execute query = %s error message = %s\n",
453 QUERY_CREATE_VIEW_5, error_message);
454 sqlite3_free(error_message);
457 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
458 NULL, NULL, &error_message)) {
459 _LOGD("Don't execute query = %s error message = %s\n",
460 QUERY_CREATE_VIEW_6, error_message);
461 sqlite3_free(error_message);
464 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
465 NULL, NULL, &error_message)) {
466 _LOGD("Don't execute query = %s error message = %s\n",
467 QUERY_CREATE_VIEW_7, error_message);
468 sqlite3_free(error_message);
471 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
472 NULL, NULL, &error_message)) {
473 _LOGD("Don't execute query = %s error message = %s\n",
474 QUERY_CREATE_VIEW_8, error_message);
475 sqlite3_free(error_message);
478 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
479 NULL, NULL, &error_message)) {
480 _LOGD("Don't execute query = %s error message = %s\n",
481 QUERY_CREATE_VIEW_9, error_message);
482 sqlite3_free(error_message);
485 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
486 NULL, NULL, &error_message)) {
487 _LOGD("Don't execute query = %s error message = %s\n",
488 QUERY_CREATE_VIEW_10, error_message);
489 sqlite3_free(error_message);
492 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
493 NULL, NULL, &error_message)) {
494 _LOGD("Don't execute query = %s error message = %s\n",
495 QUERY_CREATE_VIEW_11, error_message);
496 sqlite3_free(error_message);
499 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
500 NULL, NULL, &error_message)) {
501 _LOGD("Don't execute query = %s error message = %s\n",
502 QUERY_CREATE_VIEW_12, error_message);
503 sqlite3_free(error_message);
506 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
507 NULL, NULL, &error_message)) {
508 _LOGD("Don't execute query = %s error message = %s\n",
509 QUERY_CREATE_VIEW_13, error_message);
510 sqlite3_free(error_message);
513 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
514 NULL, NULL, &error_message)) {
515 _LOGD("Don't execute query = %s error message = %s\n",
516 QUERY_CREATE_VIEW_14, error_message);
517 sqlite3_free(error_message);
525 static int _check_create_Cert_db( sqlite3 *certdb)
528 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
531 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
537 API char *getIconPath(uid_t uid)
540 struct group *grpinfo = NULL;
541 struct passwd *userinfo = getpwuid(uid);
544 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
547 if (uid != GLOBAL_USER) {
548 if (userinfo == NULL) {
549 _LOGE("getpwuid(%d) returns NULL !", uid);
552 grpinfo = getgrnam("users");
553 if (grpinfo == NULL) {
554 _LOGE("getgrnam(users) returns NULL !");
557 // Compare git_t type and not group name
558 if (grpinfo->gr_gid != userinfo->pw_gid) {
559 _LOGE("UID [%d] does not belong to 'users' group!", uid);
562 ret = asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir);
564 _LOGE("asprintf fails");
569 result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
572 ret = _mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
573 if (ret == -1 && errno != EEXIST) {
574 _LOGE("FAIL : to create directory %s %d", result, errno);
575 } else if (getuid() == OWNER_ROOT) {
576 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
579 strerror_r(errno, buf, sizeof(buf));
580 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
586 API char *getUserPkgParserDBPath(void)
588 return getUserPkgParserDBPathUID(GLOBAL_USER);
591 API char *getUserPkgParserDBPathUID(uid_t uid)
593 const char *result = NULL;
594 const char *journal = NULL;
595 struct group *grpinfo = NULL;
597 struct passwd *userinfo = getpwuid(uid);
600 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
603 if (uid != GLOBAL_USER) {
604 if (userinfo == NULL) {
605 _LOGE("getpwuid(%d) returns NULL !", uid);
608 grpinfo = getgrnam("users");
609 if (grpinfo == NULL) {
610 _LOGE("getgrnam(users) returns NULL !");
613 // Compare git_t type and not group name
614 if (grpinfo->gr_gid != userinfo->pw_gid) {
615 _LOGE("UID [%d] does not belong to 'users' group!", uid);
618 ret = asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
620 _LOGE("asprintf fails");
623 ret = asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir);
625 _LOGE("asprintf fails");
629 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
630 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
632 char *temp = strdup(result);
633 dir = strrchr(temp, '/');
641 ret = _mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
642 if (ret == -1 && errno != EEXIST) {
643 _LOGE("FAIL : to create directory %s %d", temp, errno);
644 } else if (getuid() == OWNER_ROOT) {
645 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
648 strerror_r(errno, buf, sizeof(buf));
649 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
656 API char *getUserPkgCertDBPath(void)
658 return getUserPkgCertDBPathUID(GLOBAL_USER);
661 API char *getUserPkgCertDBPathUID(uid_t uid)
664 char *journal = NULL;
665 struct group *grpinfo = NULL;
667 struct passwd *userinfo = getpwuid(uid);
670 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
673 if (uid != GLOBAL_USER) {
674 if (userinfo == NULL) {
675 _LOGE("getpwuid(%d) returns NULL !", uid);
678 grpinfo = getgrnam("users");
679 if (grpinfo == NULL) {
680 _LOGE("getgrnam(users) returns NULL !");
683 // Compare git_t type and not group name
684 if (grpinfo->gr_gid != userinfo->pw_gid) {
685 _LOGE("UID [%d] does not belong to 'users' group!", uid);
688 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
689 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_cert.db-journal", userinfo->pw_dir);
691 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
692 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db-journal");
694 char *temp = strdup(result);
695 dir = strrchr(temp, '/');
703 int ret = _mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
704 if (ret == -1 && errno != EEXIST) {
705 _LOGE("FAIL : to create directory %s %d", temp, errno);
706 } else if (getuid() == OWNER_ROOT) {
707 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
710 strerror_r(errno, buf, sizeof(buf));
711 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
718 API const char* getUserDesktopPath(uid_t uid)
721 struct group *grpinfo = NULL;
723 struct passwd *userinfo = getpwuid(uid);
726 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
729 if (uid != GLOBAL_USER) {
730 if (userinfo == NULL) {
731 _LOGE("getpwuid(%d) returns NULL !", uid);
734 grpinfo = getgrnam("users");
735 if (grpinfo == NULL) {
736 _LOGE("getgrnam(users) returns NULL !");
739 // Compare git_t type and not group name
740 if (grpinfo->gr_gid != userinfo->pw_gid) {
741 _LOGE("UID [%d] does not belong to 'users' group!", uid);
744 asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir);
746 result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
749 int ret = _mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
750 if (ret == -1 && errno != EEXIST) {
751 _LOGE("FAIL : to create directory %s %d", result, errno);
752 } else if (getuid() == OWNER_ROOT) {
753 ret = chown(result, uid,((grpinfo)?grpinfo->gr_gid:0));
756 strerror_r(errno, buf, sizeof(buf));
757 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
763 API const char* getUserManifestPath(uid_t uid)
766 struct group *grpinfo = NULL;
768 struct passwd *userinfo = getpwuid(uid);
771 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
774 if (uid != GLOBAL_USER) {
775 if (userinfo == NULL) {
776 _LOGE("getpwuid(%d) returns NULL !", uid);
779 grpinfo = getgrnam("users");
780 if (grpinfo == NULL) {
781 _LOGE("getgrnam(users) returns NULL !");
784 // Compare git_t type and not group name
785 if (grpinfo->gr_gid != userinfo->pw_gid) {
786 _LOGE("UID [%d] does not belong to 'users' group!", uid);
789 asprintf(&result, "%s/.applications/manifest/", userinfo->pw_dir);
791 result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
794 int ret = _mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
795 if (ret == -1 && errno != EEXIST) {
796 _LOGE("FAIL : to create directory %s %d", result, errno);
797 } else if (getuid() == OWNER_ROOT) {
798 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
801 strerror_r(errno, buf, sizeof(buf));
802 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
809 static gint __compare_func(gconstpointer data1, gconstpointer data2)
811 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
812 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
813 if (node1->prop == node2->prop)
815 else if (node1->prop > node2->prop)
821 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
824 *p = atoi(coltxt[0]);
825 _LOGE("count value is %d\n", *p);
829 static void __destroy_each_node(gpointer data, gpointer user_data)
831 ret_if(data == NULL);
832 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
845 static void __get_metadata_filter_condition(gpointer data, char **condition)
847 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
848 char key[MAX_QUERY_LEN] = {'\0'};
849 char value[MAX_QUERY_LEN] = {'\0'};
851 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
854 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
859 *condition = strdup(key);
863 static void __get_filter_condition(gpointer data, char **condition)
865 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
866 char buf[MAX_QUERY_LEN + 1] = {'\0'};
867 char temp[PKG_STRING_LEN_MAX] = {'\0'};
868 switch (node->prop) {
869 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
870 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
872 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
873 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
875 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
876 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
878 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
879 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
881 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
882 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
884 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
885 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
887 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
888 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
890 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
891 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
893 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
894 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
896 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
897 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
899 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
900 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
902 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
903 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
905 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
906 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
908 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
909 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
911 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
912 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
915 case E_PMINFO_APPINFO_PROP_APP_ID:
916 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
918 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
919 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
921 case E_PMINFO_APPINFO_PROP_APP_EXEC:
922 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
924 case E_PMINFO_APPINFO_PROP_APP_ICON:
925 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
927 case E_PMINFO_APPINFO_PROP_APP_TYPE:
928 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
930 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
931 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
932 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
934 case E_PMINFO_APPINFO_PROP_APP_URI:
935 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
936 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
938 case E_PMINFO_APPINFO_PROP_APP_MIME:
939 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
940 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
942 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
943 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
944 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
946 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
947 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
949 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
950 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
952 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
953 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
955 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
956 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
958 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
959 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
961 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
962 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
964 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
965 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
967 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
968 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
971 _LOGE("Invalid Property Type\n");
975 *condition = strdup(buf);
979 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
981 if (syslocale == NULL)
982 return strdup(DEFAULT_LOCALE);
984 locale = (char *)calloc(1, 6);
985 retvm_if(!locale, NULL, "Malloc Failed\n");
987 strncpy(locale, syslocale, 2);
988 strncat(locale, "-", 1);
989 locale[3] = syslocale[3] + 32;
990 locale[4] = syslocale[4] + 32;
994 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
996 ret_if(data == NULL);
998 free((void *)data->locale);
1002 pkgmgr_parser_free_manifest_xml(data->manifest_info);
1008 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
1010 ret_if(data == NULL);
1012 free((void *)data->package);
1013 data->package = NULL;
1016 free((void *)data->locale);
1017 data->locale = NULL;
1020 manifest_x *mfx = calloc(1, sizeof(manifest_x));
1021 if (data->app_component == PMINFO_UI_APP)
1022 mfx->uiapplication = data->uiapp_info;
1023 else if (data->app_component == PMINFO_SVC_APP)
1024 mfx->serviceapplication = data->svcapp_info;
1025 pkgmgr_parser_free_manifest_xml(mfx);
1031 static int __close_manifest_db(void)
1034 if(manifest_db.ref) {
1035 if(--manifest_db.ref == 0)
1036 sqlite3_close(GET_DB(manifest_db));
1043 static int __open_manifest_db(uid_t uid)
1046 if(manifest_db.ref) {
1050 const char* user_pkg_parser = getUserPkgParserDBPathUID(uid);
1051 if (access(user_pkg_parser, F_OK) == 0) {
1053 db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
1054 SQLITE_OPEN_READONLY, NULL);
1055 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_pkg_parser);
1057 ret = _pkgmgr_parser_attach_create_view_parserdb(GET_DB(manifest_db),uid);
1058 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_pkg_parser);
1062 _LOGE("Manifest DB does not exists !!\n");
1066 static int __close_cert_db(void)
1070 if(--cert_db.ref == 0)
1071 sqlite3_close(GET_DB(cert_db));
1073 _LOGE("Certificate DB is already closed !!\n");
1078 static int __open_cert_db(uid_t uid)
1081 const char* user_cert_parser = getUserPkgCertDBPathUID(uid);
1082 if (access(user_cert_parser, F_OK) == 0) {
1084 db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
1085 SQLITE_OPEN_READWRITE, NULL);
1086 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", user_cert_parser);
1088 ret = _pkgmgr_parser_attach_create_view_certdb(GET_DB(cert_db),uid);
1089 retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n", user_cert_parser);
1093 _LOGE("Cert DB does not exists !!\n");
1097 static int __close_datacontrol_db(void)
1100 if(datacontrol_db.ref) {
1101 if(--datacontrol_db.ref == 0)
1102 sqlite3_close(GET_DB(datacontrol_db));
1104 _LOGE("Certificate DB is already closed !!\n");
1108 static int __open_datacontrol_db()
1111 if (access(DATACONTROL_DB, F_OK) == 0) {
1113 db_util_open_with_options(DATACONTROL_DB, &GET_DB(datacontrol_db),
1114 SQLITE_OPEN_READONLY, NULL);
1115 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1118 _LOGE("Datacontrol DB does not exists !!\n");
1122 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1124 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1126 pkgmgr_pkginfo_x *info = NULL;
1127 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1128 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1130 LISTADD(udata, info);
1132 for(i = 0; i < ncols; i++)
1134 if (strcmp(colname[i], "package") == 0) {
1136 info->manifest_info->package = strdup(coltxt[i]);
1138 info->manifest_info->package = NULL;
1139 } else if (strcmp(colname[i], "for_all_users") == 0) {
1141 info->manifest_info->for_all_users = strdup(coltxt[i]);
1143 info->manifest_info->for_all_users = NULL;
1148 //by default if views are not set , the column for_all_users doesn't exist,
1149 // in this case we assume we retreive information about app avaible for all users
1150 if (!info->manifest_info->for_all_users)
1151 info->manifest_info->for_all_users = strdup("1");
1156 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1158 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1161 uiapplication_x *uiapp = NULL;
1162 serviceapplication_x *svcapp = NULL;
1163 for(i = 0; i < ncols; i++)
1165 if ((strcmp(colname[i], "app_component") == 0) ||
1166 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1168 if (strcmp(coltxt[i], "uiapp") == 0) {
1169 uiapp = calloc(1, sizeof(uiapplication_x));
1170 if (uiapp == NULL) {
1171 _LOGE("Out of Memory!!!\n");
1174 LISTADD(info->manifest_info->uiapplication, uiapp);
1175 for(j = 0; j < ncols; j++)
1177 if ((strcmp(colname[j], "app_id") == 0) ||
1178 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1180 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1181 } else if (strcmp(colname[j], "package") == 0) {
1183 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1188 svcapp = calloc(1, sizeof(serviceapplication_x));
1189 if (svcapp == NULL) {
1190 _LOGE("Out of Memory!!!\n");
1193 LISTADD(info->manifest_info->serviceapplication, svcapp);
1194 for(j = 0; j < ncols; j++)
1196 if ((strcmp(colname[j], "app_id") == 0) ||
1197 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1199 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1200 } else if (strcmp(colname[j], "package") == 0) {
1202 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1216 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1218 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1220 uiapplication_x *uiapp = NULL;
1221 icon_x *icon = NULL;
1222 label_x *label = NULL;
1224 uiapp = calloc(1, sizeof(uiapplication_x));
1225 LISTADD(info->manifest_info->uiapplication, uiapp);
1226 icon = calloc(1, sizeof(icon_x));
1227 LISTADD(info->manifest_info->uiapplication->icon, icon);
1228 label = calloc(1, sizeof(label_x));
1229 LISTADD(info->manifest_info->uiapplication->label, label);
1231 for(i = 0; i < ncols; i++)
1233 if (strcmp(colname[i], "app_id") == 0) {
1235 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1237 info->manifest_info->uiapplication->appid = NULL;
1238 } else if (strcmp(colname[i], "app_exec") == 0) {
1240 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1242 info->manifest_info->uiapplication->exec = NULL;
1243 } else if (strcmp(colname[i], "app_type") == 0 ){
1245 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1247 info->manifest_info->uiapplication->type = NULL;
1248 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1250 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1252 info->manifest_info->uiapplication->nodisplay = NULL;
1253 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1255 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1257 info->manifest_info->uiapplication->multiple = NULL;
1258 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1260 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1262 info->manifest_info->uiapplication->taskmanage = NULL;
1263 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1265 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1267 info->manifest_info->uiapplication->hwacceleration = NULL;
1268 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1270 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1272 info->manifest_info->uiapplication->screenreader = NULL;
1273 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1275 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1277 info->manifest_info->uiapplication->indicatordisplay = NULL;
1278 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1280 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1282 info->manifest_info->uiapplication->portraitimg = NULL;
1283 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1285 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1287 info->manifest_info->uiapplication->landscapeimg = NULL;
1288 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1290 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1292 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1293 } else if (strcmp(colname[i], "package") == 0 ){
1295 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1297 info->manifest_info->uiapplication->package = NULL;
1298 } else if (strcmp(colname[i], "app_icon") == 0) {
1300 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1302 info->manifest_info->uiapplication->icon->text = NULL;
1303 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1305 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1307 info->manifest_info->uiapplication->enabled = NULL;
1308 } else if (strcmp(colname[i], "app_label") == 0 ) {
1310 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1312 info->manifest_info->uiapplication->label->text = NULL;
1313 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1315 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1317 info->manifest_info->uiapplication->recentimage = NULL;
1318 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1320 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1322 info->manifest_info->uiapplication->mainapp = NULL;
1323 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1325 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1326 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1329 info->manifest_info->uiapplication->icon->lang = NULL;
1330 info->manifest_info->uiapplication->label->lang = NULL;
1332 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1334 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1336 info->manifest_info->uiapplication->permission_type = NULL;
1337 } else if (strcmp(colname[i], "component_type") == 0 ) {
1339 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1341 info->manifest_info->uiapplication->component_type = NULL;
1342 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1344 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1346 info->manifest_info->uiapplication->preload = NULL;
1347 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1349 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1351 info->manifest_info->uiapplication->submode = NULL;
1352 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1354 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1356 info->manifest_info->uiapplication->submode_mainid = NULL;
1363 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1365 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1367 serviceapplication_x *svcapp = NULL;
1368 icon_x *icon = NULL;
1369 label_x *label = NULL;
1371 svcapp = calloc(1, sizeof(serviceapplication_x));
1372 LISTADD(info->manifest_info->serviceapplication, svcapp);
1373 icon = calloc(1, sizeof(icon_x));
1374 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1375 label = calloc(1, sizeof(label_x));
1376 LISTADD(info->manifest_info->serviceapplication->label, label);
1377 for(i = 0; i < ncols; i++)
1379 if (strcmp(colname[i], "app_id") == 0) {
1381 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1383 info->manifest_info->serviceapplication->appid = NULL;
1384 } else if (strcmp(colname[i], "app_exec") == 0) {
1386 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1388 info->manifest_info->serviceapplication->exec = NULL;
1389 } else if (strcmp(colname[i], "app_type") == 0 ){
1391 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1393 info->manifest_info->serviceapplication->type = NULL;
1394 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1396 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1398 info->manifest_info->serviceapplication->onboot = NULL;
1399 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1401 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1403 info->manifest_info->serviceapplication->autorestart = NULL;
1404 } else if (strcmp(colname[i], "package") == 0 ){
1406 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1408 info->manifest_info->serviceapplication->package = NULL;
1409 } else if (strcmp(colname[i], "app_icon") == 0) {
1411 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1413 info->manifest_info->serviceapplication->icon->text = NULL;
1414 } else if (strcmp(colname[i], "app_label") == 0 ) {
1416 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1418 info->manifest_info->serviceapplication->label->text = NULL;
1419 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1421 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1422 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1425 info->manifest_info->serviceapplication->icon->lang = NULL;
1426 info->manifest_info->serviceapplication->label->lang = NULL;
1428 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1430 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1432 info->manifest_info->serviceapplication->permission_type = NULL;
1439 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1441 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1444 uiapplication_x *uiapp = NULL;
1445 serviceapplication_x *svcapp = NULL;
1446 for(j = 0; j < ncols; j++)
1448 if (strcmp(colname[j], "app_component") == 0) {
1450 if (strcmp(coltxt[j], "uiapp") == 0) {
1451 uiapp = calloc(1, sizeof(uiapplication_x));
1452 if (uiapp == NULL) {
1453 _LOGE("Out of Memory!!!\n");
1456 LISTADD(info->manifest_info->uiapplication, uiapp);
1457 for(i = 0; i < ncols; i++)
1459 if (strcmp(colname[i], "app_id") == 0) {
1461 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1463 info->manifest_info->uiapplication->appid = NULL;
1464 } else if (strcmp(colname[i], "app_exec") == 0) {
1466 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1468 info->manifest_info->uiapplication->exec = NULL;
1469 } else if (strcmp(colname[i], "app_type") == 0 ){
1471 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1473 info->manifest_info->uiapplication->type = NULL;
1474 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1476 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1478 info->manifest_info->uiapplication->nodisplay = NULL;
1479 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1481 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1483 info->manifest_info->uiapplication->multiple = NULL;
1484 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1486 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1488 info->manifest_info->uiapplication->taskmanage = NULL;
1489 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1491 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1493 info->manifest_info->uiapplication->hwacceleration = NULL;
1494 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1496 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1498 info->manifest_info->uiapplication->screenreader = NULL;
1499 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1501 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1503 info->manifest_info->uiapplication->indicatordisplay = NULL;
1504 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1506 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1508 info->manifest_info->uiapplication->portraitimg = NULL;
1509 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1511 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1513 info->manifest_info->uiapplication->landscapeimg = NULL;
1514 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1516 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1518 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1519 } else if (strcmp(colname[i], "package") == 0 ){
1521 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1523 info->manifest_info->uiapplication->package = NULL;
1524 } else if (strcmp(colname[i], "app_icon") == 0) {
1526 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1528 info->manifest_info->uiapplication->icon->text = NULL;
1529 } else if (strcmp(colname[i], "app_label") == 0 ) {
1531 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1533 info->manifest_info->uiapplication->label->text = NULL;
1534 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1536 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1538 info->manifest_info->uiapplication->recentimage = NULL;
1539 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1541 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1543 info->manifest_info->uiapplication->mainapp = NULL;
1544 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1546 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1547 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1550 info->manifest_info->uiapplication->icon->lang = NULL;
1551 info->manifest_info->uiapplication->label->lang = NULL;
1553 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1555 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1557 info->manifest_info->uiapplication->permission_type = NULL;
1562 svcapp = calloc(1, sizeof(serviceapplication_x));
1563 if (svcapp == NULL) {
1564 _LOGE("Out of Memory!!!\n");
1567 LISTADD(info->manifest_info->serviceapplication, svcapp);
1568 for(i = 0; i < ncols; i++)
1570 if (strcmp(colname[i], "app_id") == 0) {
1572 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1574 info->manifest_info->serviceapplication->appid = NULL;
1575 } else if (strcmp(colname[i], "app_exec") == 0) {
1577 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1579 info->manifest_info->serviceapplication->exec = NULL;
1580 } else if (strcmp(colname[i], "app_type") == 0 ){
1582 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1584 info->manifest_info->serviceapplication->type = NULL;
1585 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1587 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1589 info->manifest_info->serviceapplication->onboot = NULL;
1590 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1592 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1594 info->manifest_info->serviceapplication->autorestart = NULL;
1595 } else if (strcmp(colname[i], "package") == 0 ){
1597 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1599 info->manifest_info->serviceapplication->package = NULL;
1600 } else if (strcmp(colname[i], "app_icon") == 0) {
1602 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1604 info->manifest_info->serviceapplication->icon->text = NULL;
1605 } else if (strcmp(colname[i], "app_label") == 0 ) {
1607 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1609 info->manifest_info->serviceapplication->label->text = NULL;
1610 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1612 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1613 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1616 info->manifest_info->serviceapplication->icon->lang = NULL;
1617 info->manifest_info->serviceapplication->label->lang = NULL;
1619 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1621 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1623 info->manifest_info->serviceapplication->permission_type = NULL;
1638 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1640 int *p = (int*)data;
1641 *p = atoi(coltxt[0]);
1645 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1647 int *p = (int*)data;
1649 *p = atoi(coltxt[0]);
1653 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1655 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1657 author_x *author = NULL;
1658 icon_x *icon = NULL;
1659 label_x *label = NULL;
1660 description_x *description = NULL;
1661 privilege_x *privilege = NULL;
1663 author = calloc(1, sizeof(author_x));
1664 LISTADD(info->manifest_info->author, author);
1665 icon = calloc(1, sizeof(icon_x));
1666 LISTADD(info->manifest_info->icon, icon);
1667 label = calloc(1, sizeof(label_x));
1668 LISTADD(info->manifest_info->label, label);
1669 description = calloc(1, sizeof(description_x));
1670 LISTADD(info->manifest_info->description, description);
1671 privilege = calloc(1, sizeof(privilege_x));
1672 LISTADD(info->manifest_info->privileges->privilege, privilege);
1673 for(i = 0; i < ncols; i++)
1675 if (strcmp(colname[i], "package_version") == 0) {
1677 info->manifest_info->version = strdup(coltxt[i]);
1679 info->manifest_info->version = NULL;
1680 } else if (strcmp(colname[i], "package_type") == 0) {
1682 info->manifest_info->type = strdup(coltxt[i]);
1684 info->manifest_info->type = NULL;
1685 } else if (strcmp(colname[i], "install_location") == 0) {
1687 info->manifest_info->installlocation = strdup(coltxt[i]);
1689 info->manifest_info->installlocation = NULL;
1690 } else if (strcmp(colname[i], "package_size") == 0) {
1692 info->manifest_info->package_size = strdup(coltxt[i]);
1694 info->manifest_info->package_size = NULL;
1695 } else if (strcmp(colname[i], "author_email") == 0 ){
1697 info->manifest_info->author->email = strdup(coltxt[i]);
1699 info->manifest_info->author->email = NULL;
1700 } else if (strcmp(colname[i], "author_href") == 0 ){
1702 info->manifest_info->author->href = strdup(coltxt[i]);
1704 info->manifest_info->author->href = NULL;
1705 } else if (strcmp(colname[i], "package_label") == 0 ){
1707 info->manifest_info->label->text = strdup(coltxt[i]);
1709 info->manifest_info->label->text = NULL;
1710 } else if (strcmp(colname[i], "package_icon") == 0 ){
1712 info->manifest_info->icon->text = strdup(coltxt[i]);
1714 info->manifest_info->icon->text = NULL;
1715 } else if (strcmp(colname[i], "package_description") == 0 ){
1717 info->manifest_info->description->text = strdup(coltxt[i]);
1719 info->manifest_info->description->text = NULL;
1720 } else if (strcmp(colname[i], "package_author") == 0 ){
1722 info->manifest_info->author->text = strdup(coltxt[i]);
1724 info->manifest_info->author->text = NULL;
1725 } else if (strcmp(colname[i], "package_removable") == 0 ){
1727 info->manifest_info->removable = strdup(coltxt[i]);
1729 info->manifest_info->removable = NULL;
1730 } else if (strcmp(colname[i], "package_preload") == 0 ){
1732 info->manifest_info->preload = strdup(coltxt[i]);
1734 info->manifest_info->preload = NULL;
1735 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1737 info->manifest_info->readonly = strdup(coltxt[i]);
1739 info->manifest_info->readonly = NULL;
1740 } else if (strcmp(colname[i], "package_update") == 0 ){
1742 info->manifest_info->update= strdup(coltxt[i]);
1744 info->manifest_info->update = NULL;
1745 } else if (strcmp(colname[i], "package_system") == 0 ){
1747 info->manifest_info->system= strdup(coltxt[i]);
1749 info->manifest_info->system = NULL;
1750 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1752 info->manifest_info->appsetting = strdup(coltxt[i]);
1754 info->manifest_info->appsetting = NULL;
1755 } else if (strcmp(colname[i], "installed_time") == 0 ){
1757 info->manifest_info->installed_time = strdup(coltxt[i]);
1759 info->manifest_info->installed_time = NULL;
1760 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1762 info->manifest_info->installed_storage = strdup(coltxt[i]);
1764 info->manifest_info->installed_storage = NULL;
1765 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1767 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1769 info->manifest_info->mainapp_id = NULL;
1770 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1772 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1774 info->manifest_info->storeclient_id = NULL;
1775 } else if (strcmp(colname[i], "root_path") == 0 ){
1777 info->manifest_info->root_path = strdup(coltxt[i]);
1779 info->manifest_info->root_path = NULL;
1780 } else if (strcmp(colname[i], "csc_path") == 0 ){
1782 info->manifest_info->csc_path = strdup(coltxt[i]);
1784 info->manifest_info->csc_path = NULL;
1785 } else if (strcmp(colname[i], "privilege") == 0 ){
1787 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1789 info->manifest_info->privileges->privilege->text = NULL;
1790 } else if (strcmp(colname[i], "package_locale") == 0 ){
1792 info->manifest_info->author->lang = strdup(coltxt[i]);
1793 info->manifest_info->icon->lang = strdup(coltxt[i]);
1794 info->manifest_info->label->lang = strdup(coltxt[i]);
1795 info->manifest_info->description->lang = strdup(coltxt[i]);
1798 info->manifest_info->author->lang = NULL;
1799 info->manifest_info->icon->lang = NULL;
1800 info->manifest_info->label->lang = NULL;
1801 info->manifest_info->description->lang = NULL;
1803 } else if (strcmp(colname[i], "package_url") == 0 ){
1805 info->manifest_info->package_url = strdup(coltxt[i]);
1807 info->manifest_info->package_url = NULL;
1815 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1817 if ( strcasecmp(comp, "uiapp") == 0)
1818 return PMINFO_UI_APP;
1819 else if ( strcasecmp(comp, "svcapp") == 0)
1820 return PMINFO_SVC_APP;
1825 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1827 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1829 for(i = 0; i < ncols; i++) {
1830 if (strcmp(colname[i], "cert_id") == 0) {
1832 info->cert_id = atoi(coltxt[i]);
1835 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1837 info->cert_ref_count = atoi(coltxt[i]);
1839 info->cert_ref_count = 0;
1845 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1847 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1849 for(i = 0; i < ncols; i++)
1851 if (strcmp(colname[i], "package") == 0) {
1853 info->pkgid = strdup(coltxt[i]);
1856 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1858 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1860 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1861 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1863 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1865 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1866 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1868 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1870 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1871 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1873 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1875 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1876 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1878 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1880 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1881 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1883 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1885 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1886 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1888 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1890 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1891 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1893 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1895 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1896 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1898 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1900 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1901 } else if (strcmp(colname[i], "cert_info") == 0 ){
1903 info->cert_value = strdup(coltxt[i]);
1905 info->cert_value = NULL;
1912 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1914 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1917 uiapplication_x *uiapp = NULL;
1918 serviceapplication_x *svcapp = NULL;
1919 for(i = 0; i < ncols; i++)
1921 if (strcmp(colname[i], "app_component") == 0) {
1923 if (strcmp(coltxt[i], "uiapp") == 0) {
1924 uiapp = calloc(1, sizeof(uiapplication_x));
1925 if (uiapp == NULL) {
1926 _LOGE("Out of Memory!!!\n");
1929 LISTADD(info->manifest_info->uiapplication, uiapp);
1930 for(j = 0; j < ncols; j++)
1932 if (strcmp(colname[j], "app_id") == 0) {
1934 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1935 } else if (strcmp(colname[j], "app_exec") == 0) {
1937 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1939 info->manifest_info->uiapplication->exec = NULL;
1940 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1942 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1944 info->manifest_info->uiapplication->nodisplay = NULL;
1945 } else if (strcmp(colname[j], "app_type") == 0 ) {
1947 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1949 info->manifest_info->uiapplication->type = NULL;
1950 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1952 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1954 info->manifest_info->uiapplication->multiple = NULL;
1955 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1957 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1959 info->manifest_info->uiapplication->taskmanage = NULL;
1960 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1962 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1964 info->manifest_info->uiapplication->hwacceleration = NULL;
1965 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1967 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1969 info->manifest_info->uiapplication->screenreader = NULL;
1970 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1972 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1974 info->manifest_info->uiapplication->enabled = NULL;
1975 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1977 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1979 info->manifest_info->uiapplication->indicatordisplay = NULL;
1980 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1982 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1984 info->manifest_info->uiapplication->portraitimg = NULL;
1985 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1987 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1989 info->manifest_info->uiapplication->landscapeimg = NULL;
1990 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1992 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1994 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1995 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1997 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1999 info->manifest_info->uiapplication->recentimage = NULL;
2000 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
2002 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
2004 info->manifest_info->uiapplication->mainapp = NULL;
2005 } else if (strcmp(colname[j], "package") == 0 ) {
2007 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
2009 info->manifest_info->uiapplication->package = NULL;
2010 } else if (strcmp(colname[j], "app_component") == 0) {
2012 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
2014 info->manifest_info->uiapplication->app_component = NULL;
2015 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
2017 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
2019 info->manifest_info->uiapplication->permission_type = NULL;
2020 } else if (strcmp(colname[j], "component_type") == 0 ) {
2022 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
2024 info->manifest_info->uiapplication->component_type = NULL;
2025 } else if (strcmp(colname[j], "app_preload") == 0 ) {
2027 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
2029 info->manifest_info->uiapplication->preload = NULL;
2030 } else if (strcmp(colname[j], "app_submode") == 0 ) {
2032 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
2034 info->manifest_info->uiapplication->submode = NULL;
2035 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
2037 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
2039 info->manifest_info->uiapplication->submode_mainid = NULL;
2044 svcapp = calloc(1, sizeof(serviceapplication_x));
2045 if (svcapp == NULL) {
2046 _LOGE("Out of Memory!!!\n");
2049 LISTADD(info->manifest_info->serviceapplication, svcapp);
2050 for(j = 0; j < ncols; j++)
2052 if (strcmp(colname[j], "app_id") == 0) {
2054 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
2055 } else if (strcmp(colname[j], "app_exec") == 0) {
2057 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
2059 info->manifest_info->serviceapplication->exec = NULL;
2060 } else if (strcmp(colname[j], "app_type") == 0 ){
2062 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
2064 info->manifest_info->serviceapplication->type = NULL;
2065 } else if (strcmp(colname[j], "app_onboot") == 0 ){
2067 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
2069 info->manifest_info->serviceapplication->onboot = NULL;
2070 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
2072 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
2074 info->manifest_info->serviceapplication->autorestart = NULL;
2075 } else if (strcmp(colname[j], "package") == 0 ){
2077 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
2079 info->manifest_info->serviceapplication->package = NULL;
2080 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
2082 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
2084 info->manifest_info->serviceapplication->permission_type = NULL;
2097 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
2099 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2101 icon_x *icon = NULL;
2102 label_x *label = NULL;
2103 category_x *category = NULL;
2104 metadata_x *metadata = NULL;
2105 permission_x *permission = NULL;
2106 image_x *image = NULL;
2108 switch (info->app_component) {
2110 icon = calloc(1, sizeof(icon_x));
2111 LISTADD(info->uiapp_info->icon, icon);
2112 label = calloc(1, sizeof(label_x));
2113 LISTADD(info->uiapp_info->label, label);
2114 category = calloc(1, sizeof(category_x));
2115 LISTADD(info->uiapp_info->category, category);
2116 metadata = calloc(1, sizeof(metadata_x));
2117 LISTADD(info->uiapp_info->metadata, metadata);
2118 permission = calloc(1, sizeof(permission_x));
2119 LISTADD(info->uiapp_info->permission, permission);
2120 image = calloc(1, sizeof(image_x));
2121 LISTADD(info->uiapp_info->image, image);
2123 for(i = 0; i < ncols; i++)
2125 if (strcmp(colname[i], "app_id") == 0) {
2126 /*appid being foreign key, is column in every table
2127 Hence appid gets strduped every time leading to memory leak.
2128 If appid is already set, just continue.*/
2129 if (info->uiapp_info->appid)
2132 info->uiapp_info->appid = strdup(coltxt[i]);
2134 info->uiapp_info->appid = NULL;
2135 } else if (strcmp(colname[i], "app_exec") == 0) {
2137 info->uiapp_info->exec = strdup(coltxt[i]);
2139 info->uiapp_info->exec = NULL;
2140 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2142 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2144 info->uiapp_info->nodisplay = NULL;
2145 } else if (strcmp(colname[i], "app_type") == 0 ) {
2147 info->uiapp_info->type = strdup(coltxt[i]);
2149 info->uiapp_info->type = NULL;
2150 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2152 info->uiapp_info->icon->section= strdup(coltxt[i]);
2154 info->uiapp_info->icon->section = NULL;
2155 } else if (strcmp(colname[i], "app_icon") == 0) {
2157 info->uiapp_info->icon->text = strdup(coltxt[i]);
2159 info->uiapp_info->icon->text = NULL;
2160 } else if (strcmp(colname[i], "app_label") == 0 ) {
2162 info->uiapp_info->label->text = strdup(coltxt[i]);
2164 info->uiapp_info->label->text = NULL;
2165 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2167 info->uiapp_info->multiple = strdup(coltxt[i]);
2169 info->uiapp_info->multiple = NULL;
2170 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2172 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2174 info->uiapp_info->taskmanage = NULL;
2175 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2177 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2179 info->uiapp_info->hwacceleration = NULL;
2180 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2182 info->uiapp_info->screenreader = strdup(coltxt[i]);
2184 info->uiapp_info->screenreader = NULL;
2185 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2187 info->uiapp_info->enabled= strdup(coltxt[i]);
2189 info->uiapp_info->enabled = NULL;
2190 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2192 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2194 info->uiapp_info->indicatordisplay = NULL;
2195 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2197 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2199 info->uiapp_info->portraitimg = NULL;
2200 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2202 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2204 info->uiapp_info->landscapeimg = NULL;
2205 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2207 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2209 info->uiapp_info->guestmode_visibility = NULL;
2210 } else if (strcmp(colname[i], "category") == 0 ) {
2212 info->uiapp_info->category->name = strdup(coltxt[i]);
2214 info->uiapp_info->category->name = NULL;
2215 } else if (strcmp(colname[i], "md_key") == 0 ) {
2217 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2219 info->uiapp_info->metadata->key = NULL;
2220 } else if (strcmp(colname[i], "md_value") == 0 ) {
2222 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2224 info->uiapp_info->metadata->value = NULL;
2225 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2227 info->uiapp_info->permission->type= strdup(coltxt[i]);
2229 info->uiapp_info->permission->type = NULL;
2230 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2232 info->uiapp_info->permission->value = strdup(coltxt[i]);
2234 info->uiapp_info->permission->value = NULL;
2235 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2237 info->uiapp_info->recentimage = strdup(coltxt[i]);
2239 info->uiapp_info->recentimage = NULL;
2240 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2242 info->uiapp_info->mainapp = strdup(coltxt[i]);
2244 info->uiapp_info->mainapp = NULL;
2245 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2247 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2248 info->uiapp_info->label->lang = strdup(coltxt[i]);
2251 info->uiapp_info->icon->lang = NULL;
2252 info->uiapp_info->label->lang = NULL;
2254 } else if (strcmp(colname[i], "app_image") == 0) {
2256 info->uiapp_info->image->text= strdup(coltxt[i]);
2258 info->uiapp_info->image->text = NULL;
2259 } else if (strcmp(colname[i], "app_image_section") == 0) {
2261 info->uiapp_info->image->section= strdup(coltxt[i]);
2263 info->uiapp_info->image->section = NULL;
2264 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2266 info->uiapp_info->permission_type = strdup(coltxt[i]);
2268 info->uiapp_info->permission_type = NULL;
2269 } else if (strcmp(colname[i], "component_type") == 0 ) {
2271 info->uiapp_info->component_type = strdup(coltxt[i]);
2273 info->uiapp_info->component_type = NULL;
2274 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2276 info->uiapp_info->preload = strdup(coltxt[i]);
2278 info->uiapp_info->preload = NULL;
2279 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2281 info->uiapp_info->submode = strdup(coltxt[i]);
2283 info->uiapp_info->submode = NULL;
2284 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2286 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2288 info->uiapp_info->submode_mainid = NULL;
2293 case PMINFO_SVC_APP:
2294 icon = calloc(1, sizeof(icon_x));
2295 LISTADD(info->svcapp_info->icon, icon);
2296 label = calloc(1, sizeof(label_x));
2297 LISTADD(info->svcapp_info->label, label);
2298 category = calloc(1, sizeof(category_x));
2299 LISTADD(info->svcapp_info->category, category);
2300 metadata = calloc(1, sizeof(metadata_x));
2301 LISTADD(info->svcapp_info->metadata, metadata);
2302 permission = calloc(1, sizeof(permission_x));
2303 LISTADD(info->svcapp_info->permission, permission);
2304 for(i = 0; i < ncols; i++)
2306 if (strcmp(colname[i], "app_id") == 0) {
2307 /*appid being foreign key, is column in every table
2308 Hence appid gets strduped every time leading to memory leak.
2309 If appid is already set, just continue.*/
2310 if (info->svcapp_info->appid)
2313 info->svcapp_info->appid = strdup(coltxt[i]);
2315 info->svcapp_info->appid = NULL;
2316 } else if (strcmp(colname[i], "app_exec") == 0) {
2318 info->svcapp_info->exec = strdup(coltxt[i]);
2320 info->svcapp_info->exec = NULL;
2321 } else if (strcmp(colname[i], "app_icon") == 0) {
2323 info->svcapp_info->icon->text = strdup(coltxt[i]);
2325 info->svcapp_info->icon->text = NULL;
2326 } else if (strcmp(colname[i], "app_label") == 0 ) {
2328 info->svcapp_info->label->text = strdup(coltxt[i]);
2330 info->svcapp_info->label->text = NULL;
2331 } else if (strcmp(colname[i], "app_type") == 0 ) {
2333 info->svcapp_info->type = strdup(coltxt[i]);
2335 info->svcapp_info->type = NULL;
2336 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2338 info->svcapp_info->onboot = strdup(coltxt[i]);
2340 info->svcapp_info->onboot = NULL;
2341 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2343 info->svcapp_info->autorestart = strdup(coltxt[i]);
2345 info->svcapp_info->autorestart = NULL;
2346 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2348 info->svcapp_info->enabled= strdup(coltxt[i]);
2350 info->svcapp_info->enabled = NULL;
2351 } else if (strcmp(colname[i], "category") == 0 ) {
2353 info->svcapp_info->category->name = strdup(coltxt[i]);
2355 info->svcapp_info->category->name = NULL;
2356 } else if (strcmp(colname[i], "md_key") == 0 ) {
2358 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2360 info->svcapp_info->metadata->key = NULL;
2361 } else if (strcmp(colname[i], "md_value") == 0 ) {
2363 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2365 info->svcapp_info->metadata->value = NULL;
2366 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2368 info->svcapp_info->permission->type= strdup(coltxt[i]);
2370 info->svcapp_info->permission->type = NULL;
2371 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2373 info->svcapp_info->permission->value = strdup(coltxt[i]);
2375 info->svcapp_info->permission->value = NULL;
2376 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2378 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2379 info->svcapp_info->label->lang = strdup(coltxt[i]);
2382 info->svcapp_info->icon->lang = NULL;
2383 info->svcapp_info->label->lang = NULL;
2385 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2387 info->svcapp_info->permission_type = strdup(coltxt[i]);
2389 info->svcapp_info->permission_type = NULL;
2402 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2404 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2406 for(i = 0; i < ncols; i++)
2408 if (strcmp(colname[i], "app_component") == 0) {
2409 info->app_component = __appcomponent_convert(coltxt[i]);
2410 } else if (strcmp(colname[i], "package") == 0) {
2411 info->package = strdup(coltxt[i]);
2418 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2420 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2422 for(i = 0; i < ncols; i++)
2424 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2426 info->appid = strdup(coltxt[i]);
2429 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2431 info->access = strdup(coltxt[i]);
2433 info->access = NULL;
2440 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2442 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2445 for(i = 0; i < ncols; i++)
2447 if (strcmp(colname[i], "author_signer_cert") == 0) {
2449 info->cert_id = atoi(coltxt[i]);
2452 } else if (strcmp(colname[i], "package") == 0) {
2454 info->pkgid= strdup(coltxt[i]);
2463 /* get the first locale value*/
2464 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2466 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2469 info->locale = strdup(coltxt[0]);
2471 info->locale = NULL;
2476 static int __exec_pkginfo_query(char *query, void *data)
2478 char *error_message = NULL;
2480 sqlite3_exec(GET_DB(manifest_db), query, __pkginfo_cb, data, &error_message)) {
2481 _LOGE("Don't execute query = %s error message = %s\n", query,
2483 sqlite3_free(error_message);
2486 sqlite3_free(error_message);
2490 static int __exec_certinfo_query(char *query, void *data)
2492 char *error_message = NULL;
2494 sqlite3_exec(GET_DB(cert_db), query, __certinfo_cb, data, &error_message)) {
2495 _LOGE("Don't execute query = %s error message = %s\n", query,
2497 sqlite3_free(error_message);
2500 sqlite3_free(error_message);
2504 static int __exec_certindexinfo_query(char *query, void *data)
2506 char *error_message = NULL;
2508 sqlite3_exec(GET_DB(cert_db), query, __certindexinfo_cb, data, &error_message)) {
2509 _LOGE("Don't execute query = %s error message = %s\n", query,
2511 sqlite3_free(error_message);
2514 sqlite3_free(error_message);
2518 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2520 char *error_message = NULL;
2521 int ret = sqlite3_exec(db, query, callback, data, &error_message);
2522 if (SQLITE_OK != ret) {
2523 _LOGE("Don't execute query = %s error message = %s ret = %d\n", query,
2524 error_message, ret);
2525 sqlite3_free(error_message);
2528 sqlite3_free(error_message);
2533 static int __child_element(xmlTextReaderPtr reader, int depth)
2535 int ret = xmlTextReaderRead(reader);
2536 int cur = xmlTextReaderDepth(reader);
2539 switch (xmlTextReaderNodeType(reader)) {
2540 case XML_READER_TYPE_ELEMENT:
2541 if (cur == depth + 1)
2544 case XML_READER_TYPE_TEXT:
2545 /*text is handled by each function separately*/
2546 if (cur == depth + 1)
2549 case XML_READER_TYPE_END_ELEMENT:
2558 ret = xmlTextReaderRead(reader);
2559 cur = xmlTextReaderDepth(reader);
2564 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2566 int *p = (int*)data;
2567 *p = atoi(coltxt[0]);
2571 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2573 int result_query = -1;
2575 char query[MAX_QUERY_LEN];
2577 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);
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 int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2585 int result_query = -1;
2587 char wildcard[2] = {'%','\0'};
2588 char query[MAX_QUERY_LEN];
2589 char lang[3] = {'\0'};
2590 strncpy(lang, locale, LANGUAGE_LENGTH);
2592 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);
2593 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2594 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2595 return result_query;
2598 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2601 char wildcard[2] = {'%','\0'};
2602 char lang[3] = {'\0'};
2603 char query[MAX_QUERY_LEN];
2604 char *locale_new = NULL;
2605 pkgmgr_locale_x *info = NULL;
2607 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2609 _LOGE("Out of Memory!!!\n");
2612 memset(info, '\0', sizeof(*info));
2614 strncpy(lang, locale, 2);
2615 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);
2616 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2617 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2618 locale_new = info->locale;
2629 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2631 char *locale = malloc(6);
2633 _LOGE("Malloc Failed\n");
2637 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2641 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2646 char *locale = NULL;
2647 char *locale_new = NULL;
2648 int check_result = 0;
2650 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2652 /*check exact matching */
2653 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2656 if (check_result == 1) {
2657 _LOGD("%s find exact locale(%s)\n", appid, locale);
2661 /* fallback matching */
2662 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2663 if(check_result == 1) {
2664 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2666 if (locale_new == NULL)
2667 locale_new = strdup(DEFAULT_LOCALE);
2671 /* default locale */
2673 return strdup(DEFAULT_LOCALE);
2676 long long _pkgmgr_calculate_dir_size(char *dirname)
2678 long long total = 0;
2680 int q = 0; /*quotient*/
2681 int r = 0; /*remainder*/
2683 struct dirent *ep = NULL;
2684 struct stat fileinfo;
2685 char abs_filename[FILENAME_MAX] = { 0, };
2686 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2688 dp = opendir(dirname);
2690 while ((ep = readdir(dp)) != NULL) {
2691 if (!strcmp(ep->d_name, ".") ||
2692 !strcmp(ep->d_name, "..")) {
2695 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2697 if (lstat(abs_filename, &fileinfo) < 0)
2698 perror(abs_filename);
2700 if (S_ISDIR(fileinfo.st_mode)) {
2701 total += fileinfo.st_size;
2702 if (strcmp(ep->d_name, ".")
2703 && strcmp(ep->d_name, "..")) {
2704 ret = _pkgmgr_calculate_dir_size
2706 total = total + ret;
2708 } else if (S_ISLNK(fileinfo.st_mode)) {
2711 /*It is a file. Calculate the actual
2712 size occupied (in terms of 4096 blocks)*/
2713 q = (fileinfo.st_size / BLOCK_SIZE);
2714 r = (fileinfo.st_size % BLOCK_SIZE);
2718 total += q * BLOCK_SIZE;
2724 _LOGE("Couldn't open the directory\n");
2731 static int __delete_certinfo(const char *pkgid)
2737 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2738 char *error_message = NULL;
2739 char query[MAX_QUERY_LEN] = {'\0'};
2740 pkgmgr_certinfo_x *certinfo = NULL;
2741 pkgmgr_certindexinfo_x *indexinfo = NULL;
2742 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2743 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2744 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2745 if (indexinfo == NULL) {
2746 _LOGE("Out of Memory!!!");
2747 ret = PMINFO_R_ERROR;
2750 /*populate certinfo from DB*/
2751 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2752 ret = __exec_certinfo_query(query, (void *)certinfo);
2754 _LOGE("Package Cert Info DB Information retrieval failed\n");
2755 ret = PMINFO_R_ERROR;
2758 /*Update cert index table*/
2759 for (i = 0; i < MAX_CERT_TYPE; i++) {
2760 if ((certinfo->cert_id)[i]) {
2761 for (j = 0; j < MAX_CERT_TYPE; j++) {
2762 if ((certinfo->cert_id)[i] == unique_id[j]) {
2763 /*Ref count has already been updated. Just continue*/
2767 if (j == MAX_CERT_TYPE)
2768 unique_id[c++] = (certinfo->cert_id)[i];
2771 memset(query, '\0', MAX_QUERY_LEN);
2772 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2773 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2775 _LOGE("Cert Info DB Information retrieval failed\n");
2776 ret = PMINFO_R_ERROR;
2779 memset(query, '\0', MAX_QUERY_LEN);
2780 if (indexinfo->cert_ref_count > 1) {
2781 /*decrease ref count*/
2782 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2783 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2785 /*delete this certificate as ref count is 1 and it will become 0*/
2786 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2789 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2790 _LOGE("Don't execute query = %s error message = %s\n", query,
2792 sqlite3_free(error_message);
2793 ret = PMINFO_R_ERROR;
2798 /*Now delete the entry from db*/
2799 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2801 sqlite3_exec(GET_DB(cert_db), query, NULL, NULL, &error_message)) {
2802 _LOGE("Don't execute query = %s error message = %s\n", query,
2804 sqlite3_free(error_message);
2805 ret = PMINFO_R_ERROR;
2814 if (certinfo->pkgid) {
2815 free(certinfo->pkgid);
2816 certinfo->pkgid = NULL;
2818 for (i = 0; i < MAX_CERT_TYPE; i++) {
2819 if ((certinfo->cert_info)[i]) {
2820 free((certinfo->cert_info)[i]);
2821 (certinfo->cert_info)[i] = NULL;
2829 static int __get_pkg_location(const char *pkgid)
2831 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2834 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2835 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2837 /*check whether application is in external memory or not */
2838 fp = fopen(pkg_mmc_path, "r");
2842 return PMINFO_EXTERNAL_STORAGE;
2845 return PMINFO_INTERNAL_STORAGE;
2848 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2850 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2851 char *error_message = NULL;
2852 int ret = PMINFO_R_OK;
2855 char query[MAX_QUERY_LEN] = {'\0'};
2856 char *syslocale = NULL;
2857 char *locale = NULL;
2858 pkgmgr_pkginfo_x *pkginfo = NULL;
2859 label_x *tmp1 = NULL;
2860 icon_x *tmp2 = NULL;
2861 description_x *tmp3 = NULL;
2862 author_x *tmp4 = NULL;
2863 privilege_x *tmp5 = NULL;
2865 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2866 if (syslocale == NULL) {
2867 _LOGE("current locale is NULL\n");
2868 return PMINFO_R_ERROR;
2870 locale = __convert_system_locale_to_manifest_locale(syslocale);
2871 if (locale == NULL) {
2872 _LOGE("manifest locale is NULL\n");
2874 return PMINFO_R_ERROR;
2877 ret_db = __open_manifest_db(uid);
2879 _LOGE("Fail to open manifest DB\n");
2882 return PMINFO_R_ERROR;
2884 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2885 pkgmgr_pkginfo_x *node = NULL;
2886 pkgmgr_pkginfo_x *temp_node = NULL;
2888 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2890 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2891 _LOGE("Don't execute query = %s error message = %s\n", query,
2893 sqlite3_free(error_message);
2894 ret = PMINFO_R_ERROR;
2898 LISTHEAD(tmphead, node);
2900 for(node = node->next; node ; node = node->next) {
2902 pkginfo->locale = strdup(locale);
2903 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2904 if (pkginfo->manifest_info->privileges == NULL) {
2905 _LOGE("Failed to allocate memory for privileges info\n");
2906 ret = PMINFO_R_ERROR;
2909 /*populate manifest_info from DB*/
2910 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2911 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2913 _LOGE("Package Info DB Information retrieval failed\n");
2914 ret = PMINFO_R_ERROR;
2917 memset(query, '\0', MAX_QUERY_LEN);
2918 /*populate privilege_info from DB*/
2919 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2920 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2922 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2923 ret = PMINFO_R_ERROR;
2926 memset(query, '\0', MAX_QUERY_LEN);
2927 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2928 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2929 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2931 _LOGE("Package Info DB Information retrieval failed\n");
2932 ret = PMINFO_R_ERROR;
2935 /*Also store the values corresponding to default locales*/
2936 memset(query, '\0', MAX_QUERY_LEN);
2937 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2938 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2939 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2941 _LOGE("Package Info DB Information retrieval failed\n");
2942 ret = PMINFO_R_ERROR;
2945 if (pkginfo->manifest_info->label) {
2946 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2947 pkginfo->manifest_info->label = tmp1;
2949 if (pkginfo->manifest_info->icon) {
2950 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2951 pkginfo->manifest_info->icon = tmp2;
2953 if (pkginfo->manifest_info->description) {
2954 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2955 pkginfo->manifest_info->description = tmp3;
2957 if (pkginfo->manifest_info->author) {
2958 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2959 pkginfo->manifest_info->author = tmp4;
2961 if (pkginfo->manifest_info->privileges->privilege) {
2962 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2963 pkginfo->manifest_info->privileges->privilege = tmp5;
2967 LISTHEAD(tmphead, node);
2969 for(node = node->next; node ; node = node->next) {
2972 ret = pkg_list_cb( (void *)pkginfo, user_data);
2980 __close_manifest_db();
2989 LISTHEAD(tmphead, node);
2990 temp_node = node->next;
2993 temp_node = node->next;
2994 __cleanup_pkginfo(node);
2997 __cleanup_pkginfo(tmphead);
3001 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
3003 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
3006 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
3008 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
3009 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3010 pkgmgr_pkginfo_x *pkginfo = NULL;
3011 int ret = PMINFO_R_OK;
3012 char query[MAX_QUERY_LEN] = {'\0'};
3013 char *syslocale = NULL;
3014 char *locale = NULL;
3016 label_x *tmp1 = NULL;
3017 icon_x *tmp2 = NULL;
3018 description_x *tmp3 = NULL;
3019 author_x *tmp4 = NULL;
3020 privilege_x *tmp5 = NULL;
3021 const char* user_pkg_parser = NULL;
3026 user_pkg_parser = getUserPkgParserDBPathUID(uid);
3027 ret = __open_manifest_db(uid);
3028 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
3030 /*check pkgid exist on db*/
3031 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
3032 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
3033 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
3034 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
3036 /*get system locale*/
3037 syslocale = vconf_get_str(VCONFKEY_LANGSET);
3038 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
3040 /*get locale on db*/
3041 locale = __convert_system_locale_to_manifest_locale(syslocale);
3042 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
3044 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
3045 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
3047 pkginfo->locale = strdup(locale);
3049 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
3050 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
3052 pkginfo->manifest_info->package = strdup(pkgid);
3053 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
3054 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
3056 /*populate manifest_info from DB*/
3057 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
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 memset(query, '\0', MAX_QUERY_LEN);
3062 /*populate privilege_info from DB*/
3063 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
3064 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3065 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
3067 memset(query, '\0', MAX_QUERY_LEN);
3068 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3069 " package='%s' and package_locale='%s'", pkgid, locale);
3070 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3071 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3073 /*Also store the values corresponding to default locales*/
3074 memset(query, '\0', MAX_QUERY_LEN);
3075 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
3076 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
3077 ret = __exec_db_query(GET_DB(manifest_db), query, __pkginfo_cb, (void *)pkginfo);
3078 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
3080 if (pkginfo->manifest_info->label) {
3081 LISTHEAD(pkginfo->manifest_info->label, tmp1);
3082 pkginfo->manifest_info->label = tmp1;
3084 if (pkginfo->manifest_info->icon) {
3085 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
3086 pkginfo->manifest_info->icon = tmp2;
3088 if (pkginfo->manifest_info->description) {
3089 LISTHEAD(pkginfo->manifest_info->description, tmp3);
3090 pkginfo->manifest_info->description = tmp3;
3092 if (pkginfo->manifest_info->author) {
3093 LISTHEAD(pkginfo->manifest_info->author, tmp4);
3094 pkginfo->manifest_info->author = tmp4;
3096 if (pkginfo->manifest_info->privileges->privilege) {
3097 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
3098 pkginfo->manifest_info->privileges->privilege = tmp5;
3102 if (ret == PMINFO_R_OK)
3103 *handle = (void*)pkginfo;
3106 __cleanup_pkginfo(pkginfo);
3108 __close_manifest_db();
3120 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3122 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3125 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3127 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3128 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3129 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3130 if (info->manifest_info->package)
3131 *pkg_name = (char *)info->manifest_info->package;
3133 return PMINFO_R_ERROR;
3138 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3140 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3141 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3142 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3143 if (info->manifest_info->package)
3144 *pkgid = (char *)info->manifest_info->package;
3146 return PMINFO_R_ERROR;
3151 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3153 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3154 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3155 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3156 if (info->manifest_info->type)
3157 *type = (char *)info->manifest_info->type;
3163 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3165 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3166 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3167 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3168 *version = (char *)info->manifest_info->version;
3172 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3174 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3175 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3177 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3178 val = (char *)info->manifest_info->installlocation;
3180 if (strcmp(val, "internal-only") == 0)
3181 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3182 else if (strcmp(val, "prefer-external") == 0)
3183 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3185 *location = PMINFO_INSTALL_LOCATION_AUTO;
3190 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3192 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3193 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3195 char *location = NULL;
3196 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3197 location = (char *)info->manifest_info->installlocation;
3198 val = (char *)info->manifest_info->package_size;
3203 _LOGE("package size is not specified\n");
3204 return PMINFO_R_ERROR;
3209 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3211 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3212 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3215 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3216 long long rw_size = 0;
3217 long long ro_size= 0;
3218 long long tmp_size= 0;
3219 long long total_size= 0;
3220 struct stat fileinfo;
3223 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3225 return PMINFO_R_ERROR;
3228 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3229 if (lstat(device_path, &fileinfo) == 0) {
3230 if (!S_ISLNK(fileinfo.st_mode)) {
3231 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3233 rw_size += tmp_size;
3237 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3238 if (lstat(device_path, &fileinfo) == 0) {
3239 if (!S_ISLNK(fileinfo.st_mode)) {
3240 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3242 rw_size += tmp_size;
3246 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3247 if (lstat(device_path, &fileinfo) == 0) {
3248 if (!S_ISLNK(fileinfo.st_mode)) {
3249 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3251 rw_size += tmp_size;
3255 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3256 if (lstat(device_path, &fileinfo) == 0) {
3257 if (!S_ISLNK(fileinfo.st_mode)) {
3258 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3260 rw_size += tmp_size;
3264 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3265 if (lstat(device_path, &fileinfo) == 0) {
3266 if (!S_ISLNK(fileinfo.st_mode)) {
3267 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3269 rw_size += tmp_size;
3273 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3274 if (lstat(device_path, &fileinfo) == 0) {
3275 if (!S_ISLNK(fileinfo.st_mode)) {
3276 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3278 rw_size += tmp_size;
3283 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3284 if (lstat(device_path, &fileinfo) == 0) {
3285 if (!S_ISLNK(fileinfo.st_mode)) {
3286 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3288 ro_size += tmp_size;
3292 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3293 if (lstat(device_path, &fileinfo) == 0) {
3294 if (!S_ISLNK(fileinfo.st_mode)) {
3295 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3297 ro_size += tmp_size;
3301 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3302 if (lstat(device_path, &fileinfo) == 0) {
3303 if (!S_ISLNK(fileinfo.st_mode)) {
3304 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3306 ro_size += tmp_size;
3310 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3311 if (lstat(device_path, &fileinfo) == 0) {
3312 if (!S_ISLNK(fileinfo.st_mode)) {
3313 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3315 ro_size += tmp_size;
3319 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3320 if (lstat(device_path, &fileinfo) == 0) {
3321 if (!S_ISLNK(fileinfo.st_mode)) {
3322 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3324 ro_size += tmp_size;
3328 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3329 if (lstat(device_path, &fileinfo) == 0) {
3330 if (!S_ISLNK(fileinfo.st_mode)) {
3331 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3333 ro_size += tmp_size;
3338 total_size = rw_size + ro_size;
3339 *size = (int)total_size;
3344 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3346 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3347 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3350 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3351 long long total_size= 0;
3354 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3356 return PMINFO_R_ERROR;
3358 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3359 if (access(device_path, R_OK) == 0)
3360 total_size = _pkgmgr_calculate_dir_size(device_path);
3362 return PMINFO_R_ERROR;
3364 *size = (int)total_size;
3369 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3371 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3372 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3373 int ret = PMINFO_R_OK;
3374 char *locale = NULL;
3378 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3380 locale = info->locale;
3381 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3383 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3386 if (strcmp(ptr->lang, locale) == 0) {
3387 *icon = (char *)ptr->text;
3388 if (strcasecmp(*icon, "(null)") == 0) {
3389 locale = DEFAULT_LOCALE;
3393 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3394 *icon = (char *)ptr->text;
3403 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3405 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3406 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3407 int ret = PMINFO_R_OK;
3408 char *locale = NULL;
3409 label_x *ptr = NULL;
3412 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3413 locale = info->locale;
3414 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3416 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3419 if (strcmp(ptr->lang, locale) == 0) {
3420 *label = (char *)ptr->text;
3421 if (strcasecmp(*label, "(null)") == 0) {
3422 locale = DEFAULT_LOCALE;
3426 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3427 *label = (char *)ptr->text;
3436 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3438 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3439 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3440 char *locale = NULL;
3441 description_x *ptr = NULL;
3442 *description = NULL;
3444 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3445 locale = info->locale;
3446 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3448 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3451 if (strcmp(ptr->lang, locale) == 0) {
3452 *description = (char *)ptr->text;
3453 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3454 locale = DEFAULT_LOCALE;
3458 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3459 *description = (char *)ptr->text;
3467 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3469 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3470 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3471 char *locale = NULL;
3472 author_x *ptr = NULL;
3473 *author_name = NULL;
3475 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3476 locale = info->locale;
3477 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3479 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3482 if (strcmp(ptr->lang, locale) == 0) {
3483 *author_name = (char *)ptr->text;
3484 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3485 locale = DEFAULT_LOCALE;
3489 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3490 *author_name = (char *)ptr->text;
3498 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3500 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3501 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3502 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3503 *author_email = (char *)info->manifest_info->author->email;
3507 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3510 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3511 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3512 *author_href = (char *)info->manifest_info->author->href;
3516 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3518 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3519 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3521 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3523 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3524 *storage = PMINFO_INTERNAL_STORAGE;
3525 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3526 *storage = PMINFO_EXTERNAL_STORAGE;
3528 return PMINFO_R_ERROR;
3533 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3535 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3536 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3537 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3538 if (info->manifest_info->installed_time)
3539 *installed_time = atoi(info->manifest_info->installed_time);
3541 return PMINFO_R_ERROR;
3546 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3548 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3549 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3550 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3551 *storeclientid = (char *)info->manifest_info->storeclient_id;
3555 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3557 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3558 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3559 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3560 *mainappid = (char *)info->manifest_info->mainapp_id;
3564 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3566 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3567 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3568 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3569 *url = (char *)info->manifest_info->package_url;
3573 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3575 const char *val = NULL;
3576 const xmlChar *node;
3577 xmlTextReaderPtr reader;
3578 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3579 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3582 reader = xmlReaderForFile(manifest, NULL, 0);
3585 if (__child_element(reader, -1)) {
3586 node = xmlTextReaderConstName(reader);
3588 _LOGE("xmlTextReaderConstName value is NULL\n");
3589 xmlFreeTextReader(reader);
3591 return PMINFO_R_ERROR;
3594 if (!strcmp(ASC_CHAR(node), "manifest")) {
3595 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3596 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3602 _LOGE("package size is not specified\n");
3603 xmlFreeTextReader(reader);
3605 return PMINFO_R_ERROR;
3608 _LOGE("Unable to create xml reader\n");
3609 xmlFreeTextReader(reader);
3611 return PMINFO_R_ERROR;
3615 _LOGE("xmlReaderForFile value is NULL\n");
3617 return PMINFO_R_ERROR;
3620 xmlFreeTextReader(reader);
3626 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3628 const char *val = NULL;
3629 const xmlChar *node;
3630 xmlTextReaderPtr reader;
3631 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3632 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3635 reader = xmlReaderForFile(manifest, NULL, 0);
3638 if ( __child_element(reader, -1)) {
3639 node = xmlTextReaderConstName(reader);
3641 _LOGE("xmlTextReaderConstName value is NULL\n");
3642 xmlFreeTextReader(reader);
3644 return PMINFO_R_ERROR;
3647 if (!strcmp(ASC_CHAR(node), "manifest")) {
3648 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3649 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3652 if (strcmp(val, "internal-only") == 0)
3653 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3654 else if (strcmp(val, "prefer-external") == 0)
3655 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3657 *location = PMINFO_INSTALL_LOCATION_AUTO;
3660 _LOGE("Unable to create xml reader\n");
3661 xmlFreeTextReader(reader);
3663 return PMINFO_R_ERROR;
3667 _LOGE("xmlReaderForFile value is NULL\n");
3669 return PMINFO_R_ERROR;
3672 xmlFreeTextReader(reader);
3679 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3682 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3684 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3685 if (info->manifest_info->root_path)
3686 *path = (char *)info->manifest_info->root_path;
3688 return PMINFO_R_ERROR;
3693 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3695 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3696 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3698 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3699 if (info->manifest_info->csc_path)
3700 *path = (char *)info->manifest_info->csc_path;
3702 *path = (char *)info->manifest_info->csc_path;
3707 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)
3709 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3710 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3711 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3713 int ret = PMINFO_R_OK;
3714 char query[MAX_QUERY_LEN] = {'\0'};
3715 char *error_message = NULL;
3716 pkgmgr_cert_x *info= NULL;
3720 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3721 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3722 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3724 ret = __open_cert_db(uid);
3726 ret = PMINFO_R_ERROR;
3729 _check_create_Cert_db(GET_DB(cert_db));
3730 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3732 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3733 _LOGE("Don't execute query = %s error message = %s\n", query,
3735 ret = PMINFO_R_ERROR;
3742 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3744 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3745 _LOGE("Don't execute query = %s error message = %s\n", query,
3747 ret = PMINFO_R_ERROR;
3750 lcert = info->cert_id;
3753 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3755 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
3756 _LOGE("Don't execute query = %s error message = %s\n", query,
3758 ret = PMINFO_R_ERROR;
3765 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3767 sqlite3_exec(GET_DB(cert_db), query, __cert_cb, (void *)info, &error_message)) {
3768 _LOGE("Don't execute query = %s error message = %s\n", query,
3770 ret = PMINFO_R_ERROR;
3773 rcert = info->cert_id;
3776 if ((lcert == 0) || (rcert == 0))
3778 if ((lcert == 0) && (rcert == 0))
3779 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3780 else if (lcert == 0)
3781 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3782 else if (rcert == 0)
3783 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3786 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3788 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3792 sqlite3_free(error_message);
3805 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)
3807 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3810 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)
3812 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3813 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3814 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3816 int ret = PMINFO_R_OK;
3817 char query[MAX_QUERY_LEN] = {'\0'};
3818 char *error_message = NULL;
3819 pkgmgr_cert_x *info= NULL;
3821 char *lpkgid = NULL;
3822 char *rpkgid = NULL;
3823 const char* user_pkg_parser = getUserPkgParserDBPath();
3825 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3826 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3828 ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
3829 SQLITE_OPEN_READONLY, NULL);
3830 if (ret != SQLITE_OK) {
3831 _LOGE("connect db [%s] failed!\n", user_pkg_parser);
3832 ret = PMINFO_R_ERROR;
3836 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3838 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3839 _LOGE("Don't execute query = %s error message = %s\n", query,
3841 ret = PMINFO_R_ERROR;
3848 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3850 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3851 _LOGE("Don't execute query = %s error message = %s\n", query,
3853 ret = PMINFO_R_ERROR;
3856 lpkgid = strdup(info->pkgid);
3857 if (lpkgid == NULL) {
3858 _LOGE("Out of Memory\n");
3859 ret = PMINFO_R_ERROR;
3866 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3868 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3869 _LOGE("Don't execute query = %s error message = %s\n", query,
3871 ret = PMINFO_R_ERROR;
3878 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3880 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3881 _LOGE("Don't execute query = %s error message = %s\n", query,
3883 ret = PMINFO_R_ERROR;
3886 rpkgid = strdup(info->pkgid);
3887 if (rpkgid == NULL) {
3888 _LOGE("Out of Memory\n");
3889 ret = PMINFO_R_ERROR;
3895 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3897 sqlite3_free(error_message);
3898 __close_manifest_db();
3918 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)
3920 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3921 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3922 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3924 int ret = PMINFO_R_OK;
3925 char query[MAX_QUERY_LEN] = {'\0'};
3926 char *error_message = NULL;
3927 pkgmgr_cert_x *info= NULL;
3929 char *lpkgid = NULL;
3930 char *rpkgid = NULL;
3932 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3933 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3935 ret = __open_manifest_db(uid);
3936 if (ret != SQLITE_OK) {
3937 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3938 ret = PMINFO_R_ERROR;
3942 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3944 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3945 _LOGE("Don't execute query = %s error message = %s\n", query,
3947 ret = PMINFO_R_ERROR;
3954 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3956 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3957 _LOGE("Don't execute query = %s error message = %s\n", query,
3959 ret = PMINFO_R_ERROR;
3962 lpkgid = strdup(info->pkgid);
3963 if (lpkgid == NULL) {
3964 _LOGE("Out of Memory\n");
3965 ret = PMINFO_R_ERROR;
3972 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3974 sqlite3_exec(GET_DB(manifest_db), query, __validate_cb, (void *)&exist, &error_message)) {
3975 _LOGE("Don't execute query = %s error message = %s\n", query,
3977 ret = PMINFO_R_ERROR;
3984 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3986 sqlite3_exec(GET_DB(manifest_db), query, __cert_cb, (void *)info, &error_message)) {
3987 _LOGE("Don't execute query = %s error message = %s\n", query,
3989 ret = PMINFO_R_ERROR;
3992 rpkgid = strdup(info->pkgid);
3993 if (rpkgid == NULL) {
3994 _LOGE("Out of Memory\n");
3995 ret = PMINFO_R_ERROR;
4001 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
4003 sqlite3_free(error_message);
4004 __close_manifest_db();
4024 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
4026 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4027 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4029 #if 0 //smack issue occured, check later
4031 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
4033 _LOGD("invalid func parameters\n");
4034 return PMINFO_R_ERROR;
4036 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
4039 char app_mmc_path[FILENAME_MAX] = { 0, };
4040 char app_dir_path[FILENAME_MAX] = { 0, };
4041 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
4042 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
4043 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
4044 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
4046 /*check whether application is in external memory or not */
4047 fp = fopen(app_mmc_path, "r");
4049 _LOGD(" app path in external memory not accesible\n");
4054 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
4058 /*check whether application is in internal or not */
4059 fp = fopen(app_dir_path, "r");
4061 _LOGD(" app path in internal memory not accesible\n");
4063 return PMINFO_R_ERROR;
4066 /*check whether the application is installed in SD card
4067 but SD card is not present*/
4068 fp = fopen(app_mmc_internal_path, "r");
4071 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
4076 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
4081 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
4088 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
4090 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4091 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4093 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4094 val = (char *)info->manifest_info->removable;
4096 if (strcasecmp(val, "true") == 0)
4098 else if (strcasecmp(val, "false") == 0)
4106 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4108 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4109 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4112 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4114 val = (char *)info->manifest_info->installlocation;
4116 if (strcmp(val, "internal-only") == 0)
4118 else if (strcmp(val, "prefer-external") == 0)
4127 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4129 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4130 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4132 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4133 val = (char *)info->manifest_info->preload;
4135 if (strcasecmp(val, "true") == 0)
4137 else if (strcasecmp(val, "false") == 0)
4145 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4147 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4148 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4151 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4152 val = (char *)info->manifest_info->system;
4154 if (strcasecmp(val, "true") == 0)
4156 else if (strcasecmp(val, "false") == 0)
4165 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4168 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4170 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4171 val = (char *)info->manifest_info->readonly;
4173 if (strcasecmp(val, "true") == 0)
4175 else if (strcasecmp(val, "false") == 0)
4183 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4185 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4186 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4189 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4190 val = (char *)info->manifest_info->update;
4192 if (strcasecmp(val, "true") == 0)
4194 else if (strcasecmp(val, "false") == 0)
4202 API int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users)
4204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4205 retvm_if(for_all_users == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4208 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4209 val = (char *)info->manifest_info->for_all_users;
4211 if (strcasecmp(val, "1") == 0)
4213 else if (strcasecmp(val, "0") == 0)
4222 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4224 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4225 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4226 __cleanup_pkginfo(info);
4230 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4232 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4234 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4235 if (filter == NULL) {
4236 _LOGE("Out of Memory!!!");
4237 return PMINFO_R_ERROR;
4243 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4245 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4246 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4248 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4249 g_slist_free(filter->list);
4256 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4257 const char *property, const int value)
4259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4260 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4261 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4263 GSList *link = NULL;
4265 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4266 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4267 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4268 _LOGE("Invalid Integer Property\n");
4269 return PMINFO_R_EINVAL;
4271 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4272 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4274 _LOGE("Out of Memory!!!\n");
4275 return PMINFO_R_ERROR;
4277 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4278 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4280 _LOGE("Out of Memory\n");
4283 return PMINFO_R_ERROR;
4287 /*If API is called multiple times for same property, we should override the previous values.
4288 Last value set will be used for filtering.*/
4289 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4291 filter->list = g_slist_delete_link(filter->list, link);
4292 filter->list = g_slist_append(filter->list, (gpointer)node);
4297 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4298 const char *property, const bool value)
4300 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4301 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4303 GSList *link = NULL;
4305 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4306 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4307 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4308 _LOGE("Invalid Boolean Property\n");
4309 return PMINFO_R_EINVAL;
4311 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4312 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4314 _LOGE("Out of Memory!!!\n");
4315 return PMINFO_R_ERROR;
4318 val = strndup("('true','True')", 15);
4320 val = strndup("('false','False')", 17);
4322 _LOGE("Out of Memory\n");
4325 return PMINFO_R_ERROR;
4329 /*If API is called multiple times for same property, we should override the previous values.
4330 Last value set will be used for filtering.*/
4331 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4333 filter->list = g_slist_delete_link(filter->list, link);
4334 filter->list = g_slist_append(filter->list, (gpointer)node);
4339 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4340 const char *property, const char *value)
4342 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4343 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4344 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4346 GSList *link = NULL;
4348 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4349 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4350 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4351 _LOGE("Invalid String Property\n");
4352 return PMINFO_R_EINVAL;
4354 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4355 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4357 _LOGE("Out of Memory!!!\n");
4358 return PMINFO_R_ERROR;
4360 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4361 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4362 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4363 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4364 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4365 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4366 else if (strcmp(value, "installed_internal") == 0)
4367 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4368 else if (strcmp(value, "installed_external") == 0)
4369 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4371 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4373 _LOGE("Out of Memory\n");
4376 return PMINFO_R_ERROR;
4380 /*If API is called multiple times for same property, we should override the previous values.
4381 Last value set will be used for filtering.*/
4382 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4384 filter->list = g_slist_delete_link(filter->list, link);
4385 filter->list = g_slist_append(filter->list, (gpointer)node);
4390 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4393 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4394 char *syslocale = NULL;
4395 char *locale = NULL;
4396 char *condition = NULL;
4397 char *error_message = NULL;
4398 char query[MAX_QUERY_LEN] = {'\0'};
4399 char where[MAX_QUERY_LEN] = {'\0'};
4403 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4405 /*Get current locale*/
4406 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4407 if (syslocale == NULL) {
4408 _LOGE("current locale is NULL\n");
4409 return PMINFO_R_ERROR;
4411 locale = __convert_system_locale_to_manifest_locale(syslocale);
4412 if (locale == NULL) {
4413 _LOGE("manifest locale is NULL\n");
4415 return PMINFO_R_ERROR;
4418 ret = __open_manifest_db(uid);
4420 _LOGE("Fail to open manifest DB\n");
4423 return PMINFO_R_ERROR;
4426 /*Start constructing query*/
4427 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4429 /*Get where clause*/
4430 for (list = filter->list; list; list = g_slist_next(list)) {
4431 __get_filter_condition(list->data, &condition);
4433 strncat(where, condition, sizeof(where) - strlen(where) -1);
4434 where[sizeof(where) - 1] = '\0';
4438 if (g_slist_next(list)) {
4439 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4440 where[sizeof(where) - 1] = '\0';
4443 _LOGE("where = %s\n", where);
4444 if (strlen(where) > 0) {
4445 strncat(query, where, sizeof(query) - strlen(query) - 1);
4446 query[sizeof(query) - 1] = '\0';
4448 _LOGE("query = %s\n", query);
4452 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
4453 _LOGE("Don't execute query = %s error message = %s\n", query,
4455 sqlite3_free(error_message);
4456 ret = PMINFO_R_ERROR;
4470 __close_manifest_db();
4474 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4476 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4479 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4480 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4482 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4483 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4484 char *syslocale = NULL;
4485 char *locale = NULL;
4486 char *condition = NULL;
4487 char *error_message = NULL;
4488 char query[MAX_QUERY_LEN] = {'\0'};
4489 char where[MAX_QUERY_LEN] = {'\0'};
4492 label_x *tmp1 = NULL;
4493 icon_x *tmp2 = NULL;
4494 description_x *tmp3 = NULL;
4495 author_x *tmp4 = NULL;
4496 privilege_x *tmp5 = NULL;
4497 pkgmgr_pkginfo_x *node = NULL;
4498 pkgmgr_pkginfo_x *tmphead = NULL;
4499 pkgmgr_pkginfo_x *pkginfo = NULL;
4501 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4502 /*Get current locale*/
4503 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4504 if (syslocale == NULL) {
4505 _LOGE("current locale is NULL\n");
4506 return PMINFO_R_ERROR;
4508 locale = __convert_system_locale_to_manifest_locale(syslocale);
4509 if (locale == NULL) {
4510 _LOGE("manifest locale is NULL\n");
4512 return PMINFO_R_ERROR;
4515 ret = __open_manifest_db(uid);
4517 _LOGE("Fail to open manifest DB\n");
4520 return PMINFO_R_ERROR;
4522 /*Start constructing query*/
4523 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4525 /*Get where clause*/
4526 for (list = filter->list; list; list = g_slist_next(list)) {
4527 __get_filter_condition(list->data, &condition);
4529 strncat(where, condition, sizeof(where) - strlen(where) -1);
4530 where[sizeof(where) - 1] = '\0';
4534 if (g_slist_next(list)) {
4535 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4536 where[sizeof(where) - 1] = '\0';
4539 _LOGE("where = %s\n", where);
4540 if (strlen(where) > 0) {
4541 strncat(query, where, sizeof(query) - strlen(query) - 1);
4542 query[sizeof(query) - 1] = '\0';
4544 _LOGE("query = %s\n", query);
4545 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4546 if (tmphead == NULL) {
4547 _LOGE("Out of Memory!!!\n");
4548 ret = PMINFO_R_ERROR;
4554 sqlite3_exec(GET_DB(manifest_db), query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4555 _LOGE("Don't execute query = %s error message = %s\n", query,
4557 sqlite3_free(error_message);
4558 ret = PMINFO_R_ERROR;
4562 LISTHEAD(tmphead, node);
4563 for(node = node->next ; node ; node = node->next) {
4565 pkginfo->locale = strdup(locale);
4566 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4567 if (pkginfo->manifest_info->privileges == NULL) {
4568 _LOGE("Failed to allocate memory for privileges info\n");
4569 ret = PMINFO_R_ERROR;
4573 /*populate manifest_info from DB*/
4574 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4575 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4577 _LOGE("Package Info DB Information retrieval failed\n");
4578 ret = PMINFO_R_ERROR;
4581 memset(query, '\0', MAX_QUERY_LEN);
4582 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4583 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4584 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4586 _LOGE("Package Info DB Information retrieval failed\n");
4587 ret = PMINFO_R_ERROR;
4590 /*Also store the values corresponding to default locales*/
4591 memset(query, '\0', MAX_QUERY_LEN);
4592 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4593 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4594 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4596 _LOGE("Package Info DB Information retrieval failed\n");
4597 ret = PMINFO_R_ERROR;
4600 if (pkginfo->manifest_info->label) {
4601 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4602 pkginfo->manifest_info->label = tmp1;
4604 if (pkginfo->manifest_info->icon) {
4605 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4606 pkginfo->manifest_info->icon = tmp2;
4608 if (pkginfo->manifest_info->description) {
4609 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4610 pkginfo->manifest_info->description = tmp3;
4612 if (pkginfo->manifest_info->author) {
4613 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4614 pkginfo->manifest_info->author = tmp4;
4616 if (pkginfo->manifest_info->privileges->privilege) {
4617 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4618 pkginfo->manifest_info->privileges->privilege = tmp5;
4622 LISTHEAD(tmphead, node);
4624 for(node = node->next ; node ; node = node->next) {
4627 ret = pkg_cb( (void *)pkginfo, user_data);
4642 __close_manifest_db();
4643 __cleanup_pkginfo(tmphead);
4647 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4648 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4650 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4653 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4654 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4656 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4657 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4659 privilege_x *ptr = NULL;
4660 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4661 ptr = info->manifest_info->privileges->privilege;
4662 for (; ptr; ptr = ptr->next) {
4664 ret = privilege_func(ptr->text, user_data);
4672 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4673 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4675 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4676 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4677 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4679 char *syslocale = NULL;
4680 char *locale = NULL;
4682 char query[MAX_QUERY_LEN] = {'\0'};
4683 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4684 pkgmgr_pkginfo_x *allinfo = NULL;
4685 pkgmgr_appinfo_x *appinfo = NULL;
4686 icon_x *ptr1 = NULL;
4687 label_x *ptr2 = NULL;
4688 category_x *ptr3 = NULL;
4689 metadata_x *ptr4 = NULL;
4690 permission_x *ptr5 = NULL;
4691 image_x *ptr6 = NULL;
4692 const char* user_pkg_parser = NULL;
4694 /*get system locale*/
4695 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4696 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4698 /*get locale on db*/
4699 locale = __convert_system_locale_to_manifest_locale(syslocale);
4700 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4703 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4704 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4706 /*calloc manifest_info*/
4707 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4708 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4711 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4712 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4714 /*set component type*/
4715 if (component == PMINFO_UI_APP)
4716 appinfo->app_component = PMINFO_UI_APP;
4717 if (component == PMINFO_SVC_APP)
4718 appinfo->app_component = PMINFO_SVC_APP;
4719 if (component == PMINFO_ALL_APP)
4720 appinfo->app_component = PMINFO_ALL_APP;
4723 user_pkg_parser = getUserPkgParserDBPathUID(uid);
4724 ret = __open_manifest_db(uid);
4725 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
4727 appinfo->package = strdup(info->manifest_info->package);
4728 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4729 "from package_app_info where " \
4730 "package='%s' and app_component='%s'",
4731 info->manifest_info->package,
4732 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4736 /*Populate ui app info */
4737 ret = __exec_db_query(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)info);
4738 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4740 uiapplication_x *tmp = NULL;
4741 if (info->manifest_info->uiapplication) {
4742 LISTHEAD(info->manifest_info->uiapplication, tmp);
4743 info->manifest_info->uiapplication = tmp;
4745 /*Populate localized info for default locales and call callback*/
4746 /*If the callback func return < 0 we break and no more call back is called*/
4749 appinfo->locale = strdup(locale);
4750 appinfo->uiapp_info = tmp;
4751 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4755 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), appinfo->uiapp_info->appid, syslocale);
4758 memset(query, '\0', MAX_QUERY_LEN);
4759 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4760 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4761 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4763 memset(query, '\0', MAX_QUERY_LEN);
4764 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);
4765 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4766 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4768 /*store setting notification icon section*/
4769 memset(query, '\0', MAX_QUERY_LEN);
4770 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4771 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4772 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4774 /*store app preview image info*/
4775 memset(query, '\0', MAX_QUERY_LEN);
4776 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4777 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4778 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4780 if (appinfo->uiapp_info->label) {
4781 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4782 appinfo->uiapp_info->label = ptr2;
4784 if (appinfo->uiapp_info->icon) {
4785 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4786 appinfo->uiapp_info->icon = ptr1;
4788 if (appinfo->uiapp_info->category) {
4789 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4790 appinfo->uiapp_info->category = ptr3;
4792 if (appinfo->uiapp_info->metadata) {
4793 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4794 appinfo->uiapp_info->metadata = ptr4;
4796 if (appinfo->uiapp_info->permission) {
4797 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4798 appinfo->uiapp_info->permission = ptr5;
4800 if (appinfo->uiapp_info->image) {
4801 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4802 appinfo->uiapp_info->image = ptr6;
4804 ret = app_func((void *)appinfo, user_data);
4810 case PMINFO_SVC_APP:
4811 /*Populate svc app info */
4812 ret = __exec_db_query(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)info);
4813 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4815 serviceapplication_x *tmp1 = NULL;
4816 if (info->manifest_info->serviceapplication) {
4817 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4818 info->manifest_info->serviceapplication = tmp1;
4820 /*Populate localized info for default locales and call callback*/
4821 /*If the callback func return < 0 we break and no more call back is called*/
4824 appinfo->locale = strdup(locale);
4825 appinfo->svcapp_info = tmp1;
4826 memset(query, '\0', MAX_QUERY_LEN);
4827 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4828 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4829 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4831 memset(query, '\0', MAX_QUERY_LEN);
4832 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);
4833 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4834 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4836 if (appinfo->svcapp_info->label) {
4837 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4838 appinfo->svcapp_info->label = ptr2;
4840 if (appinfo->svcapp_info->icon) {
4841 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4842 appinfo->svcapp_info->icon = ptr1;
4844 if (appinfo->svcapp_info->category) {
4845 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4846 appinfo->svcapp_info->category = ptr3;
4848 if (appinfo->svcapp_info->metadata) {
4849 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4850 appinfo->svcapp_info->metadata = ptr4;
4852 if (appinfo->svcapp_info->permission) {
4853 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4854 appinfo->svcapp_info->permission = ptr5;
4856 ret = app_func((void *)appinfo, user_data);
4862 case PMINFO_ALL_APP:
4863 memset(query, '\0', MAX_QUERY_LEN);
4864 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4866 /*Populate all app info */
4867 ret = __exec_db_query(GET_DB(manifest_db), query, __allapp_list_cb, (void *)allinfo);
4868 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4871 appinfo->app_component = PMINFO_UI_APP;
4872 uiapplication_x *tmp2 = NULL;
4873 if (allinfo->manifest_info->uiapplication) {
4874 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4875 allinfo->manifest_info->uiapplication = tmp2;
4877 /*Populate localized info for default locales and call callback*/
4878 /*If the callback func return < 0 we break and no more call back is called*/
4881 appinfo->locale = strdup(locale);
4882 appinfo->uiapp_info = tmp2;
4883 memset(query, '\0', MAX_QUERY_LEN);
4884 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4885 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4886 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4888 memset(query, '\0', MAX_QUERY_LEN);
4889 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);
4890 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4891 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4893 /*store setting notification icon section*/
4894 memset(query, '\0', MAX_QUERY_LEN);
4895 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4896 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4897 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4899 /*store app preview image info*/
4900 memset(query, '\0', MAX_QUERY_LEN);
4901 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4902 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4903 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4905 if (appinfo->uiapp_info->label) {
4906 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4907 appinfo->uiapp_info->label = ptr2;
4909 if (appinfo->uiapp_info->icon) {
4910 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4911 appinfo->uiapp_info->icon = ptr1;
4913 if (appinfo->uiapp_info->category) {
4914 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4915 appinfo->uiapp_info->category = ptr3;
4917 if (appinfo->uiapp_info->metadata) {
4918 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4919 appinfo->uiapp_info->metadata = ptr4;
4921 if (appinfo->uiapp_info->permission) {
4922 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4923 appinfo->uiapp_info->permission = ptr5;
4925 if (appinfo->uiapp_info->image) {
4926 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4927 appinfo->uiapp_info->image = ptr6;
4929 ret = app_func((void *)appinfo, user_data);
4936 appinfo->app_component = PMINFO_SVC_APP;
4937 serviceapplication_x *tmp3 = NULL;
4938 if (allinfo->manifest_info->serviceapplication) {
4939 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4940 allinfo->manifest_info->serviceapplication = tmp3;
4942 /*Populate localized info for default locales and call callback*/
4943 /*If the callback func return < 0 we break and no more call back is called*/
4946 appinfo->locale = strdup(locale);
4947 appinfo->svcapp_info = tmp3;
4948 memset(query, '\0', MAX_QUERY_LEN);
4949 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4950 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4951 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4953 memset(query, '\0', MAX_QUERY_LEN);
4954 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);
4955 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
4956 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4958 if (appinfo->svcapp_info->label) {
4959 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4960 appinfo->svcapp_info->label = ptr2;
4962 if (appinfo->svcapp_info->icon) {
4963 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4964 appinfo->svcapp_info->icon = ptr1;
4966 if (appinfo->svcapp_info->category) {
4967 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4968 appinfo->svcapp_info->category = ptr3;
4970 if (appinfo->svcapp_info->metadata) {
4971 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4972 appinfo->svcapp_info->metadata = ptr4;
4974 if (appinfo->svcapp_info->permission) {
4975 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4976 appinfo->svcapp_info->permission = ptr5;
4978 ret = app_func((void *)appinfo, user_data);
4983 appinfo->app_component = PMINFO_ALL_APP;
4999 if (appinfo->package) {
5000 free((void *)appinfo->package);
5001 appinfo->package = NULL;
5006 __cleanup_pkginfo(allinfo);
5008 __close_manifest_db();
5012 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
5013 pkgmgrinfo_app_list_cb app_func, void *user_data)
5015 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
5018 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5020 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5022 int ret = PMINFO_R_OK;
5023 char query[MAX_QUERY_LEN] = {'\0'};
5024 pkgmgr_appinfo_x *appinfo = NULL;
5025 uiapplication_x *ptr1 = NULL;
5026 serviceapplication_x *ptr2 = NULL;
5027 const char* user_pkg_parser = NULL;
5030 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5031 ret = __open_manifest_db(uid);
5032 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5035 pkgmgr_pkginfo_x *info = NULL;
5036 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5037 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5039 /*calloc manifest_info*/
5040 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5041 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5044 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5045 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5047 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5048 ret = __exec_db_query(GET_DB(manifest_db), query, __mini_appinfo_cb, (void *)info);
5049 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5051 if (info->manifest_info->uiapplication) {
5052 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5053 info->manifest_info->uiapplication = ptr1;
5055 if (info->manifest_info->serviceapplication) {
5056 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5057 info->manifest_info->serviceapplication = ptr2;
5061 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5063 appinfo->app_component = PMINFO_UI_APP;
5064 appinfo->package = strdup(ptr1->package);
5065 appinfo->uiapp_info = ptr1;
5067 ret = app_func((void *)appinfo, user_data);
5070 free((void *)appinfo->package);
5071 appinfo->package = NULL;
5074 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5076 appinfo->app_component = PMINFO_SVC_APP;
5077 appinfo->package = strdup(ptr2->package);
5078 appinfo->svcapp_info = ptr2;
5080 ret = app_func((void *)appinfo, user_data);
5083 free((void *)appinfo->package);
5084 appinfo->package = NULL;
5089 __close_manifest_db();
5094 __cleanup_pkginfo(info);
5098 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5100 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
5103 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
5105 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
5107 int ret = PMINFO_R_OK;
5108 char query[MAX_QUERY_LEN] = {'\0'};
5109 char *syslocale = NULL;
5110 char *locale = NULL;
5111 pkgmgr_appinfo_x *appinfo = NULL;
5112 uiapplication_x *ptr1 = NULL;
5113 serviceapplication_x *ptr2 = NULL;
5114 label_x *tmp1 = NULL;
5115 icon_x *tmp2 = NULL;
5116 category_x *tmp3 = NULL;
5117 metadata_x *tmp4 = NULL;
5118 permission_x *tmp5 = NULL;
5119 image_x *tmp6 = NULL;
5120 const char *user_pkg_parser = NULL;
5122 /*get system locale*/
5123 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5124 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5126 /*get locale on db*/
5127 locale = __convert_system_locale_to_manifest_locale(syslocale);
5128 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5131 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5132 ret = __open_manifest_db(uid);
5133 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5136 pkgmgr_pkginfo_x *info = NULL;
5137 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5138 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5140 /*calloc manifest_info*/
5141 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5142 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5145 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5146 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5148 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5149 ret = __exec_db_query(GET_DB(manifest_db), query, __app_list_cb, (void *)info);
5150 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5152 if (info->manifest_info->uiapplication) {
5153 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5154 info->manifest_info->uiapplication = ptr1;
5156 if (info->manifest_info->serviceapplication) {
5157 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5158 info->manifest_info->serviceapplication = ptr2;
5162 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5164 appinfo->locale = strdup(locale);
5165 appinfo->app_component = PMINFO_UI_APP;
5166 appinfo->package = strdup(ptr1->package);
5167 appinfo->uiapp_info = ptr1;
5168 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5169 "from package_app_info where " \
5170 "app_id='%s'", ptr1->appid);
5171 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5172 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5174 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5178 locale = __get_app_locale_by_fallback(GET_DB(manifest_db), ptr1->appid, syslocale);
5181 memset(query, '\0', MAX_QUERY_LEN);
5182 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5183 "from package_app_localized_info where " \
5184 "app_id='%s' and app_locale='%s'",
5185 ptr1->appid, locale);
5186 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5187 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5189 memset(query, '\0', MAX_QUERY_LEN);
5190 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5191 "from package_app_localized_info where " \
5192 "app_id='%s' and app_locale='%s'",
5193 ptr1->appid, DEFAULT_LOCALE);
5195 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5196 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5198 /*store setting notification icon section*/
5199 memset(query, '\0', MAX_QUERY_LEN);
5200 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5201 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5202 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5204 /*store app preview image info*/
5205 memset(query, '\0', MAX_QUERY_LEN);
5206 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5207 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5208 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5210 if (appinfo->uiapp_info->label) {
5211 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5212 appinfo->uiapp_info->label = tmp1;
5214 if (appinfo->uiapp_info->icon) {
5215 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5216 appinfo->uiapp_info->icon= tmp2;
5218 if (appinfo->uiapp_info->category) {
5219 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5220 appinfo->uiapp_info->category = tmp3;
5222 if (appinfo->uiapp_info->metadata) {
5223 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5224 appinfo->uiapp_info->metadata = tmp4;
5226 if (appinfo->uiapp_info->permission) {
5227 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5228 appinfo->uiapp_info->permission = tmp5;
5230 if (appinfo->uiapp_info->image) {
5231 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5232 appinfo->uiapp_info->image = tmp6;
5234 ret = app_func((void *)appinfo, user_data);
5237 free((void *)appinfo->package);
5238 appinfo->package = NULL;
5241 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5243 appinfo->locale = strdup(locale);
5244 appinfo->app_component = PMINFO_SVC_APP;
5245 appinfo->package = strdup(ptr2->package);
5246 appinfo->svcapp_info = ptr2;
5247 memset(query, '\0', MAX_QUERY_LEN);
5248 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5249 "from package_app_info where " \
5250 "app_id='%s'", ptr2->appid);
5251 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5252 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5254 memset(query, '\0', MAX_QUERY_LEN);
5255 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5256 "from package_app_localized_info where " \
5257 "app_id='%s' and app_locale='%s'",
5258 ptr2->appid, locale);
5259 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5260 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5262 memset(query, '\0', MAX_QUERY_LEN);
5263 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5264 "from package_app_localized_info where " \
5265 "app_id='%s' and app_locale='%s'",
5266 ptr2->appid, DEFAULT_LOCALE);
5267 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5268 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5270 if (appinfo->svcapp_info->label) {
5271 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5272 appinfo->svcapp_info->label = tmp1;
5274 if (appinfo->svcapp_info->icon) {
5275 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5276 appinfo->svcapp_info->icon= tmp2;
5278 if (appinfo->svcapp_info->category) {
5279 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5280 appinfo->svcapp_info->category = tmp3;
5282 if (appinfo->svcapp_info->metadata) {
5283 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5284 appinfo->svcapp_info->metadata = tmp4;
5286 if (appinfo->svcapp_info->permission) {
5287 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5288 appinfo->svcapp_info->permission = tmp5;
5290 ret = app_func((void *)appinfo, user_data);
5293 free((void *)appinfo->package);
5294 appinfo->package = NULL;
5307 __close_manifest_db();
5312 __cleanup_pkginfo(info);
5316 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5318 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5321 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5323 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5326 pkgmgr_appinfo_x *appinfo = NULL;
5327 char *syslocale = NULL;
5328 char *locale = NULL;
5331 label_x *tmp1 = NULL;
5332 icon_x *tmp2 = NULL;
5333 category_x *tmp3 = NULL;
5334 metadata_x *tmp4 = NULL;
5335 permission_x *tmp5 = NULL;
5336 image_x *tmp6 = NULL;
5337 char query[MAX_QUERY_LEN] = {'\0'};
5338 const char* user_pkg_parser = NULL;
5343 user_pkg_parser = getUserPkgParserDBPathUID(uid);
5344 ret = __open_manifest_db(uid);
5345 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", user_pkg_parser);
5347 /*check appid exist on db*/
5348 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5349 ret = __exec_db_query(GET_DB(manifest_db), query, __validate_cb, (void *)&exist);
5350 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5351 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5353 /*get system locale*/
5354 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5355 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5357 /*get locale on db*/
5358 locale = __convert_system_locale_to_manifest_locale(syslocale);
5359 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5362 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5363 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5365 /*check app_component from DB*/
5366 memset(query, '\0', MAX_QUERY_LEN);
5367 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5368 ret = __exec_db_query(GET_DB(manifest_db), query, __appcomponent_cb, (void *)appinfo);
5369 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5371 /*calloc app_component*/
5372 if (appinfo->app_component == PMINFO_UI_APP) {
5373 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5374 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5376 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5377 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5379 appinfo->locale = strdup(locale);
5381 /*populate app_info from DB*/
5382 memset(query, '\0', MAX_QUERY_LEN);
5383 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5384 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5385 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5387 memset(query, '\0', MAX_QUERY_LEN);
5388 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5389 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5390 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5392 /*Also store the values corresponding to default locales*/
5393 memset(query, '\0', MAX_QUERY_LEN);
5394 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5395 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5396 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5398 /*Populate app category*/
5399 memset(query, '\0', MAX_QUERY_LEN);
5400 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category 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 Category Info DB Information retrieval failed");
5404 /*Populate app metadata*/
5405 memset(query, '\0', MAX_QUERY_LEN);
5406 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata 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 Metadata Info DB Information retrieval failed");
5410 /*Populate app permission*/
5411 memset(query, '\0', MAX_QUERY_LEN);
5412 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission 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 permission Info DB Information retrieval failed");
5416 /*store setting notification icon section*/
5417 memset(query, '\0', MAX_QUERY_LEN);
5418 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5419 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5420 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5422 /*store app preview image info*/
5423 memset(query, '\0', MAX_QUERY_LEN);
5424 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5425 ret = __exec_db_query(GET_DB(manifest_db), query, __appinfo_cb, (void *)appinfo);
5426 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5428 switch (appinfo->app_component) {
5430 if (appinfo->uiapp_info->label) {
5431 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5432 appinfo->uiapp_info->label = tmp1;
5434 if (appinfo->uiapp_info->icon) {
5435 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5436 appinfo->uiapp_info->icon = tmp2;
5438 if (appinfo->uiapp_info->category) {
5439 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5440 appinfo->uiapp_info->category = tmp3;
5442 if (appinfo->uiapp_info->metadata) {
5443 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5444 appinfo->uiapp_info->metadata = tmp4;
5446 if (appinfo->uiapp_info->permission) {
5447 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5448 appinfo->uiapp_info->permission = tmp5;
5450 if (appinfo->uiapp_info->image) {
5451 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5452 appinfo->uiapp_info->image = tmp6;
5455 case PMINFO_SVC_APP:
5456 if (appinfo->svcapp_info->label) {
5457 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5458 appinfo->svcapp_info->label = tmp1;
5460 if (appinfo->svcapp_info->icon) {
5461 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5462 appinfo->svcapp_info->icon = tmp2;
5464 if (appinfo->svcapp_info->category) {
5465 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5466 appinfo->svcapp_info->category = tmp3;
5468 if (appinfo->svcapp_info->metadata) {
5469 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5470 appinfo->svcapp_info->metadata = tmp4;
5472 if (appinfo->svcapp_info->permission) {
5473 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5474 appinfo->svcapp_info->permission = tmp5;
5484 if (ret == PMINFO_R_OK)
5485 *handle = (void*)appinfo;
5488 __cleanup_appinfo(appinfo);
5491 __close_manifest_db();
5503 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5505 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5508 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5510 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5511 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5512 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5514 if (info->app_component == PMINFO_UI_APP)
5515 *appid = (char *)info->uiapp_info->appid;
5516 else if (info->app_component == PMINFO_SVC_APP)
5517 *appid = (char *)info->svcapp_info->appid;
5522 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5524 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5525 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5526 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5528 *pkg_name = (char *)info->package;
5533 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5535 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5536 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5537 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5539 *pkgid = (char *)info->package;
5544 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5547 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5548 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5550 if (info->app_component == PMINFO_UI_APP)
5551 *exec = (char *)info->uiapp_info->exec;
5552 if (info->app_component == PMINFO_SVC_APP)
5553 *exec = (char *)info->svcapp_info->exec;
5559 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5561 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5562 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5563 char *locale = NULL;
5565 icon_x *start = NULL;
5568 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5569 locale = info->locale;
5570 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5572 if (info->app_component == PMINFO_UI_APP)
5573 start = info->uiapp_info->icon;
5574 if (info->app_component == PMINFO_SVC_APP)
5575 start = info->svcapp_info->icon;
5576 for(ptr = start; ptr != NULL; ptr = ptr->next)
5579 if (strcmp(ptr->lang, locale) == 0) {
5580 *icon = (char *)ptr->text;
5581 if (strcasecmp(*icon, "(null)") == 0) {
5582 locale = DEFAULT_LOCALE;
5586 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5587 *icon = (char *)ptr->text;
5596 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5598 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5599 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5600 char *locale = NULL;
5601 label_x *ptr = NULL;
5602 label_x *start = NULL;
5605 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5606 locale = info->locale;
5607 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5609 if (info->app_component == PMINFO_UI_APP)
5610 start = info->uiapp_info->label;
5611 if (info->app_component == PMINFO_SVC_APP)
5612 start = info->svcapp_info->label;
5613 for(ptr = start; ptr != NULL; ptr = ptr->next)
5616 if (strcmp(ptr->lang, locale) == 0) {
5617 *label = (char *)ptr->text;
5618 if (strcasecmp(*label, "(null)") == 0) {
5619 locale = DEFAULT_LOCALE;
5623 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5624 *label = (char *)ptr->text;
5625 if (strcasecmp(*label, "(null)") == 0) {
5626 locale = DEFAULT_LOCALE;
5630 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5631 *label = (char *)ptr->text;
5640 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5642 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5643 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5644 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5646 if (info->app_component == PMINFO_UI_APP)
5647 *component = PMINFO_UI_APP;
5648 else if (info->app_component == PMINFO_SVC_APP)
5649 *component = PMINFO_SVC_APP;
5651 return PMINFO_R_ERROR;
5656 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5658 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5659 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5660 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5662 if (info->app_component == PMINFO_UI_APP)
5663 *app_type = (char *)info->uiapp_info->type;
5664 if (info->app_component == PMINFO_SVC_APP)
5665 *app_type = (char *)info->svcapp_info->type;
5670 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5671 int *operation_count, char ***operation)
5673 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5674 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5675 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5676 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5677 *operation_count = data->operation_count;
5678 *operation = data->operation;
5682 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5683 int *uri_count, char ***uri)
5685 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5686 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5687 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5688 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5689 *uri_count = data->uri_count;
5694 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5695 int *mime_count, char ***mime)
5697 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5698 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5699 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5700 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5701 *mime_count = data->mime_count;
5706 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5707 int *subapp_count, char ***subapp)
5709 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5710 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5711 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5712 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5713 *subapp_count = data->subapp_count;
5714 *subapp = data->subapp;
5718 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5720 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5721 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5725 icon_x *start = NULL;
5726 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5728 start = info->uiapp_info->icon;
5730 for(ptr = start; ptr != NULL; ptr = ptr->next)
5733 val = (char *)ptr->section;
5734 if (strcmp(val, "setting") == 0){
5735 *icon = (char *)ptr->text;
5744 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5746 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5747 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5751 icon_x *start = NULL;
5752 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5754 start = info->uiapp_info->icon;
5756 for(ptr = start; ptr != NULL; ptr = ptr->next)
5759 val = (char *)ptr->section;
5761 if (strcmp(val, "notification") == 0){
5762 *icon = (char *)ptr->text;
5771 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5774 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5776 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5777 val = (char *)info->uiapp_info->recentimage;
5779 if (strcasecmp(val, "capture") == 0)
5780 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5781 else if (strcasecmp(val, "icon") == 0)
5782 *type = PMINFO_RECENTIMAGE_USE_ICON;
5784 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5790 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5792 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5793 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5796 image_x *ptr = NULL;
5797 image_x *start = NULL;
5798 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5800 start = info->uiapp_info->image;
5802 for(ptr = start; ptr != NULL; ptr = ptr->next)
5805 val = (char *)ptr->section;
5807 if (strcmp(val, "preview") == 0)
5808 *preview_img = (char *)ptr->text;
5816 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5818 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5819 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5822 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5824 if (info->app_component == PMINFO_UI_APP)
5825 val = info->uiapp_info->permission_type;
5826 else if (info->app_component == PMINFO_SVC_APP)
5827 val = info->svcapp_info->permission_type;
5829 return PMINFO_R_ERROR;
5831 if (strcmp(val, "signature") == 0)
5832 *permission = PMINFO_PERMISSION_SIGNATURE;
5833 else if (strcmp(val, "privilege") == 0)
5834 *permission = PMINFO_PERMISSION_PRIVILEGE;
5836 *permission = PMINFO_PERMISSION_NORMAL;
5841 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5843 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5844 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5845 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5847 *component_type = (char *)info->uiapp_info->component_type;
5852 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5854 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5855 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5857 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5858 val = (char *)info->uiapp_info->hwacceleration;
5860 if (strcasecmp(val, "not-use-GL") == 0)
5861 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5862 else if (strcasecmp(val, "use-GL") == 0)
5863 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5865 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5870 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5872 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5873 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5875 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5876 val = (char *)info->uiapp_info->screenreader;
5878 if (strcasecmp(val, "screenreader-off") == 0)
5879 *screenreader = PMINFO_SCREENREADER_OFF;
5880 else if (strcasecmp(val, "screenreader-on") == 0)
5881 *screenreader = PMINFO_SCREENREADER_ON;
5883 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5888 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5890 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5891 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5892 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5893 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5895 if (info->app_component == PMINFO_UI_APP){
5896 *portrait_img = (char *)info->uiapp_info->portraitimg;
5897 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5903 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5905 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5906 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5907 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5909 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5914 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5915 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5918 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5920 permission_x *ptr = NULL;
5921 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5922 if (info->app_component == PMINFO_UI_APP)
5923 ptr = info->uiapp_info->permission;
5924 else if (info->app_component == PMINFO_SVC_APP)
5925 ptr = info->svcapp_info->permission;
5927 return PMINFO_R_EINVAL;
5928 for (; ptr; ptr = ptr->next) {
5930 ret = permission_func(ptr->value, user_data);
5938 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5939 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5941 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5942 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5944 category_x *ptr = NULL;
5945 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5946 if (info->app_component == PMINFO_UI_APP)
5947 ptr = info->uiapp_info->category;
5948 else if (info->app_component == PMINFO_SVC_APP)
5949 ptr = info->svcapp_info->category;
5951 return PMINFO_R_EINVAL;
5952 for (; ptr; ptr = ptr->next) {
5954 ret = category_func(ptr->name, user_data);
5962 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5963 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5965 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5966 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5968 metadata_x *ptr = NULL;
5969 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5970 if (info->app_component == PMINFO_UI_APP)
5971 ptr = info->uiapp_info->metadata;
5972 else if (info->app_component == PMINFO_SVC_APP)
5973 ptr = info->svcapp_info->metadata;
5975 return PMINFO_R_EINVAL;
5976 for (; ptr; ptr = ptr->next) {
5978 ret = metadata_func(ptr->key, ptr->value, user_data);
5986 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5987 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5989 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5990 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5998 char *manifest = NULL;
5999 char **operation = NULL;
6002 char **subapp = NULL;
6003 appcontrol_x *appcontrol = NULL;
6004 manifest_x *mfx = NULL;
6005 operation_x *op = NULL;
6008 subapp_x *sa = NULL;
6009 pkgmgrinfo_app_component component;
6010 pkgmgrinfo_appcontrol_x *ptr = NULL;
6011 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6013 _LOGE("Failed to get package name\n");
6014 return PMINFO_R_ERROR;
6016 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6018 _LOGE("Failed to get app component name\n");
6019 return PMINFO_R_ERROR;
6021 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
6022 if (manifest == NULL) {
6023 _LOGE("Failed to fetch package manifest file\n");
6024 return PMINFO_R_ERROR;
6026 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
6028 _LOGE("Failed to parse package manifest file\n");
6031 return PMINFO_R_ERROR;
6034 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6036 _LOGE("Out of Memory!!!\n");
6037 pkgmgr_parser_free_manifest_xml(mfx);
6038 return PMINFO_R_ERROR;
6040 /*Get Operation, Uri, Mime*/
6041 switch (component) {
6043 if (mfx->uiapplication) {
6044 if (mfx->uiapplication->appsvc) {
6045 appcontrol = mfx->uiapplication->appsvc;
6049 case PMINFO_SVC_APP:
6050 if (mfx->serviceapplication) {
6051 if (mfx->serviceapplication->appsvc) {
6052 appcontrol = mfx->serviceapplication->appsvc;
6059 for (; appcontrol; appcontrol = appcontrol->next) {
6060 op = appcontrol->operation;
6061 for (; op; op = op->next)
6063 op = appcontrol->operation;
6065 ui = appcontrol->uri;
6066 for (; ui; ui = ui->next)
6068 ui = appcontrol->uri;
6070 mi = appcontrol->mime;
6071 for (; mi; mi = mi->next)
6073 mi = appcontrol->mime;
6075 sa = appcontrol->subapp;
6076 for (; sa; sa = sa->next)
6078 sa = appcontrol->subapp;
6080 operation = (char **)calloc(oc, sizeof(char *));
6081 for (i = 0; i < oc; i++) {
6082 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6086 uri = (char **)calloc(uc, sizeof(char *));
6087 for (i = 0; i < uc; i++) {
6088 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6092 mime = (char **)calloc(mc, sizeof(char *));
6093 for (i = 0; i < mc; i++) {
6094 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6098 subapp = (char **)calloc(sc, sizeof(char *));
6099 for (i = 0; i < sc; i++) {
6100 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6104 /*populate appcontrol handle*/
6105 ptr->operation_count = oc;
6106 ptr->uri_count = uc;
6107 ptr->mime_count = mc;
6108 ptr->subapp_count = sc;
6109 ptr->operation = operation;
6112 ptr->subapp = subapp;
6114 ret = appcontrol_func((void *)ptr, user_data);
6115 for (i = 0; i < oc; i++) {
6118 operation[i] = NULL;
6125 for (i = 0; i < uc; i++) {
6135 for (i = 0; i < mc; i++) {
6145 for (i = 0; i < sc; i++) {
6162 pkgmgr_parser_free_manifest_xml(mfx);
6170 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6171 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6173 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6174 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6182 char *manifest = NULL;
6183 char **operation = NULL;
6186 char **subapp = NULL;
6187 appcontrol_x *appcontrol = NULL;
6188 manifest_x *mfx = NULL;
6189 operation_x *op = NULL;
6192 subapp_x *sa = NULL;
6193 pkgmgrinfo_app_component component;
6194 pkgmgrinfo_appcontrol_x *ptr = NULL;
6195 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6197 _LOGE("Failed to get package name\n");
6198 return PMINFO_R_ERROR;
6200 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6202 _LOGE("Failed to get app component name\n");
6203 return PMINFO_R_ERROR;
6205 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6206 if (manifest == NULL) {
6207 _LOGE("Failed to fetch package manifest file\n");
6208 return PMINFO_R_ERROR;
6210 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6212 _LOGE("Failed to parse package manifest file\n");
6215 return PMINFO_R_ERROR;
6218 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6220 _LOGE("Out of Memory!!!\n");
6221 pkgmgr_parser_free_manifest_xml(mfx);
6222 return PMINFO_R_ERROR;
6224 /*Get Operation, Uri, Mime*/
6225 switch (component) {
6227 if (mfx->uiapplication) {
6228 if (mfx->uiapplication->appsvc) {
6229 appcontrol = mfx->uiapplication->appsvc;
6233 case PMINFO_SVC_APP:
6234 if (mfx->serviceapplication) {
6235 if (mfx->serviceapplication->appsvc) {
6236 appcontrol = mfx->serviceapplication->appsvc;
6243 for (; appcontrol; appcontrol = appcontrol->next) {
6244 op = appcontrol->operation;
6245 for (; op; op = op->next)
6247 op = appcontrol->operation;
6249 ui = appcontrol->uri;
6250 for (; ui; ui = ui->next)
6252 ui = appcontrol->uri;
6254 mi = appcontrol->mime;
6255 for (; mi; mi = mi->next)
6257 mi = appcontrol->mime;
6259 sa = appcontrol->subapp;
6260 for (; sa; sa = sa->next)
6262 sa = appcontrol->subapp;
6264 operation = (char **)calloc(oc, sizeof(char *));
6265 for (i = 0; i < oc; i++) {
6266 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6270 uri = (char **)calloc(uc, sizeof(char *));
6271 for (i = 0; i < uc; i++) {
6272 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6276 mime = (char **)calloc(mc, sizeof(char *));
6277 for (i = 0; i < mc; i++) {
6278 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6282 subapp = (char **)calloc(sc, sizeof(char *));
6283 for (i = 0; i < sc; i++) {
6284 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6288 /*populate appcontrol handle*/
6289 ptr->operation_count = oc;
6290 ptr->uri_count = uc;
6291 ptr->mime_count = mc;
6292 ptr->subapp_count = sc;
6293 ptr->operation = operation;
6296 ptr->subapp = subapp;
6298 ret = appcontrol_func((void *)ptr, user_data);
6299 for (i = 0; i < oc; i++) {
6302 operation[i] = NULL;
6309 for (i = 0; i < uc; i++) {
6319 for (i = 0; i < mc; i++) {
6329 for (i = 0; i < sc; i++) {
6346 pkgmgr_parser_free_manifest_xml(mfx);
6354 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6356 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6357 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6359 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6360 val = (char *)info->uiapp_info->nodisplay;
6362 if (strcasecmp(val, "true") == 0)
6364 else if (strcasecmp(val, "false") == 0)
6372 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6374 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6375 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6377 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6378 val = (char *)info->uiapp_info->multiple;
6380 if (strcasecmp(val, "true") == 0)
6382 else if (strcasecmp(val, "false") == 0)
6390 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6393 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6395 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6396 val = (char *)info->uiapp_info->indicatordisplay;
6398 if (strcasecmp(val, "true") == 0){
6399 *indicator_disp = 1;
6400 }else if (strcasecmp(val, "false") == 0){
6401 *indicator_disp = 0;
6403 *indicator_disp = 0;
6409 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6411 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6412 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6414 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6415 val = (char *)info->uiapp_info->taskmanage;
6417 if (strcasecmp(val, "true") == 0)
6419 else if (strcasecmp(val, "false") == 0)
6427 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6429 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6430 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6432 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6433 if (info->app_component == PMINFO_UI_APP)
6434 val = (char *)info->uiapp_info->enabled;
6435 else if (info->app_component == PMINFO_SVC_APP)
6436 val = (char *)info->uiapp_info->enabled;
6438 _LOGE("invalid component type\n");
6439 return PMINFO_R_EINVAL;
6443 if (strcasecmp(val, "true") == 0)
6445 else if (strcasecmp(val, "false") == 0)
6454 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6456 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6457 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6459 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6460 val = (char *)info->svcapp_info->onboot;
6462 if (strcasecmp(val, "true") == 0)
6464 else if (strcasecmp(val, "false") == 0)
6472 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6474 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6475 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6477 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6478 val = (char *)info->svcapp_info->autorestart;
6480 if (strcasecmp(val, "true") == 0)
6482 else if (strcasecmp(val, "false") == 0)
6490 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6492 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6493 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6495 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6496 val = (char *)info->uiapp_info->mainapp;
6498 if (strcasecmp(val, "true") == 0)
6500 else if (strcasecmp(val, "false") == 0)
6508 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6510 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6511 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6513 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6514 val = (char *)info->uiapp_info->preload;
6516 if (strcasecmp(val, "true") == 0)
6518 else if (strcasecmp(val, "false") == 0)
6526 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6528 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6529 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6531 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6532 val = (char *)info->uiapp_info->submode;
6534 if (strcasecmp(val, "true") == 0)
6536 else if (strcasecmp(val, "false") == 0)
6544 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6547 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6548 __cleanup_appinfo(info);
6552 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6554 return (pkgmgrinfo_pkginfo_filter_create(handle));
6557 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6559 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6562 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6563 const char *property, const int value)
6565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6566 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6567 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6569 GSList *link = NULL;
6571 prop = _pminfo_appinfo_convert_to_prop_int(property);
6572 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6573 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6574 _LOGE("Invalid Integer Property\n");
6575 return PMINFO_R_EINVAL;
6577 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6578 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6580 _LOGE("Out of Memory!!!\n");
6581 return PMINFO_R_ERROR;
6583 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6584 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6586 _LOGE("Out of Memory\n");
6589 return PMINFO_R_ERROR;
6593 /*If API is called multiple times for same property, we should override the previous values.
6594 Last value set will be used for filtering.*/
6595 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6597 filter->list = g_slist_delete_link(filter->list, link);
6598 filter->list = g_slist_append(filter->list, (gpointer)node);
6603 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6604 const char *property, const bool value)
6606 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6607 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6609 GSList *link = NULL;
6611 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6612 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6613 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6614 _LOGE("Invalid Boolean Property\n");
6615 return PMINFO_R_EINVAL;
6617 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6618 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6620 _LOGE("Out of Memory!!!\n");
6621 return PMINFO_R_ERROR;
6624 val = strndup("('true','True')", 15);
6626 val = strndup("('false','False')", 17);
6628 _LOGE("Out of Memory\n");
6631 return PMINFO_R_ERROR;
6635 /*If API is called multiple times for same property, we should override the previous values.
6636 Last value set will be used for filtering.*/
6637 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6639 filter->list = g_slist_delete_link(filter->list, link);
6640 filter->list = g_slist_append(filter->list, (gpointer)node);
6645 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6646 const char *property, const char *value)
6648 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6649 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6650 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6652 pkgmgrinfo_node_x *ptr = NULL;
6653 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6654 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6655 GSList *link = NULL;
6657 prop = _pminfo_appinfo_convert_to_prop_str(property);
6658 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6659 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6660 _LOGE("Invalid String Property\n");
6661 return PMINFO_R_EINVAL;
6663 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6664 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6666 _LOGE("Out of Memory!!!\n");
6667 return PMINFO_R_ERROR;
6671 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6672 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6673 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6675 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6677 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6679 filter->list = g_slist_delete_link(filter->list, link);
6680 filter->list = g_slist_append(filter->list, (gpointer)node);
6682 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6683 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6684 case E_PMINFO_APPINFO_PROP_APP_URI:
6685 case E_PMINFO_APPINFO_PROP_APP_MIME:
6686 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6688 _LOGE("Out of Memory\n");
6691 return PMINFO_R_ERROR;
6693 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6695 ptr = (pkgmgrinfo_node_x *)link->data;
6696 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6697 _LOGE("Previous value is %s\n", prev);
6698 filter->list = g_slist_delete_link(filter->list, link);
6699 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6700 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6701 _LOGE("New value is %s\n", val);
6703 filter->list = g_slist_append(filter->list, (gpointer)node);
6704 memset(temp, '\0', PKG_STRING_LEN_MAX);
6706 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6707 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6708 _LOGE("First value is %s\n", val);
6710 filter->list = g_slist_append(filter->list, (gpointer)node);
6711 memset(temp, '\0', PKG_STRING_LEN_MAX);
6715 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6716 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6718 filter->list = g_slist_delete_link(filter->list, link);
6719 filter->list = g_slist_append(filter->list, (gpointer)node);
6725 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6727 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6728 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6729 char *syslocale = NULL;
6730 char *locale = NULL;
6731 char *condition = NULL;
6732 char *error_message = NULL;
6733 char query[MAX_QUERY_LEN] = {'\0'};
6734 char where[MAX_QUERY_LEN] = {'\0'};
6738 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6739 /*Get current locale*/
6740 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6741 if (syslocale == NULL) {
6742 _LOGE("current locale is NULL\n");
6743 return PMINFO_R_ERROR;
6745 locale = __convert_system_locale_to_manifest_locale(syslocale);
6746 if (locale == NULL) {
6747 _LOGE("manifest locale is NULL\n");
6749 return PMINFO_R_ERROR;
6752 ret = __open_manifest_db(uid);
6754 _LOGE("Fail to open manifest DB\n");
6757 return PMINFO_R_ERROR;
6760 /*Start constructing query*/
6761 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6763 /*Get where clause*/
6764 for (list = filter->list; list; list = g_slist_next(list)) {
6765 __get_filter_condition(list->data, &condition);
6767 strncat(where, condition, sizeof(where) - strlen(where) -1);
6768 where[sizeof(where) - 1] = '\0';
6772 if (g_slist_next(list)) {
6773 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6774 where[sizeof(where) - 1] = '\0';
6777 _LOGE("where = %s\n", where);
6778 if (strlen(where) > 0) {
6779 strncat(query, where, sizeof(query) - strlen(query) - 1);
6780 query[sizeof(query) - 1] = '\0';
6782 _LOGE("query = %s\n", query);
6786 sqlite3_exec(GET_DB(manifest_db), query, __count_cb, (void *)count, &error_message)) {
6787 _LOGE("Don't execute query = %s error message = %s\n", query,
6789 sqlite3_free(error_message);
6790 ret = PMINFO_R_ERROR;
6804 __close_manifest_db();
6808 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6810 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6813 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6814 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6816 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6817 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6818 char *syslocale = NULL;
6819 char *locale = NULL;
6820 char *condition = NULL;
6821 char *error_message = NULL;
6822 char query[MAX_QUERY_LEN] = {'\0'};
6823 char where[MAX_QUERY_LEN] = {'\0'};
6826 uiapplication_x *ptr1 = NULL;
6827 serviceapplication_x *ptr2 = NULL;
6828 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6829 /*Get current locale*/
6830 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6831 if (syslocale == NULL) {
6832 _LOGE("current locale is NULL\n");
6833 return PMINFO_R_ERROR;
6835 locale = __convert_system_locale_to_manifest_locale(syslocale);
6836 if (locale == NULL) {
6837 _LOGE("manifest locale is NULL\n");
6839 return PMINFO_R_ERROR;
6842 ret = __open_manifest_db(uid);
6844 _LOGE("Fail to open manifest DB\n");
6847 return PMINFO_R_ERROR;
6849 /*Start constructing query*/
6850 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6851 /*Get where clause*/
6852 for (list = filter->list; list; list = g_slist_next(list)) {
6853 __get_filter_condition(list->data, &condition);
6855 strncat(where, condition, sizeof(where) - strlen(where) -1);
6856 where[sizeof(where) - 1] = '\0';
6860 if (g_slist_next(list)) {
6861 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6862 where[sizeof(where) - 1] = '\0';
6865 _LOGE("where = %s\n", where);
6866 if (strlen(where) > 0) {
6867 strncat(query, where, sizeof(query) - strlen(query) - 1);
6868 query[sizeof(query) - 1] = '\0';
6870 _LOGE("query = %s\n", query);
6871 /*To get filtered list*/
6872 pkgmgr_pkginfo_x *info = NULL;
6873 pkgmgr_pkginfo_x *filtinfo = NULL;
6874 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6876 _LOGE("Out of Memory!!!\n");
6877 ret = PMINFO_R_ERROR;
6880 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6881 if (info->manifest_info == NULL) {
6882 _LOGE("Out of Memory!!!\n");
6883 ret = PMINFO_R_ERROR;
6886 /*To get detail app info for each member of filtered list*/
6887 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6888 if (filtinfo == NULL) {
6889 _LOGE("Out of Memory!!!\n");
6890 ret = PMINFO_R_ERROR;
6893 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6894 if (filtinfo->manifest_info == NULL) {
6895 _LOGE("Out of Memory!!!\n");
6896 ret = PMINFO_R_ERROR;
6899 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6900 if (appinfo == NULL) {
6901 _LOGE("Out of Memory!!!\n");
6902 ret = PMINFO_R_ERROR;
6906 sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message)) {
6907 _LOGE("Don't execute query = %s error message = %s\n", query,
6909 sqlite3_free(error_message);
6910 ret = PMINFO_R_ERROR;
6913 memset(query, '\0', MAX_QUERY_LEN);
6914 if (info->manifest_info->uiapplication) {
6915 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6916 info->manifest_info->uiapplication = ptr1;
6918 if (info->manifest_info->serviceapplication) {
6919 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6920 info->manifest_info->serviceapplication = ptr2;
6922 /*Filtered UI Apps*/
6923 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6925 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6926 ptr1->appid, "uiapp");
6928 sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6929 _LOGE("Don't execute query = %s error message = %s\n", query,
6931 sqlite3_free(error_message);
6932 ret = PMINFO_R_ERROR;
6936 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6938 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6939 ptr2->appid, "svcapp");
6941 sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6942 _LOGE("Don't execute query = %s error message = %s\n", query,
6944 sqlite3_free(error_message);
6945 ret = PMINFO_R_ERROR;
6949 if (filtinfo->manifest_info->uiapplication) {
6950 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6951 filtinfo->manifest_info->uiapplication = ptr1;
6953 /*If the callback func return < 0 we break and no more call back is called*/
6956 appinfo->locale = strdup(locale);
6957 appinfo->uiapp_info = ptr1;
6958 appinfo->app_component = PMINFO_UI_APP;
6959 ret = app_cb((void *)appinfo, user_data);
6964 /*Filtered Service Apps*/
6965 if (filtinfo->manifest_info->serviceapplication) {
6966 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6967 filtinfo->manifest_info->serviceapplication = ptr2;
6969 /*If the callback func return < 0 we break and no more call back is called*/
6972 appinfo->locale = strdup(locale);
6973 appinfo->svcapp_info = ptr2;
6974 appinfo->app_component = PMINFO_SVC_APP;
6975 ret = app_cb((void *)appinfo, user_data);
6990 __close_manifest_db();
6995 __cleanup_pkginfo(info);
6996 __cleanup_pkginfo(filtinfo);
7000 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
7001 pkgmgrinfo_app_list_cb app_cb, void * user_data)
7003 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
7006 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
7008 return (pkgmgrinfo_pkginfo_filter_create(handle));
7011 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
7013 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
7016 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
7017 const char *key, const char *value)
7019 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7020 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
7021 /*value can be NULL. In that case all apps with specified key should be displayed*/
7025 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7026 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
7027 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
7029 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7033 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7036 /*If API is called multiple times, we should OR all conditions.*/
7037 filter->list = g_slist_append(filter->list, (gpointer)node);
7038 /*All memory will be freed in destroy API*/
7056 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7057 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
7059 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
7060 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
7061 char *syslocale = NULL;
7062 char *locale = NULL;
7063 char *condition = NULL;
7064 char *error_message = NULL;
7065 char query[MAX_QUERY_LEN] = {'\0'};
7066 char where[MAX_QUERY_LEN] = {'\0'};
7069 pkgmgr_pkginfo_x *info = NULL;
7070 pkgmgr_pkginfo_x *filtinfo = NULL;
7071 pkgmgr_appinfo_x *appinfo = NULL;
7072 uiapplication_x *ptr1 = NULL;
7073 serviceapplication_x *ptr2 = NULL;
7074 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
7076 /*Get current locale*/
7077 syslocale = vconf_get_str(VCONFKEY_LANGSET);
7078 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
7079 locale = __convert_system_locale_to_manifest_locale(syslocale);
7080 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
7082 ret = __open_manifest_db(uid);
7084 _LOGE("Fail to open manifest DB\n");
7087 return PMINFO_R_ERROR;
7089 /*Start constructing query*/
7090 memset(where, '\0', MAX_QUERY_LEN);
7091 memset(query, '\0', MAX_QUERY_LEN);
7092 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
7093 /*Get where clause*/
7094 for (list = filter->list; list; list = g_slist_next(list)) {
7095 __get_metadata_filter_condition(list->data, &condition);
7097 strncat(where, condition, sizeof(where) - strlen(where) -1);
7101 if (g_slist_next(list)) {
7102 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
7105 _LOGE("where = %s (%d)\n", where, strlen(where));
7106 if (strlen(where) > 0) {
7107 strncat(query, where, sizeof(query) - strlen(query) - 1);
7109 _LOGE("query = %s (%d)\n", query, strlen(query));
7110 /*To get filtered list*/
7111 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7112 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7114 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7115 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7117 /*To get detail app info for each member of filtered list*/
7118 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
7119 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7121 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
7122 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7124 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
7125 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
7127 ret = sqlite3_exec(GET_DB(manifest_db), query, __app_list_cb, (void *)info, &error_message);
7128 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7129 memset(query, '\0', MAX_QUERY_LEN);
7131 if (info->manifest_info->uiapplication) {
7132 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7133 info->manifest_info->uiapplication = ptr1;
7135 if (info->manifest_info->serviceapplication) {
7136 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7137 info->manifest_info->serviceapplication = ptr2;
7141 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7143 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7144 ptr1->appid, "uiapp");
7145 ret = sqlite3_exec(GET_DB(manifest_db), query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7146 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7147 memset(query, '\0', MAX_QUERY_LEN);
7150 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7152 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7153 ptr2->appid, "svcapp");
7154 ret = sqlite3_exec(GET_DB(manifest_db), query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7155 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7156 memset(query, '\0', MAX_QUERY_LEN);
7158 /*Filtered UI Apps*/
7159 if (filtinfo->manifest_info->uiapplication) {
7160 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7161 filtinfo->manifest_info->uiapplication = ptr1;
7163 /*If the callback func return < 0 we break and no more call back is called*/
7166 appinfo->locale = strdup(locale);
7167 appinfo->uiapp_info = ptr1;
7168 appinfo->app_component = PMINFO_UI_APP;
7169 ret = app_cb((void *)appinfo, user_data);
7174 /*Filtered Service Apps*/
7175 if (filtinfo->manifest_info->serviceapplication) {
7176 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7177 filtinfo->manifest_info->serviceapplication = ptr2;
7179 /*If the callback func return < 0 we break and no more call back is called*/
7182 appinfo->locale = strdup(locale);
7183 appinfo->svcapp_info = ptr2;
7184 appinfo->app_component = PMINFO_SVC_APP;
7185 ret = app_cb((void *)appinfo, user_data);
7200 sqlite3_free(error_message);
7201 __close_manifest_db();
7206 __cleanup_pkginfo(info);
7207 __cleanup_pkginfo(filtinfo);
7211 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7212 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7214 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7217 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7220 pkgmgr_certinfo_x *certinfo = NULL;
7221 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7223 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7224 *handle = (void *)certinfo;
7228 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
7230 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7231 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7232 pkgmgr_certinfo_x *certinfo = NULL;
7233 char *error_message = NULL;
7234 int ret = PMINFO_R_OK;
7235 char query[MAX_QUERY_LEN] = {'\0'};
7238 const char* user_pkg_cert = NULL;
7241 user_pkg_cert = getUserPkgCertDBPath();
7242 ret = db_util_open_with_options(user_pkg_cert, &GET_DB(cert_db),
7243 SQLITE_OPEN_READWRITE, NULL);
7244 if (ret != SQLITE_OK) {
7245 _LOGE("connect db [%s] failed!\n", user_pkg_cert);
7246 return PMINFO_R_ERROR;
7248 _check_create_Cert_db(GET_DB(cert_db));
7250 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7252 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7253 _LOGE("Don't execute query = %s error message = %s\n", query,
7255 sqlite3_free(error_message);
7256 ret = PMINFO_R_ERROR;
7260 _LOGE("Package not found in DB\n");
7261 ret = PMINFO_R_ERROR;
7264 certinfo = (pkgmgr_certinfo_x *)handle;
7265 /*populate certinfo from DB*/
7266 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7267 ret = __exec_certinfo_query(query, (void *)certinfo);
7269 _LOGE("Package Cert Info DB Information retrieval failed\n");
7270 ret = PMINFO_R_ERROR;
7273 for (i = 0; i < MAX_CERT_TYPE; i++) {
7274 memset(query, '\0', MAX_QUERY_LEN);
7275 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7276 ret = __exec_certinfo_query(query, (void *)certinfo);
7278 _LOGE("Cert Info DB Information retrieval failed\n");
7279 ret = PMINFO_R_ERROR;
7282 if (certinfo->cert_value) {
7283 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7284 free(certinfo->cert_value);
7285 certinfo->cert_value = NULL;
7293 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7296 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7297 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7298 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7299 pkgmgr_certinfo_x *certinfo = NULL;
7300 certinfo = (pkgmgr_certinfo_x *)handle;
7301 if ((certinfo->cert_info)[cert_type])
7302 *cert_value = (certinfo->cert_info)[cert_type];
7308 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7310 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7312 pkgmgr_certinfo_x *certinfo = NULL;
7313 certinfo = (pkgmgr_certinfo_x *)handle;
7314 if (certinfo->pkgid) {
7315 free(certinfo->pkgid);
7316 certinfo->pkgid = NULL;
7318 for (i = 0; i < MAX_CERT_TYPE; i++) {
7319 if ((certinfo->cert_info)[i]) {
7320 free((certinfo->cert_info)[i]);
7321 (certinfo->cert_info)[i] = NULL;
7329 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7331 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7332 pkgmgr_instcertinfo_x *certinfo = NULL;
7334 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7335 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7336 *handle = (void *)certinfo;
7340 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7342 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7343 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7344 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7345 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7346 pkgmgr_instcertinfo_x *certinfo = NULL;
7347 certinfo = (pkgmgr_instcertinfo_x *)handle;
7348 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7352 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
7354 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7355 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7356 char *error_message = NULL;
7357 char query[MAX_QUERY_LEN] = {'\0'};
7358 char *vquery = NULL;
7363 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7370 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7371 pkgmgr_certindexinfo_x *indexinfo = NULL;
7372 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7373 if (indexinfo == NULL) {
7374 _LOGE("Out of Memory!!!");
7375 return PMINFO_R_ERROR;
7377 info->pkgid = strdup(pkgid);
7380 ret = db_util_open_with_options(getUserPkgCertDBPath(), &GET_DB(cert_db),
7381 SQLITE_OPEN_READWRITE, NULL);
7382 if (ret != SQLITE_OK) {
7383 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7384 ret = PMINFO_R_ERROR;
7387 _check_create_Cert_db(GET_DB(cert_db));
7388 /*Begin Transaction*/
7389 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7390 if (ret != SQLITE_OK) {
7391 _LOGE("Failed to begin transaction\n");
7392 ret = PMINFO_R_ERROR;
7395 _LOGE("Transaction Begin\n");
7396 /*Check if request is to insert/update*/
7397 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7399 sqlite3_exec(GET_DB(cert_db), query, __validate_cb, (void *)&exist, &error_message)) {
7400 _LOGE("Don't execute query = %s error message = %s\n", query,
7402 sqlite3_free(error_message);
7403 ret = PMINFO_R_ERROR;
7408 We cant just issue update query directly. We need to manage index table also.
7409 Hence it is better to delete and insert again in case of update*/
7410 ret = __delete_certinfo(pkgid);
7412 _LOGE("Certificate Deletion Failed\n");
7414 for (i = 0; i < MAX_CERT_TYPE; i++) {
7415 if ((info->cert_info)[i]) {
7416 for (j = 0; j < i; j++) {
7417 if ( (info->cert_info)[j]) {
7418 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7419 (info->cert_id)[i] = (info->cert_id)[j];
7420 (info->is_new)[i] = 0;
7421 (info->ref_count)[i] = (info->ref_count)[j];
7428 memset(query, '\0', MAX_QUERY_LEN);
7429 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7430 "where cert_info='%s'",(info->cert_info)[i]);
7431 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7433 _LOGE("Cert Info DB Information retrieval failed\n");
7434 ret = PMINFO_R_ERROR;
7437 if (indexinfo->cert_id == 0) {
7438 /*New certificate. Get newid*/
7439 memset(query, '\0', MAX_QUERY_LEN);
7440 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7442 sqlite3_exec(GET_DB(cert_db), query, __maxid_cb, (void *)&newid, &error_message)) {
7443 _LOGE("Don't execute query = %s error message = %s\n", query,
7445 sqlite3_free(error_message);
7446 ret = PMINFO_R_ERROR;
7454 indexinfo->cert_id = maxid;
7455 indexinfo->cert_ref_count = 1;
7459 (info->cert_id)[i] = indexinfo->cert_id;
7460 (info->is_new)[i] = is_new;
7461 (info->ref_count)[i] = indexinfo->cert_ref_count;
7462 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
7463 indexinfo->cert_id = 0;
7464 indexinfo->cert_ref_count = 0;
7468 len = MAX_QUERY_LEN;
7469 for (i = 0; i < MAX_CERT_TYPE; i++) {
7470 if ((info->cert_info)[i])
7471 len+= strlen((info->cert_info)[i]);
7473 vquery = (char *)calloc(1, len);
7475 snprintf(vquery, len,
7476 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7477 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7478 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7479 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7480 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7481 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7482 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7483 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7485 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7486 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7488 sqlite3_free(error_message);
7489 ret = PMINFO_R_ERROR;
7492 /*Update index table info*/
7493 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7494 for (i = 0; i < MAX_CERT_TYPE; i++) {
7495 if ((info->cert_info)[i]) {
7496 memset(vquery, '\0', len);
7497 if ((info->is_new)[i]) {
7498 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7499 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7500 unique_id[c++] = (info->cert_id)[i];
7503 for (j = 0; j < MAX_CERT_TYPE; j++) {
7504 if ((info->cert_id)[i] == unique_id[j]) {
7505 /*Ref count has already been increased. Just continue*/
7509 if (j == MAX_CERT_TYPE)
7510 unique_id[c++] = (info->cert_id)[i];
7513 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7514 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7517 sqlite3_exec(GET_DB(cert_db), vquery, NULL, NULL, &error_message)) {
7518 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7520 sqlite3_free(error_message);
7521 ret = PMINFO_R_ERROR;
7526 /*Commit transaction*/
7527 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7528 if (ret != SQLITE_OK) {
7529 _LOGE("Failed to commit transaction, Rollback now\n");
7530 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7531 ret = PMINFO_R_ERROR;
7534 _LOGE("Transaction Commit and End\n");
7549 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7551 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7553 pkgmgr_instcertinfo_x *certinfo = NULL;
7554 certinfo = (pkgmgr_instcertinfo_x *)handle;
7555 if (certinfo->pkgid) {
7556 free(certinfo->pkgid);
7557 certinfo->pkgid = NULL;
7559 for (i = 0; i < MAX_CERT_TYPE; i++) {
7560 if ((certinfo->cert_info)[i]) {
7561 free((certinfo->cert_info)[i]);
7562 (certinfo->cert_info)[i] = NULL;
7570 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7572 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7575 ret = __open_cert_db(uid);
7577 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7578 ret = PMINFO_R_ERROR;
7581 _check_create_Cert_db(GET_DB(cert_db));
7582 /*Begin Transaction*/
7583 ret = sqlite3_exec(GET_DB(cert_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7584 if (ret != SQLITE_OK) {
7585 _LOGE("Failed to begin transaction\n");
7586 ret = PMINFO_R_ERROR;
7589 _LOGE("Transaction Begin\n");
7590 ret = __delete_certinfo(pkgid);
7592 _LOGE("Certificate Deletion Failed\n");
7594 _LOGE("Certificate Deletion Success\n");
7596 /*Commit transaction*/
7597 ret = sqlite3_exec(GET_DB(cert_db), "COMMIT", NULL, NULL, NULL);
7598 if (ret != SQLITE_OK) {
7599 _LOGE("Failed to commit transaction, Rollback now\n");
7600 sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
7601 ret = PMINFO_R_ERROR;
7604 _LOGE("Transaction Commit and End\n");
7612 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7614 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7617 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7619 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7620 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7622 char *manifest = NULL;
7623 manifest_x *mfx = NULL;
7625 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7626 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7628 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7633 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7635 *handle = (void *)mfx;
7640 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7642 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7643 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7645 char *manifest = NULL;
7646 manifest_x *mfx = NULL;
7648 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7649 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7651 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7656 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7658 *handle = (void *)mfx;
7663 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7665 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7666 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7668 int len = strlen(type);
7669 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7671 manifest_x *mfx = (manifest_x *)handle;
7673 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7677 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7679 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7680 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7682 int len = strlen(version);
7683 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7685 manifest_x *mfx = (manifest_x *)handle;
7687 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7691 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7693 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7694 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7696 manifest_x *mfx = (manifest_x *)handle;
7698 if (location == INSTALL_INTERNAL)
7699 strcpy(mfx->installlocation, "internal-only");
7700 else if (location == INSTALL_EXTERNAL)
7701 strcpy(mfx->installlocation, "prefer-external");
7706 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7708 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7709 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7711 manifest_x *mfx = (manifest_x *)handle;
7713 mfx->package_size = strdup(size);
7718 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7720 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7721 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7723 int len = strlen(label_txt);
7724 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7726 manifest_x *mfx = (manifest_x *)handle;
7728 label_x *label = calloc(1, sizeof(label_x));
7729 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7731 LISTADD(mfx->label, label);
7733 mfx->label->lang = strdup(locale);
7735 mfx->label->lang = strdup(DEFAULT_LOCALE);
7736 mfx->label->text = strdup(label_txt);
7741 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7743 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7744 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7746 int len = strlen(icon_txt);
7747 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7749 manifest_x *mfx = (manifest_x *)handle;
7751 icon_x *icon = calloc(1, sizeof(icon_x));
7752 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7754 LISTADD(mfx->icon, icon);
7756 mfx->icon->lang = strdup(locale);
7758 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7759 mfx->icon->text = strdup(icon_txt);
7764 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7766 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7767 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7769 int len = strlen(desc_txt);
7770 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7772 manifest_x *mfx = (manifest_x *)handle;
7774 description_x *description = calloc(1, sizeof(description_x));
7775 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7777 LISTADD(mfx->description, description);
7779 mfx->description->lang = strdup(locale);
7781 mfx->description->lang = strdup(DEFAULT_LOCALE);
7782 mfx->description->text = strdup(desc_txt);
7787 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7788 const char *author_email, const char *author_href, const char *locale)
7790 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7791 manifest_x *mfx = (manifest_x *)handle;
7792 author_x *author = calloc(1, sizeof(author_x));
7793 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7795 LISTADD(mfx->author, author);
7797 mfx->author->text = strdup(author_name);
7799 mfx->author->email = strdup(author_email);
7801 mfx->author->href = strdup(author_href);
7803 mfx->author->lang = strdup(locale);
7805 mfx->author->lang = strdup(DEFAULT_LOCALE);
7809 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7811 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7812 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7814 manifest_x *mfx = (manifest_x *)handle;
7817 strcpy(mfx->removable, "false");
7818 else if (removable == 1)
7819 strcpy(mfx->removable, "true");
7824 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7826 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7827 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7829 manifest_x *mfx = (manifest_x *)handle;
7832 strcpy(mfx->preload, "false");
7833 else if (preload == 1)
7834 strcpy(mfx->preload, "true");
7839 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7841 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7842 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7844 manifest_x *mfx = (manifest_x *)handle;
7846 if (location == INSTALL_INTERNAL)
7847 strcpy(mfx->installed_storage, "installed_internal");
7848 else if (location == INSTALL_EXTERNAL)
7849 strcpy(mfx->installed_storage, "installed_external");
7854 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7856 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7859 manifest_x *mfx = NULL;
7860 mfx = (manifest_x *)handle;
7862 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7864 _LOGE("Successfully stored info in DB\n");
7867 _LOGE("Failed to store info in DB\n");
7868 return PMINFO_R_ERROR;
7872 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7874 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7877 manifest_x *mfx = NULL;
7878 mfx = (manifest_x *)handle;
7880 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7882 _LOGE("Successfully stored info in DB\n");
7885 _LOGE("Failed to store info in DB\n");
7886 return PMINFO_R_ERROR;
7890 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7892 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7894 manifest_x *mfx = NULL;
7895 mfx = (manifest_x *)handle;
7896 pkgmgr_parser_free_manifest_xml(mfx);
7900 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7902 /* Should be implemented later */
7906 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7908 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7910 char query[MAX_QUERY_LEN] = {'\0'};
7913 ret = __open_manifest_db(uid);
7914 if (ret != SQLITE_OK) {
7915 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
7916 return PMINFO_R_ERROR;
7919 /*Begin transaction*/
7920 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7921 if (ret != SQLITE_OK) {
7922 _LOGE("Failed to begin transaction\n");
7923 __close_manifest_db();
7924 return PMINFO_R_ERROR;
7926 _LOGD("Transaction Begin\n");
7928 memset(query, '\0', MAX_QUERY_LEN);
7929 snprintf(query, MAX_QUERY_LEN,
7930 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7932 char *error_message = NULL;
7934 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
7935 _LOGE("Don't execute query = %s error message = %s\n", query,
7937 sqlite3_free(error_message);
7938 return PMINFO_R_ERROR;
7940 sqlite3_free(error_message);
7942 /*Commit transaction*/
7943 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
7944 if (ret != SQLITE_OK) {
7945 _LOGE("Failed to commit transaction. Rollback now\n");
7946 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
7947 __close_manifest_db();
7948 return PMINFO_R_ERROR;
7950 _LOGD("Transaction Commit and End\n");
7951 __close_manifest_db();
7955 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7957 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7960 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7962 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7963 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7964 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7965 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7966 int ret = PMINFO_R_OK;
7967 char query[MAX_QUERY_LEN] = {'\0'};
7968 char *error_message = NULL;
7969 pkgmgr_datacontrol_x *data = NULL;
7971 ret = __open_datacontrol_db();
7973 _LOGE("Fail to open datacontrol DB\n");
7974 return PMINFO_R_ERROR;
7977 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7979 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7980 __close_datacontrol_db();
7981 return PMINFO_R_ERROR;
7984 snprintf(query, MAX_QUERY_LEN,
7985 "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",
7989 sqlite3_exec(GET_DB(datacontrol_db), query, __datacontrol_cb, (void *)data, &error_message)) {
7990 _LOGE("Don't execute query = %s error message = %s\n", query,
7992 sqlite3_free(error_message);
7993 __close_datacontrol_db();
7994 return PMINFO_R_ERROR;
7997 *appid = (char *)data->appid;
7998 *access = (char *)data->access;
8000 __close_datacontrol_db();
8005 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
8007 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
8009 char query[MAX_QUERY_LEN] = {'\0'};
8010 char *error_message = NULL;
8011 ret = __open_manifest_db(uid);
8014 /*Begin transaction*/
8015 ret = sqlite3_exec(GET_DB(manifest_db), "BEGIN EXCLUSIVE", NULL, NULL, NULL);
8016 if (ret != SQLITE_OK) {
8017 _LOGE("Failed to begin transaction\n");
8018 __close_manifest_db();
8019 return PMINFO_R_ERROR;
8021 _LOGD("Transaction Begin\n");
8023 memset(query, '\0', MAX_QUERY_LEN);
8024 snprintf(query, MAX_QUERY_LEN,
8025 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
8028 sqlite3_exec(GET_DB(manifest_db), query, NULL, NULL, &error_message)) {
8029 _LOGE("Don't execute query = %s error message = %s\n", query,
8031 sqlite3_free(error_message);
8032 return PMINFO_R_ERROR;
8035 /*Commit transaction*/
8036 ret = sqlite3_exec(GET_DB(manifest_db), "COMMIT", NULL, NULL, NULL);
8037 if (ret != SQLITE_OK) {
8038 _LOGE("Failed to commit transaction. Rollback now\n");
8039 sqlite3_exec(GET_DB(manifest_db), "ROLLBACK", NULL, NULL, NULL);
8040 __close_manifest_db();
8041 return PMINFO_R_ERROR;
8043 _LOGD("Transaction Commit and End\n");
8044 __close_manifest_db();
8048 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
8050 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
8053 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
8055 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8056 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
8058 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8059 val = (char *)info->uiapp_info->guestmode_visibility;
8061 if (strcasecmp(val, "true") == 0){
8063 }else if (strcasecmp(val, "false") == 0){
8072 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
8074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
8077 char *noti_string = NULL;
8079 char query[MAX_QUERY_LEN] = {'\0'};
8080 char *errmsg = NULL;
8081 sqlite3 *pkgmgr_parser_db;
8083 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
8084 val = (char *)info->uiapp_info->guestmode_visibility;
8087 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
8088 SQLITE_OPEN_READWRITE, NULL);
8090 if (ret != SQLITE_OK) {
8091 _LOGE("DB Open Failed\n");
8092 return PMINFO_R_ERROR;
8095 /*TODO: Write to DB here*/
8097 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
8099 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
8101 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
8102 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
8104 sqlite3_close(pkgmgr_parser_db);
8105 return PMINFO_R_ERROR;
8107 sqlite3_close(pkgmgr_parser_db);
8108 len = strlen((char *)info->uiapp_info->appid) + 8;
8109 noti_string = calloc(1, len);
8110 if (noti_string == NULL){
8111 return PMINFO_R_ERROR;
8113 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
8114 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
8115 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
8122 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
8124 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
8127 /* pkgmgrinfo client start*/
8128 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8131 char *errmsg = NULL;
8133 void *handle = NULL;
8134 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8136 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8137 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8139 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8141 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8143 pc = __pkgmgr_client_new(ctype);
8144 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8148 return (pkgmgrinfo_client *) pc;
8151 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8154 char *errmsg = NULL;
8155 void *handle = NULL;
8156 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8158 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8159 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8161 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8163 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8165 ret = __pkgmgr_client_set_status_type(pc, status_type);
8166 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8170 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8172 * The lib dependency chain like below
8173 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8175 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8176 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8177 * on libpkgmgr-installer-client.
8179 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8182 * However, when the libdbus call into the callback function, it suddenly fond that the
8183 * function address is gone (unmapped), then we receive a SIGSEGV.
8185 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8186 * robust if we just link to the well-known lib.
8188 * See https://bugs.tizen.org/jira/browse/PTREL-591
8194 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8197 char *errmsg = NULL;
8198 void *handle = NULL;
8199 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8201 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8202 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8204 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8206 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8208 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8209 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8212 /* same as pkgmgrinfo_client_new */
8216 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8219 char *errmsg = NULL;
8220 void *handle = NULL;
8221 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8223 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8224 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8226 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8228 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8230 ret = __pkgmgr_client_free(pc);
8231 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8234 /* same as pkgmgrinfo_client_new */
8238 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8241 DBusConnection *bus;
8242 DBusMessage *message;
8244 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8246 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8249 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8250 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8252 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8253 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8255 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8257 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8258 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8260 dbus_connection_flush(bus);
8261 dbus_message_unref(message);
8266 /* pkgmgrinfo client end*/