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.
36 #include <sys/smack.h>
38 #include <libxml/parser.h>
39 #include <libxml/xmlreader.h>
40 #include <libxml/xmlschemas.h>
42 #include <dbus/dbus.h>
43 #include <dbus/dbus-glib-lowlevel.h>
45 /* For multi-user support */
46 #include <tzplatform_config.h>
48 #include "pkgmgr_parser.h"
49 #include "pkgmgr-info-internal.h"
50 #include "pkgmgr-info-debug.h"
51 #include "pkgmgr-info.h"
52 #include "pkgmgr_parser_db.h"
59 #define LOG_TAG "PKGMGR_INFO"
61 #define ASC_CHAR(s) (const char *)s
62 #define XML_CHAR(s) (const xmlChar *)s
64 #define MANIFEST_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
65 #define MAX_QUERY_LEN 4096
66 #define MAX_CERT_TYPE 9
67 #define CERT_DB tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
68 #define DATACONTROL_DB tzplatform_mkpath(TZ_USER_DB, ".app-package.db")
69 #define PKG_TYPE_STRING_LEN_MAX 128
70 #define PKG_VERSION_STRING_LEN_MAX 128
71 #define PKG_VALUE_STRING_LEN_MAX 512
72 #define PKG_LOCALE_STRING_LEN_MAX 8
73 #define PKG_RW_PATH tzplatform_mkpath(TZ_USER_APP, "")
74 #define PKG_RO_PATH tzplatform_mkpath(TZ_SYS_RO_APP, "")
75 #define BLOCK_SIZE 4096 /*in bytes*/
78 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
79 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
80 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
82 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
83 "from package_info LEFT OUTER JOIN package_localized_info " \
84 "ON package_info.package=package_localized_info.package " \
85 "and package_localized_info.package_locale='%s' where "
87 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
88 "from package_info LEFT OUTER JOIN package_localized_info " \
89 "ON package_info.package=package_localized_info.package " \
90 "and package_localized_info.package_locale='%s' where "
92 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
93 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
94 "ON package_app_info.app_id=package_app_localized_info.app_id " \
95 "and package_app_localized_info.app_locale='%s' " \
96 "LEFT OUTER JOIN package_app_app_svc " \
97 "ON package_app_info.app_id=package_app_app_svc.app_id " \
98 "LEFT OUTER JOIN package_app_app_category " \
99 "ON package_app_info.app_id=package_app_app_category.app_id where "
101 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
102 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
103 "ON package_app_info.app_id=package_app_localized_info.app_id " \
104 "and package_app_localized_info.app_locale='%s' " \
105 "LEFT OUTER JOIN package_app_app_svc " \
106 "ON package_app_info.app_id=package_app_app_svc.app_id " \
107 "LEFT OUTER JOIN package_app_app_category " \
108 "ON package_app_info.app_id=package_app_app_category.app_id where "
110 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
111 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
112 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
114 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
116 #define LANGUAGE_LENGTH 2
117 #define LIBAIL_PATH "/usr/lib/libail.so.0"
119 #define SERVICE_NAME "org.tizen.system.deviced"
120 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
121 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
122 #define METHOD_NAME "RequestMountApp2ext"
126 typedef struct _pkgmgr_instcertinfo_x {
128 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
129 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
130 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
131 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
132 } pkgmgr_instcertinfo_x;
134 typedef struct _pkgmgr_certindexinfo_x {
137 } pkgmgr_certindexinfo_x;
139 typedef struct _pkgmgr_pkginfo_x {
140 manifest_x *manifest_info;
143 struct _pkgmgr_pkginfo_x *prev;
144 struct _pkgmgr_pkginfo_x *next;
147 typedef struct _pkgmgr_cert_x {
152 typedef struct _pkgmgr_datacontrol_x {
155 } pkgmgr_datacontrol_x;
157 typedef struct _pkgmgr_iconpath_x {
162 typedef struct _pkgmgr_image_x {
166 typedef struct _pkgmgr_locale_x {
170 typedef struct _pkgmgr_appinfo_x {
173 pkgmgrinfo_app_component app_component;
175 uiapplication_x *uiapp_info;
176 serviceapplication_x *svcapp_info;
180 typedef struct _pkgmgr_certinfo_x {
183 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
184 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
188 typedef struct _pkgmgrinfo_filter_x {
190 } pkgmgrinfo_filter_x;
192 typedef struct _pkgmgrinfo_node_x {
198 typedef struct _pkgmgrinfo_appcontrol_x {
207 } pkgmgrinfo_appcontrol_x;
209 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
211 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
212 const char *pkgid, const char *key,
213 const char *val, const void *pmsg, void *data);
215 typedef void pkgmgr_client;
216 typedef void pkgmgr_info;
221 PM_REQUEST_GET_SIZE = 2,
222 PM_REQUEST_KILL_APP = 3,
223 PM_REQUEST_CHECK_APP = 4,
225 }pkgmgr_request_service_type;
228 PM_GET_TOTAL_SIZE= 0,
229 PM_GET_DATA_SIZE = 1,
231 PM_GET_SIZE_INFO = 3,
232 PM_GET_TOTAL_AND_DATA = 4,
233 PM_GET_SIZE_FILE = 5,
235 }pkgmgr_getsize_type;
243 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
244 #define MAX_PKG_BUF_LEN 1024
245 #define MAX_PKG_INFO_LEN 10
247 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
248 "(cert_info text not null, " \
249 "cert_id integer, " \
250 "cert_ref_count integer, " \
251 "PRIMARY KEY(cert_id)) "
253 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
254 "(package text not null, " \
255 "author_root_cert integer, " \
256 "author_im_cert integer, " \
257 "author_signer_cert integer, " \
258 "dist_root_cert integer, " \
259 "dist_im_cert integer, " \
260 "dist_signer_cert integer, " \
261 "dist2_root_cert integer, " \
262 "dist2_im_cert integer, " \
263 "dist2_signer_cert integer, " \
264 "PRIMARY KEY(package)) "
267 #define QUERY_ATTACH "attach database '%s' as Global"
268 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select distinct * " \
269 "from (select * from main.package_app_app_category m union select * from Global.package_app_app_category g WHERE m.app_id=g.app_id AND m.category=g.category)"
270 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select distinct * "\
271 "from (select * from main.package_app_info m union select * from Global.package_app_info g WHERE m.package=g.package)"
272 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select distinct * "\
273 "from (select * from main.package_app_app_control m union select * from Globalpackage_app_app_control g WHERE m.app_id=g.app_id AND m.operation=g.operation "\
274 "AND m.uri_scheme=guri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
275 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select distinct * "\
276 "from (select * from main.package_app_localized_info m union select * from Global.package_app_localized_info g WHERE m.app_id=g.app_id AND m.app_locale=g.app_locale)"
277 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select distinct * "\
278 "from (select * from main.package_app_app_metadata m union select * from Global.package_app_app_metadata g WHERE m.app_id=g.app_id AND m.md_key=g.md_key "\
279 "AND m.md_value=g.md_value)"
280 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select distinct * "\
281 "from (select * from main.package_app_share_allowed m union select * from Global.package_app_share_allowed g WHERE m.app_id=g.app_id AND m.data_share_path=g.data_share_path "\
282 "AND m.data_share_allowed=g.data_share_allowed)"
283 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select distinct * "\
284 "from (select * from main.package_app_app_permission m union select * from Global.package_app_app_permission g WHERE m.app_id=g.app_id AND m.pm_type=g.pm_type "\
285 "AND m.pm_value=g.pm_value)"
286 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select distinct * "\
287 "from (select * from main.package_app_share_request m union select * from Global.package_app_share_request g WHERE m.app_id=g.app_id AND m.data_share_request=g.data_share_request)"
288 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select distinct * "\
289 "from (select * from main.package_app_app_svc m union select * from Global.package_app_app_svc g WHERE m.app_id=g.app_id AND m.operation=g.operation "\
290 "AND m.uri_scheme=g.uri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
291 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select distinct * "\
292 "from (select * from main.package_info m union select * from Global.package_info g WHERE m.package=g.package)"
293 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select distinct * "\
294 "from (select * from main.package_app_icon_section_info m union select * from Global.package_app_icon_section_info g WHERE m.app_id=g.app_id "\
295 "AND m.app_icon_section=g.app_icon_section AND m.app_icon_resolution=g.app_icon_resolution)"
296 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select distinct * "\
297 "from (select * from main.package_localized_info m union select * from Global.package_localized_info g WHERE m.package=g.package AND m.package_locale=g.package_locale)"
298 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select distinct * "\
299 "from (select * from main.package_localized_info m union select * from Global.package_localized_info g WHERE m.app_id=g.app_id AND m.app_icon_section=g.app_icon_section "\
300 "AND m.app_icon_resolution=g.app_icon_resolution)"
301 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select distinct * "\
302 "from (select * from main.package_privilege_info m union select * from Global.package_privilege_info g WHERE m.package=g.package AND m.privilege=g.privilege)"
306 char *pkgtype = "rpm";
307 __thread sqlite3 *manifest_db = NULL;
308 __thread sqlite3 *datacontrol_db = NULL;
309 __thread sqlite3 *cert_db = NULL;
311 static int __open_manifest_db(uid_t uid);
312 static int __exec_pkginfo_query(char *query, void *data);
313 static int __exec_certinfo_query(char *query, void *data);
314 static int __exec_certindexinfo_query(char *query, void *data);
315 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
316 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
317 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
318 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
319 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
320 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
321 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
322 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
323 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
324 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
325 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
326 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
327 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
328 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
329 static void __destroy_each_node(gpointer data, gpointer user_data);
330 static void __get_filter_condition(gpointer data, char **condition);
331 static void __get_metadata_filter_condition(gpointer data, char **condition);
332 static gint __compare_func(gconstpointer data1, gconstpointer data2);
333 static int __delete_certinfo(const char *pkgid);
334 static int _check_create_Cert_db( sqlite3 *certdb);
335 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
337 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
339 char *error_message = NULL;
340 char query_attach[MAX_QUERY_LEN] = {'\0'};
341 char query_view[MAX_QUERY_LEN] = {'\0'};
343 if(uid != GLOBAL_USER){
344 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
346 sqlite3_exec(handle, query_attach,
347 NULL, NULL, &error_message)) {
348 _LOGD("Don't execute query = %s error message = %s\n",
349 query_attach, error_message);
350 sqlite3_free(error_message);
357 snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select distinct * from (select * from main.%s m union select * from Global.%s g WHERE m.%s=g.%s)", "package_cert_index_info", "package_cert_index_info", "package_cert_index_info", "cert_id");
359 sqlite3_exec(handle, query_view,
360 NULL, NULL, &error_message)) {
361 _LOGD("Don't execute query = %s error message = %s\n",
362 query_view, error_message);
363 sqlite3_free(error_message);
365 snprintf(query_view, MAX_QUERY_LEN - 1, "CREATE temp VIEW %s as select distinct * from (select * from main.%s m union select * from Global.%s g WHERE m.%s=g.%s)", "package_cert_info", "package_cert_info", "package_cert_info", "package");
367 sqlite3_exec(handle, query_view,
368 NULL, NULL, &error_message)) {
369 _LOGD("Don't execute query = %s error message = %s\n",
370 query_view, error_message);
371 sqlite3_free(error_message);
378 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
380 char *error_message = NULL;
381 char query_attach[MAX_QUERY_LEN] = {'\0'};
382 char query_view[MAX_QUERY_LEN] = {'\0'};
383 if(uid != GLOBAL_USER){
384 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
386 sqlite3_exec(handle, query_attach,
387 NULL, NULL, &error_message)) {
388 _LOGD("Don't execute query = %s error message = %s\n",
389 query_attach, error_message);
390 sqlite3_free(error_message);
393 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
394 NULL, NULL, &error_message)) {
395 _LOGD("Don't execute query = %s error message = %s\n",
396 QUERY_CREATE_VIEW_1, error_message);
397 sqlite3_free(error_message);
400 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
401 NULL, NULL, &error_message)) {
402 _LOGD("Don't execute query = %s error message = %s\n",
403 QUERY_CREATE_VIEW_2, error_message);
404 sqlite3_free(error_message);
407 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
408 NULL, NULL, &error_message)) {
409 _LOGD("Don't execute query = %s error message = %s\n",
410 QUERY_CREATE_VIEW_3, error_message);
411 sqlite3_free(error_message);
414 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
415 NULL, NULL, &error_message)) {
416 _LOGD("Don't execute query = %s error message = %s\n",
417 QUERY_CREATE_VIEW_4, error_message);
418 sqlite3_free(error_message);
421 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
422 NULL, NULL, &error_message)) {
423 _LOGD("Don't execute query = %s error message = %s\n",
424 QUERY_CREATE_VIEW_5, error_message);
425 sqlite3_free(error_message);
428 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
429 NULL, NULL, &error_message)) {
430 _LOGD("Don't execute query = %s error message = %s\n",
431 QUERY_CREATE_VIEW_6, error_message);
432 sqlite3_free(error_message);
435 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
436 NULL, NULL, &error_message)) {
437 _LOGD("Don't execute query = %s error message = %s\n",
438 QUERY_CREATE_VIEW_7, error_message);
439 sqlite3_free(error_message);
442 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
443 NULL, NULL, &error_message)) {
444 _LOGD("Don't execute query = %s error message = %s\n",
445 QUERY_CREATE_VIEW_8, error_message);
446 sqlite3_free(error_message);
449 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
450 NULL, NULL, &error_message)) {
451 _LOGD("Don't execute query = %s error message = %s\n",
452 QUERY_CREATE_VIEW_9, error_message);
453 sqlite3_free(error_message);
456 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
457 NULL, NULL, &error_message)) {
458 _LOGD("Don't execute query = %s error message = %s\n",
459 QUERY_CREATE_VIEW_10, error_message);
460 sqlite3_free(error_message);
463 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
464 NULL, NULL, &error_message)) {
465 _LOGD("Don't execute query = %s error message = %s\n",
466 QUERY_CREATE_VIEW_11, error_message);
467 sqlite3_free(error_message);
470 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
471 NULL, NULL, &error_message)) {
472 _LOGD("Don't execute query = %s error message = %s\n",
473 QUERY_CREATE_VIEW_12, error_message);
474 sqlite3_free(error_message);
477 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
478 NULL, NULL, &error_message)) {
479 _LOGD("Don't execute query = %s error message = %s\n",
480 QUERY_CREATE_VIEW_13, error_message);
481 sqlite3_free(error_message);
484 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
485 NULL, NULL, &error_message)) {
486 _LOGD("Don't execute query = %s error message = %s\n",
487 QUERY_CREATE_VIEW_14, error_message);
488 sqlite3_free(error_message);
496 static int _check_create_Cert_db( sqlite3 *certdb)
499 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
502 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
508 API char *getIconPath(uid_t uid)
511 struct group *grpinfo = NULL;
513 struct passwd *userinfo = getpwuid(uid);
515 if (uid != GLOBAL_USER) {
516 if (userinfo == NULL) {
517 _LOGE("getpwuid(%d) returns NULL !", uid);
520 grpinfo = getgrnam("users");
521 if (grpinfo == NULL) {
522 _LOGE("getgrnam(users) returns NULL !");
525 // Compare git_t type and not group name
526 if (grpinfo->gr_gid != userinfo->pw_gid) {
527 _LOGE("UID [%d] does not belong to 'users' group!", uid);
530 asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir);
532 grpinfo = getgrnam("root");
533 if (grpinfo == NULL) {
534 _LOGE("getgrnam(root) returns NULL !");
537 if (grpinfo->gr_gid != userinfo->pw_gid) {
538 _LOGE("UID [%d] does not belong to 'root' group!", uid);
541 result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
545 mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
546 ret = chown(result, uid, grpinfo->gr_gid);
549 strerror_r(errno, buf, sizeof(buf));
550 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, grpinfo->gr_gid, buf);
555 API char *getUserPkgParserDBPath(void)
557 return getUserPkgParserDBPathUID(GLOBAL_USER);
560 API char *getUserPkgParserDBPathUID(uid_t uid)
563 char *journal = NULL;
564 struct group *grpinfo = NULL;
566 struct passwd *userinfo = getpwuid(uid);
568 if (uid != GLOBAL_USER) {
569 if (userinfo == NULL) {
570 _LOGE("getpwuid(%d) returns NULL !", uid);
573 grpinfo = getgrnam("users");
574 if (grpinfo == NULL) {
575 _LOGE("getgrnam(users) returns NULL !");
578 // Compare git_t type and not group name
579 if (grpinfo->gr_gid != userinfo->pw_gid) {
580 _LOGE("UID [%d] does not belong to 'users' group!", uid);
583 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
584 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir);
586 grpinfo = getgrnam("root");
587 if (grpinfo == NULL) {
588 _LOGE("getgrnam(root) returns NULL !");
591 if (grpinfo->gr_gid != userinfo->pw_gid) {
592 _LOGE("UID [%d] does not belong to 'root' group!", uid);
595 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
596 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser-journal.db");
598 char *temp = strdup(result);
599 dir = strrchr(temp, '/');
608 mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
609 ret = chown(dir + 1, uid, grpinfo->gr_gid);
612 strerror_r(errno, buf, sizeof(buf));
613 _LOGE("FAIL : chown %s %d.%d, because %s", dir + 1, uid, grpinfo->gr_gid, buf);
619 API char *getUserPkgCertDBPath(void)
621 return getUserPkgCertDBPathUID(GLOBAL_USER);
624 API char *getUserPkgCertDBPathUID(uid_t uid)
627 char *journal = NULL;
628 struct group *grpinfo = NULL;
630 struct passwd *userinfo = getpwuid(uid);
632 if (uid != GLOBAL_USER) {
634 if (userinfo == NULL) {
635 _LOGE("getpwuid(%d) returns NULL !", uid);
638 grpinfo = getgrnam("users");
639 if (grpinfo == NULL) {
640 _LOGE("getgrnam(users) returns NULL !");
643 // Compare git_t type and not group name
644 if (grpinfo->gr_gid != userinfo->pw_gid) {
645 _LOGE("UID [%d] does not belong to 'users' group!", uid);
648 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_cert.db", userinfo->pw_dir);
649 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_cert.db-journal", userinfo->pw_dir);
651 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
652 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert-journal.db");
653 grpinfo = getgrnam("root");
654 if (grpinfo == NULL) {
655 _LOGE("getgrnam(root) returns NULL !");
659 char *temp = strdup(result);
660 dir = strrchr(temp, '/');
669 mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
670 ret = chown(dir + 1, uid, grpinfo->gr_gid);
673 strerror_r(errno, buf, sizeof(buf));
674 _LOGE("FAIL : chown %s %d.%d, because %s", dir + 1, uid, grpinfo->gr_gid, buf);
680 API const char* getUserDesktopPath(uid_t uid)
683 struct group *grpinfo = NULL;
685 struct passwd *userinfo = getpwuid(uid);
687 if (uid != GLOBAL_USER) {
689 if (userinfo == NULL) {
690 _LOGE("getpwuid(%d) returns NULL !", uid);
693 grpinfo = getgrnam("users");
694 if (grpinfo == NULL) {
695 _LOGE("getgrnam(users) returns NULL !");
698 // Compare git_t type and not group name
699 if (grpinfo->gr_gid != userinfo->pw_gid) {
700 _LOGE("UID [%d] does not belong to 'users' group!", uid);
703 asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir);
705 grpinfo = getgrnam("root");
706 if (grpinfo == NULL) {
707 _LOGE("getgrnam(root) returns NULL !");
710 if (grpinfo->gr_gid != userinfo->pw_gid) {
711 _LOGE("UID [%d] does not belong to 'root' group!", uid);
714 result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
718 mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
719 ret = chown(result, uid, grpinfo->gr_gid);
722 strerror_r(errno, buf, sizeof(buf));
723 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, grpinfo->gr_gid, buf);
728 API const char* getUserManifestPath(uid_t uid)
731 struct group *grpinfo = NULL;
733 struct passwd *userinfo = getpwuid(uid);
735 if (uid != GLOBAL_USER) {
737 if (userinfo == NULL) {
738 _LOGE("getpwuid(%d) returns NULL !", uid);
741 grpinfo = getgrnam("users");
742 if (grpinfo == NULL) {
743 _LOGE("getgrnam(users) returns NULL !");
746 // Compare git_t type and not group name
747 if (grpinfo->gr_gid != userinfo->pw_gid) {
748 _LOGE("UID [%d] does not belong to 'users' group!", uid);
751 asprintf(&result, "%s/.config/xwalk-service/applications/", userinfo->pw_dir);
753 grpinfo = getgrnam("root");
754 if (grpinfo == NULL) {
755 _LOGE("getgrnam(root) returns NULL !");
758 if (grpinfo->gr_gid != userinfo->pw_gid) {
759 _LOGE("UID [%d] does not belong to 'root' group!", uid);
762 result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
766 mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
767 ret = chown(result, uid, grpinfo->gr_gid);
770 strerror_r(errno, buf, sizeof(buf));
771 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, grpinfo->gr_gid, buf);
777 static gint __compare_func(gconstpointer data1, gconstpointer data2)
779 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
780 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
781 if (node1->prop == node2->prop)
783 else if (node1->prop > node2->prop)
789 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
792 *p = atoi(coltxt[0]);
793 _LOGE("count value is %d\n", *p);
797 static void __destroy_each_node(gpointer data, gpointer user_data)
799 ret_if(data == NULL);
800 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
813 static void __get_metadata_filter_condition(gpointer data, char **condition)
815 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
816 char key[MAX_QUERY_LEN] = {'\0'};
817 char value[MAX_QUERY_LEN] = {'\0'};
819 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
822 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
827 *condition = strdup(key);
831 static void __get_filter_condition(gpointer data, char **condition)
833 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
834 char buf[MAX_QUERY_LEN + 1] = {'\0'};
835 char temp[PKG_STRING_LEN_MAX] = {'\0'};
836 switch (node->prop) {
837 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
838 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
840 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
841 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
843 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
844 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
846 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
847 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
849 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
850 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
852 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
853 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
855 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
856 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
858 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
859 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
861 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
862 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
864 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
865 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
867 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
868 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
870 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
871 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
873 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
874 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
876 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
877 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
879 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
880 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
883 case E_PMINFO_APPINFO_PROP_APP_ID:
884 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
886 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
887 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
889 case E_PMINFO_APPINFO_PROP_APP_EXEC:
890 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
892 case E_PMINFO_APPINFO_PROP_APP_ICON:
893 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
895 case E_PMINFO_APPINFO_PROP_APP_TYPE:
896 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
898 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
899 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
900 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
902 case E_PMINFO_APPINFO_PROP_APP_URI:
903 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
904 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
906 case E_PMINFO_APPINFO_PROP_APP_MIME:
907 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
908 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
910 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
911 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
912 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
914 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
915 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
917 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
918 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
920 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
921 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
923 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
924 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
926 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
927 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
929 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
930 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
932 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
933 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
935 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
936 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
939 _LOGE("Invalid Property Type\n");
943 *condition = strdup(buf);
947 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
949 if (syslocale == NULL)
950 return strdup(DEFAULT_LOCALE);
952 locale = (char *)calloc(1, 6);
953 retvm_if(!locale, NULL, "Malloc Failed\n");
955 strncpy(locale, syslocale, 2);
956 strncat(locale, "-", 1);
957 locale[3] = syslocale[3] + 32;
958 locale[4] = syslocale[4] + 32;
962 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
964 ret_if(data == NULL);
966 free((void *)data->locale);
970 pkgmgr_parser_free_manifest_xml(data->manifest_info);
976 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
978 ret_if(data == NULL);
980 free((void *)data->package);
981 data->package = NULL;
984 free((void *)data->locale);
988 manifest_x *mfx = calloc(1, sizeof(manifest_x));
989 if (data->app_component == PMINFO_UI_APP)
990 mfx->uiapplication = data->uiapp_info;
991 else if (data->app_component == PMINFO_SVC_APP)
992 mfx->serviceapplication = data->svcapp_info;
993 pkgmgr_parser_free_manifest_xml(mfx);
999 static int __open_manifest_db(uid_t uid)
1002 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
1004 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
1005 SQLITE_OPEN_READONLY, NULL);
1006 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
1009 _LOGE("Manifest DB does not exists !!\n");
1013 static int __open_datacontrol_db()
1016 if (access(DATACONTROL_DB, F_OK) == 0) {
1018 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
1019 SQLITE_OPEN_READONLY, NULL);
1020 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1023 _LOGE("Datacontrol DB does not exists !!\n");
1027 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1029 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1031 pkgmgr_pkginfo_x *info = NULL;
1032 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1033 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1035 LISTADD(udata, info);
1036 for(i = 0; i < ncols; i++)
1038 if (strcmp(colname[i], "package") == 0) {
1040 info->manifest_info->package = strdup(coltxt[i]);
1042 info->manifest_info->package = NULL;
1050 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1052 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1055 uiapplication_x *uiapp = NULL;
1056 serviceapplication_x *svcapp = NULL;
1057 for(i = 0; i < ncols; i++)
1059 if ((strcmp(colname[i], "app_component") == 0) ||
1060 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1062 if (strcmp(coltxt[i], "uiapp") == 0) {
1063 uiapp = calloc(1, sizeof(uiapplication_x));
1064 if (uiapp == NULL) {
1065 _LOGE("Out of Memory!!!\n");
1068 LISTADD(info->manifest_info->uiapplication, uiapp);
1069 for(j = 0; j < ncols; j++)
1071 if ((strcmp(colname[j], "app_id") == 0) ||
1072 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1074 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1075 } else if (strcmp(colname[j], "package") == 0) {
1077 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1082 svcapp = calloc(1, sizeof(serviceapplication_x));
1083 if (svcapp == NULL) {
1084 _LOGE("Out of Memory!!!\n");
1087 LISTADD(info->manifest_info->serviceapplication, svcapp);
1088 for(j = 0; j < ncols; j++)
1090 if ((strcmp(colname[j], "app_id") == 0) ||
1091 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1093 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1094 } else if (strcmp(colname[j], "package") == 0) {
1096 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1110 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1112 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1114 uiapplication_x *uiapp = NULL;
1115 icon_x *icon = NULL;
1116 label_x *label = NULL;
1118 uiapp = calloc(1, sizeof(uiapplication_x));
1119 LISTADD(info->manifest_info->uiapplication, uiapp);
1120 icon = calloc(1, sizeof(icon_x));
1121 LISTADD(info->manifest_info->uiapplication->icon, icon);
1122 label = calloc(1, sizeof(label_x));
1123 LISTADD(info->manifest_info->uiapplication->label, label);
1125 for(i = 0; i < ncols; i++)
1127 if (strcmp(colname[i], "app_id") == 0) {
1129 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1131 info->manifest_info->uiapplication->appid = NULL;
1132 } else if (strcmp(colname[i], "app_exec") == 0) {
1134 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1136 info->manifest_info->uiapplication->exec = NULL;
1137 } else if (strcmp(colname[i], "app_type") == 0 ){
1139 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1141 info->manifest_info->uiapplication->type = NULL;
1142 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1144 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1146 info->manifest_info->uiapplication->nodisplay = NULL;
1147 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1149 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1151 info->manifest_info->uiapplication->multiple = NULL;
1152 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1154 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1156 info->manifest_info->uiapplication->taskmanage = NULL;
1157 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1159 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1161 info->manifest_info->uiapplication->hwacceleration = NULL;
1162 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1164 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1166 info->manifest_info->uiapplication->screenreader = NULL;
1167 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1169 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1171 info->manifest_info->uiapplication->indicatordisplay = NULL;
1172 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1174 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1176 info->manifest_info->uiapplication->portraitimg = NULL;
1177 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1179 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1181 info->manifest_info->uiapplication->landscapeimg = NULL;
1182 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1184 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1186 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1187 } else if (strcmp(colname[i], "package") == 0 ){
1189 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1191 info->manifest_info->uiapplication->package = NULL;
1192 } else if (strcmp(colname[i], "app_icon") == 0) {
1194 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1196 info->manifest_info->uiapplication->icon->text = NULL;
1197 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1199 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1201 info->manifest_info->uiapplication->enabled = NULL;
1202 } else if (strcmp(colname[i], "app_label") == 0 ) {
1204 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1206 info->manifest_info->uiapplication->label->text = NULL;
1207 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1209 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1211 info->manifest_info->uiapplication->recentimage = NULL;
1212 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1214 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1216 info->manifest_info->uiapplication->mainapp = NULL;
1217 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1219 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1220 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1223 info->manifest_info->uiapplication->icon->lang = NULL;
1224 info->manifest_info->uiapplication->label->lang = NULL;
1226 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1228 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1230 info->manifest_info->uiapplication->permission_type = NULL;
1231 } else if (strcmp(colname[i], "component_type") == 0 ) {
1233 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1235 info->manifest_info->uiapplication->component_type = NULL;
1236 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1238 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1240 info->manifest_info->uiapplication->preload = NULL;
1241 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1243 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1245 info->manifest_info->uiapplication->submode = NULL;
1246 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1248 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1250 info->manifest_info->uiapplication->submode_mainid = NULL;
1257 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1259 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1261 serviceapplication_x *svcapp = NULL;
1262 icon_x *icon = NULL;
1263 label_x *label = NULL;
1265 svcapp = calloc(1, sizeof(serviceapplication_x));
1266 LISTADD(info->manifest_info->serviceapplication, svcapp);
1267 icon = calloc(1, sizeof(icon_x));
1268 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1269 label = calloc(1, sizeof(label_x));
1270 LISTADD(info->manifest_info->serviceapplication->label, label);
1271 for(i = 0; i < ncols; i++)
1273 if (strcmp(colname[i], "app_id") == 0) {
1275 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1277 info->manifest_info->serviceapplication->appid = NULL;
1278 } else if (strcmp(colname[i], "app_exec") == 0) {
1280 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1282 info->manifest_info->serviceapplication->exec = NULL;
1283 } else if (strcmp(colname[i], "app_type") == 0 ){
1285 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1287 info->manifest_info->serviceapplication->type = NULL;
1288 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1290 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1292 info->manifest_info->serviceapplication->onboot = NULL;
1293 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1295 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1297 info->manifest_info->serviceapplication->autorestart = NULL;
1298 } else if (strcmp(colname[i], "package") == 0 ){
1300 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1302 info->manifest_info->serviceapplication->package = NULL;
1303 } else if (strcmp(colname[i], "app_icon") == 0) {
1305 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1307 info->manifest_info->serviceapplication->icon->text = NULL;
1308 } else if (strcmp(colname[i], "app_label") == 0 ) {
1310 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1312 info->manifest_info->serviceapplication->label->text = NULL;
1313 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1315 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1316 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1319 info->manifest_info->serviceapplication->icon->lang = NULL;
1320 info->manifest_info->serviceapplication->label->lang = NULL;
1322 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1324 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1326 info->manifest_info->serviceapplication->permission_type = NULL;
1333 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1335 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1338 uiapplication_x *uiapp = NULL;
1339 serviceapplication_x *svcapp = NULL;
1340 for(j = 0; j < ncols; j++)
1342 if (strcmp(colname[j], "app_component") == 0) {
1344 if (strcmp(coltxt[j], "uiapp") == 0) {
1345 uiapp = calloc(1, sizeof(uiapplication_x));
1346 if (uiapp == NULL) {
1347 _LOGE("Out of Memory!!!\n");
1350 LISTADD(info->manifest_info->uiapplication, uiapp);
1351 for(i = 0; i < ncols; i++)
1353 if (strcmp(colname[i], "app_id") == 0) {
1355 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1357 info->manifest_info->uiapplication->appid = NULL;
1358 } else if (strcmp(colname[i], "app_exec") == 0) {
1360 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1362 info->manifest_info->uiapplication->exec = NULL;
1363 } else if (strcmp(colname[i], "app_type") == 0 ){
1365 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1367 info->manifest_info->uiapplication->type = NULL;
1368 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1370 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1372 info->manifest_info->uiapplication->nodisplay = NULL;
1373 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1375 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1377 info->manifest_info->uiapplication->multiple = NULL;
1378 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1380 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1382 info->manifest_info->uiapplication->taskmanage = NULL;
1383 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1385 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1387 info->manifest_info->uiapplication->hwacceleration = NULL;
1388 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1390 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1392 info->manifest_info->uiapplication->screenreader = NULL;
1393 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1395 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1397 info->manifest_info->uiapplication->indicatordisplay = NULL;
1398 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1400 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1402 info->manifest_info->uiapplication->portraitimg = NULL;
1403 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1405 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1407 info->manifest_info->uiapplication->landscapeimg = NULL;
1408 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1410 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1412 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1413 } else if (strcmp(colname[i], "package") == 0 ){
1415 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1417 info->manifest_info->uiapplication->package = NULL;
1418 } else if (strcmp(colname[i], "app_icon") == 0) {
1420 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1422 info->manifest_info->uiapplication->icon->text = NULL;
1423 } else if (strcmp(colname[i], "app_label") == 0 ) {
1425 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1427 info->manifest_info->uiapplication->label->text = NULL;
1428 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1430 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1432 info->manifest_info->uiapplication->recentimage = NULL;
1433 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1435 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1437 info->manifest_info->uiapplication->mainapp = NULL;
1438 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1440 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1441 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1444 info->manifest_info->uiapplication->icon->lang = NULL;
1445 info->manifest_info->uiapplication->label->lang = NULL;
1447 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1449 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1451 info->manifest_info->uiapplication->permission_type = NULL;
1456 svcapp = calloc(1, sizeof(serviceapplication_x));
1457 if (svcapp == NULL) {
1458 _LOGE("Out of Memory!!!\n");
1461 LISTADD(info->manifest_info->serviceapplication, svcapp);
1462 for(i = 0; i < ncols; i++)
1464 if (strcmp(colname[i], "app_id") == 0) {
1466 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1468 info->manifest_info->serviceapplication->appid = NULL;
1469 } else if (strcmp(colname[i], "app_exec") == 0) {
1471 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1473 info->manifest_info->serviceapplication->exec = NULL;
1474 } else if (strcmp(colname[i], "app_type") == 0 ){
1476 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1478 info->manifest_info->serviceapplication->type = NULL;
1479 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1481 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1483 info->manifest_info->serviceapplication->onboot = NULL;
1484 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1486 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1488 info->manifest_info->serviceapplication->autorestart = NULL;
1489 } else if (strcmp(colname[i], "package") == 0 ){
1491 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1493 info->manifest_info->serviceapplication->package = NULL;
1494 } else if (strcmp(colname[i], "app_icon") == 0) {
1496 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1498 info->manifest_info->serviceapplication->icon->text = NULL;
1499 } else if (strcmp(colname[i], "app_label") == 0 ) {
1501 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1503 info->manifest_info->serviceapplication->label->text = NULL;
1504 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1506 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1507 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1510 info->manifest_info->serviceapplication->icon->lang = NULL;
1511 info->manifest_info->serviceapplication->label->lang = NULL;
1513 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1515 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1517 info->manifest_info->serviceapplication->permission_type = NULL;
1532 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1534 int *p = (int*)data;
1535 *p = atoi(coltxt[0]);
1539 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1541 int *p = (int*)data;
1543 *p = atoi(coltxt[0]);
1547 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1549 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1551 author_x *author = NULL;
1552 icon_x *icon = NULL;
1553 label_x *label = NULL;
1554 description_x *description = NULL;
1555 privilege_x *privilege = NULL;
1557 author = calloc(1, sizeof(author_x));
1558 LISTADD(info->manifest_info->author, author);
1559 icon = calloc(1, sizeof(icon_x));
1560 LISTADD(info->manifest_info->icon, icon);
1561 label = calloc(1, sizeof(label_x));
1562 LISTADD(info->manifest_info->label, label);
1563 description = calloc(1, sizeof(description_x));
1564 LISTADD(info->manifest_info->description, description);
1565 privilege = calloc(1, sizeof(privilege_x));
1566 LISTADD(info->manifest_info->privileges->privilege, privilege);
1567 for(i = 0; i < ncols; i++)
1569 if (strcmp(colname[i], "package_version") == 0) {
1571 info->manifest_info->version = strdup(coltxt[i]);
1573 info->manifest_info->version = NULL;
1574 } else if (strcmp(colname[i], "package_type") == 0) {
1576 info->manifest_info->type = strdup(coltxt[i]);
1578 info->manifest_info->type = NULL;
1579 } else if (strcmp(colname[i], "install_location") == 0) {
1581 info->manifest_info->installlocation = strdup(coltxt[i]);
1583 info->manifest_info->installlocation = NULL;
1584 } else if (strcmp(colname[i], "package_size") == 0) {
1586 info->manifest_info->package_size = strdup(coltxt[i]);
1588 info->manifest_info->package_size = NULL;
1589 } else if (strcmp(colname[i], "author_email") == 0 ){
1591 info->manifest_info->author->email = strdup(coltxt[i]);
1593 info->manifest_info->author->email = NULL;
1594 } else if (strcmp(colname[i], "author_href") == 0 ){
1596 info->manifest_info->author->href = strdup(coltxt[i]);
1598 info->manifest_info->author->href = NULL;
1599 } else if (strcmp(colname[i], "package_label") == 0 ){
1601 info->manifest_info->label->text = strdup(coltxt[i]);
1603 info->manifest_info->label->text = NULL;
1604 } else if (strcmp(colname[i], "package_icon") == 0 ){
1606 info->manifest_info->icon->text = strdup(coltxt[i]);
1608 info->manifest_info->icon->text = NULL;
1609 } else if (strcmp(colname[i], "package_description") == 0 ){
1611 info->manifest_info->description->text = strdup(coltxt[i]);
1613 info->manifest_info->description->text = NULL;
1614 } else if (strcmp(colname[i], "package_author") == 0 ){
1616 info->manifest_info->author->text = strdup(coltxt[i]);
1618 info->manifest_info->author->text = NULL;
1619 } else if (strcmp(colname[i], "package_removable") == 0 ){
1621 info->manifest_info->removable = strdup(coltxt[i]);
1623 info->manifest_info->removable = NULL;
1624 } else if (strcmp(colname[i], "package_preload") == 0 ){
1626 info->manifest_info->preload = strdup(coltxt[i]);
1628 info->manifest_info->preload = NULL;
1629 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1631 info->manifest_info->readonly = strdup(coltxt[i]);
1633 info->manifest_info->readonly = NULL;
1634 } else if (strcmp(colname[i], "package_update") == 0 ){
1636 info->manifest_info->update= strdup(coltxt[i]);
1638 info->manifest_info->update = NULL;
1639 } else if (strcmp(colname[i], "package_system") == 0 ){
1641 info->manifest_info->system= strdup(coltxt[i]);
1643 info->manifest_info->system = NULL;
1644 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1646 info->manifest_info->appsetting = strdup(coltxt[i]);
1648 info->manifest_info->appsetting = NULL;
1649 } else if (strcmp(colname[i], "installed_time") == 0 ){
1651 info->manifest_info->installed_time = strdup(coltxt[i]);
1653 info->manifest_info->installed_time = NULL;
1654 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1656 info->manifest_info->installed_storage = strdup(coltxt[i]);
1658 info->manifest_info->installed_storage = NULL;
1659 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1661 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1663 info->manifest_info->mainapp_id = NULL;
1664 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1666 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1668 info->manifest_info->storeclient_id = NULL;
1669 } else if (strcmp(colname[i], "root_path") == 0 ){
1671 info->manifest_info->root_path = strdup(coltxt[i]);
1673 info->manifest_info->root_path = NULL;
1674 } else if (strcmp(colname[i], "csc_path") == 0 ){
1676 info->manifest_info->csc_path = strdup(coltxt[i]);
1678 info->manifest_info->csc_path = NULL;
1679 } else if (strcmp(colname[i], "privilege") == 0 ){
1681 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1683 info->manifest_info->privileges->privilege->text = NULL;
1684 } else if (strcmp(colname[i], "package_locale") == 0 ){
1686 info->manifest_info->author->lang = strdup(coltxt[i]);
1687 info->manifest_info->icon->lang = strdup(coltxt[i]);
1688 info->manifest_info->label->lang = strdup(coltxt[i]);
1689 info->manifest_info->description->lang = strdup(coltxt[i]);
1692 info->manifest_info->author->lang = NULL;
1693 info->manifest_info->icon->lang = NULL;
1694 info->manifest_info->label->lang = NULL;
1695 info->manifest_info->description->lang = NULL;
1697 } else if (strcmp(colname[i], "package_url") == 0 ){
1699 info->manifest_info->package_url = strdup(coltxt[i]);
1701 info->manifest_info->package_url = NULL;
1709 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1711 if ( strcasecmp(comp, "uiapp") == 0)
1712 return PMINFO_UI_APP;
1713 else if ( strcasecmp(comp, "svcapp") == 0)
1714 return PMINFO_SVC_APP;
1719 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1721 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1723 for(i = 0; i < ncols; i++) {
1724 if (strcmp(colname[i], "cert_id") == 0) {
1726 info->cert_id = atoi(coltxt[i]);
1729 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1731 info->cert_ref_count = atoi(coltxt[i]);
1733 info->cert_ref_count = 0;
1739 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1741 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1743 for(i = 0; i < ncols; i++)
1745 if (strcmp(colname[i], "package") == 0) {
1747 info->pkgid = strdup(coltxt[i]);
1750 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1752 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1754 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1755 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1757 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1759 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1760 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1762 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1764 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1765 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1767 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1769 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1770 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1772 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1774 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1775 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1777 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1779 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1780 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1782 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1784 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1785 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1787 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1789 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1790 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1792 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1794 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1795 } else if (strcmp(colname[i], "cert_info") == 0 ){
1797 info->cert_value = strdup(coltxt[i]);
1799 info->cert_value = NULL;
1806 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1808 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1811 uiapplication_x *uiapp = NULL;
1812 serviceapplication_x *svcapp = NULL;
1813 for(i = 0; i < ncols; i++)
1815 if (strcmp(colname[i], "app_component") == 0) {
1817 if (strcmp(coltxt[i], "uiapp") == 0) {
1818 uiapp = calloc(1, sizeof(uiapplication_x));
1819 if (uiapp == NULL) {
1820 _LOGE("Out of Memory!!!\n");
1823 LISTADD(info->manifest_info->uiapplication, uiapp);
1824 for(j = 0; j < ncols; j++)
1826 if (strcmp(colname[j], "app_id") == 0) {
1828 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1829 } else if (strcmp(colname[j], "app_exec") == 0) {
1831 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1833 info->manifest_info->uiapplication->exec = NULL;
1834 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1836 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1838 info->manifest_info->uiapplication->nodisplay = NULL;
1839 } else if (strcmp(colname[j], "app_type") == 0 ) {
1841 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1843 info->manifest_info->uiapplication->type = NULL;
1844 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1846 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1848 info->manifest_info->uiapplication->multiple = NULL;
1849 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1851 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1853 info->manifest_info->uiapplication->taskmanage = NULL;
1854 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1856 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1858 info->manifest_info->uiapplication->hwacceleration = NULL;
1859 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1861 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1863 info->manifest_info->uiapplication->screenreader = NULL;
1864 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1866 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1868 info->manifest_info->uiapplication->enabled = NULL;
1869 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1871 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1873 info->manifest_info->uiapplication->indicatordisplay = NULL;
1874 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1876 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1878 info->manifest_info->uiapplication->portraitimg = NULL;
1879 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1881 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1883 info->manifest_info->uiapplication->landscapeimg = NULL;
1884 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1886 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1888 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1889 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1891 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1893 info->manifest_info->uiapplication->recentimage = NULL;
1894 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1896 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1898 info->manifest_info->uiapplication->mainapp = NULL;
1899 } else if (strcmp(colname[j], "package") == 0 ) {
1901 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1903 info->manifest_info->uiapplication->package = NULL;
1904 } else if (strcmp(colname[j], "app_component") == 0) {
1906 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1908 info->manifest_info->uiapplication->app_component = NULL;
1909 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1911 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1913 info->manifest_info->uiapplication->permission_type = NULL;
1914 } else if (strcmp(colname[j], "component_type") == 0 ) {
1916 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1918 info->manifest_info->uiapplication->component_type = NULL;
1919 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1921 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1923 info->manifest_info->uiapplication->preload = NULL;
1924 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1926 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1928 info->manifest_info->uiapplication->submode = NULL;
1929 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1931 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1933 info->manifest_info->uiapplication->submode_mainid = NULL;
1938 svcapp = calloc(1, sizeof(serviceapplication_x));
1939 if (svcapp == NULL) {
1940 _LOGE("Out of Memory!!!\n");
1943 LISTADD(info->manifest_info->serviceapplication, svcapp);
1944 for(j = 0; j < ncols; j++)
1946 if (strcmp(colname[j], "app_id") == 0) {
1948 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1949 } else if (strcmp(colname[j], "app_exec") == 0) {
1951 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1953 info->manifest_info->serviceapplication->exec = NULL;
1954 } else if (strcmp(colname[j], "app_type") == 0 ){
1956 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1958 info->manifest_info->serviceapplication->type = NULL;
1959 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1961 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1963 info->manifest_info->serviceapplication->onboot = NULL;
1964 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1966 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1968 info->manifest_info->serviceapplication->autorestart = NULL;
1969 } else if (strcmp(colname[j], "package") == 0 ){
1971 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1973 info->manifest_info->serviceapplication->package = NULL;
1974 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1976 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1978 info->manifest_info->serviceapplication->permission_type = NULL;
1991 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1993 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1995 icon_x *icon = NULL;
1996 label_x *label = NULL;
1997 category_x *category = NULL;
1998 metadata_x *metadata = NULL;
1999 permission_x *permission = NULL;
2000 image_x *image = NULL;
2002 switch (info->app_component) {
2004 icon = calloc(1, sizeof(icon_x));
2005 LISTADD(info->uiapp_info->icon, icon);
2006 label = calloc(1, sizeof(label_x));
2007 LISTADD(info->uiapp_info->label, label);
2008 category = calloc(1, sizeof(category_x));
2009 LISTADD(info->uiapp_info->category, category);
2010 metadata = calloc(1, sizeof(metadata_x));
2011 LISTADD(info->uiapp_info->metadata, metadata);
2012 permission = calloc(1, sizeof(permission_x));
2013 LISTADD(info->uiapp_info->permission, permission);
2014 image = calloc(1, sizeof(image_x));
2015 LISTADD(info->uiapp_info->image, image);
2017 for(i = 0; i < ncols; i++)
2019 if (strcmp(colname[i], "app_id") == 0) {
2020 /*appid being foreign key, is column in every table
2021 Hence appid gets strduped every time leading to memory leak.
2022 If appid is already set, just continue.*/
2023 if (info->uiapp_info->appid)
2026 info->uiapp_info->appid = strdup(coltxt[i]);
2028 info->uiapp_info->appid = NULL;
2029 } else if (strcmp(colname[i], "app_exec") == 0) {
2031 info->uiapp_info->exec = strdup(coltxt[i]);
2033 info->uiapp_info->exec = NULL;
2034 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2036 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2038 info->uiapp_info->nodisplay = NULL;
2039 } else if (strcmp(colname[i], "app_type") == 0 ) {
2041 info->uiapp_info->type = strdup(coltxt[i]);
2043 info->uiapp_info->type = NULL;
2044 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2046 info->uiapp_info->icon->section= strdup(coltxt[i]);
2048 info->uiapp_info->icon->section = NULL;
2049 } else if (strcmp(colname[i], "app_icon") == 0) {
2051 info->uiapp_info->icon->text = strdup(coltxt[i]);
2053 info->uiapp_info->icon->text = NULL;
2054 } else if (strcmp(colname[i], "app_label") == 0 ) {
2056 info->uiapp_info->label->text = strdup(coltxt[i]);
2058 info->uiapp_info->label->text = NULL;
2059 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2061 info->uiapp_info->multiple = strdup(coltxt[i]);
2063 info->uiapp_info->multiple = NULL;
2064 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2066 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2068 info->uiapp_info->taskmanage = NULL;
2069 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2071 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2073 info->uiapp_info->hwacceleration = NULL;
2074 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2076 info->uiapp_info->screenreader = strdup(coltxt[i]);
2078 info->uiapp_info->screenreader = NULL;
2079 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2081 info->uiapp_info->enabled= strdup(coltxt[i]);
2083 info->uiapp_info->enabled = NULL;
2084 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2086 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2088 info->uiapp_info->indicatordisplay = NULL;
2089 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2091 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2093 info->uiapp_info->portraitimg = NULL;
2094 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2096 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2098 info->uiapp_info->landscapeimg = NULL;
2099 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2101 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2103 info->uiapp_info->guestmode_visibility = NULL;
2104 } else if (strcmp(colname[i], "category") == 0 ) {
2106 info->uiapp_info->category->name = strdup(coltxt[i]);
2108 info->uiapp_info->category->name = NULL;
2109 } else if (strcmp(colname[i], "md_key") == 0 ) {
2111 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2113 info->uiapp_info->metadata->key = NULL;
2114 } else if (strcmp(colname[i], "md_value") == 0 ) {
2116 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2118 info->uiapp_info->metadata->value = NULL;
2119 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2121 info->uiapp_info->permission->type= strdup(coltxt[i]);
2123 info->uiapp_info->permission->type = NULL;
2124 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2126 info->uiapp_info->permission->value = strdup(coltxt[i]);
2128 info->uiapp_info->permission->value = NULL;
2129 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2131 info->uiapp_info->recentimage = strdup(coltxt[i]);
2133 info->uiapp_info->recentimage = NULL;
2134 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2136 info->uiapp_info->mainapp = strdup(coltxt[i]);
2138 info->uiapp_info->mainapp = NULL;
2139 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2141 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2142 info->uiapp_info->label->lang = strdup(coltxt[i]);
2145 info->uiapp_info->icon->lang = NULL;
2146 info->uiapp_info->label->lang = NULL;
2148 } else if (strcmp(colname[i], "app_image") == 0) {
2150 info->uiapp_info->image->text= strdup(coltxt[i]);
2152 info->uiapp_info->image->text = NULL;
2153 } else if (strcmp(colname[i], "app_image_section") == 0) {
2155 info->uiapp_info->image->section= strdup(coltxt[i]);
2157 info->uiapp_info->image->section = NULL;
2158 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2160 info->uiapp_info->permission_type = strdup(coltxt[i]);
2162 info->uiapp_info->permission_type = NULL;
2163 } else if (strcmp(colname[i], "component_type") == 0 ) {
2165 info->uiapp_info->component_type = strdup(coltxt[i]);
2167 info->uiapp_info->component_type = NULL;
2168 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2170 info->uiapp_info->preload = strdup(coltxt[i]);
2172 info->uiapp_info->preload = NULL;
2173 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2175 info->uiapp_info->submode = strdup(coltxt[i]);
2177 info->uiapp_info->submode = NULL;
2178 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2180 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2182 info->uiapp_info->submode_mainid = NULL;
2187 case PMINFO_SVC_APP:
2188 icon = calloc(1, sizeof(icon_x));
2189 LISTADD(info->svcapp_info->icon, icon);
2190 label = calloc(1, sizeof(label_x));
2191 LISTADD(info->svcapp_info->label, label);
2192 category = calloc(1, sizeof(category_x));
2193 LISTADD(info->svcapp_info->category, category);
2194 metadata = calloc(1, sizeof(metadata_x));
2195 LISTADD(info->svcapp_info->metadata, metadata);
2196 permission = calloc(1, sizeof(permission_x));
2197 LISTADD(info->svcapp_info->permission, permission);
2198 for(i = 0; i < ncols; i++)
2200 if (strcmp(colname[i], "app_id") == 0) {
2201 /*appid being foreign key, is column in every table
2202 Hence appid gets strduped every time leading to memory leak.
2203 If appid is already set, just continue.*/
2204 if (info->svcapp_info->appid)
2207 info->svcapp_info->appid = strdup(coltxt[i]);
2209 info->svcapp_info->appid = NULL;
2210 } else if (strcmp(colname[i], "app_exec") == 0) {
2212 info->svcapp_info->exec = strdup(coltxt[i]);
2214 info->svcapp_info->exec = NULL;
2215 } else if (strcmp(colname[i], "app_icon") == 0) {
2217 info->svcapp_info->icon->text = strdup(coltxt[i]);
2219 info->svcapp_info->icon->text = NULL;
2220 } else if (strcmp(colname[i], "app_label") == 0 ) {
2222 info->svcapp_info->label->text = strdup(coltxt[i]);
2224 info->svcapp_info->label->text = NULL;
2225 } else if (strcmp(colname[i], "app_type") == 0 ) {
2227 info->svcapp_info->type = strdup(coltxt[i]);
2229 info->svcapp_info->type = NULL;
2230 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2232 info->svcapp_info->onboot = strdup(coltxt[i]);
2234 info->svcapp_info->onboot = NULL;
2235 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2237 info->svcapp_info->autorestart = strdup(coltxt[i]);
2239 info->svcapp_info->autorestart = NULL;
2240 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2242 info->svcapp_info->enabled= strdup(coltxt[i]);
2244 info->svcapp_info->enabled = NULL;
2245 } else if (strcmp(colname[i], "category") == 0 ) {
2247 info->svcapp_info->category->name = strdup(coltxt[i]);
2249 info->svcapp_info->category->name = NULL;
2250 } else if (strcmp(colname[i], "md_key") == 0 ) {
2252 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2254 info->svcapp_info->metadata->key = NULL;
2255 } else if (strcmp(colname[i], "md_value") == 0 ) {
2257 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2259 info->svcapp_info->metadata->value = NULL;
2260 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2262 info->svcapp_info->permission->type= strdup(coltxt[i]);
2264 info->svcapp_info->permission->type = NULL;
2265 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2267 info->svcapp_info->permission->value = strdup(coltxt[i]);
2269 info->svcapp_info->permission->value = NULL;
2270 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2272 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2273 info->svcapp_info->label->lang = strdup(coltxt[i]);
2276 info->svcapp_info->icon->lang = NULL;
2277 info->svcapp_info->label->lang = NULL;
2279 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2281 info->svcapp_info->permission_type = strdup(coltxt[i]);
2283 info->svcapp_info->permission_type = NULL;
2296 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2298 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2300 for(i = 0; i < ncols; i++)
2302 if (strcmp(colname[i], "app_component") == 0) {
2303 info->app_component = __appcomponent_convert(coltxt[i]);
2304 } else if (strcmp(colname[i], "package") == 0) {
2305 info->package = strdup(coltxt[i]);
2312 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2314 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2316 for(i = 0; i < ncols; i++)
2318 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2320 info->appid = strdup(coltxt[i]);
2323 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2325 info->access = strdup(coltxt[i]);
2327 info->access = NULL;
2334 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2336 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2339 for(i = 0; i < ncols; i++)
2341 if (strcmp(colname[i], "author_signer_cert") == 0) {
2343 info->cert_id = atoi(coltxt[i]);
2346 } else if (strcmp(colname[i], "package") == 0) {
2348 info->pkgid= strdup(coltxt[i]);
2357 /* get the first locale value*/
2358 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2360 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2363 info->locale = strdup(coltxt[0]);
2365 info->locale = NULL;
2370 static int __exec_pkginfo_query(char *query, void *data)
2372 char *error_message = NULL;
2374 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
2375 _LOGE("Don't execute query = %s error message = %s\n", query,
2377 sqlite3_free(error_message);
2380 sqlite3_free(error_message);
2384 static int __exec_certinfo_query(char *query, void *data)
2386 char *error_message = NULL;
2388 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
2389 _LOGE("Don't execute query = %s error message = %s\n", query,
2391 sqlite3_free(error_message);
2394 sqlite3_free(error_message);
2398 static int __exec_certindexinfo_query(char *query, void *data)
2400 char *error_message = NULL;
2402 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
2403 _LOGE("Don't execute query = %s error message = %s\n", query,
2405 sqlite3_free(error_message);
2408 sqlite3_free(error_message);
2412 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2414 char *error_message = NULL;
2416 sqlite3_exec(db, query, callback, data, &error_message)) {
2417 _LOGE("Don't execute query = %s error message = %s\n", query,
2419 sqlite3_free(error_message);
2422 sqlite3_free(error_message);
2427 static int __child_element(xmlTextReaderPtr reader, int depth)
2429 int ret = xmlTextReaderRead(reader);
2430 int cur = xmlTextReaderDepth(reader);
2433 switch (xmlTextReaderNodeType(reader)) {
2434 case XML_READER_TYPE_ELEMENT:
2435 if (cur == depth + 1)
2438 case XML_READER_TYPE_TEXT:
2439 /*text is handled by each function separately*/
2440 if (cur == depth + 1)
2443 case XML_READER_TYPE_END_ELEMENT:
2452 ret = xmlTextReaderRead(reader);
2453 cur = xmlTextReaderDepth(reader);
2458 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2460 int *p = (int*)data;
2461 *p = atoi(coltxt[0]);
2465 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2467 int result_query = -1;
2469 char query[MAX_QUERY_LEN];
2471 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);
2472 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2473 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2474 return result_query;
2477 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2479 int result_query = -1;
2481 char wildcard[2] = {'%','\0'};
2482 char query[MAX_QUERY_LEN];
2483 char lang[3] = {'\0'};
2484 strncpy(lang, locale, LANGUAGE_LENGTH);
2486 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);
2487 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2488 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2489 return result_query;
2492 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2495 char wildcard[2] = {'%','\0'};
2496 char lang[3] = {'\0'};
2497 char query[MAX_QUERY_LEN];
2498 char *locale_new = NULL;
2499 pkgmgr_locale_x *info = NULL;
2501 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2503 _LOGE("Out of Memory!!!\n");
2506 memset(info, '\0', sizeof(*info));
2508 strncpy(lang, locale, 2);
2509 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);
2510 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2511 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2512 locale_new = info->locale;
2523 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2525 char *locale = malloc(6);
2527 _LOGE("Malloc Failed\n");
2531 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2535 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2540 char *locale = NULL;
2541 char *locale_new = NULL;
2542 int check_result = 0;
2544 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2546 /*check exact matching */
2547 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2550 if (check_result == 1) {
2551 _LOGD("%s find exact locale(%s)\n", appid, locale);
2555 /* fallback matching */
2556 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2557 if(check_result == 1) {
2558 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2560 if (locale_new == NULL)
2561 locale_new = strdup(DEFAULT_LOCALE);
2565 /* default locale */
2567 return strdup(DEFAULT_LOCALE);
2570 long long _pkgmgr_calculate_dir_size(char *dirname)
2572 long long total = 0;
2574 int q = 0; /*quotient*/
2575 int r = 0; /*remainder*/
2577 struct dirent *ep = NULL;
2578 struct stat fileinfo;
2579 char abs_filename[FILENAME_MAX] = { 0, };
2580 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2582 dp = opendir(dirname);
2584 while ((ep = readdir(dp)) != NULL) {
2585 if (!strcmp(ep->d_name, ".") ||
2586 !strcmp(ep->d_name, "..")) {
2589 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2591 if (lstat(abs_filename, &fileinfo) < 0)
2592 perror(abs_filename);
2594 if (S_ISDIR(fileinfo.st_mode)) {
2595 total += fileinfo.st_size;
2596 if (strcmp(ep->d_name, ".")
2597 && strcmp(ep->d_name, "..")) {
2598 ret = _pkgmgr_calculate_dir_size
2600 total = total + ret;
2602 } else if (S_ISLNK(fileinfo.st_mode)) {
2605 /*It is a file. Calculate the actual
2606 size occupied (in terms of 4096 blocks)*/
2607 q = (fileinfo.st_size / BLOCK_SIZE);
2608 r = (fileinfo.st_size % BLOCK_SIZE);
2612 total += q * BLOCK_SIZE;
2618 _LOGE("Couldn't open the directory\n");
2625 static int __delete_certinfo(const char *pkgid)
2631 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2632 char *error_message = NULL;
2633 char query[MAX_QUERY_LEN] = {'\0'};
2634 pkgmgr_certinfo_x *certinfo = NULL;
2635 pkgmgr_certindexinfo_x *indexinfo = NULL;
2636 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2637 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2638 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2639 if (indexinfo == NULL) {
2640 _LOGE("Out of Memory!!!");
2641 ret = PMINFO_R_ERROR;
2644 /*populate certinfo from DB*/
2645 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2646 ret = __exec_certinfo_query(query, (void *)certinfo);
2648 _LOGE("Package Cert Info DB Information retrieval failed\n");
2649 ret = PMINFO_R_ERROR;
2652 /*Update cert index table*/
2653 for (i = 0; i < MAX_CERT_TYPE; i++) {
2654 if ((certinfo->cert_id)[i]) {
2655 for (j = 0; j < MAX_CERT_TYPE; j++) {
2656 if ((certinfo->cert_id)[i] == unique_id[j]) {
2657 /*Ref count has already been updated. Just continue*/
2661 if (j == MAX_CERT_TYPE)
2662 unique_id[c++] = (certinfo->cert_id)[i];
2665 memset(query, '\0', MAX_QUERY_LEN);
2666 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2667 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2669 _LOGE("Cert Info DB Information retrieval failed\n");
2670 ret = PMINFO_R_ERROR;
2673 memset(query, '\0', MAX_QUERY_LEN);
2674 if (indexinfo->cert_ref_count > 1) {
2675 /*decrease ref count*/
2676 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2677 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2679 /*delete this certificate as ref count is 1 and it will become 0*/
2680 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2683 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2684 _LOGE("Don't execute query = %s error message = %s\n", query,
2686 sqlite3_free(error_message);
2687 ret = PMINFO_R_ERROR;
2692 /*Now delete the entry from db*/
2693 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2695 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2696 _LOGE("Don't execute query = %s error message = %s\n", query,
2698 sqlite3_free(error_message);
2699 ret = PMINFO_R_ERROR;
2708 if (certinfo->pkgid) {
2709 free(certinfo->pkgid);
2710 certinfo->pkgid = NULL;
2712 for (i = 0; i < MAX_CERT_TYPE; i++) {
2713 if ((certinfo->cert_info)[i]) {
2714 free((certinfo->cert_info)[i]);
2715 (certinfo->cert_info)[i] = NULL;
2723 static int __get_pkg_location(const char *pkgid)
2725 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2728 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2729 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2731 /*check whether application is in external memory or not */
2732 fp = fopen(pkg_mmc_path, "r");
2736 return PMINFO_EXTERNAL_STORAGE;
2739 return PMINFO_INTERNAL_STORAGE;
2742 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2744 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2745 char *error_message = NULL;
2746 int ret = PMINFO_R_OK;
2747 char query[MAX_QUERY_LEN] = {'\0'};
2748 char *syslocale = NULL;
2749 char *locale = NULL;
2750 pkgmgr_pkginfo_x *pkginfo = NULL;
2751 label_x *tmp1 = NULL;
2752 icon_x *tmp2 = NULL;
2753 description_x *tmp3 = NULL;
2754 author_x *tmp4 = NULL;
2755 privilege_x *tmp5 = NULL;
2757 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2758 if (syslocale == NULL) {
2759 _LOGE("current locale is NULL\n");
2760 ret = PMINFO_R_ERROR;
2763 locale = __convert_system_locale_to_manifest_locale(syslocale);
2764 if (locale == NULL) {
2765 _LOGE("manifest locale is NULL\n");
2766 ret = PMINFO_R_EINVAL;
2770 ret = __open_manifest_db(uid);
2772 _LOGE("Fail to open manifest DB\n");
2773 ret = PMINFO_R_ERROR;
2776 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2777 pkgmgr_pkginfo_x *node = NULL;
2778 pkgmgr_pkginfo_x *temp_node = NULL;
2780 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2782 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2783 _LOGE("Don't execute query = %s error message = %s\n", query,
2785 sqlite3_free(error_message);
2786 sqlite3_close(manifest_db);
2787 ret = PMINFO_R_ERROR;
2791 LISTHEAD(tmphead, node);
2793 for(node = node->next; node ; node = node->next) {
2795 pkginfo->locale = strdup(locale);
2796 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2797 if (pkginfo->manifest_info->privileges == NULL) {
2798 _LOGE("Failed to allocate memory for privileges info\n");
2799 ret = PMINFO_R_ERROR;
2802 /*populate manifest_info from DB*/
2803 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2804 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2806 _LOGE("Package Info DB Information retrieval failed\n");
2807 ret = PMINFO_R_ERROR;
2810 memset(query, '\0', MAX_QUERY_LEN);
2811 /*populate privilege_info from DB*/
2812 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2813 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2815 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2816 ret = PMINFO_R_ERROR;
2819 memset(query, '\0', MAX_QUERY_LEN);
2820 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2821 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2822 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2824 _LOGE("Package Info DB Information retrieval failed\n");
2825 ret = PMINFO_R_ERROR;
2828 /*Also store the values corresponding to default locales*/
2829 memset(query, '\0', MAX_QUERY_LEN);
2830 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2831 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2832 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2834 _LOGE("Package Info DB Information retrieval failed\n");
2835 ret = PMINFO_R_ERROR;
2838 if (pkginfo->manifest_info->label) {
2839 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2840 pkginfo->manifest_info->label = tmp1;
2842 if (pkginfo->manifest_info->icon) {
2843 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2844 pkginfo->manifest_info->icon = tmp2;
2846 if (pkginfo->manifest_info->description) {
2847 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2848 pkginfo->manifest_info->description = tmp3;
2850 if (pkginfo->manifest_info->author) {
2851 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2852 pkginfo->manifest_info->author = tmp4;
2854 if (pkginfo->manifest_info->privileges->privilege) {
2855 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2856 pkginfo->manifest_info->privileges->privilege = tmp5;
2860 LISTHEAD(tmphead, node);
2862 for(node = node->next; node ; node = node->next) {
2864 ret = pkg_list_cb( (void *)pkginfo, user_data);
2872 sqlite3_close(manifest_db);
2881 LISTHEAD(tmphead, node);
2882 temp_node = node->next;
2885 temp_node = node->next;
2886 __cleanup_pkginfo(node);
2889 __cleanup_pkginfo(tmphead);
2893 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2895 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2898 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2900 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2901 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2902 pkgmgr_pkginfo_x *pkginfo = NULL;
2903 int ret = PMINFO_R_OK;
2904 char query[MAX_QUERY_LEN] = {'\0'};
2905 char *syslocale = NULL;
2906 char *locale = NULL;
2908 label_x *tmp1 = NULL;
2909 icon_x *tmp2 = NULL;
2910 description_x *tmp3 = NULL;
2911 author_x *tmp4 = NULL;
2912 privilege_x *tmp5 = NULL;
2913 sqlite3 *pkginfo_db = NULL;
2916 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2917 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
2919 /*check pkgid exist on db*/
2920 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2921 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2922 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2923 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2925 /*get system locale*/
2926 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2927 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2929 /*get locale on db*/
2930 locale = __convert_system_locale_to_manifest_locale(syslocale);
2931 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2933 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2934 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2936 pkginfo->locale = strdup(locale);
2938 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2939 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2941 pkginfo->manifest_info->package = strdup(pkgid);
2942 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2943 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2945 /*populate manifest_info from DB*/
2946 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2947 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2948 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2950 memset(query, '\0', MAX_QUERY_LEN);
2951 /*populate privilege_info from DB*/
2952 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2953 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2954 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2956 memset(query, '\0', MAX_QUERY_LEN);
2957 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2958 " package='%s' and package_locale='%s'", pkgid, locale);
2959 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2960 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2962 /*Also store the values corresponding to default locales*/
2963 memset(query, '\0', MAX_QUERY_LEN);
2964 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2965 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2966 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2967 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2969 if (pkginfo->manifest_info->label) {
2970 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2971 pkginfo->manifest_info->label = tmp1;
2973 if (pkginfo->manifest_info->icon) {
2974 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2975 pkginfo->manifest_info->icon = tmp2;
2977 if (pkginfo->manifest_info->description) {
2978 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2979 pkginfo->manifest_info->description = tmp3;
2981 if (pkginfo->manifest_info->author) {
2982 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2983 pkginfo->manifest_info->author = tmp4;
2985 if (pkginfo->manifest_info->privileges->privilege) {
2986 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2987 pkginfo->manifest_info->privileges->privilege = tmp5;
2991 if (ret == PMINFO_R_OK)
2992 *handle = (void*)pkginfo;
2995 __cleanup_pkginfo(pkginfo);
2997 sqlite3_close(pkginfo_db);
3010 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3012 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3015 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3017 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3018 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3019 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3020 if (info->manifest_info->package)
3021 *pkg_name = (char *)info->manifest_info->package;
3023 return PMINFO_R_ERROR;
3028 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3030 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3031 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3032 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3033 if (info->manifest_info->package)
3034 *pkgid = (char *)info->manifest_info->package;
3036 return PMINFO_R_ERROR;
3041 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3043 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3044 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3045 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3046 if (info->manifest_info->type)
3047 *type = (char *)info->manifest_info->type;
3053 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3055 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3056 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3057 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3058 *version = (char *)info->manifest_info->version;
3062 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3064 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3065 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3067 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3068 val = (char *)info->manifest_info->installlocation;
3070 if (strcmp(val, "internal-only") == 0)
3071 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3072 else if (strcmp(val, "prefer-external") == 0)
3073 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3075 *location = PMINFO_INSTALL_LOCATION_AUTO;
3080 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3082 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3083 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3085 char *location = NULL;
3086 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3087 location = (char *)info->manifest_info->installlocation;
3088 val = (char *)info->manifest_info->package_size;
3093 _LOGE("package size is not specified\n");
3094 return PMINFO_R_ERROR;
3099 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3101 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3102 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3105 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3106 long long rw_size = 0;
3107 long long ro_size= 0;
3108 long long tmp_size= 0;
3109 long long total_size= 0;
3110 struct stat fileinfo;
3113 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3115 return PMINFO_R_ERROR;
3118 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3119 if (lstat(device_path, &fileinfo) == 0) {
3120 if (!S_ISLNK(fileinfo.st_mode)) {
3121 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3123 rw_size += tmp_size;
3127 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3128 if (lstat(device_path, &fileinfo) == 0) {
3129 if (!S_ISLNK(fileinfo.st_mode)) {
3130 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3132 rw_size += tmp_size;
3136 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3137 if (lstat(device_path, &fileinfo) == 0) {
3138 if (!S_ISLNK(fileinfo.st_mode)) {
3139 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3141 rw_size += tmp_size;
3145 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3146 if (lstat(device_path, &fileinfo) == 0) {
3147 if (!S_ISLNK(fileinfo.st_mode)) {
3148 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3150 rw_size += tmp_size;
3154 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3155 if (lstat(device_path, &fileinfo) == 0) {
3156 if (!S_ISLNK(fileinfo.st_mode)) {
3157 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3159 rw_size += tmp_size;
3163 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3164 if (lstat(device_path, &fileinfo) == 0) {
3165 if (!S_ISLNK(fileinfo.st_mode)) {
3166 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3168 rw_size += tmp_size;
3173 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3174 if (lstat(device_path, &fileinfo) == 0) {
3175 if (!S_ISLNK(fileinfo.st_mode)) {
3176 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3178 ro_size += tmp_size;
3182 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3183 if (lstat(device_path, &fileinfo) == 0) {
3184 if (!S_ISLNK(fileinfo.st_mode)) {
3185 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3187 ro_size += tmp_size;
3191 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3192 if (lstat(device_path, &fileinfo) == 0) {
3193 if (!S_ISLNK(fileinfo.st_mode)) {
3194 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3196 ro_size += tmp_size;
3200 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3201 if (lstat(device_path, &fileinfo) == 0) {
3202 if (!S_ISLNK(fileinfo.st_mode)) {
3203 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3205 ro_size += tmp_size;
3209 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3210 if (lstat(device_path, &fileinfo) == 0) {
3211 if (!S_ISLNK(fileinfo.st_mode)) {
3212 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3214 ro_size += tmp_size;
3218 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3219 if (lstat(device_path, &fileinfo) == 0) {
3220 if (!S_ISLNK(fileinfo.st_mode)) {
3221 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3223 ro_size += tmp_size;
3228 total_size = rw_size + ro_size;
3229 *size = (int)total_size;
3234 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3236 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3237 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3240 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3241 long long total_size= 0;
3244 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3246 return PMINFO_R_ERROR;
3248 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3249 if (access(device_path, R_OK) == 0)
3250 total_size = _pkgmgr_calculate_dir_size(device_path);
3252 return PMINFO_R_ERROR;
3254 *size = (int)total_size;
3259 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3261 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3262 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3263 int ret = PMINFO_R_OK;
3264 char *locale = NULL;
3268 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3270 locale = info->locale;
3271 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3273 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3276 if (strcmp(ptr->lang, locale) == 0) {
3277 *icon = (char *)ptr->text;
3278 if (strcasecmp(*icon, "(null)") == 0) {
3279 locale = DEFAULT_LOCALE;
3283 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3284 *icon = (char *)ptr->text;
3293 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3295 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3296 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3297 int ret = PMINFO_R_OK;
3298 char *locale = NULL;
3299 label_x *ptr = NULL;
3302 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3303 locale = info->locale;
3304 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3306 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3309 if (strcmp(ptr->lang, locale) == 0) {
3310 *label = (char *)ptr->text;
3311 if (strcasecmp(*label, "(null)") == 0) {
3312 locale = DEFAULT_LOCALE;
3316 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3317 *label = (char *)ptr->text;
3326 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3328 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3329 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3330 char *locale = NULL;
3331 description_x *ptr = NULL;
3332 *description = NULL;
3334 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3335 locale = info->locale;
3336 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3338 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3341 if (strcmp(ptr->lang, locale) == 0) {
3342 *description = (char *)ptr->text;
3343 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3344 locale = DEFAULT_LOCALE;
3348 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3349 *description = (char *)ptr->text;
3357 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3359 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3360 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3361 char *locale = NULL;
3362 author_x *ptr = NULL;
3363 *author_name = NULL;
3365 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3366 locale = info->locale;
3367 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3369 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3372 if (strcmp(ptr->lang, locale) == 0) {
3373 *author_name = (char *)ptr->text;
3374 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3375 locale = DEFAULT_LOCALE;
3379 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3380 *author_name = (char *)ptr->text;
3388 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3390 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3391 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3392 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3393 *author_email = (char *)info->manifest_info->author->email;
3397 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3399 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3400 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3401 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3402 *author_href = (char *)info->manifest_info->author->href;
3406 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3408 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3409 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3411 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3413 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3414 *storage = PMINFO_INTERNAL_STORAGE;
3415 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3416 *storage = PMINFO_EXTERNAL_STORAGE;
3418 return PMINFO_R_ERROR;
3423 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3425 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3426 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3427 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3428 if (info->manifest_info->installed_time)
3429 *installed_time = atoi(info->manifest_info->installed_time);
3431 return PMINFO_R_ERROR;
3436 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3438 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3439 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3440 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3441 *storeclientid = (char *)info->manifest_info->storeclient_id;
3445 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3447 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3448 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3449 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3450 *mainappid = (char *)info->manifest_info->mainapp_id;
3454 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3456 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3457 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3458 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3459 *url = (char *)info->manifest_info->package_url;
3463 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3465 const char *val = NULL;
3466 const xmlChar *node;
3467 xmlTextReaderPtr reader;
3468 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3469 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3472 reader = xmlReaderForFile(manifest, NULL, 0);
3475 if (__child_element(reader, -1)) {
3476 node = xmlTextReaderConstName(reader);
3478 _LOGE("xmlTextReaderConstName value is NULL\n");
3479 xmlFreeTextReader(reader);
3481 return PMINFO_R_ERROR;
3484 if (!strcmp(ASC_CHAR(node), "manifest")) {
3485 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3486 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3492 _LOGE("package size is not specified\n");
3493 xmlFreeTextReader(reader);
3495 return PMINFO_R_ERROR;
3498 _LOGE("Unable to create xml reader\n");
3499 xmlFreeTextReader(reader);
3501 return PMINFO_R_ERROR;
3505 _LOGE("xmlReaderForFile value is NULL\n");
3507 return PMINFO_R_ERROR;
3510 xmlFreeTextReader(reader);
3516 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3518 const char *val = NULL;
3519 const xmlChar *node;
3520 xmlTextReaderPtr reader;
3521 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3522 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3525 reader = xmlReaderForFile(manifest, NULL, 0);
3528 if ( __child_element(reader, -1)) {
3529 node = xmlTextReaderConstName(reader);
3531 _LOGE("xmlTextReaderConstName value is NULL\n");
3532 xmlFreeTextReader(reader);
3534 return PMINFO_R_ERROR;
3537 if (!strcmp(ASC_CHAR(node), "manifest")) {
3538 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3539 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3542 if (strcmp(val, "internal-only") == 0)
3543 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3544 else if (strcmp(val, "prefer-external") == 0)
3545 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3547 *location = PMINFO_INSTALL_LOCATION_AUTO;
3550 _LOGE("Unable to create xml reader\n");
3551 xmlFreeTextReader(reader);
3553 return PMINFO_R_ERROR;
3557 _LOGE("xmlReaderForFile value is NULL\n");
3559 return PMINFO_R_ERROR;
3562 xmlFreeTextReader(reader);
3569 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3571 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3572 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3574 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3575 if (info->manifest_info->root_path)
3576 *path = (char *)info->manifest_info->root_path;
3578 return PMINFO_R_ERROR;
3583 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3585 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3586 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3588 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3589 if (info->manifest_info->csc_path)
3590 *path = (char *)info->manifest_info->csc_path;
3592 *path = (char *)info->manifest_info->csc_path;
3597 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)
3599 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3600 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3601 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3603 int ret = PMINFO_R_OK;
3604 char query[MAX_QUERY_LEN] = {'\0'};
3605 char *error_message = NULL;
3606 pkgmgr_cert_x *info= NULL;
3610 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3611 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3612 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3614 ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
3615 SQLITE_OPEN_READWRITE, NULL);
3616 if (ret != SQLITE_OK) {
3617 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
3618 ret = PMINFO_R_ERROR;
3621 _check_create_Cert_db(cert_db);
3622 _pkgmgr_parser_attach_create_view_certdb(cert_db,uid);
3623 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3625 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3626 _LOGE("Don't execute query = %s error message = %s\n", query,
3628 ret = PMINFO_R_ERROR;
3635 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3637 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3638 _LOGE("Don't execute query = %s error message = %s\n", query,
3640 ret = PMINFO_R_ERROR;
3643 lcert = info->cert_id;
3646 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3648 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3649 _LOGE("Don't execute query = %s error message = %s\n", query,
3651 ret = PMINFO_R_ERROR;
3658 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3660 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3661 _LOGE("Don't execute query = %s error message = %s\n", query,
3663 ret = PMINFO_R_ERROR;
3666 rcert = info->cert_id;
3669 if ((lcert == 0) || (rcert == 0))
3671 if ((lcert == 0) && (rcert == 0))
3672 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3673 else if (lcert == 0)
3674 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3675 else if (rcert == 0)
3676 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3679 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3681 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3685 sqlite3_free(error_message);
3686 sqlite3_close(cert_db);
3698 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)
3700 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3703 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)
3705 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3706 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3707 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3709 int ret = PMINFO_R_OK;
3710 char query[MAX_QUERY_LEN] = {'\0'};
3711 char *error_message = NULL;
3712 pkgmgr_cert_x *info= NULL;
3714 char *lpkgid = NULL;
3715 char *rpkgid = NULL;
3717 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3718 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3720 ret = db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
3721 SQLITE_OPEN_READONLY, NULL);
3722 if (ret != SQLITE_OK) {
3723 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPath());
3724 ret = PMINFO_R_ERROR;
3728 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3730 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3731 _LOGE("Don't execute query = %s error message = %s\n", query,
3733 ret = PMINFO_R_ERROR;
3740 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3742 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3743 _LOGE("Don't execute query = %s error message = %s\n", query,
3745 ret = PMINFO_R_ERROR;
3748 lpkgid = strdup(info->pkgid);
3749 if (lpkgid == NULL) {
3750 _LOGE("Out of Memory\n");
3751 ret = PMINFO_R_ERROR;
3758 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3760 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3761 _LOGE("Don't execute query = %s error message = %s\n", query,
3763 ret = PMINFO_R_ERROR;
3770 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3772 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3773 _LOGE("Don't execute query = %s error message = %s\n", query,
3775 ret = PMINFO_R_ERROR;
3778 rpkgid = strdup(info->pkgid);
3779 if (rpkgid == NULL) {
3780 _LOGE("Out of Memory\n");
3781 ret = PMINFO_R_ERROR;
3787 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3789 sqlite3_free(error_message);
3790 sqlite3_close(manifest_db);
3810 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)
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;
3824 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3825 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3827 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
3828 SQLITE_OPEN_READONLY, NULL);
3829 if (ret != SQLITE_OK) {
3830 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3831 ret = PMINFO_R_ERROR;
3834 _pkgmgr_parser_attach_create_view_parserdb(manifest_db,uid);
3836 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3838 sqlite3_exec(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(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(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(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_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3897 sqlite3_free(error_message);
3898 sqlite3_close(manifest_db);
3918 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3920 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3921 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3923 #if 0 //smack issue occured, check later
3925 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3927 _LOGD("invalid func parameters\n");
3928 return PMINFO_R_ERROR;
3930 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3933 char app_mmc_path[FILENAME_MAX] = { 0, };
3934 char app_dir_path[FILENAME_MAX] = { 0, };
3935 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3936 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3937 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3938 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3940 /*check whether application is in external memory or not */
3941 fp = fopen(app_mmc_path, "r");
3943 _LOGD(" app path in external memory not accesible\n");
3948 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3952 /*check whether application is in internal or not */
3953 fp = fopen(app_dir_path, "r");
3955 _LOGD(" app path in internal memory not accesible\n");
3957 return PMINFO_R_ERROR;
3960 /*check whether the application is installed in SD card
3961 but SD card is not present*/
3962 fp = fopen(app_mmc_internal_path, "r");
3965 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3970 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3975 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3982 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3984 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3985 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3987 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3988 val = (char *)info->manifest_info->removable;
3990 if (strcasecmp(val, "true") == 0)
3992 else if (strcasecmp(val, "false") == 0)
4000 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
4002 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4003 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4006 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4008 val = (char *)info->manifest_info->installlocation;
4010 if (strcmp(val, "internal-only") == 0)
4012 else if (strcmp(val, "prefer-external") == 0)
4021 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4023 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4024 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4026 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4027 val = (char *)info->manifest_info->preload;
4029 if (strcasecmp(val, "true") == 0)
4031 else if (strcasecmp(val, "false") == 0)
4039 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4041 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4042 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4045 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4046 val = (char *)info->manifest_info->system;
4048 if (strcasecmp(val, "true") == 0)
4050 else if (strcasecmp(val, "false") == 0)
4059 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4061 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4062 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4064 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4065 val = (char *)info->manifest_info->readonly;
4067 if (strcasecmp(val, "true") == 0)
4069 else if (strcasecmp(val, "false") == 0)
4077 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4079 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4080 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4083 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4084 val = (char *)info->manifest_info->update;
4086 if (strcasecmp(val, "true") == 0)
4088 else if (strcasecmp(val, "false") == 0)
4096 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4098 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4099 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4100 __cleanup_pkginfo(info);
4104 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4106 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4108 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4109 if (filter == NULL) {
4110 _LOGE("Out of Memory!!!");
4111 return PMINFO_R_ERROR;
4117 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4119 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4120 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4122 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4123 g_slist_free(filter->list);
4130 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4131 const char *property, const int value)
4133 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4134 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4135 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4137 GSList *link = NULL;
4139 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4140 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4141 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4142 _LOGE("Invalid Integer Property\n");
4143 return PMINFO_R_EINVAL;
4145 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4146 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4148 _LOGE("Out of Memory!!!\n");
4149 return PMINFO_R_ERROR;
4151 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4152 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4154 _LOGE("Out of Memory\n");
4157 return PMINFO_R_ERROR;
4161 /*If API is called multiple times for same property, we should override the previous values.
4162 Last value set will be used for filtering.*/
4163 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4165 filter->list = g_slist_delete_link(filter->list, link);
4166 filter->list = g_slist_append(filter->list, (gpointer)node);
4171 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4172 const char *property, const bool value)
4174 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4175 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4177 GSList *link = NULL;
4179 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4180 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4181 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4182 _LOGE("Invalid Boolean Property\n");
4183 return PMINFO_R_EINVAL;
4185 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4186 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4188 _LOGE("Out of Memory!!!\n");
4189 return PMINFO_R_ERROR;
4192 val = strndup("('true','True')", 15);
4194 val = strndup("('false','False')", 17);
4196 _LOGE("Out of Memory\n");
4199 return PMINFO_R_ERROR;
4203 /*If API is called multiple times for same property, we should override the previous values.
4204 Last value set will be used for filtering.*/
4205 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4207 filter->list = g_slist_delete_link(filter->list, link);
4208 filter->list = g_slist_append(filter->list, (gpointer)node);
4213 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4214 const char *property, const char *value)
4216 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4217 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4218 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4220 GSList *link = NULL;
4222 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4223 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4224 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4225 _LOGE("Invalid String Property\n");
4226 return PMINFO_R_EINVAL;
4228 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4229 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4231 _LOGE("Out of Memory!!!\n");
4232 return PMINFO_R_ERROR;
4234 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4235 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4236 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4237 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4238 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4239 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4240 else if (strcmp(value, "installed_internal") == 0)
4241 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4242 else if (strcmp(value, "installed_external") == 0)
4243 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4245 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4247 _LOGE("Out of Memory\n");
4250 return PMINFO_R_ERROR;
4254 /*If API is called multiple times for same property, we should override the previous values.
4255 Last value set will be used for filtering.*/
4256 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4258 filter->list = g_slist_delete_link(filter->list, link);
4259 filter->list = g_slist_append(filter->list, (gpointer)node);
4264 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4266 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4267 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4268 char *syslocale = NULL;
4269 char *locale = NULL;
4270 char *condition = NULL;
4271 char *error_message = NULL;
4272 char query[MAX_QUERY_LEN] = {'\0'};
4273 char where[MAX_QUERY_LEN] = {'\0'};
4277 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4278 /*Get current locale*/
4279 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4280 if (syslocale == NULL) {
4281 _LOGE("current locale is NULL\n");
4282 return PMINFO_R_ERROR;
4284 locale = __convert_system_locale_to_manifest_locale(syslocale);
4285 if (locale == NULL) {
4286 _LOGE("manifest locale is NULL\n");
4288 return PMINFO_R_ERROR;
4291 ret = __open_manifest_db(uid);
4293 _LOGE("Fail to open manifest DB\n");
4294 ret = PMINFO_R_ERROR;
4298 /*Start constructing query*/
4299 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4301 /*Get where clause*/
4302 for (list = filter->list; list; list = g_slist_next(list)) {
4303 __get_filter_condition(list->data, &condition);
4305 strncat(where, condition, sizeof(where) - strlen(where) -1);
4306 where[sizeof(where) - 1] = '\0';
4310 if (g_slist_next(list)) {
4311 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4312 where[sizeof(where) - 1] = '\0';
4315 _LOGE("where = %s\n", where);
4316 if (strlen(where) > 0) {
4317 strncat(query, where, sizeof(query) - strlen(query) - 1);
4318 query[sizeof(query) - 1] = '\0';
4320 _LOGE("query = %s\n", query);
4324 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
4325 _LOGE("Don't execute query = %s error message = %s\n", query,
4327 sqlite3_free(error_message);
4328 sqlite3_close(manifest_db);
4329 ret = PMINFO_R_ERROR;
4343 sqlite3_close(manifest_db);
4347 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4349 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4352 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4353 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4355 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4356 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4357 char *syslocale = NULL;
4358 char *locale = NULL;
4359 char *condition = NULL;
4360 char *error_message = NULL;
4361 char query[MAX_QUERY_LEN] = {'\0'};
4362 char where[MAX_QUERY_LEN] = {'\0'};
4365 label_x *tmp1 = NULL;
4366 icon_x *tmp2 = NULL;
4367 description_x *tmp3 = NULL;
4368 author_x *tmp4 = NULL;
4369 privilege_x *tmp5 = NULL;
4370 pkgmgr_pkginfo_x *node = NULL;
4371 pkgmgr_pkginfo_x *tmphead = NULL;
4372 pkgmgr_pkginfo_x *pkginfo = NULL;
4374 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4375 /*Get current locale*/
4376 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4377 if (syslocale == NULL) {
4378 _LOGE("current locale is NULL\n");
4379 return PMINFO_R_ERROR;
4381 locale = __convert_system_locale_to_manifest_locale(syslocale);
4382 if (locale == NULL) {
4383 _LOGE("manifest locale is NULL\n");
4385 return PMINFO_R_ERROR;
4388 ret = __open_manifest_db(uid);
4390 _LOGE("Fail to open manifest DB\n");
4391 ret = PMINFO_R_ERROR;
4394 /*Start constructing query*/
4395 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4397 /*Get where clause*/
4398 for (list = filter->list; list; list = g_slist_next(list)) {
4399 __get_filter_condition(list->data, &condition);
4401 strncat(where, condition, sizeof(where) - strlen(where) -1);
4402 where[sizeof(where) - 1] = '\0';
4406 if (g_slist_next(list)) {
4407 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4408 where[sizeof(where) - 1] = '\0';
4411 _LOGE("where = %s\n", where);
4412 if (strlen(where) > 0) {
4413 strncat(query, where, sizeof(query) - strlen(query) - 1);
4414 query[sizeof(query) - 1] = '\0';
4416 _LOGE("query = %s\n", query);
4417 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4418 if (tmphead == NULL) {
4419 _LOGE("Out of Memory!!!\n");
4420 ret = PMINFO_R_ERROR;
4425 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4426 _LOGE("Don't execute query = %s error message = %s\n", query,
4428 sqlite3_free(error_message);
4429 sqlite3_close(manifest_db);
4430 ret = PMINFO_R_ERROR;
4434 LISTHEAD(tmphead, node);
4435 for(node = node->next ; node ; node = node->next) {
4437 pkginfo->locale = strdup(locale);
4438 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4439 if (pkginfo->manifest_info->privileges == NULL) {
4440 _LOGE("Failed to allocate memory for privileges info\n");
4441 ret = PMINFO_R_ERROR;
4445 /*populate manifest_info from DB*/
4446 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4447 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4449 _LOGE("Package Info DB Information retrieval failed\n");
4450 ret = PMINFO_R_ERROR;
4453 memset(query, '\0', MAX_QUERY_LEN);
4454 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4455 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4456 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4458 _LOGE("Package Info DB Information retrieval failed\n");
4459 ret = PMINFO_R_ERROR;
4462 /*Also store the values corresponding to default locales*/
4463 memset(query, '\0', MAX_QUERY_LEN);
4464 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4465 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4466 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4468 _LOGE("Package Info DB Information retrieval failed\n");
4469 ret = PMINFO_R_ERROR;
4472 if (pkginfo->manifest_info->label) {
4473 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4474 pkginfo->manifest_info->label = tmp1;
4476 if (pkginfo->manifest_info->icon) {
4477 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4478 pkginfo->manifest_info->icon = tmp2;
4480 if (pkginfo->manifest_info->description) {
4481 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4482 pkginfo->manifest_info->description = tmp3;
4484 if (pkginfo->manifest_info->author) {
4485 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4486 pkginfo->manifest_info->author = tmp4;
4488 if (pkginfo->manifest_info->privileges->privilege) {
4489 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4490 pkginfo->manifest_info->privileges->privilege = tmp5;
4494 LISTHEAD(tmphead, node);
4496 for(node = node->next ; node ; node = node->next) {
4498 ret = pkg_cb( (void *)pkginfo, user_data);
4513 sqlite3_close(manifest_db);
4514 __cleanup_pkginfo(tmphead);
4518 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4519 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4521 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4524 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4525 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4527 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4528 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4530 privilege_x *ptr = NULL;
4531 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4532 ptr = info->manifest_info->privileges->privilege;
4533 for (; ptr; ptr = ptr->next) {
4535 ret = privilege_func(ptr->text, user_data);
4543 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4544 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4547 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4548 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4550 char *syslocale = NULL;
4551 char *locale = NULL;
4553 char query[MAX_QUERY_LEN] = {'\0'};
4554 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4555 pkgmgr_pkginfo_x *allinfo = NULL;
4556 pkgmgr_appinfo_x *appinfo = NULL;
4557 icon_x *ptr1 = NULL;
4558 label_x *ptr2 = NULL;
4559 category_x *ptr3 = NULL;
4560 metadata_x *ptr4 = NULL;
4561 permission_x *ptr5 = NULL;
4562 image_x *ptr6 = NULL;
4563 sqlite3 *appinfo_db = NULL;
4565 /*get system locale*/
4566 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4567 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4569 /*get locale on db*/
4570 locale = __convert_system_locale_to_manifest_locale(syslocale);
4571 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4574 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4575 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4577 /*calloc manifest_info*/
4578 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4579 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4582 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4583 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4585 /*set component type*/
4586 if (component == PMINFO_UI_APP)
4587 appinfo->app_component = PMINFO_UI_APP;
4588 if (component == PMINFO_SVC_APP)
4589 appinfo->app_component = PMINFO_SVC_APP;
4590 if (component == PMINFO_ALL_APP)
4591 appinfo->app_component = PMINFO_ALL_APP;
4594 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4595 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4597 appinfo->package = strdup(info->manifest_info->package);
4598 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4599 "from package_app_info where " \
4600 "package='%s' and app_component='%s'",
4601 info->manifest_info->package,
4602 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4606 /*Populate ui app info */
4607 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
4608 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4610 uiapplication_x *tmp = NULL;
4611 if (info->manifest_info->uiapplication) {
4612 LISTHEAD(info->manifest_info->uiapplication, tmp);
4613 info->manifest_info->uiapplication = tmp;
4615 /*Populate localized info for default locales and call callback*/
4616 /*If the callback func return < 0 we break and no more call back is called*/
4619 appinfo->locale = strdup(locale);
4620 appinfo->uiapp_info = tmp;
4621 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4625 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
4628 memset(query, '\0', MAX_QUERY_LEN);
4629 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4630 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4631 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4633 memset(query, '\0', MAX_QUERY_LEN);
4634 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);
4635 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4636 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4638 /*store setting notification icon section*/
4639 memset(query, '\0', MAX_QUERY_LEN);
4640 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4641 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4642 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4644 /*store app preview image info*/
4645 memset(query, '\0', MAX_QUERY_LEN);
4646 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4647 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4648 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4650 if (appinfo->uiapp_info->label) {
4651 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4652 appinfo->uiapp_info->label = ptr2;
4654 if (appinfo->uiapp_info->icon) {
4655 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4656 appinfo->uiapp_info->icon = ptr1;
4658 if (appinfo->uiapp_info->category) {
4659 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4660 appinfo->uiapp_info->category = ptr3;
4662 if (appinfo->uiapp_info->metadata) {
4663 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4664 appinfo->uiapp_info->metadata = ptr4;
4666 if (appinfo->uiapp_info->permission) {
4667 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4668 appinfo->uiapp_info->permission = ptr5;
4670 if (appinfo->uiapp_info->image) {
4671 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4672 appinfo->uiapp_info->image = ptr6;
4674 ret = app_func((void *)appinfo, user_data);
4680 case PMINFO_SVC_APP:
4681 /*Populate svc app info */
4682 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
4683 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4685 serviceapplication_x *tmp1 = NULL;
4686 if (info->manifest_info->serviceapplication) {
4687 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4688 info->manifest_info->serviceapplication = tmp1;
4690 /*Populate localized info for default locales and call callback*/
4691 /*If the callback func return < 0 we break and no more call back is called*/
4694 appinfo->locale = strdup(locale);
4695 appinfo->svcapp_info = tmp1;
4696 memset(query, '\0', MAX_QUERY_LEN);
4697 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4698 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4699 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4701 memset(query, '\0', MAX_QUERY_LEN);
4702 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);
4703 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4704 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4706 if (appinfo->svcapp_info->label) {
4707 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4708 appinfo->svcapp_info->label = ptr2;
4710 if (appinfo->svcapp_info->icon) {
4711 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4712 appinfo->svcapp_info->icon = ptr1;
4714 if (appinfo->svcapp_info->category) {
4715 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4716 appinfo->svcapp_info->category = ptr3;
4718 if (appinfo->svcapp_info->metadata) {
4719 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4720 appinfo->svcapp_info->metadata = ptr4;
4722 if (appinfo->svcapp_info->permission) {
4723 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4724 appinfo->svcapp_info->permission = ptr5;
4726 ret = app_func((void *)appinfo, user_data);
4732 case PMINFO_ALL_APP:
4733 memset(query, '\0', MAX_QUERY_LEN);
4734 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4736 /*Populate all app info */
4737 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
4738 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4741 appinfo->app_component = PMINFO_UI_APP;
4742 uiapplication_x *tmp2 = NULL;
4743 if (allinfo->manifest_info->uiapplication) {
4744 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4745 allinfo->manifest_info->uiapplication = tmp2;
4747 /*Populate localized info for default locales and call callback*/
4748 /*If the callback func return < 0 we break and no more call back is called*/
4751 appinfo->locale = strdup(locale);
4752 appinfo->uiapp_info = tmp2;
4753 memset(query, '\0', MAX_QUERY_LEN);
4754 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4755 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4756 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
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, DEFAULT_LOCALE);
4760 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4761 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4763 /*store setting notification icon section*/
4764 memset(query, '\0', MAX_QUERY_LEN);
4765 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4766 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4767 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4769 /*store app preview image info*/
4770 memset(query, '\0', MAX_QUERY_LEN);
4771 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4772 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4773 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4775 if (appinfo->uiapp_info->label) {
4776 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4777 appinfo->uiapp_info->label = ptr2;
4779 if (appinfo->uiapp_info->icon) {
4780 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4781 appinfo->uiapp_info->icon = ptr1;
4783 if (appinfo->uiapp_info->category) {
4784 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4785 appinfo->uiapp_info->category = ptr3;
4787 if (appinfo->uiapp_info->metadata) {
4788 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4789 appinfo->uiapp_info->metadata = ptr4;
4791 if (appinfo->uiapp_info->permission) {
4792 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4793 appinfo->uiapp_info->permission = ptr5;
4795 if (appinfo->uiapp_info->image) {
4796 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4797 appinfo->uiapp_info->image = ptr6;
4799 ret = app_func((void *)appinfo, user_data);
4806 appinfo->app_component = PMINFO_SVC_APP;
4807 serviceapplication_x *tmp3 = NULL;
4808 if (allinfo->manifest_info->serviceapplication) {
4809 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4810 allinfo->manifest_info->serviceapplication = tmp3;
4812 /*Populate localized info for default locales and call callback*/
4813 /*If the callback func return < 0 we break and no more call back is called*/
4816 appinfo->locale = strdup(locale);
4817 appinfo->svcapp_info = tmp3;
4818 memset(query, '\0', MAX_QUERY_LEN);
4819 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4820 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4821 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4823 memset(query, '\0', MAX_QUERY_LEN);
4824 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);
4825 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4826 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4828 if (appinfo->svcapp_info->label) {
4829 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4830 appinfo->svcapp_info->label = ptr2;
4832 if (appinfo->svcapp_info->icon) {
4833 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4834 appinfo->svcapp_info->icon = ptr1;
4836 if (appinfo->svcapp_info->category) {
4837 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4838 appinfo->svcapp_info->category = ptr3;
4840 if (appinfo->svcapp_info->metadata) {
4841 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4842 appinfo->svcapp_info->metadata = ptr4;
4844 if (appinfo->svcapp_info->permission) {
4845 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4846 appinfo->svcapp_info->permission = ptr5;
4848 ret = app_func((void *)appinfo, user_data);
4853 appinfo->app_component = PMINFO_ALL_APP;
4869 if (appinfo->package) {
4870 free((void *)appinfo->package);
4871 appinfo->package = NULL;
4876 __cleanup_pkginfo(allinfo);
4878 sqlite3_close(appinfo_db);
4882 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4883 pkgmgrinfo_app_list_cb app_func, void *user_data)
4885 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4888 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4890 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4892 int ret = PMINFO_R_OK;
4893 char query[MAX_QUERY_LEN] = {'\0'};
4894 pkgmgr_appinfo_x *appinfo = NULL;
4895 uiapplication_x *ptr1 = NULL;
4896 serviceapplication_x *ptr2 = NULL;
4897 sqlite3 *appinfo_db = NULL;
4900 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4901 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4904 pkgmgr_pkginfo_x *info = NULL;
4905 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4906 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4908 /*calloc manifest_info*/
4909 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4910 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4913 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4914 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4916 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4917 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4918 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4920 if (info->manifest_info->uiapplication) {
4921 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4922 info->manifest_info->uiapplication = ptr1;
4924 if (info->manifest_info->serviceapplication) {
4925 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4926 info->manifest_info->serviceapplication = ptr2;
4930 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4932 appinfo->app_component = PMINFO_UI_APP;
4933 appinfo->package = strdup(ptr1->package);
4934 appinfo->uiapp_info = ptr1;
4936 ret = app_func((void *)appinfo, user_data);
4939 free((void *)appinfo->package);
4940 appinfo->package = NULL;
4943 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4945 appinfo->app_component = PMINFO_SVC_APP;
4946 appinfo->package = strdup(ptr2->package);
4947 appinfo->svcapp_info = ptr2;
4949 ret = app_func((void *)appinfo, user_data);
4952 free((void *)appinfo->package);
4953 appinfo->package = NULL;
4958 sqlite3_close(appinfo_db);
4964 __cleanup_pkginfo(info);
4968 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4970 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4973 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4975 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4977 int ret = PMINFO_R_OK;
4978 char query[MAX_QUERY_LEN] = {'\0'};
4979 char *syslocale = NULL;
4980 char *locale = NULL;
4981 pkgmgr_appinfo_x *appinfo = NULL;
4982 uiapplication_x *ptr1 = NULL;
4983 serviceapplication_x *ptr2 = NULL;
4984 label_x *tmp1 = NULL;
4985 icon_x *tmp2 = NULL;
4986 category_x *tmp3 = NULL;
4987 metadata_x *tmp4 = NULL;
4988 permission_x *tmp5 = NULL;
4989 image_x *tmp6 = NULL;
4990 sqlite3 *appinfo_db = NULL;
4992 /*get system locale*/
4993 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4994 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4996 /*get locale on db*/
4997 locale = __convert_system_locale_to_manifest_locale(syslocale);
4998 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5001 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5002 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5005 pkgmgr_pkginfo_x *info = NULL;
5006 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5007 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5009 /*calloc manifest_info*/
5010 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5011 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5014 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5015 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5017 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5018 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
5019 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5021 if (info->manifest_info->uiapplication) {
5022 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5023 info->manifest_info->uiapplication = ptr1;
5025 if (info->manifest_info->serviceapplication) {
5026 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5027 info->manifest_info->serviceapplication = ptr2;
5031 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5033 appinfo->locale = strdup(locale);
5034 appinfo->app_component = PMINFO_UI_APP;
5035 appinfo->package = strdup(ptr1->package);
5036 appinfo->uiapp_info = ptr1;
5037 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5038 "from package_app_info where " \
5039 "app_id='%s'", ptr1->appid);
5040 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5041 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5043 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5047 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
5050 memset(query, '\0', MAX_QUERY_LEN);
5051 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5052 "from package_app_localized_info where " \
5053 "app_id='%s' and app_locale='%s'",
5054 ptr1->appid, locale);
5055 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5056 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5058 memset(query, '\0', MAX_QUERY_LEN);
5059 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5060 "from package_app_localized_info where " \
5061 "app_id='%s' and app_locale='%s'",
5062 ptr1->appid, DEFAULT_LOCALE);
5064 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5065 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5067 /*store setting notification icon section*/
5068 memset(query, '\0', MAX_QUERY_LEN);
5069 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5070 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5071 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5073 /*store app preview image info*/
5074 memset(query, '\0', MAX_QUERY_LEN);
5075 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5076 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5077 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5079 if (appinfo->uiapp_info->label) {
5080 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5081 appinfo->uiapp_info->label = tmp1;
5083 if (appinfo->uiapp_info->icon) {
5084 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5085 appinfo->uiapp_info->icon= tmp2;
5087 if (appinfo->uiapp_info->category) {
5088 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5089 appinfo->uiapp_info->category = tmp3;
5091 if (appinfo->uiapp_info->metadata) {
5092 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5093 appinfo->uiapp_info->metadata = tmp4;
5095 if (appinfo->uiapp_info->permission) {
5096 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5097 appinfo->uiapp_info->permission = tmp5;
5099 if (appinfo->uiapp_info->image) {
5100 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5101 appinfo->uiapp_info->image = tmp6;
5103 ret = app_func((void *)appinfo, user_data);
5106 free((void *)appinfo->package);
5107 appinfo->package = NULL;
5110 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5112 appinfo->locale = strdup(locale);
5113 appinfo->app_component = PMINFO_SVC_APP;
5114 appinfo->package = strdup(ptr2->package);
5115 appinfo->svcapp_info = ptr2;
5116 memset(query, '\0', MAX_QUERY_LEN);
5117 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5118 "from package_app_info where " \
5119 "app_id='%s'", ptr2->appid);
5120 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5121 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5123 memset(query, '\0', MAX_QUERY_LEN);
5124 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5125 "from package_app_localized_info where " \
5126 "app_id='%s' and app_locale='%s'",
5127 ptr2->appid, locale);
5128 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5129 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5131 memset(query, '\0', MAX_QUERY_LEN);
5132 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5133 "from package_app_localized_info where " \
5134 "app_id='%s' and app_locale='%s'",
5135 ptr2->appid, DEFAULT_LOCALE);
5136 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5137 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5139 if (appinfo->svcapp_info->label) {
5140 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5141 appinfo->svcapp_info->label = tmp1;
5143 if (appinfo->svcapp_info->icon) {
5144 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5145 appinfo->svcapp_info->icon= tmp2;
5147 if (appinfo->svcapp_info->category) {
5148 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5149 appinfo->svcapp_info->category = tmp3;
5151 if (appinfo->svcapp_info->metadata) {
5152 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5153 appinfo->svcapp_info->metadata = tmp4;
5155 if (appinfo->svcapp_info->permission) {
5156 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5157 appinfo->svcapp_info->permission = tmp5;
5159 ret = app_func((void *)appinfo, user_data);
5162 free((void *)appinfo->package);
5163 appinfo->package = NULL;
5176 sqlite3_close(appinfo_db);
5181 __cleanup_pkginfo(info);
5185 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5187 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5190 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5192 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5193 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5195 pkgmgr_appinfo_x *appinfo = NULL;
5196 char *syslocale = NULL;
5197 char *locale = NULL;
5200 label_x *tmp1 = NULL;
5201 icon_x *tmp2 = NULL;
5202 category_x *tmp3 = NULL;
5203 metadata_x *tmp4 = NULL;
5204 permission_x *tmp5 = NULL;
5205 image_x *tmp6 = NULL;
5206 char query[MAX_QUERY_LEN] = {'\0'};
5207 sqlite3 *appinfo_db = NULL;
5210 _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
5211 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5212 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5215 /*check appid exist on db*/
5216 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5217 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
5218 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5219 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5221 /*get system locale*/
5222 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5223 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5225 /*get locale on db*/
5226 locale = __convert_system_locale_to_manifest_locale(syslocale);
5227 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5230 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5231 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5233 /*check app_component from DB*/
5234 memset(query, '\0', MAX_QUERY_LEN);
5235 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5236 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
5237 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5239 /*calloc app_component*/
5240 if (appinfo->app_component == PMINFO_UI_APP) {
5241 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5242 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5244 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5245 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5247 appinfo->locale = strdup(locale);
5249 /*populate app_info from DB*/
5250 memset(query, '\0', MAX_QUERY_LEN);
5251 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5252 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5253 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5255 memset(query, '\0', MAX_QUERY_LEN);
5256 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5257 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5258 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5260 /*Also store the values corresponding to default locales*/
5261 memset(query, '\0', MAX_QUERY_LEN);
5262 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5263 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5264 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5266 /*Populate app category*/
5267 memset(query, '\0', MAX_QUERY_LEN);
5268 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5269 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5270 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5272 /*Populate app metadata*/
5273 memset(query, '\0', MAX_QUERY_LEN);
5274 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5275 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5276 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5278 /*Populate app permission*/
5279 memset(query, '\0', MAX_QUERY_LEN);
5280 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5281 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5282 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5284 /*store setting notification icon section*/
5285 memset(query, '\0', MAX_QUERY_LEN);
5286 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5287 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5288 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5290 /*store app preview image info*/
5291 memset(query, '\0', MAX_QUERY_LEN);
5292 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5293 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5294 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5296 switch (appinfo->app_component) {
5298 if (appinfo->uiapp_info->label) {
5299 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5300 appinfo->uiapp_info->label = tmp1;
5302 if (appinfo->uiapp_info->icon) {
5303 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5304 appinfo->uiapp_info->icon = tmp2;
5306 if (appinfo->uiapp_info->category) {
5307 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5308 appinfo->uiapp_info->category = tmp3;
5310 if (appinfo->uiapp_info->metadata) {
5311 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5312 appinfo->uiapp_info->metadata = tmp4;
5314 if (appinfo->uiapp_info->permission) {
5315 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5316 appinfo->uiapp_info->permission = tmp5;
5318 if (appinfo->uiapp_info->image) {
5319 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5320 appinfo->uiapp_info->image = tmp6;
5323 case PMINFO_SVC_APP:
5324 if (appinfo->svcapp_info->label) {
5325 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5326 appinfo->svcapp_info->label = tmp1;
5328 if (appinfo->svcapp_info->icon) {
5329 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5330 appinfo->svcapp_info->icon = tmp2;
5332 if (appinfo->svcapp_info->category) {
5333 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5334 appinfo->svcapp_info->category = tmp3;
5336 if (appinfo->svcapp_info->metadata) {
5337 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5338 appinfo->svcapp_info->metadata = tmp4;
5340 if (appinfo->svcapp_info->permission) {
5341 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5342 appinfo->svcapp_info->permission = tmp5;
5352 if (ret == PMINFO_R_OK)
5353 *handle = (void*)appinfo;
5356 __cleanup_appinfo(appinfo);
5359 sqlite3_close(appinfo_db);
5371 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5373 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5376 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5378 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5379 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5380 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5382 if (info->app_component == PMINFO_UI_APP)
5383 *appid = (char *)info->uiapp_info->appid;
5384 else if (info->app_component == PMINFO_SVC_APP)
5385 *appid = (char *)info->svcapp_info->appid;
5390 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5393 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5394 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5396 *pkg_name = (char *)info->package;
5401 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5403 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5404 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5405 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5407 *pkgid = (char *)info->package;
5412 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5415 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5416 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5418 if (info->app_component == PMINFO_UI_APP)
5419 *exec = (char *)info->uiapp_info->exec;
5420 if (info->app_component == PMINFO_SVC_APP)
5421 *exec = (char *)info->svcapp_info->exec;
5427 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5429 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5430 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5431 char *locale = NULL;
5433 icon_x *start = NULL;
5436 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5437 locale = info->locale;
5438 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5440 if (info->app_component == PMINFO_UI_APP)
5441 start = info->uiapp_info->icon;
5442 if (info->app_component == PMINFO_SVC_APP)
5443 start = info->svcapp_info->icon;
5444 for(ptr = start; ptr != NULL; ptr = ptr->next)
5447 if (strcmp(ptr->lang, locale) == 0) {
5448 *icon = (char *)ptr->text;
5449 if (strcasecmp(*icon, "(null)") == 0) {
5450 locale = DEFAULT_LOCALE;
5454 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5455 *icon = (char *)ptr->text;
5464 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5466 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5467 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5468 char *locale = NULL;
5469 label_x *ptr = NULL;
5470 label_x *start = NULL;
5473 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5474 locale = info->locale;
5475 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5477 if (info->app_component == PMINFO_UI_APP)
5478 start = info->uiapp_info->label;
5479 if (info->app_component == PMINFO_SVC_APP)
5480 start = info->svcapp_info->label;
5481 for(ptr = start; ptr != NULL; ptr = ptr->next)
5484 if (strcmp(ptr->lang, locale) == 0) {
5485 *label = (char *)ptr->text;
5486 if (strcasecmp(*label, "(null)") == 0) {
5487 locale = DEFAULT_LOCALE;
5491 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5492 *label = (char *)ptr->text;
5493 if (strcasecmp(*label, "(null)") == 0) {
5494 locale = DEFAULT_LOCALE;
5498 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5499 *label = (char *)ptr->text;
5508 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5510 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5511 retvm_if(component == 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 *component = PMINFO_UI_APP;
5516 else if (info->app_component == PMINFO_SVC_APP)
5517 *component = PMINFO_SVC_APP;
5519 return PMINFO_R_ERROR;
5524 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5526 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5527 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5528 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5530 if (info->app_component == PMINFO_UI_APP)
5531 *app_type = (char *)info->uiapp_info->type;
5532 if (info->app_component == PMINFO_SVC_APP)
5533 *app_type = (char *)info->svcapp_info->type;
5538 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5539 int *operation_count, char ***operation)
5541 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5542 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5543 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5544 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5545 *operation_count = data->operation_count;
5546 *operation = data->operation;
5550 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5551 int *uri_count, char ***uri)
5553 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5554 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5555 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5556 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5557 *uri_count = data->uri_count;
5562 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5563 int *mime_count, char ***mime)
5565 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5566 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5567 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5568 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5569 *mime_count = data->mime_count;
5574 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5575 int *subapp_count, char ***subapp)
5577 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5578 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5579 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5580 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5581 *subapp_count = data->subapp_count;
5582 *subapp = data->subapp;
5586 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5588 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5589 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5593 icon_x *start = NULL;
5594 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5596 start = info->uiapp_info->icon;
5598 for(ptr = start; ptr != NULL; ptr = ptr->next)
5601 val = (char *)ptr->section;
5602 if (strcmp(val, "setting") == 0){
5603 *icon = (char *)ptr->text;
5612 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5614 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5615 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5619 icon_x *start = NULL;
5620 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5622 start = info->uiapp_info->icon;
5624 for(ptr = start; ptr != NULL; ptr = ptr->next)
5627 val = (char *)ptr->section;
5629 if (strcmp(val, "notification") == 0){
5630 *icon = (char *)ptr->text;
5639 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5641 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5642 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5644 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5645 val = (char *)info->uiapp_info->recentimage;
5647 if (strcasecmp(val, "capture") == 0)
5648 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5649 else if (strcasecmp(val, "icon") == 0)
5650 *type = PMINFO_RECENTIMAGE_USE_ICON;
5652 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5658 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5660 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5661 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5664 image_x *ptr = NULL;
5665 image_x *start = NULL;
5666 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5668 start = info->uiapp_info->image;
5670 for(ptr = start; ptr != NULL; ptr = ptr->next)
5673 val = (char *)ptr->section;
5675 if (strcmp(val, "preview") == 0)
5676 *preview_img = (char *)ptr->text;
5684 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5686 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5687 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5690 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5692 if (info->app_component == PMINFO_UI_APP)
5693 val = info->uiapp_info->permission_type;
5694 else if (info->app_component == PMINFO_SVC_APP)
5695 val = info->svcapp_info->permission_type;
5697 return PMINFO_R_ERROR;
5699 if (strcmp(val, "signature") == 0)
5700 *permission = PMINFO_PERMISSION_SIGNATURE;
5701 else if (strcmp(val, "privilege") == 0)
5702 *permission = PMINFO_PERMISSION_PRIVILEGE;
5704 *permission = PMINFO_PERMISSION_NORMAL;
5709 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5711 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5712 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5713 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5715 *component_type = (char *)info->uiapp_info->component_type;
5720 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5722 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5723 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5725 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5726 val = (char *)info->uiapp_info->hwacceleration;
5728 if (strcasecmp(val, "not-use-GL") == 0)
5729 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5730 else if (strcasecmp(val, "use-GL") == 0)
5731 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5733 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5738 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5740 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5741 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5743 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5744 val = (char *)info->uiapp_info->screenreader;
5746 if (strcasecmp(val, "screenreader-off") == 0)
5747 *screenreader = PMINFO_SCREENREADER_OFF;
5748 else if (strcasecmp(val, "screenreader-on") == 0)
5749 *screenreader = PMINFO_SCREENREADER_ON;
5751 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5756 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5758 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5759 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5760 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5761 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5763 if (info->app_component == PMINFO_UI_APP){
5764 *portrait_img = (char *)info->uiapp_info->portraitimg;
5765 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5771 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5774 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5775 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5777 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5782 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5783 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5785 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5786 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5788 permission_x *ptr = NULL;
5789 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5790 if (info->app_component == PMINFO_UI_APP)
5791 ptr = info->uiapp_info->permission;
5792 else if (info->app_component == PMINFO_SVC_APP)
5793 ptr = info->svcapp_info->permission;
5795 return PMINFO_R_EINVAL;
5796 for (; ptr; ptr = ptr->next) {
5798 ret = permission_func(ptr->value, user_data);
5806 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5807 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5809 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5810 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5812 category_x *ptr = NULL;
5813 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5814 if (info->app_component == PMINFO_UI_APP)
5815 ptr = info->uiapp_info->category;
5816 else if (info->app_component == PMINFO_SVC_APP)
5817 ptr = info->svcapp_info->category;
5819 return PMINFO_R_EINVAL;
5820 for (; ptr; ptr = ptr->next) {
5822 ret = category_func(ptr->name, user_data);
5830 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5831 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5833 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5834 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5836 metadata_x *ptr = NULL;
5837 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5838 if (info->app_component == PMINFO_UI_APP)
5839 ptr = info->uiapp_info->metadata;
5840 else if (info->app_component == PMINFO_SVC_APP)
5841 ptr = info->svcapp_info->metadata;
5843 return PMINFO_R_EINVAL;
5844 for (; ptr; ptr = ptr->next) {
5846 ret = metadata_func(ptr->key, ptr->value, user_data);
5854 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5855 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5857 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5858 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5866 char *manifest = NULL;
5867 char **operation = NULL;
5870 char **subapp = NULL;
5871 appcontrol_x *appcontrol = NULL;
5872 manifest_x *mfx = NULL;
5873 operation_x *op = NULL;
5876 subapp_x *sa = NULL;
5877 pkgmgrinfo_app_component component;
5878 pkgmgrinfo_appcontrol_x *ptr = NULL;
5879 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5881 _LOGE("Failed to get package name\n");
5882 return PMINFO_R_ERROR;
5884 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5886 _LOGE("Failed to get app component name\n");
5887 return PMINFO_R_ERROR;
5889 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
5890 if (manifest == NULL) {
5891 _LOGE("Failed to fetch package manifest file\n");
5892 return PMINFO_R_ERROR;
5894 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
5896 _LOGE("Failed to parse package manifest file\n");
5899 return PMINFO_R_ERROR;
5902 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5904 _LOGE("Out of Memory!!!\n");
5905 pkgmgr_parser_free_manifest_xml(mfx);
5906 return PMINFO_R_ERROR;
5908 /*Get Operation, Uri, Mime*/
5909 switch (component) {
5911 if (mfx->uiapplication) {
5912 if (mfx->uiapplication->appsvc) {
5913 appcontrol = mfx->uiapplication->appsvc;
5917 case PMINFO_SVC_APP:
5918 if (mfx->serviceapplication) {
5919 if (mfx->serviceapplication->appsvc) {
5920 appcontrol = mfx->serviceapplication->appsvc;
5927 for (; appcontrol; appcontrol = appcontrol->next) {
5928 op = appcontrol->operation;
5929 for (; op; op = op->next)
5931 op = appcontrol->operation;
5933 ui = appcontrol->uri;
5934 for (; ui; ui = ui->next)
5936 ui = appcontrol->uri;
5938 mi = appcontrol->mime;
5939 for (; mi; mi = mi->next)
5941 mi = appcontrol->mime;
5943 sa = appcontrol->subapp;
5944 for (; sa; sa = sa->next)
5946 sa = appcontrol->subapp;
5948 operation = (char **)calloc(oc, sizeof(char *));
5949 for (i = 0; i < oc; i++) {
5950 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5954 uri = (char **)calloc(uc, sizeof(char *));
5955 for (i = 0; i < uc; i++) {
5956 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5960 mime = (char **)calloc(mc, sizeof(char *));
5961 for (i = 0; i < mc; i++) {
5962 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5966 subapp = (char **)calloc(sc, sizeof(char *));
5967 for (i = 0; i < sc; i++) {
5968 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5972 /*populate appcontrol handle*/
5973 ptr->operation_count = oc;
5974 ptr->uri_count = uc;
5975 ptr->mime_count = mc;
5976 ptr->subapp_count = sc;
5977 ptr->operation = operation;
5980 ptr->subapp = subapp;
5982 ret = appcontrol_func((void *)ptr, user_data);
5983 for (i = 0; i < oc; i++) {
5986 operation[i] = NULL;
5993 for (i = 0; i < uc; i++) {
6003 for (i = 0; i < mc; i++) {
6013 for (i = 0; i < sc; i++) {
6030 pkgmgr_parser_free_manifest_xml(mfx);
6038 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6039 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6041 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6042 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6050 char *manifest = NULL;
6051 char **operation = NULL;
6054 char **subapp = NULL;
6055 appcontrol_x *appcontrol = NULL;
6056 manifest_x *mfx = NULL;
6057 operation_x *op = NULL;
6060 subapp_x *sa = NULL;
6061 pkgmgrinfo_app_component component;
6062 pkgmgrinfo_appcontrol_x *ptr = NULL;
6063 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6065 _LOGE("Failed to get package name\n");
6066 return PMINFO_R_ERROR;
6068 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6070 _LOGE("Failed to get app component name\n");
6071 return PMINFO_R_ERROR;
6073 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6074 if (manifest == NULL) {
6075 _LOGE("Failed to fetch package manifest file\n");
6076 return PMINFO_R_ERROR;
6078 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6080 _LOGE("Failed to parse package manifest file\n");
6083 return PMINFO_R_ERROR;
6086 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6088 _LOGE("Out of Memory!!!\n");
6089 pkgmgr_parser_free_manifest_xml(mfx);
6090 return PMINFO_R_ERROR;
6092 /*Get Operation, Uri, Mime*/
6093 switch (component) {
6095 if (mfx->uiapplication) {
6096 if (mfx->uiapplication->appsvc) {
6097 appcontrol = mfx->uiapplication->appsvc;
6101 case PMINFO_SVC_APP:
6102 if (mfx->serviceapplication) {
6103 if (mfx->serviceapplication->appsvc) {
6104 appcontrol = mfx->serviceapplication->appsvc;
6111 for (; appcontrol; appcontrol = appcontrol->next) {
6112 op = appcontrol->operation;
6113 for (; op; op = op->next)
6115 op = appcontrol->operation;
6117 ui = appcontrol->uri;
6118 for (; ui; ui = ui->next)
6120 ui = appcontrol->uri;
6122 mi = appcontrol->mime;
6123 for (; mi; mi = mi->next)
6125 mi = appcontrol->mime;
6127 sa = appcontrol->subapp;
6128 for (; sa; sa = sa->next)
6130 sa = appcontrol->subapp;
6132 operation = (char **)calloc(oc, sizeof(char *));
6133 for (i = 0; i < oc; i++) {
6134 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6138 uri = (char **)calloc(uc, sizeof(char *));
6139 for (i = 0; i < uc; i++) {
6140 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6144 mime = (char **)calloc(mc, sizeof(char *));
6145 for (i = 0; i < mc; i++) {
6146 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6150 subapp = (char **)calloc(sc, sizeof(char *));
6151 for (i = 0; i < sc; i++) {
6152 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6156 /*populate appcontrol handle*/
6157 ptr->operation_count = oc;
6158 ptr->uri_count = uc;
6159 ptr->mime_count = mc;
6160 ptr->subapp_count = sc;
6161 ptr->operation = operation;
6164 ptr->subapp = subapp;
6166 ret = appcontrol_func((void *)ptr, user_data);
6167 for (i = 0; i < oc; i++) {
6170 operation[i] = NULL;
6177 for (i = 0; i < uc; i++) {
6187 for (i = 0; i < mc; i++) {
6197 for (i = 0; i < sc; i++) {
6214 pkgmgr_parser_free_manifest_xml(mfx);
6222 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6224 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6225 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6227 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6228 val = (char *)info->uiapp_info->nodisplay;
6230 if (strcasecmp(val, "true") == 0)
6232 else if (strcasecmp(val, "false") == 0)
6240 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6242 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6243 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6245 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6246 val = (char *)info->uiapp_info->multiple;
6248 if (strcasecmp(val, "true") == 0)
6250 else if (strcasecmp(val, "false") == 0)
6258 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6260 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6261 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6263 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6264 val = (char *)info->uiapp_info->indicatordisplay;
6266 if (strcasecmp(val, "true") == 0){
6267 *indicator_disp = 1;
6268 }else if (strcasecmp(val, "false") == 0){
6269 *indicator_disp = 0;
6271 *indicator_disp = 0;
6277 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6279 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6280 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6282 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6283 val = (char *)info->uiapp_info->taskmanage;
6285 if (strcasecmp(val, "true") == 0)
6287 else if (strcasecmp(val, "false") == 0)
6295 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6297 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6298 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6300 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6301 if (info->app_component == PMINFO_UI_APP)
6302 val = (char *)info->uiapp_info->enabled;
6303 else if (info->app_component == PMINFO_SVC_APP)
6304 val = (char *)info->uiapp_info->enabled;
6306 _LOGE("invalid component type\n");
6307 return PMINFO_R_EINVAL;
6311 if (strcasecmp(val, "true") == 0)
6313 else if (strcasecmp(val, "false") == 0)
6322 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6324 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6325 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6327 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6328 val = (char *)info->svcapp_info->onboot;
6330 if (strcasecmp(val, "true") == 0)
6332 else if (strcasecmp(val, "false") == 0)
6340 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6342 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6343 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6345 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6346 val = (char *)info->svcapp_info->autorestart;
6348 if (strcasecmp(val, "true") == 0)
6350 else if (strcasecmp(val, "false") == 0)
6358 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6360 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6361 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6363 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6364 val = (char *)info->uiapp_info->mainapp;
6366 if (strcasecmp(val, "true") == 0)
6368 else if (strcasecmp(val, "false") == 0)
6376 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6378 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6379 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6381 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6382 val = (char *)info->uiapp_info->preload;
6384 if (strcasecmp(val, "true") == 0)
6386 else if (strcasecmp(val, "false") == 0)
6394 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6397 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6399 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6400 val = (char *)info->uiapp_info->submode;
6402 if (strcasecmp(val, "true") == 0)
6404 else if (strcasecmp(val, "false") == 0)
6412 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6414 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6415 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6416 __cleanup_appinfo(info);
6420 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6422 return (pkgmgrinfo_pkginfo_filter_create(handle));
6425 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6427 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6430 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6431 const char *property, const int value)
6433 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6434 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6435 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6437 GSList *link = NULL;
6439 prop = _pminfo_appinfo_convert_to_prop_int(property);
6440 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6441 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6442 _LOGE("Invalid Integer Property\n");
6443 return PMINFO_R_EINVAL;
6445 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6446 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6448 _LOGE("Out of Memory!!!\n");
6449 return PMINFO_R_ERROR;
6451 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6452 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6454 _LOGE("Out of Memory\n");
6457 return PMINFO_R_ERROR;
6461 /*If API is called multiple times for same property, we should override the previous values.
6462 Last value set will be used for filtering.*/
6463 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6465 filter->list = g_slist_delete_link(filter->list, link);
6466 filter->list = g_slist_append(filter->list, (gpointer)node);
6471 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6472 const char *property, const bool value)
6474 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6475 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6477 GSList *link = NULL;
6479 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6480 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6481 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6482 _LOGE("Invalid Boolean Property\n");
6483 return PMINFO_R_EINVAL;
6485 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6486 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6488 _LOGE("Out of Memory!!!\n");
6489 return PMINFO_R_ERROR;
6492 val = strndup("('true','True')", 15);
6494 val = strndup("('false','False')", 17);
6496 _LOGE("Out of Memory\n");
6499 return PMINFO_R_ERROR;
6503 /*If API is called multiple times for same property, we should override the previous values.
6504 Last value set will be used for filtering.*/
6505 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6507 filter->list = g_slist_delete_link(filter->list, link);
6508 filter->list = g_slist_append(filter->list, (gpointer)node);
6513 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6514 const char *property, const char *value)
6516 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6517 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6518 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6520 pkgmgrinfo_node_x *ptr = NULL;
6521 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6522 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6523 GSList *link = NULL;
6525 prop = _pminfo_appinfo_convert_to_prop_str(property);
6526 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6527 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6528 _LOGE("Invalid String Property\n");
6529 return PMINFO_R_EINVAL;
6531 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6532 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6534 _LOGE("Out of Memory!!!\n");
6535 return PMINFO_R_ERROR;
6539 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6540 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6541 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6543 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6545 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6547 filter->list = g_slist_delete_link(filter->list, link);
6548 filter->list = g_slist_append(filter->list, (gpointer)node);
6550 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6551 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6552 case E_PMINFO_APPINFO_PROP_APP_URI:
6553 case E_PMINFO_APPINFO_PROP_APP_MIME:
6554 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6556 _LOGE("Out of Memory\n");
6559 return PMINFO_R_ERROR;
6561 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6563 ptr = (pkgmgrinfo_node_x *)link->data;
6564 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6565 _LOGE("Previous value is %s\n", prev);
6566 filter->list = g_slist_delete_link(filter->list, link);
6567 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6568 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6569 _LOGE("New value is %s\n", val);
6571 filter->list = g_slist_append(filter->list, (gpointer)node);
6572 memset(temp, '\0', PKG_STRING_LEN_MAX);
6574 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6575 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6576 _LOGE("First value is %s\n", val);
6578 filter->list = g_slist_append(filter->list, (gpointer)node);
6579 memset(temp, '\0', PKG_STRING_LEN_MAX);
6583 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6584 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6586 filter->list = g_slist_delete_link(filter->list, link);
6587 filter->list = g_slist_append(filter->list, (gpointer)node);
6593 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6595 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6596 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6597 char *syslocale = NULL;
6598 char *locale = NULL;
6599 char *condition = NULL;
6600 char *error_message = NULL;
6601 char query[MAX_QUERY_LEN] = {'\0'};
6602 char where[MAX_QUERY_LEN] = {'\0'};
6606 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6607 /*Get current locale*/
6608 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6609 if (syslocale == NULL) {
6610 _LOGE("current locale is NULL\n");
6611 return PMINFO_R_ERROR;
6613 locale = __convert_system_locale_to_manifest_locale(syslocale);
6614 if (locale == NULL) {
6615 _LOGE("manifest locale is NULL\n");
6617 return PMINFO_R_ERROR;
6620 ret = __open_manifest_db(uid);
6622 _LOGE("Fail to open manifest DB\n");
6623 ret = PMINFO_R_ERROR;
6627 /*Start constructing query*/
6628 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6630 /*Get where clause*/
6631 for (list = filter->list; list; list = g_slist_next(list)) {
6632 __get_filter_condition(list->data, &condition);
6634 strncat(where, condition, sizeof(where) - strlen(where) -1);
6635 where[sizeof(where) - 1] = '\0';
6639 if (g_slist_next(list)) {
6640 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6641 where[sizeof(where) - 1] = '\0';
6644 _LOGE("where = %s\n", where);
6645 if (strlen(where) > 0) {
6646 strncat(query, where, sizeof(query) - strlen(query) - 1);
6647 query[sizeof(query) - 1] = '\0';
6649 _LOGE("query = %s\n", query);
6653 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
6654 _LOGE("Don't execute query = %s error message = %s\n", query,
6656 sqlite3_free(error_message);
6657 sqlite3_close(manifest_db);
6658 ret = PMINFO_R_ERROR;
6672 sqlite3_close(manifest_db);
6676 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6678 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6681 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6682 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6684 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6685 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6686 char *syslocale = NULL;
6687 char *locale = NULL;
6688 char *condition = NULL;
6689 char *error_message = NULL;
6690 char query[MAX_QUERY_LEN] = {'\0'};
6691 char where[MAX_QUERY_LEN] = {'\0'};
6694 uiapplication_x *ptr1 = NULL;
6695 serviceapplication_x *ptr2 = NULL;
6696 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6697 /*Get current locale*/
6698 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6699 if (syslocale == NULL) {
6700 _LOGE("current locale is NULL\n");
6701 return PMINFO_R_ERROR;
6703 locale = __convert_system_locale_to_manifest_locale(syslocale);
6704 if (locale == NULL) {
6705 _LOGE("manifest locale is NULL\n");
6707 return PMINFO_R_ERROR;
6710 ret = __open_manifest_db(uid);
6712 _LOGE("Fail to open manifest DB\n");
6713 ret = PMINFO_R_ERROR;
6716 /*Start constructing query*/
6717 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6718 /*Get where clause*/
6719 for (list = filter->list; list; list = g_slist_next(list)) {
6720 __get_filter_condition(list->data, &condition);
6722 strncat(where, condition, sizeof(where) - strlen(where) -1);
6723 where[sizeof(where) - 1] = '\0';
6727 if (g_slist_next(list)) {
6728 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6729 where[sizeof(where) - 1] = '\0';
6732 _LOGE("where = %s\n", where);
6733 if (strlen(where) > 0) {
6734 strncat(query, where, sizeof(query) - strlen(query) - 1);
6735 query[sizeof(query) - 1] = '\0';
6737 _LOGE("query = %s\n", query);
6738 /*To get filtered list*/
6739 pkgmgr_pkginfo_x *info = NULL;
6740 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6742 _LOGE("Out of Memory!!!\n");
6743 ret = PMINFO_R_ERROR;
6746 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6747 if (info->manifest_info == NULL) {
6748 _LOGE("Out of Memory!!!\n");
6749 ret = PMINFO_R_ERROR;
6752 /*To get detail app info for each member of filtered list*/
6753 pkgmgr_pkginfo_x *filtinfo = NULL;
6754 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6755 if (filtinfo == NULL) {
6756 _LOGE("Out of Memory!!!\n");
6757 ret = PMINFO_R_ERROR;
6760 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6761 if (filtinfo->manifest_info == NULL) {
6762 _LOGE("Out of Memory!!!\n");
6763 ret = PMINFO_R_ERROR;
6766 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6767 if (appinfo == NULL) {
6768 _LOGE("Out of Memory!!!\n");
6769 ret = PMINFO_R_ERROR;
6773 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
6774 _LOGE("Don't execute query = %s error message = %s\n", query,
6776 sqlite3_free(error_message);
6777 sqlite3_close(manifest_db);
6778 ret = PMINFO_R_ERROR;
6781 memset(query, '\0', MAX_QUERY_LEN);
6782 if (info->manifest_info->uiapplication) {
6783 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6784 info->manifest_info->uiapplication = ptr1;
6786 if (info->manifest_info->serviceapplication) {
6787 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6788 info->manifest_info->serviceapplication = ptr2;
6790 /*Filtered UI Apps*/
6791 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6793 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6794 ptr1->appid, "uiapp");
6796 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6797 _LOGE("Don't execute query = %s error message = %s\n", query,
6799 sqlite3_free(error_message);
6800 sqlite3_close(manifest_db);
6801 ret = PMINFO_R_ERROR;
6805 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6807 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6808 ptr2->appid, "svcapp");
6810 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6811 _LOGE("Don't execute query = %s error message = %s\n", query,
6813 sqlite3_free(error_message);
6814 sqlite3_close(manifest_db);
6815 ret = PMINFO_R_ERROR;
6819 if (filtinfo->manifest_info->uiapplication) {
6820 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6821 filtinfo->manifest_info->uiapplication = ptr1;
6823 /*If the callback func return < 0 we break and no more call back is called*/
6826 appinfo->locale = strdup(locale);
6827 appinfo->uiapp_info = ptr1;
6828 appinfo->app_component = PMINFO_UI_APP;
6829 ret = app_cb((void *)appinfo, user_data);
6834 /*Filtered Service Apps*/
6835 if (filtinfo->manifest_info->serviceapplication) {
6836 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6837 filtinfo->manifest_info->serviceapplication = ptr2;
6839 /*If the callback func return < 0 we break and no more call back is called*/
6842 appinfo->locale = strdup(locale);
6843 appinfo->svcapp_info = ptr2;
6844 appinfo->app_component = PMINFO_SVC_APP;
6845 ret = app_cb((void *)appinfo, user_data);
6860 sqlite3_close(manifest_db);
6865 __cleanup_pkginfo(info);
6866 __cleanup_pkginfo(filtinfo);
6870 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6871 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6873 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6876 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6878 return (pkgmgrinfo_pkginfo_filter_create(handle));
6881 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6883 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6886 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6887 const char *key, const char *value)
6889 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6890 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6891 /*value can be NULL. In that case all apps with specified key should be displayed*/
6895 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6896 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6897 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6899 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6903 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6906 /*If API is called multiple times, we should OR all conditions.*/
6907 filter->list = g_slist_append(filter->list, (gpointer)node);
6908 /*All memory will be freed in destroy API*/
6926 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6927 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6929 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6930 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6931 char *syslocale = NULL;
6932 char *locale = NULL;
6933 char *condition = NULL;
6934 char *error_message = NULL;
6935 char query[MAX_QUERY_LEN] = {'\0'};
6936 char where[MAX_QUERY_LEN] = {'\0'};
6939 pkgmgr_pkginfo_x *info = NULL;
6940 pkgmgr_pkginfo_x *filtinfo = NULL;
6941 pkgmgr_appinfo_x *appinfo = NULL;
6942 uiapplication_x *ptr1 = NULL;
6943 serviceapplication_x *ptr2 = NULL;
6944 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6946 /*Get current locale*/
6947 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6948 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
6949 locale = __convert_system_locale_to_manifest_locale(syslocale);
6950 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6952 ret = __open_manifest_db(uid);
6953 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Fail to open manifest DB\n");
6955 /*Start constructing query*/
6956 memset(where, '\0', MAX_QUERY_LEN);
6957 memset(query, '\0', MAX_QUERY_LEN);
6958 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6959 /*Get where clause*/
6960 for (list = filter->list; list; list = g_slist_next(list)) {
6961 __get_metadata_filter_condition(list->data, &condition);
6963 strncat(where, condition, sizeof(where) - strlen(where) -1);
6967 if (g_slist_next(list)) {
6968 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6971 _LOGE("where = %s (%d)\n", where, strlen(where));
6972 if (strlen(where) > 0) {
6973 strncat(query, where, sizeof(query) - strlen(query) - 1);
6975 _LOGE("query = %s (%d)\n", query, strlen(query));
6976 /*To get filtered list*/
6977 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6978 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6980 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6981 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6983 /*To get detail app info for each member of filtered list*/
6984 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6985 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6987 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6988 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6990 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6991 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6993 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
6994 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6995 memset(query, '\0', MAX_QUERY_LEN);
6997 if (info->manifest_info->uiapplication) {
6998 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6999 info->manifest_info->uiapplication = ptr1;
7001 if (info->manifest_info->serviceapplication) {
7002 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7003 info->manifest_info->serviceapplication = ptr2;
7007 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7009 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7010 ptr1->appid, "uiapp");
7011 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7012 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7013 memset(query, '\0', MAX_QUERY_LEN);
7016 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7018 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7019 ptr2->appid, "svcapp");
7020 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7021 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7022 memset(query, '\0', MAX_QUERY_LEN);
7024 /*Filtered UI Apps*/
7025 if (filtinfo->manifest_info->uiapplication) {
7026 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7027 filtinfo->manifest_info->uiapplication = ptr1;
7029 /*If the callback func return < 0 we break and no more call back is called*/
7032 appinfo->locale = strdup(locale);
7033 appinfo->uiapp_info = ptr1;
7034 appinfo->app_component = PMINFO_UI_APP;
7035 ret = app_cb((void *)appinfo, user_data);
7040 /*Filtered Service Apps*/
7041 if (filtinfo->manifest_info->serviceapplication) {
7042 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7043 filtinfo->manifest_info->serviceapplication = ptr2;
7045 /*If the callback func return < 0 we break and no more call back is called*/
7048 appinfo->locale = strdup(locale);
7049 appinfo->svcapp_info = ptr2;
7050 appinfo->app_component = PMINFO_SVC_APP;
7051 ret = app_cb((void *)appinfo, user_data);
7066 sqlite3_free(error_message);
7067 sqlite3_close(manifest_db);
7072 __cleanup_pkginfo(info);
7073 __cleanup_pkginfo(filtinfo);
7077 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7078 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7080 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7083 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7085 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7086 pkgmgr_certinfo_x *certinfo = NULL;
7087 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7088 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7089 *handle = (void *)certinfo;
7093 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
7095 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7096 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7097 pkgmgr_certinfo_x *certinfo = NULL;
7098 char *error_message = NULL;
7099 int ret = PMINFO_R_OK;
7100 char query[MAX_QUERY_LEN] = {'\0'};
7105 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7106 SQLITE_OPEN_READWRITE, NULL);
7107 if (ret != SQLITE_OK) {
7108 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7109 return PMINFO_R_ERROR;
7111 _check_create_Cert_db(cert_db);
7113 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7115 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7116 _LOGE("Don't execute query = %s error message = %s\n", query,
7118 sqlite3_free(error_message);
7119 ret = PMINFO_R_ERROR;
7123 _LOGE("Package not found in DB\n");
7124 ret = PMINFO_R_ERROR;
7127 certinfo = (pkgmgr_certinfo_x *)handle;
7128 /*populate certinfo from DB*/
7129 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7130 ret = __exec_certinfo_query(query, (void *)certinfo);
7132 _LOGE("Package Cert Info DB Information retrieval failed\n");
7133 ret = PMINFO_R_ERROR;
7136 for (i = 0; i < MAX_CERT_TYPE; i++) {
7137 memset(query, '\0', MAX_QUERY_LEN);
7138 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7139 ret = __exec_certinfo_query(query, (void *)certinfo);
7141 _LOGE("Cert Info DB Information retrieval failed\n");
7142 ret = PMINFO_R_ERROR;
7145 if (certinfo->cert_value) {
7146 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7147 free(certinfo->cert_value);
7148 certinfo->cert_value = NULL;
7152 sqlite3_close(cert_db);
7156 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7158 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7159 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7160 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7161 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7162 pkgmgr_certinfo_x *certinfo = NULL;
7163 certinfo = (pkgmgr_certinfo_x *)handle;
7164 if ((certinfo->cert_info)[cert_type])
7165 *cert_value = (certinfo->cert_info)[cert_type];
7171 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7173 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7175 pkgmgr_certinfo_x *certinfo = NULL;
7176 certinfo = (pkgmgr_certinfo_x *)handle;
7177 if (certinfo->pkgid) {
7178 free(certinfo->pkgid);
7179 certinfo->pkgid = NULL;
7181 for (i = 0; i < MAX_CERT_TYPE; i++) {
7182 if ((certinfo->cert_info)[i]) {
7183 free((certinfo->cert_info)[i]);
7184 (certinfo->cert_info)[i] = NULL;
7192 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7194 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7195 pkgmgr_instcertinfo_x *certinfo = NULL;
7196 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7197 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7198 *handle = (void *)certinfo;
7202 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7204 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7205 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7206 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7207 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7208 pkgmgr_instcertinfo_x *certinfo = NULL;
7209 certinfo = (pkgmgr_instcertinfo_x *)handle;
7210 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7214 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
7216 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7218 char *error_message = NULL;
7219 char query[MAX_QUERY_LEN] = {'\0'};
7220 char *vquery = NULL;
7225 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7232 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7233 pkgmgr_certindexinfo_x *indexinfo = NULL;
7234 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7235 if (indexinfo == NULL) {
7236 _LOGE("Out of Memory!!!");
7237 return PMINFO_R_ERROR;
7239 info->pkgid = strdup(pkgid);
7242 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7243 SQLITE_OPEN_READWRITE, NULL);
7244 if (ret != SQLITE_OK) {
7245 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7246 ret = PMINFO_R_ERROR;
7249 _check_create_Cert_db(cert_db);
7250 /*Begin Transaction*/
7251 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7252 if (ret != SQLITE_OK) {
7253 _LOGE("Failed to begin transaction\n");
7254 ret = PMINFO_R_ERROR;
7257 _LOGE("Transaction Begin\n");
7258 /*Check if request is to insert/update*/
7259 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7261 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7262 _LOGE("Don't execute query = %s error message = %s\n", query,
7264 sqlite3_free(error_message);
7265 ret = PMINFO_R_ERROR;
7270 We cant just issue update query directly. We need to manage index table also.
7271 Hence it is better to delete and insert again in case of update*/
7272 ret = __delete_certinfo(pkgid);
7274 _LOGE("Certificate Deletion Failed\n");
7276 for (i = 0; i < MAX_CERT_TYPE; i++) {
7277 if ((info->cert_info)[i]) {
7278 for (j = 0; j < i; j++) {
7279 if ( (info->cert_info)[j]) {
7280 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7281 (info->cert_id)[i] = (info->cert_id)[j];
7282 (info->is_new)[i] = 0;
7283 (info->ref_count)[i] = (info->ref_count)[j];
7290 memset(query, '\0', MAX_QUERY_LEN);
7291 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7292 "where cert_info='%s'",(info->cert_info)[i]);
7293 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7295 _LOGE("Cert Info DB Information retrieval failed\n");
7296 ret = PMINFO_R_ERROR;
7299 if (indexinfo->cert_id == 0) {
7300 /*New certificate. Get newid*/
7301 memset(query, '\0', MAX_QUERY_LEN);
7302 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7304 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
7305 _LOGE("Don't execute query = %s error message = %s\n", query,
7307 sqlite3_free(error_message);
7308 ret = PMINFO_R_ERROR;
7316 indexinfo->cert_id = maxid;
7317 indexinfo->cert_ref_count = 1;
7321 (info->cert_id)[i] = indexinfo->cert_id;
7322 (info->is_new)[i] = is_new;
7323 (info->ref_count)[i] = indexinfo->cert_ref_count;
7324 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
7325 indexinfo->cert_id = 0;
7326 indexinfo->cert_ref_count = 0;
7330 len = MAX_QUERY_LEN;
7331 for (i = 0; i < MAX_CERT_TYPE; i++) {
7332 if ((info->cert_info)[i])
7333 len+= strlen((info->cert_info)[i]);
7335 vquery = (char *)calloc(1, len);
7337 snprintf(vquery, len,
7338 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7339 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7340 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7341 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7342 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7343 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7344 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7345 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7347 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7348 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7350 sqlite3_free(error_message);
7351 ret = PMINFO_R_ERROR;
7354 /*Update index table info*/
7355 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7356 for (i = 0; i < MAX_CERT_TYPE; i++) {
7357 if ((info->cert_info)[i]) {
7358 memset(vquery, '\0', len);
7359 if ((info->is_new)[i]) {
7360 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7361 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7362 unique_id[c++] = (info->cert_id)[i];
7365 for (j = 0; j < MAX_CERT_TYPE; j++) {
7366 if ((info->cert_id)[i] == unique_id[j]) {
7367 /*Ref count has already been increased. Just continue*/
7371 if (j == MAX_CERT_TYPE)
7372 unique_id[c++] = (info->cert_id)[i];
7375 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7376 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7379 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7380 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7382 sqlite3_free(error_message);
7383 ret = PMINFO_R_ERROR;
7388 /*Commit transaction*/
7389 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7390 if (ret != SQLITE_OK) {
7391 _LOGE("Failed to commit transaction, Rollback now\n");
7392 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7393 ret = PMINFO_R_ERROR;
7396 _LOGE("Transaction Commit and End\n");
7399 sqlite3_close(cert_db);
7411 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7413 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7415 pkgmgr_instcertinfo_x *certinfo = NULL;
7416 certinfo = (pkgmgr_instcertinfo_x *)handle;
7417 if (certinfo->pkgid) {
7418 free(certinfo->pkgid);
7419 certinfo->pkgid = NULL;
7421 for (i = 0; i < MAX_CERT_TYPE; i++) {
7422 if ((certinfo->cert_info)[i]) {
7423 free((certinfo->cert_info)[i]);
7424 (certinfo->cert_info)[i] = NULL;
7432 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7434 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7437 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7438 SQLITE_OPEN_READWRITE, NULL);
7439 if (ret != SQLITE_OK) {
7440 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7441 ret = PMINFO_R_ERROR;
7444 _check_create_Cert_db(cert_db);
7445 /*Begin Transaction*/
7446 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7447 if (ret != SQLITE_OK) {
7448 _LOGE("Failed to begin transaction\n");
7449 ret = PMINFO_R_ERROR;
7452 _LOGE("Transaction Begin\n");
7453 ret = __delete_certinfo(pkgid);
7455 _LOGE("Certificate Deletion Failed\n");
7457 _LOGE("Certificate Deletion Success\n");
7459 /*Commit transaction*/
7460 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7461 if (ret != SQLITE_OK) {
7462 _LOGE("Failed to commit transaction, Rollback now\n");
7463 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7464 ret = PMINFO_R_ERROR;
7467 _LOGE("Transaction Commit and End\n");
7470 sqlite3_close(cert_db);
7474 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7476 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7477 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7479 char *manifest = NULL;
7480 manifest_x *mfx = NULL;
7482 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7483 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7485 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7490 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7492 *handle = (void *)mfx;
7497 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7499 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7500 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7502 char *manifest = NULL;
7503 manifest_x *mfx = NULL;
7505 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7506 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7508 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7513 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7515 *handle = (void *)mfx;
7520 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7522 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7523 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7525 int len = strlen(type);
7526 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7528 manifest_x *mfx = (manifest_x *)handle;
7530 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7534 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7536 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7537 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7539 int len = strlen(version);
7540 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7542 manifest_x *mfx = (manifest_x *)handle;
7544 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7548 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7550 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7551 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7553 manifest_x *mfx = (manifest_x *)handle;
7555 if (location == INSTALL_INTERNAL)
7556 strcpy(mfx->installlocation, "internal-only");
7557 else if (location == INSTALL_EXTERNAL)
7558 strcpy(mfx->installlocation, "prefer-external");
7563 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7565 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7566 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7568 manifest_x *mfx = (manifest_x *)handle;
7570 mfx->package_size = strdup(size);
7575 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7577 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7578 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7580 int len = strlen(label_txt);
7581 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7583 manifest_x *mfx = (manifest_x *)handle;
7585 label_x *label = calloc(1, sizeof(label_x));
7586 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7588 LISTADD(mfx->label, label);
7590 mfx->label->lang = strdup(locale);
7592 mfx->label->lang = strdup(DEFAULT_LOCALE);
7593 mfx->label->text = strdup(label_txt);
7598 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7600 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7601 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7603 int len = strlen(icon_txt);
7604 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7606 manifest_x *mfx = (manifest_x *)handle;
7608 icon_x *icon = calloc(1, sizeof(icon_x));
7609 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7611 LISTADD(mfx->icon, icon);
7613 mfx->icon->lang = strdup(locale);
7615 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7616 mfx->icon->text = strdup(icon_txt);
7621 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7623 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7624 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7626 int len = strlen(desc_txt);
7627 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7629 manifest_x *mfx = (manifest_x *)handle;
7631 description_x *description = calloc(1, sizeof(description_x));
7632 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7634 LISTADD(mfx->description, description);
7636 mfx->description->lang = strdup(locale);
7638 mfx->description->lang = strdup(DEFAULT_LOCALE);
7639 mfx->description->text = strdup(desc_txt);
7644 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7645 const char *author_email, const char *author_href, const char *locale)
7647 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7648 manifest_x *mfx = (manifest_x *)handle;
7649 author_x *author = calloc(1, sizeof(author_x));
7650 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7652 LISTADD(mfx->author, author);
7654 mfx->author->text = strdup(author_name);
7656 mfx->author->email = strdup(author_email);
7658 mfx->author->href = strdup(author_href);
7660 mfx->author->lang = strdup(locale);
7662 mfx->author->lang = strdup(DEFAULT_LOCALE);
7666 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7668 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7669 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7671 manifest_x *mfx = (manifest_x *)handle;
7674 strcpy(mfx->removable, "false");
7675 else if (removable == 1)
7676 strcpy(mfx->removable, "true");
7681 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7683 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7684 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7686 manifest_x *mfx = (manifest_x *)handle;
7689 strcpy(mfx->preload, "false");
7690 else if (preload == 1)
7691 strcpy(mfx->preload, "true");
7696 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7698 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7699 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7701 manifest_x *mfx = (manifest_x *)handle;
7703 if (location == INSTALL_INTERNAL)
7704 strcpy(mfx->installed_storage, "installed_internal");
7705 else if (location == INSTALL_EXTERNAL)
7706 strcpy(mfx->installed_storage, "installed_external");
7711 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7713 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7716 manifest_x *mfx = NULL;
7717 mfx = (manifest_x *)handle;
7719 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7721 _LOGE("Successfully stored info in DB\n");
7724 _LOGE("Failed to store info in DB\n");
7725 return PMINFO_R_ERROR;
7729 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7731 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7734 manifest_x *mfx = NULL;
7735 mfx = (manifest_x *)handle;
7737 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7739 _LOGE("Successfully stored info in DB\n");
7742 _LOGE("Failed to store info in DB\n");
7743 return PMINFO_R_ERROR;
7747 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7749 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7751 manifest_x *mfx = NULL;
7752 mfx = (manifest_x *)handle;
7753 pkgmgr_parser_free_manifest_xml(mfx);
7757 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7759 /* Should be implemented later */
7763 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7765 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7767 char query[MAX_QUERY_LEN] = {'\0'};
7768 ret = __open_manifest_db(uid);
7770 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
7771 ret = db_util_open(MANIFEST_DB, &manifest_db,
7772 DB_UTIL_REGISTER_HOOK_METHOD);
7773 if (ret != SQLITE_OK) {
7774 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPathUID(uid));
7775 return PMINFO_R_ERROR;
7779 /*Begin transaction*/
7780 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7781 if (ret != SQLITE_OK) {
7782 _LOGE("Failed to begin transaction\n");
7783 sqlite3_close(manifest_db);
7784 return PMINFO_R_ERROR;
7786 _LOGD("Transaction Begin\n");
7788 memset(query, '\0', MAX_QUERY_LEN);
7789 snprintf(query, MAX_QUERY_LEN,
7790 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7792 char *error_message = NULL;
7794 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7795 _LOGE("Don't execute query = %s error message = %s\n", query,
7797 sqlite3_free(error_message);
7798 return PMINFO_R_ERROR;
7800 sqlite3_free(error_message);
7802 /*Commit transaction*/
7803 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7804 if (ret != SQLITE_OK) {
7805 _LOGE("Failed to commit transaction. Rollback now\n");
7806 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7807 sqlite3_close(manifest_db);
7808 return PMINFO_R_ERROR;
7810 _LOGD("Transaction Commit and End\n");
7811 sqlite3_close(manifest_db);
7816 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7818 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7821 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7823 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7824 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7825 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7826 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7827 int ret = PMINFO_R_OK;
7828 char query[MAX_QUERY_LEN] = {'\0'};
7829 char *error_message = NULL;
7830 pkgmgr_datacontrol_x *data = NULL;
7832 ret = __open_datacontrol_db();
7834 _LOGE("Fail to open datacontrol DB\n");
7835 return PMINFO_R_ERROR;
7838 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7840 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7841 sqlite3_close(datacontrol_db);
7842 return PMINFO_R_ERROR;
7845 snprintf(query, MAX_QUERY_LEN,
7846 "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",
7850 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
7851 _LOGE("Don't execute query = %s error message = %s\n", query,
7853 sqlite3_free(error_message);
7854 sqlite3_close(datacontrol_db);
7855 return PMINFO_R_ERROR;
7858 *appid = (char *)data->appid;
7859 *access = (char *)data->access;
7861 sqlite3_close(datacontrol_db);
7866 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7868 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7870 char query[MAX_QUERY_LEN] = {'\0'};
7871 char *error_message = NULL;
7872 ret = __open_manifest_db(uid);
7874 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
7875 ret = db_util_open(getUserPkgParserDBPathUID(uid), &manifest_db,
7876 DB_UTIL_REGISTER_HOOK_METHOD);
7877 if (ret != SQLITE_OK) {
7878 _LOGE("connect db [%s] failed! Manifest DB does not exists!!\n", getUserPkgParserDBPathUID(uid));
7879 return PMINFO_R_ERROR;
7883 /*Begin transaction*/
7884 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7885 if (ret != SQLITE_OK) {
7886 _LOGE("Failed to begin transaction\n");
7887 sqlite3_close(manifest_db);
7888 return PMINFO_R_ERROR;
7890 _LOGD("Transaction Begin\n");
7892 memset(query, '\0', MAX_QUERY_LEN);
7893 snprintf(query, MAX_QUERY_LEN,
7894 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7897 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7898 _LOGE("Don't execute query = %s error message = %s\n", query,
7900 sqlite3_free(error_message);
7901 return PMINFO_R_ERROR;
7904 /*Commit transaction*/
7905 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7906 if (ret != SQLITE_OK) {
7907 _LOGE("Failed to commit transaction. Rollback now\n");
7908 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7909 sqlite3_close(manifest_db);
7910 return PMINFO_R_ERROR;
7912 _LOGD("Transaction Commit and End\n");
7913 sqlite3_close(manifest_db);
7918 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7920 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7923 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7925 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7926 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7928 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7929 val = (char *)info->uiapp_info->guestmode_visibility;
7931 if (strcasecmp(val, "true") == 0){
7933 }else if (strcasecmp(val, "false") == 0){
7942 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
7944 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7947 char *noti_string = NULL;
7949 char query[MAX_QUERY_LEN] = {'\0'};
7950 char *errmsg = NULL;
7951 sqlite3 *pkgmgr_parser_db;
7953 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7954 val = (char *)info->uiapp_info->guestmode_visibility;
7957 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
7958 SQLITE_OPEN_READWRITE, NULL);
7960 if (ret != SQLITE_OK) {
7961 _LOGE("DB Open Failed\n");
7962 return PMINFO_R_ERROR;
7965 /*TODO: Write to DB here*/
7967 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7969 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7971 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7972 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7974 sqlite3_close(pkgmgr_parser_db);
7975 return PMINFO_R_ERROR;
7977 sqlite3_close(pkgmgr_parser_db);
7978 len = strlen((char *)info->uiapp_info->appid) + 8;
7979 noti_string = calloc(1, len);
7980 if (noti_string == NULL){
7981 return PMINFO_R_ERROR;
7983 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7984 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7985 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
7992 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7994 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
7997 /* pkgmgrinfo client start*/
7998 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
8001 char *errmsg = NULL;
8003 void *handle = NULL;
8004 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
8006 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8007 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8009 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8011 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8013 pc = __pkgmgr_client_new(ctype);
8014 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8018 return (pkgmgrinfo_client *) pc;
8021 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8024 char *errmsg = NULL;
8025 void *handle = NULL;
8026 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8028 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8029 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8031 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8033 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8035 ret = __pkgmgr_client_set_status_type(pc, status_type);
8036 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8040 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8042 * The lib dependency chain like below
8043 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8045 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8046 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8047 * on libpkgmgr-installer-client.
8049 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8052 * However, when the libdbus call into the callback function, it suddenly fond that the
8053 * function address is gone (unmapped), then we receive a SIGSEGV.
8055 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8056 * robust if we just link to the well-known lib.
8058 * See https://bugs.tizen.org/jira/browse/PTREL-591
8064 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8067 char *errmsg = NULL;
8068 void *handle = NULL;
8069 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8071 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8072 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8074 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8076 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8078 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8079 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8082 /* same as pkgmgrinfo_client_new */
8086 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8089 char *errmsg = NULL;
8090 void *handle = NULL;
8091 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8093 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8094 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8096 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8098 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8100 ret = __pkgmgr_client_free(pc);
8101 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8104 /* same as pkgmgrinfo_client_new */
8108 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8111 DBusConnection *bus;
8112 DBusMessage *message;
8114 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8116 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8119 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8120 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8122 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8123 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8125 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8127 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8128 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8130 dbus_connection_flush(bus);
8131 dbus_message_unref(message);
8136 /* pkgmgrinfo client end*/