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*/
79 #define MMC_PATH tzplatform_mkpath(TZ_SYS_STORAGE, "sdcard")
80 #define PKG_SD_PATH tzplatform_mkpath3(TZ_SYS_STORAGE, "sdcard", "app2sd/")
81 #define PKG_INSTALLATION_PATH tzplatform_mkpath(TZ_USER_APP, "")
83 #define FILTER_QUERY_COUNT_PACKAGE "select count(DISTINCT package_info.package) " \
84 "from package_info LEFT OUTER JOIN package_localized_info " \
85 "ON package_info.package=package_localized_info.package " \
86 "and package_localized_info.package_locale='%s' where "
88 #define FILTER_QUERY_LIST_PACKAGE "select DISTINCT package_info.package " \
89 "from package_info LEFT OUTER JOIN package_localized_info " \
90 "ON package_info.package=package_localized_info.package " \
91 "and package_localized_info.package_locale='%s' where "
93 #define FILTER_QUERY_COUNT_APP "select count(DISTINCT package_app_info.app_id) " \
94 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
95 "ON package_app_info.app_id=package_app_localized_info.app_id " \
96 "and package_app_localized_info.app_locale='%s' " \
97 "LEFT OUTER JOIN package_app_app_svc " \
98 "ON package_app_info.app_id=package_app_app_svc.app_id " \
99 "LEFT OUTER JOIN package_app_app_category " \
100 "ON package_app_info.app_id=package_app_app_category.app_id where "
102 #define FILTER_QUERY_LIST_APP "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
103 "from package_app_info LEFT OUTER JOIN package_app_localized_info " \
104 "ON package_app_info.app_id=package_app_localized_info.app_id " \
105 "and package_app_localized_info.app_locale='%s' " \
106 "LEFT OUTER JOIN package_app_app_svc " \
107 "ON package_app_info.app_id=package_app_app_svc.app_id " \
108 "LEFT OUTER JOIN package_app_app_category " \
109 "ON package_app_info.app_id=package_app_app_category.app_id where "
111 #define METADATA_FILTER_QUERY_SELECT_CLAUSE "select DISTINCT package_app_info.app_id, package_app_info.app_component " \
112 "from package_app_info LEFT OUTER JOIN package_app_app_metadata " \
113 "ON package_app_info.app_id=package_app_app_metadata.app_id where "
115 #define METADATA_FILTER_QUERY_UNION_CLAUSE " UNION "METADATA_FILTER_QUERY_SELECT_CLAUSE
117 #define LANGUAGE_LENGTH 2
118 #define LIBAIL_PATH "/usr/lib/libail.so.0"
120 #define SERVICE_NAME "org.tizen.system.deviced"
121 #define PATH_NAME "/Org/Tizen/System/DeviceD/Mmc"
122 #define INTERFACE_NAME "org.tizen.system.deviced.Mmc"
123 #define METHOD_NAME "RequestMountApp2ext"
127 typedef struct _pkgmgr_instcertinfo_x {
129 char *cert_info[MAX_CERT_TYPE]; /*certificate data*/
130 int is_new[MAX_CERT_TYPE]; /*whether already exist in table or not*/
131 int ref_count[MAX_CERT_TYPE]; /*reference count of certificate data*/
132 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
133 } pkgmgr_instcertinfo_x;
135 typedef struct _pkgmgr_certindexinfo_x {
138 } pkgmgr_certindexinfo_x;
140 typedef struct _pkgmgr_pkginfo_x {
141 manifest_x *manifest_info;
144 struct _pkgmgr_pkginfo_x *prev;
145 struct _pkgmgr_pkginfo_x *next;
148 typedef struct _pkgmgr_cert_x {
153 typedef struct _pkgmgr_datacontrol_x {
156 } pkgmgr_datacontrol_x;
158 typedef struct _pkgmgr_iconpath_x {
163 typedef struct _pkgmgr_image_x {
167 typedef struct _pkgmgr_locale_x {
171 typedef struct _pkgmgr_appinfo_x {
174 pkgmgrinfo_app_component app_component;
176 uiapplication_x *uiapp_info;
177 serviceapplication_x *svcapp_info;
181 typedef struct _pkgmgr_certinfo_x {
184 char *cert_info[MAX_CERT_TYPE]; /*certificate info*/
185 int cert_id[MAX_CERT_TYPE]; /*certificate ID in index table*/
189 typedef struct _pkgmgrinfo_filter_x {
191 } pkgmgrinfo_filter_x;
193 typedef struct _pkgmgrinfo_node_x {
199 typedef struct _pkgmgrinfo_appcontrol_x {
208 } pkgmgrinfo_appcontrol_x;
210 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
212 typedef int (*pkgmgr_handler)(int req_id, const char *pkg_type,
213 const char *pkgid, const char *key,
214 const char *val, const void *pmsg, void *data);
216 typedef void pkgmgr_client;
217 typedef void pkgmgr_info;
222 PM_REQUEST_GET_SIZE = 2,
223 PM_REQUEST_KILL_APP = 3,
224 PM_REQUEST_CHECK_APP = 4,
226 }pkgmgr_request_service_type;
229 PM_GET_TOTAL_SIZE= 0,
230 PM_GET_DATA_SIZE = 1,
232 PM_GET_SIZE_INFO = 3,
233 PM_GET_TOTAL_AND_DATA = 4,
234 PM_GET_SIZE_FILE = 5,
236 }pkgmgr_getsize_type;
244 #define PKG_SIZE_INFO_FILE "/tmp/pkgmgr_size_info.txt"
245 #define MAX_PKG_BUF_LEN 1024
246 #define MAX_PKG_INFO_LEN 10
248 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
249 "(cert_info text not null, " \
250 "cert_id integer, " \
251 "cert_ref_count integer, " \
252 "PRIMARY KEY(cert_id)) "
254 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
255 "(package text not null, " \
256 "author_root_cert integer, " \
257 "author_im_cert integer, " \
258 "author_signer_cert integer, " \
259 "dist_root_cert integer, " \
260 "dist_im_cert integer, " \
261 "dist_signer_cert integer, " \
262 "dist2_root_cert integer, " \
263 "dist2_im_cert integer, " \
264 "dist2_signer_cert integer, " \
265 "PRIMARY KEY(package)) "
268 #define QUERY_ATTACH "attach database '%s' as Global"
269 #define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_category as select distinct * " \
270 "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)"
271 #define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select distinct * "\
272 "from (select * from main.package_app_info m union select * from Global.package_app_info g WHERE m.package=g.package)"
273 #define QUERY_CREATE_VIEW_3 "CREATE temp VIEW package_app_app_control as select distinct * "\
274 "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 "\
275 "AND m.uri_scheme=guri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
276 #define QUERY_CREATE_VIEW_4 "CREATE temp VIEW package_app_localized_info as select distinct * "\
277 "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)"
278 #define QUERY_CREATE_VIEW_5 "CREATE temp VIEW package_app_app_metadata as select distinct * "\
279 "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 "\
280 "AND m.md_value=g.md_value)"
281 #define QUERY_CREATE_VIEW_6 "CREATE temp VIEW package_app_share_allowed as select distinct * "\
282 "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 "\
283 "AND m.data_share_allowed=g.data_share_allowed)"
284 #define QUERY_CREATE_VIEW_7 "CREATE temp VIEW package_app_app_permission as select distinct * "\
285 "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 "\
286 "AND m.pm_value=g.pm_value)"
287 #define QUERY_CREATE_VIEW_8 "CREATE temp VIEW package_app_share_request as select distinct * "\
288 "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)"
289 #define QUERY_CREATE_VIEW_9 "CREATE temp VIEW package_app_app_svc as select distinct * "\
290 "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 "\
291 "AND m.uri_scheme=g.uri_scheme AND m.mime_type=g.mime_type AND m.subapp_name=g.subapp_name)"
292 #define QUERY_CREATE_VIEW_10 "CREATE temp VIEW package_info as select distinct * "\
293 "from (select * from main.package_info m union select * from Global.package_info g WHERE m.package=g.package)"
294 #define QUERY_CREATE_VIEW_11 "CREATE temp VIEW package_app_icon_section_info as select distinct * "\
295 "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 "\
296 "AND m.app_icon_section=g.app_icon_section AND m.app_icon_resolution=g.app_icon_resolution)"
297 #define QUERY_CREATE_VIEW_12 "CREATE temp VIEW package_localized_info as select distinct * "\
298 "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)"
299 #define QUERY_CREATE_VIEW_13 "CREATE temp VIEW package_app_image_info as select distinct * "\
300 "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 "\
301 "AND m.app_icon_resolution=g.app_icon_resolution)"
302 #define QUERY_CREATE_VIEW_14 "CREATE temp VIEW package_privilege_info as select distinct * "\
303 "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)"
307 char *pkgtype = "rpm";
308 __thread sqlite3 *manifest_db = NULL;
309 __thread sqlite3 *datacontrol_db = NULL;
310 __thread sqlite3 *cert_db = NULL;
312 static int __open_manifest_db(uid_t uid);
313 static int __exec_pkginfo_query(char *query, void *data);
314 static int __exec_certinfo_query(char *query, void *data);
315 static int __exec_certindexinfo_query(char *query, void *data);
316 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname);
317 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname);
318 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname);
319 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname);
320 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname);
321 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname);
322 static int __count_cb(void *data, int ncols, char **coltxt, char **colname);
323 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
324 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname);
325 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname);
326 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname);
327 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data);
328 static void __cleanup_appinfo(pkgmgr_appinfo_x *data);
329 static char* __convert_system_locale_to_manifest_locale(char *syslocale);
330 static void __destroy_each_node(gpointer data, gpointer user_data);
331 static void __get_filter_condition(gpointer data, char **condition);
332 static void __get_metadata_filter_condition(gpointer data, char **condition);
333 static gint __compare_func(gconstpointer data1, gconstpointer data2);
334 static int __delete_certinfo(const char *pkgid);
335 static int _check_create_Cert_db( sqlite3 *certdb);
336 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data);
338 static int _pkgmgr_parser_attach_create_view_certdb(sqlite3 *handle, uid_t uid)
340 char *error_message = NULL;
341 char query_attach[MAX_QUERY_LEN] = {'\0'};
342 char query_view[MAX_QUERY_LEN] = {'\0'};
344 if(uid != GLOBAL_USER){
345 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, CERT_DB);
347 sqlite3_exec(handle, query_attach,
348 NULL, NULL, &error_message)) {
349 _LOGD("Don't execute query = %s error message = %s\n",
350 query_attach, error_message);
351 sqlite3_free(error_message);
358 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");
360 sqlite3_exec(handle, query_view,
361 NULL, NULL, &error_message)) {
362 _LOGD("Don't execute query = %s error message = %s\n",
363 query_view, error_message);
364 sqlite3_free(error_message);
366 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");
368 sqlite3_exec(handle, query_view,
369 NULL, NULL, &error_message)) {
370 _LOGD("Don't execute query = %s error message = %s\n",
371 query_view, error_message);
372 sqlite3_free(error_message);
379 static int _pkgmgr_parser_attach_create_view_parserdb(sqlite3 *handle, uid_t uid)
381 char *error_message = NULL;
382 char query_attach[MAX_QUERY_LEN] = {'\0'};
383 char query_view[MAX_QUERY_LEN] = {'\0'};
384 if(uid != GLOBAL_USER){
385 snprintf(query_attach, MAX_QUERY_LEN - 1, QUERY_ATTACH, MANIFEST_DB);
387 sqlite3_exec(handle, query_attach,
388 NULL, NULL, &error_message)) {
389 _LOGD("Don't execute query = %s error message = %s\n",
390 query_attach, error_message);
391 sqlite3_free(error_message);
394 sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
395 NULL, NULL, &error_message)) {
396 _LOGD("Don't execute query = %s error message = %s\n",
397 QUERY_CREATE_VIEW_1, error_message);
398 sqlite3_free(error_message);
401 sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
402 NULL, NULL, &error_message)) {
403 _LOGD("Don't execute query = %s error message = %s\n",
404 QUERY_CREATE_VIEW_2, error_message);
405 sqlite3_free(error_message);
408 sqlite3_exec(handle, QUERY_CREATE_VIEW_3,
409 NULL, NULL, &error_message)) {
410 _LOGD("Don't execute query = %s error message = %s\n",
411 QUERY_CREATE_VIEW_3, error_message);
412 sqlite3_free(error_message);
415 sqlite3_exec(handle, QUERY_CREATE_VIEW_4,
416 NULL, NULL, &error_message)) {
417 _LOGD("Don't execute query = %s error message = %s\n",
418 QUERY_CREATE_VIEW_4, error_message);
419 sqlite3_free(error_message);
422 sqlite3_exec(handle, QUERY_CREATE_VIEW_5,
423 NULL, NULL, &error_message)) {
424 _LOGD("Don't execute query = %s error message = %s\n",
425 QUERY_CREATE_VIEW_5, error_message);
426 sqlite3_free(error_message);
429 sqlite3_exec(handle, QUERY_CREATE_VIEW_6,
430 NULL, NULL, &error_message)) {
431 _LOGD("Don't execute query = %s error message = %s\n",
432 QUERY_CREATE_VIEW_6, error_message);
433 sqlite3_free(error_message);
436 sqlite3_exec(handle, QUERY_CREATE_VIEW_7,
437 NULL, NULL, &error_message)) {
438 _LOGD("Don't execute query = %s error message = %s\n",
439 QUERY_CREATE_VIEW_7, error_message);
440 sqlite3_free(error_message);
443 sqlite3_exec(handle, QUERY_CREATE_VIEW_8,
444 NULL, NULL, &error_message)) {
445 _LOGD("Don't execute query = %s error message = %s\n",
446 QUERY_CREATE_VIEW_8, error_message);
447 sqlite3_free(error_message);
450 sqlite3_exec(handle, QUERY_CREATE_VIEW_9,
451 NULL, NULL, &error_message)) {
452 _LOGD("Don't execute query = %s error message = %s\n",
453 QUERY_CREATE_VIEW_9, error_message);
454 sqlite3_free(error_message);
457 sqlite3_exec(handle, QUERY_CREATE_VIEW_10,
458 NULL, NULL, &error_message)) {
459 _LOGD("Don't execute query = %s error message = %s\n",
460 QUERY_CREATE_VIEW_10, error_message);
461 sqlite3_free(error_message);
464 sqlite3_exec(handle, QUERY_CREATE_VIEW_11,
465 NULL, NULL, &error_message)) {
466 _LOGD("Don't execute query = %s error message = %s\n",
467 QUERY_CREATE_VIEW_11, error_message);
468 sqlite3_free(error_message);
471 sqlite3_exec(handle, QUERY_CREATE_VIEW_12,
472 NULL, NULL, &error_message)) {
473 _LOGD("Don't execute query = %s error message = %s\n",
474 QUERY_CREATE_VIEW_12, error_message);
475 sqlite3_free(error_message);
478 sqlite3_exec(handle, QUERY_CREATE_VIEW_13,
479 NULL, NULL, &error_message)) {
480 _LOGD("Don't execute query = %s error message = %s\n",
481 QUERY_CREATE_VIEW_13, error_message);
482 sqlite3_free(error_message);
485 sqlite3_exec(handle, QUERY_CREATE_VIEW_14,
486 NULL, NULL, &error_message)) {
487 _LOGD("Don't execute query = %s error message = %s\n",
488 QUERY_CREATE_VIEW_14, error_message);
489 sqlite3_free(error_message);
497 static int _check_create_Cert_db( sqlite3 *certdb)
500 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO, NULL, NULL);
503 ret = __exec_db_query(certdb, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO, NULL, NULL);
509 API char *getIconPath(uid_t uid)
512 struct group *grpinfo = NULL;
514 struct passwd *userinfo = getpwuid(uid);
517 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
520 if (uid != GLOBAL_USER) {
521 if (userinfo == NULL) {
522 _LOGE("getpwuid(%d) returns NULL !", uid);
525 grpinfo = getgrnam("users");
526 if (grpinfo == NULL) {
527 _LOGE("getgrnam(users) returns NULL !");
530 // Compare git_t type and not group name
531 if (grpinfo->gr_gid != userinfo->pw_gid) {
532 _LOGE("UID [%d] does not belong to 'users' group!", uid);
535 asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir);
537 result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/");
540 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
541 if (ret == -1 && errno != EEXIST) {
542 _LOGE("FAIL : to create directory %s %d", result, errno);
543 } else if (getuid() == OWNER_ROOT) {
544 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
547 strerror_r(errno, buf, sizeof(buf));
548 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
554 API char *getUserPkgParserDBPath(void)
556 return getUserPkgParserDBPathUID(GLOBAL_USER);
559 API char *getUserPkgParserDBPathUID(uid_t uid)
562 char *journal = NULL;
563 struct group *grpinfo = NULL;
565 struct passwd *userinfo = getpwuid(uid);
568 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
571 if (uid != GLOBAL_USER) {
572 if (userinfo == NULL) {
573 _LOGE("getpwuid(%d) returns NULL !", uid);
576 grpinfo = getgrnam("users");
577 if (grpinfo == NULL) {
578 _LOGE("getgrnam(users) returns NULL !");
581 // Compare git_t type and not group name
582 if (grpinfo->gr_gid != userinfo->pw_gid) {
583 _LOGE("UID [%d] does not belong to 'users' group!", uid);
586 asprintf(&result, "%s/.applications/dbspace/.pkgmgr_parser.db", userinfo->pw_dir);
587 asprintf(&journal, "%s/.applications/dbspace/.pkgmgr_parser.db-journal", userinfo->pw_dir);
589 result = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
590 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db-journal");
592 char *temp = strdup(result);
593 dir = strrchr(temp, '/');
601 int ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
602 if (ret == -1 && errno != EEXIST) {
603 _LOGE("FAIL : to create directory %s %d", temp, errno);
604 } else if (getuid() == OWNER_ROOT) {
605 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
608 strerror_r(errno, buf, sizeof(buf));
609 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
616 API char *getUserPkgCertDBPath(void)
618 return getUserPkgCertDBPathUID(GLOBAL_USER);
621 API char *getUserPkgCertDBPathUID(uid_t uid)
624 char *journal = NULL;
625 struct group *grpinfo = NULL;
627 struct passwd *userinfo = getpwuid(uid);
630 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
633 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 journal = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db-journal");
654 char *temp = strdup(result);
655 dir = strrchr(temp, '/');
663 int ret = mkdir(temp, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
664 if (ret == -1 && errno != EEXIST) {
665 _LOGE("FAIL : to create directory %s %d", temp, errno);
666 } else if (getuid() == OWNER_ROOT) {
667 ret = chown(temp, uid, ((grpinfo)?grpinfo->gr_gid:0));
670 strerror_r(errno, buf, sizeof(buf));
671 _LOGE("FAIL : chown %s %d.%d, because %s", temp, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
678 API const char* getUserDesktopPath(uid_t uid)
681 struct group *grpinfo = NULL;
683 struct passwd *userinfo = getpwuid(uid);
686 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
689 if (uid != GLOBAL_USER) {
690 if (userinfo == NULL) {
691 _LOGE("getpwuid(%d) returns NULL !", uid);
694 grpinfo = getgrnam("users");
695 if (grpinfo == NULL) {
696 _LOGE("getgrnam(users) returns NULL !");
699 // Compare git_t type and not group name
700 if (grpinfo->gr_gid != userinfo->pw_gid) {
701 _LOGE("UID [%d] does not belong to 'users' group!", uid);
704 asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir);
706 result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/");
709 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
710 if (ret == -1 && errno != EEXIST) {
711 _LOGE("FAIL : to create directory %s %d", result, errno);
712 } else if (getuid() == OWNER_ROOT) {
713 ret = chown(result, uid,((grpinfo)?grpinfo->gr_gid:0));
716 strerror_r(errno, buf, sizeof(buf));
717 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
723 API const char* getUserManifestPath(uid_t uid)
726 struct group *grpinfo = NULL;
728 struct passwd *userinfo = getpwuid(uid);
731 _LOGE("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER");
734 if (uid != GLOBAL_USER) {
735 if (userinfo == NULL) {
736 _LOGE("getpwuid(%d) returns NULL !", uid);
739 grpinfo = getgrnam("users");
740 if (grpinfo == NULL) {
741 _LOGE("getgrnam(users) returns NULL !");
744 // Compare git_t type and not group name
745 if (grpinfo->gr_gid != userinfo->pw_gid) {
746 _LOGE("UID [%d] does not belong to 'users' group!", uid);
749 asprintf(&result, "%s/.applications/manifest/", userinfo->pw_dir);
751 result = tzplatform_mkpath(TZ_SYS_RW_PACKAGES, "/");
754 int ret = mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
755 if (ret == -1 && errno != EEXIST) {
756 _LOGE("FAIL : to create directory %s %d", result, errno);
757 } else if (getuid() == OWNER_ROOT) {
758 ret = chown(result, uid, ((grpinfo)?grpinfo->gr_gid:0));
761 strerror_r(errno, buf, sizeof(buf));
762 _LOGE("FAIL : chown %s %d.%d, because %s", result, uid, ((grpinfo)?grpinfo->gr_gid:0), buf);
769 static gint __compare_func(gconstpointer data1, gconstpointer data2)
771 pkgmgrinfo_node_x *node1 = (pkgmgrinfo_node_x*)data1;
772 pkgmgrinfo_node_x *node2 = (pkgmgrinfo_node_x*)data2;
773 if (node1->prop == node2->prop)
775 else if (node1->prop > node2->prop)
781 static int __count_cb(void *data, int ncols, char **coltxt, char **colname)
784 *p = atoi(coltxt[0]);
785 _LOGE("count value is %d\n", *p);
789 static void __destroy_each_node(gpointer data, gpointer user_data)
791 ret_if(data == NULL);
792 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
805 static void __get_metadata_filter_condition(gpointer data, char **condition)
807 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
808 char key[MAX_QUERY_LEN] = {'\0'};
809 char value[MAX_QUERY_LEN] = {'\0'};
811 snprintf(key, MAX_QUERY_LEN, "(package_app_app_metadata.md_key='%s'", node->key);
814 snprintf(value, MAX_QUERY_LEN, " AND package_app_app_metadata.md_value='%s')", node->value);
819 *condition = strdup(key);
823 static void __get_filter_condition(gpointer data, char **condition)
825 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
826 char buf[MAX_QUERY_LEN + 1] = {'\0'};
827 char temp[PKG_STRING_LEN_MAX] = {'\0'};
828 switch (node->prop) {
829 case E_PMINFO_PKGINFO_PROP_PACKAGE_ID:
830 snprintf(buf, MAX_QUERY_LEN, "package_info.package='%s'", node->value);
832 case E_PMINFO_PKGINFO_PROP_PACKAGE_TYPE:
833 snprintf(buf, MAX_QUERY_LEN, "package_info.package_type='%s'", node->value);
835 case E_PMINFO_PKGINFO_PROP_PACKAGE_VERSION:
836 snprintf(buf, MAX_QUERY_LEN, "package_info.package_version='%s'", node->value);
838 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION:
839 snprintf(buf, MAX_QUERY_LEN, "package_info.install_location='%s'", node->value);
841 case E_PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE:
842 snprintf(buf, MAX_QUERY_LEN, "package_info.installed_storage='%s'", node->value);
844 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME:
845 snprintf(buf, MAX_QUERY_LEN, "package_info.author_name='%s'", node->value);
847 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF:
848 snprintf(buf, MAX_QUERY_LEN, "package_info.author_href='%s'", node->value);
850 case E_PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL:
851 snprintf(buf, MAX_QUERY_LEN, "package_info.author_email='%s'", node->value);
853 case E_PMINFO_PKGINFO_PROP_PACKAGE_SIZE:
854 snprintf(buf, MAX_QUERY_LEN, "package_info.package_size='%s'", node->value);
856 case E_PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE:
857 snprintf(buf, MAX_QUERY_LEN, "package_info.package_removable IN %s", node->value);
859 case E_PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD:
860 snprintf(buf, MAX_QUERY_LEN, "package_info.package_preload IN %s", node->value);
862 case E_PMINFO_PKGINFO_PROP_PACKAGE_READONLY:
863 snprintf(buf, MAX_QUERY_LEN, "package_info.package_readonly IN %s", node->value);
865 case E_PMINFO_PKGINFO_PROP_PACKAGE_UPDATE:
866 snprintf(buf, MAX_QUERY_LEN, "package_info.package_update IN %s", node->value);
868 case E_PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING:
869 snprintf(buf, MAX_QUERY_LEN, "package_info.package_appsetting IN %s", node->value);
871 case E_PMINFO_PKGINFO_PROP_PACKAGE_NODISPLAY_SETTING:
872 snprintf(buf, MAX_QUERY_LEN, "package_info.package_nodisplay IN %s", node->value);
875 case E_PMINFO_APPINFO_PROP_APP_ID:
876 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_id='%s'", node->value);
878 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
879 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_component='%s'", node->value);
881 case E_PMINFO_APPINFO_PROP_APP_EXEC:
882 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_exec='%s'", node->value);
884 case E_PMINFO_APPINFO_PROP_APP_ICON:
885 snprintf(buf, MAX_QUERY_LEN, "package_app_localized_info.app_icon='%s'", node->value);
887 case E_PMINFO_APPINFO_PROP_APP_TYPE:
888 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_type='%s'", node->value);
890 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
891 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
892 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.operation IN %s", temp);
894 case E_PMINFO_APPINFO_PROP_APP_URI:
895 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
896 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.uri_scheme IN %s", temp);
898 case E_PMINFO_APPINFO_PROP_APP_MIME:
899 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
900 snprintf(buf, MAX_QUERY_LEN, "package_app_app_svc.mime_type IN %s", temp);
902 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
903 snprintf(temp, PKG_STRING_LEN_MAX, "(%s)", node->value);
904 snprintf(buf, MAX_QUERY_LEN, "package_app_app_category.category IN %s", temp);
906 case E_PMINFO_APPINFO_PROP_APP_NODISPLAY:
907 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_nodisplay IN %s", node->value);
909 case E_PMINFO_APPINFO_PROP_APP_MULTIPLE:
910 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_multiple IN %s", node->value);
912 case E_PMINFO_APPINFO_PROP_APP_ONBOOT:
913 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_onboot IN %s", node->value);
915 case E_PMINFO_APPINFO_PROP_APP_AUTORESTART:
916 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_autorestart IN %s", node->value);
918 case E_PMINFO_APPINFO_PROP_APP_TASKMANAGE:
919 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_taskmanage IN %s", node->value);
921 case E_PMINFO_APPINFO_PROP_APP_HWACCELERATION:
922 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_hwacceleration='%s'", node->value);
924 case E_PMINFO_APPINFO_PROP_APP_SCREENREADER:
925 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_screenreader='%s'", node->value);
927 case E_PMINFO_APPINFO_PROP_APP_LAUNCHCONDITION:
928 snprintf(buf, MAX_QUERY_LEN, "package_app_info.app_launchcondition IN %s", node->value);
931 _LOGE("Invalid Property Type\n");
935 *condition = strdup(buf);
939 static char* __convert_system_locale_to_manifest_locale(char *syslocale)
941 if (syslocale == NULL)
942 return strdup(DEFAULT_LOCALE);
944 locale = (char *)calloc(1, 6);
945 retvm_if(!locale, NULL, "Malloc Failed\n");
947 strncpy(locale, syslocale, 2);
948 strncat(locale, "-", 1);
949 locale[3] = syslocale[3] + 32;
950 locale[4] = syslocale[4] + 32;
954 static void __cleanup_pkginfo(pkgmgr_pkginfo_x *data)
956 ret_if(data == NULL);
958 free((void *)data->locale);
962 pkgmgr_parser_free_manifest_xml(data->manifest_info);
968 static void __cleanup_appinfo(pkgmgr_appinfo_x *data)
970 ret_if(data == NULL);
972 free((void *)data->package);
973 data->package = NULL;
976 free((void *)data->locale);
980 manifest_x *mfx = calloc(1, sizeof(manifest_x));
981 if (data->app_component == PMINFO_UI_APP)
982 mfx->uiapplication = data->uiapp_info;
983 else if (data->app_component == PMINFO_SVC_APP)
984 mfx->serviceapplication = data->svcapp_info;
985 pkgmgr_parser_free_manifest_xml(mfx);
991 static int __open_manifest_db(uid_t uid)
994 if (access(getUserPkgParserDBPathUID(uid), F_OK) == 0) {
996 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
997 SQLITE_OPEN_READONLY, NULL);
998 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
1001 _LOGE("Manifest DB does not exists !!\n");
1005 static int __open_datacontrol_db()
1008 if (access(DATACONTROL_DB, F_OK) == 0) {
1010 db_util_open_with_options(DATACONTROL_DB, &datacontrol_db,
1011 SQLITE_OPEN_READONLY, NULL);
1012 retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n", DATACONTROL_DB);
1015 _LOGE("Datacontrol DB does not exists !!\n");
1019 static int __pkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
1021 pkgmgr_pkginfo_x *udata = (pkgmgr_pkginfo_x *)data;
1023 pkgmgr_pkginfo_x *info = NULL;
1024 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
1025 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
1027 LISTADD(udata, info);
1028 for(i = 0; i < ncols; i++)
1030 if (strcmp(colname[i], "package") == 0) {
1032 info->manifest_info->package = strdup(coltxt[i]);
1034 info->manifest_info->package = NULL;
1042 static int __app_list_cb(void *data, int ncols, char **coltxt, char **colname)
1044 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1047 uiapplication_x *uiapp = NULL;
1048 serviceapplication_x *svcapp = NULL;
1049 for(i = 0; i < ncols; i++)
1051 if ((strcmp(colname[i], "app_component") == 0) ||
1052 (strcmp(colname[i], "package_app_info.app_component") == 0)) {
1054 if (strcmp(coltxt[i], "uiapp") == 0) {
1055 uiapp = calloc(1, sizeof(uiapplication_x));
1056 if (uiapp == NULL) {
1057 _LOGE("Out of Memory!!!\n");
1060 LISTADD(info->manifest_info->uiapplication, uiapp);
1061 for(j = 0; j < ncols; j++)
1063 if ((strcmp(colname[j], "app_id") == 0) ||
1064 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1066 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1067 } else if (strcmp(colname[j], "package") == 0) {
1069 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1074 svcapp = calloc(1, sizeof(serviceapplication_x));
1075 if (svcapp == NULL) {
1076 _LOGE("Out of Memory!!!\n");
1079 LISTADD(info->manifest_info->serviceapplication, svcapp);
1080 for(j = 0; j < ncols; j++)
1082 if ((strcmp(colname[j], "app_id") == 0) ||
1083 (strcmp(colname[j], "package_app_info.app_id") == 0)) {
1085 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1086 } else if (strcmp(colname[j], "package") == 0) {
1088 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1102 static int __uiapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1104 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1106 uiapplication_x *uiapp = NULL;
1107 icon_x *icon = NULL;
1108 label_x *label = NULL;
1110 uiapp = calloc(1, sizeof(uiapplication_x));
1111 LISTADD(info->manifest_info->uiapplication, uiapp);
1112 icon = calloc(1, sizeof(icon_x));
1113 LISTADD(info->manifest_info->uiapplication->icon, icon);
1114 label = calloc(1, sizeof(label_x));
1115 LISTADD(info->manifest_info->uiapplication->label, label);
1117 for(i = 0; i < ncols; i++)
1119 if (strcmp(colname[i], "app_id") == 0) {
1121 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1123 info->manifest_info->uiapplication->appid = NULL;
1124 } else if (strcmp(colname[i], "app_exec") == 0) {
1126 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1128 info->manifest_info->uiapplication->exec = NULL;
1129 } else if (strcmp(colname[i], "app_type") == 0 ){
1131 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1133 info->manifest_info->uiapplication->type = NULL;
1134 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1136 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1138 info->manifest_info->uiapplication->nodisplay = NULL;
1139 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1141 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1143 info->manifest_info->uiapplication->multiple = NULL;
1144 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1146 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1148 info->manifest_info->uiapplication->taskmanage = NULL;
1149 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1151 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1153 info->manifest_info->uiapplication->hwacceleration = NULL;
1154 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1156 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1158 info->manifest_info->uiapplication->screenreader = NULL;
1159 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1161 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1163 info->manifest_info->uiapplication->indicatordisplay = NULL;
1164 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1166 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1168 info->manifest_info->uiapplication->portraitimg = NULL;
1169 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1171 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1173 info->manifest_info->uiapplication->landscapeimg = NULL;
1174 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1176 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1178 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1179 } else if (strcmp(colname[i], "package") == 0 ){
1181 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1183 info->manifest_info->uiapplication->package = NULL;
1184 } else if (strcmp(colname[i], "app_icon") == 0) {
1186 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1188 info->manifest_info->uiapplication->icon->text = NULL;
1189 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
1191 info->manifest_info->uiapplication->enabled= strdup(coltxt[i]);
1193 info->manifest_info->uiapplication->enabled = NULL;
1194 } else if (strcmp(colname[i], "app_label") == 0 ) {
1196 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1198 info->manifest_info->uiapplication->label->text = NULL;
1199 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1201 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1203 info->manifest_info->uiapplication->recentimage = NULL;
1204 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1206 info->manifest_info->uiapplication->mainapp = strdup(coltxt[i]);
1208 info->manifest_info->uiapplication->mainapp = NULL;
1209 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1211 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1212 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1215 info->manifest_info->uiapplication->icon->lang = NULL;
1216 info->manifest_info->uiapplication->label->lang = NULL;
1218 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1220 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1222 info->manifest_info->uiapplication->permission_type = NULL;
1223 } else if (strcmp(colname[i], "component_type") == 0 ) {
1225 info->manifest_info->uiapplication->component_type = strdup(coltxt[i]);
1227 info->manifest_info->uiapplication->component_type = NULL;
1228 } else if (strcmp(colname[i], "app_preload") == 0 ) {
1230 info->manifest_info->uiapplication->preload = strdup(coltxt[i]);
1232 info->manifest_info->uiapplication->preload = NULL;
1233 } else if (strcmp(colname[i], "app_submode") == 0 ) {
1235 info->manifest_info->uiapplication->submode = strdup(coltxt[i]);
1237 info->manifest_info->uiapplication->submode = NULL;
1238 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
1240 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[i]);
1242 info->manifest_info->uiapplication->submode_mainid = NULL;
1249 static int __svcapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1251 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1253 serviceapplication_x *svcapp = NULL;
1254 icon_x *icon = NULL;
1255 label_x *label = NULL;
1257 svcapp = calloc(1, sizeof(serviceapplication_x));
1258 LISTADD(info->manifest_info->serviceapplication, svcapp);
1259 icon = calloc(1, sizeof(icon_x));
1260 LISTADD(info->manifest_info->serviceapplication->icon, icon);
1261 label = calloc(1, sizeof(label_x));
1262 LISTADD(info->manifest_info->serviceapplication->label, label);
1263 for(i = 0; i < ncols; i++)
1265 if (strcmp(colname[i], "app_id") == 0) {
1267 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1269 info->manifest_info->serviceapplication->appid = NULL;
1270 } else if (strcmp(colname[i], "app_exec") == 0) {
1272 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1274 info->manifest_info->serviceapplication->exec = NULL;
1275 } else if (strcmp(colname[i], "app_type") == 0 ){
1277 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1279 info->manifest_info->serviceapplication->type = NULL;
1280 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1282 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1284 info->manifest_info->serviceapplication->onboot = NULL;
1285 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1287 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1289 info->manifest_info->serviceapplication->autorestart = NULL;
1290 } else if (strcmp(colname[i], "package") == 0 ){
1292 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1294 info->manifest_info->serviceapplication->package = NULL;
1295 } else if (strcmp(colname[i], "app_icon") == 0) {
1297 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1299 info->manifest_info->serviceapplication->icon->text = NULL;
1300 } else if (strcmp(colname[i], "app_label") == 0 ) {
1302 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1304 info->manifest_info->serviceapplication->label->text = NULL;
1305 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1307 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1308 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1311 info->manifest_info->serviceapplication->icon->lang = NULL;
1312 info->manifest_info->serviceapplication->label->lang = NULL;
1314 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1316 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1318 info->manifest_info->serviceapplication->permission_type = NULL;
1325 static int __allapp_list_cb(void *data, int ncols, char **coltxt, char **colname)
1327 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1330 uiapplication_x *uiapp = NULL;
1331 serviceapplication_x *svcapp = NULL;
1332 for(j = 0; j < ncols; j++)
1334 if (strcmp(colname[j], "app_component") == 0) {
1336 if (strcmp(coltxt[j], "uiapp") == 0) {
1337 uiapp = calloc(1, sizeof(uiapplication_x));
1338 if (uiapp == NULL) {
1339 _LOGE("Out of Memory!!!\n");
1342 LISTADD(info->manifest_info->uiapplication, uiapp);
1343 for(i = 0; i < ncols; i++)
1345 if (strcmp(colname[i], "app_id") == 0) {
1347 info->manifest_info->uiapplication->appid = strdup(coltxt[i]);
1349 info->manifest_info->uiapplication->appid = NULL;
1350 } else if (strcmp(colname[i], "app_exec") == 0) {
1352 info->manifest_info->uiapplication->exec = strdup(coltxt[i]);
1354 info->manifest_info->uiapplication->exec = NULL;
1355 } else if (strcmp(colname[i], "app_type") == 0 ){
1357 info->manifest_info->uiapplication->type = strdup(coltxt[i]);
1359 info->manifest_info->uiapplication->type = NULL;
1360 } else if (strcmp(colname[i], "app_nodisplay") == 0 ){
1362 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[i]);
1364 info->manifest_info->uiapplication->nodisplay = NULL;
1365 } else if (strcmp(colname[i], "app_multiple") == 0 ){
1367 info->manifest_info->uiapplication->multiple = strdup(coltxt[i]);
1369 info->manifest_info->uiapplication->multiple = NULL;
1370 } else if (strcmp(colname[i], "app_taskmanage") == 0 ){
1372 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[i]);
1374 info->manifest_info->uiapplication->taskmanage = NULL;
1375 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ){
1377 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[i]);
1379 info->manifest_info->uiapplication->hwacceleration = NULL;
1380 } else if (strcmp(colname[i], "app_screenreader") == 0 ){
1382 info->manifest_info->uiapplication->screenreader = strdup(coltxt[i]);
1384 info->manifest_info->uiapplication->screenreader = NULL;
1385 } else if (strcmp(colname[i], "app_indicatordisplay") == 0 ){
1387 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[i]);
1389 info->manifest_info->uiapplication->indicatordisplay = NULL;
1390 } else if (strcmp(colname[i], "app_portraitimg") == 0 ){
1392 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[i]);
1394 info->manifest_info->uiapplication->portraitimg = NULL;
1395 } else if (strcmp(colname[i], "app_landscapeimg") == 0 ){
1397 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[i]);
1399 info->manifest_info->uiapplication->landscapeimg = NULL;
1400 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0 ){
1402 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[i]);
1404 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1405 } else if (strcmp(colname[i], "package") == 0 ){
1407 info->manifest_info->uiapplication->package = strdup(coltxt[i]);
1409 info->manifest_info->uiapplication->package = NULL;
1410 } else if (strcmp(colname[i], "app_icon") == 0) {
1412 info->manifest_info->uiapplication->icon->text = strdup(coltxt[i]);
1414 info->manifest_info->uiapplication->icon->text = NULL;
1415 } else if (strcmp(colname[i], "app_label") == 0 ) {
1417 info->manifest_info->uiapplication->label->text = strdup(coltxt[i]);
1419 info->manifest_info->uiapplication->label->text = NULL;
1420 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
1422 info->manifest_info->uiapplication->recentimage = strdup(coltxt[i]);
1424 info->manifest_info->uiapplication->recentimage = NULL;
1425 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
1427 info->manifest_info->uiapplication->mainapp= strdup(coltxt[i]);
1429 info->manifest_info->uiapplication->mainapp = NULL;
1430 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1432 info->manifest_info->uiapplication->icon->lang = strdup(coltxt[i]);
1433 info->manifest_info->uiapplication->label->lang = strdup(coltxt[i]);
1436 info->manifest_info->uiapplication->icon->lang = NULL;
1437 info->manifest_info->uiapplication->label->lang = NULL;
1439 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1441 info->manifest_info->uiapplication->permission_type = strdup(coltxt[i]);
1443 info->manifest_info->uiapplication->permission_type = NULL;
1448 svcapp = calloc(1, sizeof(serviceapplication_x));
1449 if (svcapp == NULL) {
1450 _LOGE("Out of Memory!!!\n");
1453 LISTADD(info->manifest_info->serviceapplication, svcapp);
1454 for(i = 0; i < ncols; i++)
1456 if (strcmp(colname[i], "app_id") == 0) {
1458 info->manifest_info->serviceapplication->appid = strdup(coltxt[i]);
1460 info->manifest_info->serviceapplication->appid = NULL;
1461 } else if (strcmp(colname[i], "app_exec") == 0) {
1463 info->manifest_info->serviceapplication->exec = strdup(coltxt[i]);
1465 info->manifest_info->serviceapplication->exec = NULL;
1466 } else if (strcmp(colname[i], "app_type") == 0 ){
1468 info->manifest_info->serviceapplication->type = strdup(coltxt[i]);
1470 info->manifest_info->serviceapplication->type = NULL;
1471 } else if (strcmp(colname[i], "app_onboot") == 0 ){
1473 info->manifest_info->serviceapplication->onboot = strdup(coltxt[i]);
1475 info->manifest_info->serviceapplication->onboot = NULL;
1476 } else if (strcmp(colname[i], "app_autorestart") == 0 ){
1478 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[i]);
1480 info->manifest_info->serviceapplication->autorestart = NULL;
1481 } else if (strcmp(colname[i], "package") == 0 ){
1483 info->manifest_info->serviceapplication->package = strdup(coltxt[i]);
1485 info->manifest_info->serviceapplication->package = NULL;
1486 } else if (strcmp(colname[i], "app_icon") == 0) {
1488 info->manifest_info->serviceapplication->icon->text = strdup(coltxt[i]);
1490 info->manifest_info->serviceapplication->icon->text = NULL;
1491 } else if (strcmp(colname[i], "app_label") == 0 ) {
1493 info->manifest_info->serviceapplication->label->text = strdup(coltxt[i]);
1495 info->manifest_info->serviceapplication->label->text = NULL;
1496 } else if (strcmp(colname[i], "app_locale") == 0 ) {
1498 info->manifest_info->serviceapplication->icon->lang = strdup(coltxt[i]);
1499 info->manifest_info->serviceapplication->label->lang = strdup(coltxt[i]);
1502 info->manifest_info->serviceapplication->icon->lang = NULL;
1503 info->manifest_info->serviceapplication->label->lang = NULL;
1505 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
1507 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[i]);
1509 info->manifest_info->serviceapplication->permission_type = NULL;
1524 static int __validate_cb(void *data, int ncols, char **coltxt, char **colname)
1526 int *p = (int*)data;
1527 *p = atoi(coltxt[0]);
1531 static int __maxid_cb(void *data, int ncols, char **coltxt, char **colname)
1533 int *p = (int*)data;
1535 *p = atoi(coltxt[0]);
1539 static int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
1541 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1543 author_x *author = NULL;
1544 icon_x *icon = NULL;
1545 label_x *label = NULL;
1546 description_x *description = NULL;
1547 privilege_x *privilege = NULL;
1549 author = calloc(1, sizeof(author_x));
1550 LISTADD(info->manifest_info->author, author);
1551 icon = calloc(1, sizeof(icon_x));
1552 LISTADD(info->manifest_info->icon, icon);
1553 label = calloc(1, sizeof(label_x));
1554 LISTADD(info->manifest_info->label, label);
1555 description = calloc(1, sizeof(description_x));
1556 LISTADD(info->manifest_info->description, description);
1557 privilege = calloc(1, sizeof(privilege_x));
1558 LISTADD(info->manifest_info->privileges->privilege, privilege);
1559 for(i = 0; i < ncols; i++)
1561 if (strcmp(colname[i], "package_version") == 0) {
1563 info->manifest_info->version = strdup(coltxt[i]);
1565 info->manifest_info->version = NULL;
1566 } else if (strcmp(colname[i], "package_type") == 0) {
1568 info->manifest_info->type = strdup(coltxt[i]);
1570 info->manifest_info->type = NULL;
1571 } else if (strcmp(colname[i], "install_location") == 0) {
1573 info->manifest_info->installlocation = strdup(coltxt[i]);
1575 info->manifest_info->installlocation = NULL;
1576 } else if (strcmp(colname[i], "package_size") == 0) {
1578 info->manifest_info->package_size = strdup(coltxt[i]);
1580 info->manifest_info->package_size = NULL;
1581 } else if (strcmp(colname[i], "author_email") == 0 ){
1583 info->manifest_info->author->email = strdup(coltxt[i]);
1585 info->manifest_info->author->email = NULL;
1586 } else if (strcmp(colname[i], "author_href") == 0 ){
1588 info->manifest_info->author->href = strdup(coltxt[i]);
1590 info->manifest_info->author->href = NULL;
1591 } else if (strcmp(colname[i], "package_label") == 0 ){
1593 info->manifest_info->label->text = strdup(coltxt[i]);
1595 info->manifest_info->label->text = NULL;
1596 } else if (strcmp(colname[i], "package_icon") == 0 ){
1598 info->manifest_info->icon->text = strdup(coltxt[i]);
1600 info->manifest_info->icon->text = NULL;
1601 } else if (strcmp(colname[i], "package_description") == 0 ){
1603 info->manifest_info->description->text = strdup(coltxt[i]);
1605 info->manifest_info->description->text = NULL;
1606 } else if (strcmp(colname[i], "package_author") == 0 ){
1608 info->manifest_info->author->text = strdup(coltxt[i]);
1610 info->manifest_info->author->text = NULL;
1611 } else if (strcmp(colname[i], "package_removable") == 0 ){
1613 info->manifest_info->removable = strdup(coltxt[i]);
1615 info->manifest_info->removable = NULL;
1616 } else if (strcmp(colname[i], "package_preload") == 0 ){
1618 info->manifest_info->preload = strdup(coltxt[i]);
1620 info->manifest_info->preload = NULL;
1621 } else if (strcmp(colname[i], "package_readonly") == 0 ){
1623 info->manifest_info->readonly = strdup(coltxt[i]);
1625 info->manifest_info->readonly = NULL;
1626 } else if (strcmp(colname[i], "package_update") == 0 ){
1628 info->manifest_info->update= strdup(coltxt[i]);
1630 info->manifest_info->update = NULL;
1631 } else if (strcmp(colname[i], "package_system") == 0 ){
1633 info->manifest_info->system= strdup(coltxt[i]);
1635 info->manifest_info->system = NULL;
1636 } else if (strcmp(colname[i], "package_appsetting") == 0 ){
1638 info->manifest_info->appsetting = strdup(coltxt[i]);
1640 info->manifest_info->appsetting = NULL;
1641 } else if (strcmp(colname[i], "installed_time") == 0 ){
1643 info->manifest_info->installed_time = strdup(coltxt[i]);
1645 info->manifest_info->installed_time = NULL;
1646 } else if (strcmp(colname[i], "installed_storage") == 0 ){
1648 info->manifest_info->installed_storage = strdup(coltxt[i]);
1650 info->manifest_info->installed_storage = NULL;
1651 } else if (strcmp(colname[i], "mainapp_id") == 0 ){
1653 info->manifest_info->mainapp_id = strdup(coltxt[i]);
1655 info->manifest_info->mainapp_id = NULL;
1656 } else if (strcmp(colname[i], "storeclient_id") == 0 ){
1658 info->manifest_info->storeclient_id = strdup(coltxt[i]);
1660 info->manifest_info->storeclient_id = NULL;
1661 } else if (strcmp(colname[i], "root_path") == 0 ){
1663 info->manifest_info->root_path = strdup(coltxt[i]);
1665 info->manifest_info->root_path = NULL;
1666 } else if (strcmp(colname[i], "csc_path") == 0 ){
1668 info->manifest_info->csc_path = strdup(coltxt[i]);
1670 info->manifest_info->csc_path = NULL;
1671 } else if (strcmp(colname[i], "privilege") == 0 ){
1673 info->manifest_info->privileges->privilege->text = strdup(coltxt[i]);
1675 info->manifest_info->privileges->privilege->text = NULL;
1676 } else if (strcmp(colname[i], "package_locale") == 0 ){
1678 info->manifest_info->author->lang = strdup(coltxt[i]);
1679 info->manifest_info->icon->lang = strdup(coltxt[i]);
1680 info->manifest_info->label->lang = strdup(coltxt[i]);
1681 info->manifest_info->description->lang = strdup(coltxt[i]);
1684 info->manifest_info->author->lang = NULL;
1685 info->manifest_info->icon->lang = NULL;
1686 info->manifest_info->label->lang = NULL;
1687 info->manifest_info->description->lang = NULL;
1689 } else if (strcmp(colname[i], "package_url") == 0 ){
1691 info->manifest_info->package_url = strdup(coltxt[i]);
1693 info->manifest_info->package_url = NULL;
1701 static pkgmgrinfo_app_component __appcomponent_convert(const char *comp)
1703 if ( strcasecmp(comp, "uiapp") == 0)
1704 return PMINFO_UI_APP;
1705 else if ( strcasecmp(comp, "svcapp") == 0)
1706 return PMINFO_SVC_APP;
1711 static int __certindexinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1713 pkgmgr_certindexinfo_x *info = (pkgmgr_certindexinfo_x *)data;
1715 for(i = 0; i < ncols; i++) {
1716 if (strcmp(colname[i], "cert_id") == 0) {
1718 info->cert_id = atoi(coltxt[i]);
1721 } else if (strcmp(colname[i], "cert_ref_count") == 0) {
1723 info->cert_ref_count = atoi(coltxt[i]);
1725 info->cert_ref_count = 0;
1731 static int __certinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1733 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)data;
1735 for(i = 0; i < ncols; i++)
1737 if (strcmp(colname[i], "package") == 0) {
1739 info->pkgid = strdup(coltxt[i]);
1742 } else if (strcmp(colname[i], "author_signer_cert") == 0) {
1744 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = atoi(coltxt[i]);
1746 (info->cert_id)[PMINFO_AUTHOR_SIGNER_CERT] = 0;
1747 } else if (strcmp(colname[i], "author_im_cert") == 0) {
1749 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1751 (info->cert_id)[PMINFO_AUTHOR_INTERMEDIATE_CERT] = 0;
1752 } else if (strcmp(colname[i], "author_root_cert") == 0) {
1754 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = atoi(coltxt[i]);
1756 (info->cert_id)[PMINFO_AUTHOR_ROOT_CERT] = 0;
1757 } else if (strcmp(colname[i], "dist_signer_cert") == 0 ){
1759 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = atoi(coltxt[i]);
1761 (info->cert_id)[PMINFO_DISTRIBUTOR_SIGNER_CERT] = 0;
1762 } else if (strcmp(colname[i], "dist_im_cert") == 0 ){
1764 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1766 (info->cert_id)[PMINFO_DISTRIBUTOR_INTERMEDIATE_CERT] = 0;
1767 } else if (strcmp(colname[i], "dist_root_cert") == 0 ){
1769 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = atoi(coltxt[i]);
1771 (info->cert_id)[PMINFO_DISTRIBUTOR_ROOT_CERT] = 0;
1772 } else if (strcmp(colname[i], "dist2_signer_cert") == 0 ){
1774 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = atoi(coltxt[i]);
1776 (info->cert_id)[PMINFO_DISTRIBUTOR2_SIGNER_CERT] = 0;
1777 } else if (strcmp(colname[i], "dist2_im_cert") == 0 ){
1779 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = atoi(coltxt[i]);
1781 (info->cert_id)[PMINFO_DISTRIBUTOR2_INTERMEDIATE_CERT] = 0;
1782 } else if (strcmp(colname[i], "dist2_root_cert") == 0 ){
1784 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = atoi(coltxt[i]);
1786 (info->cert_id)[PMINFO_DISTRIBUTOR2_ROOT_CERT] = 0;
1787 } else if (strcmp(colname[i], "cert_info") == 0 ){
1789 info->cert_value = strdup(coltxt[i]);
1791 info->cert_value = NULL;
1798 static int __mini_appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1800 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
1803 uiapplication_x *uiapp = NULL;
1804 serviceapplication_x *svcapp = NULL;
1805 for(i = 0; i < ncols; i++)
1807 if (strcmp(colname[i], "app_component") == 0) {
1809 if (strcmp(coltxt[i], "uiapp") == 0) {
1810 uiapp = calloc(1, sizeof(uiapplication_x));
1811 if (uiapp == NULL) {
1812 _LOGE("Out of Memory!!!\n");
1815 LISTADD(info->manifest_info->uiapplication, uiapp);
1816 for(j = 0; j < ncols; j++)
1818 if (strcmp(colname[j], "app_id") == 0) {
1820 info->manifest_info->uiapplication->appid = strdup(coltxt[j]);
1821 } else if (strcmp(colname[j], "app_exec") == 0) {
1823 info->manifest_info->uiapplication->exec = strdup(coltxt[j]);
1825 info->manifest_info->uiapplication->exec = NULL;
1826 } else if (strcmp(colname[j], "app_nodisplay") == 0) {
1828 info->manifest_info->uiapplication->nodisplay = strdup(coltxt[j]);
1830 info->manifest_info->uiapplication->nodisplay = NULL;
1831 } else if (strcmp(colname[j], "app_type") == 0 ) {
1833 info->manifest_info->uiapplication->type = strdup(coltxt[j]);
1835 info->manifest_info->uiapplication->type = NULL;
1836 } else if (strcmp(colname[j], "app_multiple") == 0 ) {
1838 info->manifest_info->uiapplication->multiple = strdup(coltxt[j]);
1840 info->manifest_info->uiapplication->multiple = NULL;
1841 } else if (strcmp(colname[j], "app_taskmanage") == 0 ) {
1843 info->manifest_info->uiapplication->taskmanage = strdup(coltxt[j]);
1845 info->manifest_info->uiapplication->taskmanage = NULL;
1846 } else if (strcmp(colname[j], "app_hwacceleration") == 0 ) {
1848 info->manifest_info->uiapplication->hwacceleration = strdup(coltxt[j]);
1850 info->manifest_info->uiapplication->hwacceleration = NULL;
1851 } else if (strcmp(colname[j], "app_screenreader") == 0 ) {
1853 info->manifest_info->uiapplication->screenreader = strdup(coltxt[j]);
1855 info->manifest_info->uiapplication->screenreader = NULL;
1856 } else if (strcmp(colname[j], "app_enabled") == 0 ) {
1858 info->manifest_info->uiapplication->enabled= strdup(coltxt[j]);
1860 info->manifest_info->uiapplication->enabled = NULL;
1861 } else if (strcmp(colname[j], "app_indicatordisplay") == 0){
1863 info->manifest_info->uiapplication->indicatordisplay = strdup(coltxt[j]);
1865 info->manifest_info->uiapplication->indicatordisplay = NULL;
1866 } else if (strcmp(colname[j], "app_portraitimg") == 0){
1868 info->manifest_info->uiapplication->portraitimg = strdup(coltxt[j]);
1870 info->manifest_info->uiapplication->portraitimg = NULL;
1871 } else if (strcmp(colname[j], "app_landscapeimg") == 0){
1873 info->manifest_info->uiapplication->landscapeimg = strdup(coltxt[j]);
1875 info->manifest_info->uiapplication->landscapeimg = NULL;
1876 } else if (strcmp(colname[j], "app_guestmodevisibility") == 0){
1878 info->manifest_info->uiapplication->guestmode_visibility = strdup(coltxt[j]);
1880 info->manifest_info->uiapplication->guestmode_visibility = NULL;
1881 } else if (strcmp(colname[j], "app_recentimage") == 0 ) {
1883 info->manifest_info->uiapplication->recentimage = strdup(coltxt[j]);
1885 info->manifest_info->uiapplication->recentimage = NULL;
1886 } else if (strcmp(colname[j], "app_mainapp") == 0 ) {
1888 info->manifest_info->uiapplication->mainapp = strdup(coltxt[j]);
1890 info->manifest_info->uiapplication->mainapp = NULL;
1891 } else if (strcmp(colname[j], "package") == 0 ) {
1893 info->manifest_info->uiapplication->package = strdup(coltxt[j]);
1895 info->manifest_info->uiapplication->package = NULL;
1896 } else if (strcmp(colname[j], "app_component") == 0) {
1898 info->manifest_info->uiapplication->app_component = strdup(coltxt[j]);
1900 info->manifest_info->uiapplication->app_component = NULL;
1901 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1903 info->manifest_info->uiapplication->permission_type = strdup(coltxt[j]);
1905 info->manifest_info->uiapplication->permission_type = NULL;
1906 } else if (strcmp(colname[j], "component_type") == 0 ) {
1908 info->manifest_info->uiapplication->component_type = strdup(coltxt[j]);
1910 info->manifest_info->uiapplication->component_type = NULL;
1911 } else if (strcmp(colname[j], "app_preload") == 0 ) {
1913 info->manifest_info->uiapplication->preload = strdup(coltxt[j]);
1915 info->manifest_info->uiapplication->preload = NULL;
1916 } else if (strcmp(colname[j], "app_submode") == 0 ) {
1918 info->manifest_info->uiapplication->submode = strdup(coltxt[j]);
1920 info->manifest_info->uiapplication->submode = NULL;
1921 } else if (strcmp(colname[j], "app_submode_mainid") == 0 ) {
1923 info->manifest_info->uiapplication->submode_mainid = strdup(coltxt[j]);
1925 info->manifest_info->uiapplication->submode_mainid = NULL;
1930 svcapp = calloc(1, sizeof(serviceapplication_x));
1931 if (svcapp == NULL) {
1932 _LOGE("Out of Memory!!!\n");
1935 LISTADD(info->manifest_info->serviceapplication, svcapp);
1936 for(j = 0; j < ncols; j++)
1938 if (strcmp(colname[j], "app_id") == 0) {
1940 info->manifest_info->serviceapplication->appid = strdup(coltxt[j]);
1941 } else if (strcmp(colname[j], "app_exec") == 0) {
1943 info->manifest_info->serviceapplication->exec = strdup(coltxt[j]);
1945 info->manifest_info->serviceapplication->exec = NULL;
1946 } else if (strcmp(colname[j], "app_type") == 0 ){
1948 info->manifest_info->serviceapplication->type = strdup(coltxt[j]);
1950 info->manifest_info->serviceapplication->type = NULL;
1951 } else if (strcmp(colname[j], "app_onboot") == 0 ){
1953 info->manifest_info->serviceapplication->onboot = strdup(coltxt[j]);
1955 info->manifest_info->serviceapplication->onboot = NULL;
1956 } else if (strcmp(colname[j], "app_autorestart") == 0 ){
1958 info->manifest_info->serviceapplication->autorestart = strdup(coltxt[j]);
1960 info->manifest_info->serviceapplication->autorestart = NULL;
1961 } else if (strcmp(colname[j], "package") == 0 ){
1963 info->manifest_info->serviceapplication->package = strdup(coltxt[j]);
1965 info->manifest_info->serviceapplication->package = NULL;
1966 } else if (strcmp(colname[j], "app_permissiontype") == 0 ) {
1968 info->manifest_info->serviceapplication->permission_type = strdup(coltxt[j]);
1970 info->manifest_info->serviceapplication->permission_type = NULL;
1983 static int __appinfo_cb(void *data, int ncols, char **coltxt, char **colname)
1985 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
1987 icon_x *icon = NULL;
1988 label_x *label = NULL;
1989 category_x *category = NULL;
1990 metadata_x *metadata = NULL;
1991 permission_x *permission = NULL;
1992 image_x *image = NULL;
1994 switch (info->app_component) {
1996 icon = calloc(1, sizeof(icon_x));
1997 LISTADD(info->uiapp_info->icon, icon);
1998 label = calloc(1, sizeof(label_x));
1999 LISTADD(info->uiapp_info->label, label);
2000 category = calloc(1, sizeof(category_x));
2001 LISTADD(info->uiapp_info->category, category);
2002 metadata = calloc(1, sizeof(metadata_x));
2003 LISTADD(info->uiapp_info->metadata, metadata);
2004 permission = calloc(1, sizeof(permission_x));
2005 LISTADD(info->uiapp_info->permission, permission);
2006 image = calloc(1, sizeof(image_x));
2007 LISTADD(info->uiapp_info->image, image);
2009 for(i = 0; i < ncols; i++)
2011 if (strcmp(colname[i], "app_id") == 0) {
2012 /*appid being foreign key, is column in every table
2013 Hence appid gets strduped every time leading to memory leak.
2014 If appid is already set, just continue.*/
2015 if (info->uiapp_info->appid)
2018 info->uiapp_info->appid = strdup(coltxt[i]);
2020 info->uiapp_info->appid = NULL;
2021 } else if (strcmp(colname[i], "app_exec") == 0) {
2023 info->uiapp_info->exec = strdup(coltxt[i]);
2025 info->uiapp_info->exec = NULL;
2026 } else if (strcmp(colname[i], "app_nodisplay") == 0) {
2028 info->uiapp_info->nodisplay = strdup(coltxt[i]);
2030 info->uiapp_info->nodisplay = NULL;
2031 } else if (strcmp(colname[i], "app_type") == 0 ) {
2033 info->uiapp_info->type = strdup(coltxt[i]);
2035 info->uiapp_info->type = NULL;
2036 } else if (strcmp(colname[i], "app_icon_section") == 0 ) {
2038 info->uiapp_info->icon->section= strdup(coltxt[i]);
2040 info->uiapp_info->icon->section = NULL;
2041 } else if (strcmp(colname[i], "app_icon") == 0) {
2043 info->uiapp_info->icon->text = strdup(coltxt[i]);
2045 info->uiapp_info->icon->text = NULL;
2046 } else if (strcmp(colname[i], "app_label") == 0 ) {
2048 info->uiapp_info->label->text = strdup(coltxt[i]);
2050 info->uiapp_info->label->text = NULL;
2051 } else if (strcmp(colname[i], "app_multiple") == 0 ) {
2053 info->uiapp_info->multiple = strdup(coltxt[i]);
2055 info->uiapp_info->multiple = NULL;
2056 } else if (strcmp(colname[i], "app_taskmanage") == 0 ) {
2058 info->uiapp_info->taskmanage = strdup(coltxt[i]);
2060 info->uiapp_info->taskmanage = NULL;
2061 } else if (strcmp(colname[i], "app_hwacceleration") == 0 ) {
2063 info->uiapp_info->hwacceleration = strdup(coltxt[i]);
2065 info->uiapp_info->hwacceleration = NULL;
2066 } else if (strcmp(colname[i], "app_screenreader") == 0 ) {
2068 info->uiapp_info->screenreader = strdup(coltxt[i]);
2070 info->uiapp_info->screenreader = NULL;
2071 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2073 info->uiapp_info->enabled= strdup(coltxt[i]);
2075 info->uiapp_info->enabled = NULL;
2076 } else if (strcmp(colname[i], "app_indicatordisplay") == 0){
2078 info->uiapp_info->indicatordisplay = strdup(coltxt[i]);
2080 info->uiapp_info->indicatordisplay = NULL;
2081 } else if (strcmp(colname[i], "app_portraitimg") == 0){
2083 info->uiapp_info->portraitimg = strdup(coltxt[i]);
2085 info->uiapp_info->portraitimg = NULL;
2086 } else if (strcmp(colname[i], "app_landscapeimg") == 0){
2088 info->uiapp_info->landscapeimg = strdup(coltxt[i]);
2090 info->uiapp_info->landscapeimg = NULL;
2091 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0){
2093 info->uiapp_info->guestmode_visibility = strdup(coltxt[i]);
2095 info->uiapp_info->guestmode_visibility = NULL;
2096 } else if (strcmp(colname[i], "category") == 0 ) {
2098 info->uiapp_info->category->name = strdup(coltxt[i]);
2100 info->uiapp_info->category->name = NULL;
2101 } else if (strcmp(colname[i], "md_key") == 0 ) {
2103 info->uiapp_info->metadata->key = strdup(coltxt[i]);
2105 info->uiapp_info->metadata->key = NULL;
2106 } else if (strcmp(colname[i], "md_value") == 0 ) {
2108 info->uiapp_info->metadata->value = strdup(coltxt[i]);
2110 info->uiapp_info->metadata->value = NULL;
2111 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2113 info->uiapp_info->permission->type= strdup(coltxt[i]);
2115 info->uiapp_info->permission->type = NULL;
2116 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2118 info->uiapp_info->permission->value = strdup(coltxt[i]);
2120 info->uiapp_info->permission->value = NULL;
2121 } else if (strcmp(colname[i], "app_recentimage") == 0 ) {
2123 info->uiapp_info->recentimage = strdup(coltxt[i]);
2125 info->uiapp_info->recentimage = NULL;
2126 } else if (strcmp(colname[i], "app_mainapp") == 0 ) {
2128 info->uiapp_info->mainapp = strdup(coltxt[i]);
2130 info->uiapp_info->mainapp = NULL;
2131 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2133 info->uiapp_info->icon->lang = strdup(coltxt[i]);
2134 info->uiapp_info->label->lang = strdup(coltxt[i]);
2137 info->uiapp_info->icon->lang = NULL;
2138 info->uiapp_info->label->lang = NULL;
2140 } else if (strcmp(colname[i], "app_image") == 0) {
2142 info->uiapp_info->image->text= strdup(coltxt[i]);
2144 info->uiapp_info->image->text = NULL;
2145 } else if (strcmp(colname[i], "app_image_section") == 0) {
2147 info->uiapp_info->image->section= strdup(coltxt[i]);
2149 info->uiapp_info->image->section = NULL;
2150 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2152 info->uiapp_info->permission_type = strdup(coltxt[i]);
2154 info->uiapp_info->permission_type = NULL;
2155 } else if (strcmp(colname[i], "component_type") == 0 ) {
2157 info->uiapp_info->component_type = strdup(coltxt[i]);
2159 info->uiapp_info->component_type = NULL;
2160 } else if (strcmp(colname[i], "app_preload") == 0 ) {
2162 info->uiapp_info->preload = strdup(coltxt[i]);
2164 info->uiapp_info->preload = NULL;
2165 } else if (strcmp(colname[i], "app_submode") == 0 ) {
2167 info->uiapp_info->submode = strdup(coltxt[i]);
2169 info->uiapp_info->submode = NULL;
2170 } else if (strcmp(colname[i], "app_submode_mainid") == 0 ) {
2172 info->uiapp_info->submode_mainid = strdup(coltxt[i]);
2174 info->uiapp_info->submode_mainid = NULL;
2179 case PMINFO_SVC_APP:
2180 icon = calloc(1, sizeof(icon_x));
2181 LISTADD(info->svcapp_info->icon, icon);
2182 label = calloc(1, sizeof(label_x));
2183 LISTADD(info->svcapp_info->label, label);
2184 category = calloc(1, sizeof(category_x));
2185 LISTADD(info->svcapp_info->category, category);
2186 metadata = calloc(1, sizeof(metadata_x));
2187 LISTADD(info->svcapp_info->metadata, metadata);
2188 permission = calloc(1, sizeof(permission_x));
2189 LISTADD(info->svcapp_info->permission, permission);
2190 for(i = 0; i < ncols; i++)
2192 if (strcmp(colname[i], "app_id") == 0) {
2193 /*appid being foreign key, is column in every table
2194 Hence appid gets strduped every time leading to memory leak.
2195 If appid is already set, just continue.*/
2196 if (info->svcapp_info->appid)
2199 info->svcapp_info->appid = strdup(coltxt[i]);
2201 info->svcapp_info->appid = NULL;
2202 } else if (strcmp(colname[i], "app_exec") == 0) {
2204 info->svcapp_info->exec = strdup(coltxt[i]);
2206 info->svcapp_info->exec = NULL;
2207 } else if (strcmp(colname[i], "app_icon") == 0) {
2209 info->svcapp_info->icon->text = strdup(coltxt[i]);
2211 info->svcapp_info->icon->text = NULL;
2212 } else if (strcmp(colname[i], "app_label") == 0 ) {
2214 info->svcapp_info->label->text = strdup(coltxt[i]);
2216 info->svcapp_info->label->text = NULL;
2217 } else if (strcmp(colname[i], "app_type") == 0 ) {
2219 info->svcapp_info->type = strdup(coltxt[i]);
2221 info->svcapp_info->type = NULL;
2222 } else if (strcmp(colname[i], "app_onboot") == 0 ) {
2224 info->svcapp_info->onboot = strdup(coltxt[i]);
2226 info->svcapp_info->onboot = NULL;
2227 } else if (strcmp(colname[i], "app_autorestart") == 0 ) {
2229 info->svcapp_info->autorestart = strdup(coltxt[i]);
2231 info->svcapp_info->autorestart = NULL;
2232 } else if (strcmp(colname[i], "app_enabled") == 0 ) {
2234 info->svcapp_info->enabled= strdup(coltxt[i]);
2236 info->svcapp_info->enabled = NULL;
2237 } else if (strcmp(colname[i], "category") == 0 ) {
2239 info->svcapp_info->category->name = strdup(coltxt[i]);
2241 info->svcapp_info->category->name = NULL;
2242 } else if (strcmp(colname[i], "md_key") == 0 ) {
2244 info->svcapp_info->metadata->key = strdup(coltxt[i]);
2246 info->svcapp_info->metadata->key = NULL;
2247 } else if (strcmp(colname[i], "md_value") == 0 ) {
2249 info->svcapp_info->metadata->value = strdup(coltxt[i]);
2251 info->svcapp_info->metadata->value = NULL;
2252 } else if (strcmp(colname[i], "pm_type") == 0 ) {
2254 info->svcapp_info->permission->type= strdup(coltxt[i]);
2256 info->svcapp_info->permission->type = NULL;
2257 } else if (strcmp(colname[i], "pm_value") == 0 ) {
2259 info->svcapp_info->permission->value = strdup(coltxt[i]);
2261 info->svcapp_info->permission->value = NULL;
2262 } else if (strcmp(colname[i], "app_locale") == 0 ) {
2264 info->svcapp_info->icon->lang = strdup(coltxt[i]);
2265 info->svcapp_info->label->lang = strdup(coltxt[i]);
2268 info->svcapp_info->icon->lang = NULL;
2269 info->svcapp_info->label->lang = NULL;
2271 } else if (strcmp(colname[i], "app_permissiontype") == 0 ) {
2273 info->svcapp_info->permission_type = strdup(coltxt[i]);
2275 info->svcapp_info->permission_type = NULL;
2288 static int __appcomponent_cb(void *data, int ncols, char **coltxt, char **colname)
2290 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)data;
2292 for(i = 0; i < ncols; i++)
2294 if (strcmp(colname[i], "app_component") == 0) {
2295 info->app_component = __appcomponent_convert(coltxt[i]);
2296 } else if (strcmp(colname[i], "package") == 0) {
2297 info->package = strdup(coltxt[i]);
2304 static int __datacontrol_cb(void *data, int ncols, char **coltxt, char **colname)
2306 pkgmgr_datacontrol_x *info = (pkgmgr_datacontrol_x *)data;
2308 for(i = 0; i < ncols; i++)
2310 if (strcmp(colname[i], "PACKAGE_NAME") == 0) {
2312 info->appid = strdup(coltxt[i]);
2315 } else if (strcmp(colname[i], "ACCESS") == 0 ){
2317 info->access = strdup(coltxt[i]);
2319 info->access = NULL;
2326 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
2328 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
2331 for(i = 0; i < ncols; i++)
2333 if (strcmp(colname[i], "author_signer_cert") == 0) {
2335 info->cert_id = atoi(coltxt[i]);
2338 } else if (strcmp(colname[i], "package") == 0) {
2340 info->pkgid= strdup(coltxt[i]);
2349 /* get the first locale value*/
2350 static int __fallback_locale_cb(void *data, int ncols, char **coltxt, char **colname)
2352 pkgmgr_locale_x *info = (pkgmgr_locale_x *)data;
2355 info->locale = strdup(coltxt[0]);
2357 info->locale = NULL;
2362 static int __exec_pkginfo_query(char *query, void *data)
2364 char *error_message = NULL;
2366 sqlite3_exec(manifest_db, query, __pkginfo_cb, data, &error_message)) {
2367 _LOGE("Don't execute query = %s error message = %s\n", query,
2369 sqlite3_free(error_message);
2372 sqlite3_free(error_message);
2376 static int __exec_certinfo_query(char *query, void *data)
2378 char *error_message = NULL;
2380 sqlite3_exec(cert_db, query, __certinfo_cb, data, &error_message)) {
2381 _LOGE("Don't execute query = %s error message = %s\n", query,
2383 sqlite3_free(error_message);
2386 sqlite3_free(error_message);
2390 static int __exec_certindexinfo_query(char *query, void *data)
2392 char *error_message = NULL;
2394 sqlite3_exec(cert_db, query, __certindexinfo_cb, data, &error_message)) {
2395 _LOGE("Don't execute query = %s error message = %s\n", query,
2397 sqlite3_free(error_message);
2400 sqlite3_free(error_message);
2404 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
2406 char *error_message = NULL;
2408 sqlite3_exec(db, query, callback, data, &error_message)) {
2409 _LOGE("Don't execute query = %s error message = %s\n", query,
2411 sqlite3_free(error_message);
2414 sqlite3_free(error_message);
2419 static int __child_element(xmlTextReaderPtr reader, int depth)
2421 int ret = xmlTextReaderRead(reader);
2422 int cur = xmlTextReaderDepth(reader);
2425 switch (xmlTextReaderNodeType(reader)) {
2426 case XML_READER_TYPE_ELEMENT:
2427 if (cur == depth + 1)
2430 case XML_READER_TYPE_TEXT:
2431 /*text is handled by each function separately*/
2432 if (cur == depth + 1)
2435 case XML_READER_TYPE_END_ELEMENT:
2444 ret = xmlTextReaderRead(reader);
2445 cur = xmlTextReaderDepth(reader);
2450 static int __check_validation_of_qurey_cb(void *data, int ncols, char **coltxt, char **colname)
2452 int *p = (int*)data;
2453 *p = atoi(coltxt[0]);
2457 static int __check_app_locale_from_app_localized_info_by_exact(sqlite3 *db, const char *appid, const char *locale)
2459 int result_query = -1;
2461 char query[MAX_QUERY_LEN];
2463 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);
2464 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2465 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2466 return result_query;
2469 static int __check_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2471 int result_query = -1;
2473 char wildcard[2] = {'%','\0'};
2474 char query[MAX_QUERY_LEN];
2475 char lang[3] = {'\0'};
2476 strncpy(lang, locale, LANGUAGE_LENGTH);
2478 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);
2479 ret = __exec_db_query(db, query, __check_validation_of_qurey_cb, (void *)&result_query);
2480 retvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2481 return result_query;
2484 static char* __get_app_locale_from_app_localized_info_by_fallback(sqlite3 *db, const char *appid, const char *locale)
2487 char wildcard[2] = {'%','\0'};
2488 char lang[3] = {'\0'};
2489 char query[MAX_QUERY_LEN];
2490 char *locale_new = NULL;
2491 pkgmgr_locale_x *info = NULL;
2493 info = (pkgmgr_locale_x *)malloc(sizeof(pkgmgr_locale_x));
2495 _LOGE("Out of Memory!!!\n");
2498 memset(info, '\0', sizeof(*info));
2500 strncpy(lang, locale, 2);
2501 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);
2502 ret = __exec_db_query(db, query, __fallback_locale_cb, (void *)info);
2503 tryvm_if(ret == -1, PMINFO_R_ERROR, "Exec DB query failed");
2504 locale_new = info->locale;
2515 static char* __convert_syslocale_to_manifest_locale(char *syslocale)
2517 char *locale = malloc(6);
2519 _LOGE("Malloc Failed\n");
2523 sprintf(locale, "%c%c-%c%c", syslocale[0], syslocale[1], tolower(syslocale[3]), tolower(syslocale[4]));
2527 static char* __get_app_locale_by_fallback(sqlite3 *db, const char *appid, const char *syslocale)
2532 char *locale = NULL;
2533 char *locale_new = NULL;
2534 int check_result = 0;
2536 locale = __convert_syslocale_to_manifest_locale((char *)syslocale);
2538 /*check exact matching */
2539 check_result = __check_app_locale_from_app_localized_info_by_exact(db, appid, locale);
2542 if (check_result == 1) {
2543 _LOGD("%s find exact locale(%s)\n", appid, locale);
2547 /* fallback matching */
2548 check_result = __check_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2549 if(check_result == 1) {
2550 locale_new = __get_app_locale_from_app_localized_info_by_fallback(db, appid, locale);
2552 if (locale_new == NULL)
2553 locale_new = strdup(DEFAULT_LOCALE);
2557 /* default locale */
2559 return strdup(DEFAULT_LOCALE);
2562 long long _pkgmgr_calculate_dir_size(char *dirname)
2564 long long total = 0;
2566 int q = 0; /*quotient*/
2567 int r = 0; /*remainder*/
2569 struct dirent *ep = NULL;
2570 struct stat fileinfo;
2571 char abs_filename[FILENAME_MAX] = { 0, };
2572 retvm_if(dirname == NULL, PMINFO_R_ERROR, "dirname is NULL");
2574 dp = opendir(dirname);
2576 while ((ep = readdir(dp)) != NULL) {
2577 if (!strcmp(ep->d_name, ".") ||
2578 !strcmp(ep->d_name, "..")) {
2581 snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
2583 if (lstat(abs_filename, &fileinfo) < 0)
2584 perror(abs_filename);
2586 if (S_ISDIR(fileinfo.st_mode)) {
2587 total += fileinfo.st_size;
2588 if (strcmp(ep->d_name, ".")
2589 && strcmp(ep->d_name, "..")) {
2590 ret = _pkgmgr_calculate_dir_size
2592 total = total + ret;
2594 } else if (S_ISLNK(fileinfo.st_mode)) {
2597 /*It is a file. Calculate the actual
2598 size occupied (in terms of 4096 blocks)*/
2599 q = (fileinfo.st_size / BLOCK_SIZE);
2600 r = (fileinfo.st_size % BLOCK_SIZE);
2604 total += q * BLOCK_SIZE;
2610 _LOGE("Couldn't open the directory\n");
2617 static int __delete_certinfo(const char *pkgid)
2623 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
2624 char *error_message = NULL;
2625 char query[MAX_QUERY_LEN] = {'\0'};
2626 pkgmgr_certinfo_x *certinfo = NULL;
2627 pkgmgr_certindexinfo_x *indexinfo = NULL;
2628 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
2629 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
2630 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
2631 if (indexinfo == NULL) {
2632 _LOGE("Out of Memory!!!");
2633 ret = PMINFO_R_ERROR;
2636 /*populate certinfo from DB*/
2637 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
2638 ret = __exec_certinfo_query(query, (void *)certinfo);
2640 _LOGE("Package Cert Info DB Information retrieval failed\n");
2641 ret = PMINFO_R_ERROR;
2644 /*Update cert index table*/
2645 for (i = 0; i < MAX_CERT_TYPE; i++) {
2646 if ((certinfo->cert_id)[i]) {
2647 for (j = 0; j < MAX_CERT_TYPE; j++) {
2648 if ((certinfo->cert_id)[i] == unique_id[j]) {
2649 /*Ref count has already been updated. Just continue*/
2653 if (j == MAX_CERT_TYPE)
2654 unique_id[c++] = (certinfo->cert_id)[i];
2657 memset(query, '\0', MAX_QUERY_LEN);
2658 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2659 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
2661 _LOGE("Cert Info DB Information retrieval failed\n");
2662 ret = PMINFO_R_ERROR;
2665 memset(query, '\0', MAX_QUERY_LEN);
2666 if (indexinfo->cert_ref_count > 1) {
2667 /*decrease ref count*/
2668 snprintf(query, MAX_QUERY_LEN, "update package_cert_index_info set cert_ref_count=%d where cert_id=%d ",
2669 indexinfo->cert_ref_count - 1, (certinfo->cert_id)[i]);
2671 /*delete this certificate as ref count is 1 and it will become 0*/
2672 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
2675 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2676 _LOGE("Don't execute query = %s error message = %s\n", query,
2678 sqlite3_free(error_message);
2679 ret = PMINFO_R_ERROR;
2684 /*Now delete the entry from db*/
2685 snprintf(query, MAX_QUERY_LEN, "delete from package_cert_info where package='%s'", pkgid);
2687 sqlite3_exec(cert_db, query, NULL, NULL, &error_message)) {
2688 _LOGE("Don't execute query = %s error message = %s\n", query,
2690 sqlite3_free(error_message);
2691 ret = PMINFO_R_ERROR;
2700 if (certinfo->pkgid) {
2701 free(certinfo->pkgid);
2702 certinfo->pkgid = NULL;
2704 for (i = 0; i < MAX_CERT_TYPE; i++) {
2705 if ((certinfo->cert_info)[i]) {
2706 free((certinfo->cert_info)[i]);
2707 (certinfo->cert_info)[i] = NULL;
2715 static int __get_pkg_location(const char *pkgid)
2717 retvm_if(pkgid == NULL, PMINFO_R_OK, "pkginfo handle is NULL");
2720 char pkg_mmc_path[FILENAME_MAX] = { 0, };
2721 snprintf(pkg_mmc_path, FILENAME_MAX, "%s%s", PKG_SD_PATH, pkgid);
2723 /*check whether application is in external memory or not */
2724 fp = fopen(pkg_mmc_path, "r");
2728 return PMINFO_EXTERNAL_STORAGE;
2731 return PMINFO_INTERNAL_STORAGE;
2734 API int pkgmgrinfo_pkginfo_get_usr_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data, uid_t uid)
2736 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2737 char *error_message = NULL;
2738 int ret = PMINFO_R_OK;
2739 char query[MAX_QUERY_LEN] = {'\0'};
2740 char *syslocale = NULL;
2741 char *locale = NULL;
2742 pkgmgr_pkginfo_x *pkginfo = NULL;
2743 label_x *tmp1 = NULL;
2744 icon_x *tmp2 = NULL;
2745 description_x *tmp3 = NULL;
2746 author_x *tmp4 = NULL;
2747 privilege_x *tmp5 = NULL;
2749 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2750 if (syslocale == NULL) {
2751 _LOGE("current locale is NULL\n");
2752 return PMINFO_R_ERROR;
2754 locale = __convert_system_locale_to_manifest_locale(syslocale);
2755 if (locale == NULL) {
2756 _LOGE("manifest locale is NULL\n");
2758 return PMINFO_R_ERROR;
2761 ret = __open_manifest_db(uid);
2763 _LOGE("Fail to open manifest DB\n");
2766 return PMINFO_R_ERROR;
2768 pkgmgr_pkginfo_x *tmphead = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2769 pkgmgr_pkginfo_x *node = NULL;
2770 pkgmgr_pkginfo_x *temp_node = NULL;
2772 snprintf(query, MAX_QUERY_LEN, "select * from package_info");
2774 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
2775 _LOGE("Don't execute query = %s error message = %s\n", query,
2777 sqlite3_free(error_message);
2778 sqlite3_close(manifest_db);
2779 ret = PMINFO_R_ERROR;
2783 LISTHEAD(tmphead, node);
2785 for(node = node->next; node ; node = node->next) {
2787 pkginfo->locale = strdup(locale);
2788 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2789 if (pkginfo->manifest_info->privileges == NULL) {
2790 _LOGE("Failed to allocate memory for privileges info\n");
2791 ret = PMINFO_R_ERROR;
2794 /*populate manifest_info from DB*/
2795 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
2796 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2798 _LOGE("Package Info DB Information retrieval failed\n");
2799 ret = PMINFO_R_ERROR;
2802 memset(query, '\0', MAX_QUERY_LEN);
2803 /*populate privilege_info from DB*/
2804 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkginfo->manifest_info->package);
2805 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2807 _LOGE("Package Privilege Info DB Information retrieval failed\n");
2808 ret = PMINFO_R_ERROR;
2811 memset(query, '\0', MAX_QUERY_LEN);
2812 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2813 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
2814 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2816 _LOGE("Package Info DB Information retrieval failed\n");
2817 ret = PMINFO_R_ERROR;
2820 /*Also store the values corresponding to default locales*/
2821 memset(query, '\0', MAX_QUERY_LEN);
2822 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2823 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
2824 ret = __exec_pkginfo_query(query, (void *)pkginfo);
2826 _LOGE("Package Info DB Information retrieval failed\n");
2827 ret = PMINFO_R_ERROR;
2830 if (pkginfo->manifest_info->label) {
2831 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2832 pkginfo->manifest_info->label = tmp1;
2834 if (pkginfo->manifest_info->icon) {
2835 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2836 pkginfo->manifest_info->icon = tmp2;
2838 if (pkginfo->manifest_info->description) {
2839 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2840 pkginfo->manifest_info->description = tmp3;
2842 if (pkginfo->manifest_info->author) {
2843 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2844 pkginfo->manifest_info->author = tmp4;
2846 if (pkginfo->manifest_info->privileges->privilege) {
2847 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2848 pkginfo->manifest_info->privileges->privilege = tmp5;
2852 LISTHEAD(tmphead, node);
2854 for(node = node->next; node ; node = node->next) {
2856 ret = pkg_list_cb( (void *)pkginfo, user_data);
2864 sqlite3_close(manifest_db);
2873 LISTHEAD(tmphead, node);
2874 temp_node = node->next;
2877 temp_node = node->next;
2878 __cleanup_pkginfo(node);
2881 __cleanup_pkginfo(tmphead);
2885 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2887 return pkgmgrinfo_pkginfo_get_usr_list(pkg_list_cb, user_data, GLOBAL_USER);
2890 API int pkgmgrinfo_pkginfo_get_usr_pkginfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkginfo_h *handle)
2892 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
2893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
2894 pkgmgr_pkginfo_x *pkginfo = NULL;
2895 int ret = PMINFO_R_OK;
2896 char query[MAX_QUERY_LEN] = {'\0'};
2897 char *syslocale = NULL;
2898 char *locale = NULL;
2900 label_x *tmp1 = NULL;
2901 icon_x *tmp2 = NULL;
2902 description_x *tmp3 = NULL;
2903 author_x *tmp4 = NULL;
2904 privilege_x *tmp5 = NULL;
2905 sqlite3 *pkginfo_db = NULL;
2908 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2909 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
2911 /*check pkgid exist on db*/
2912 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2913 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2914 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2915 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2917 /*get system locale*/
2918 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2919 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2921 /*get locale on db*/
2922 locale = __convert_system_locale_to_manifest_locale(syslocale);
2923 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2925 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2926 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2928 pkginfo->locale = strdup(locale);
2930 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2931 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2933 pkginfo->manifest_info->package = strdup(pkgid);
2934 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2935 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2937 /*populate manifest_info from DB*/
2938 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2939 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2940 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2942 memset(query, '\0', MAX_QUERY_LEN);
2943 /*populate privilege_info from DB*/
2944 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2945 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2946 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2948 memset(query, '\0', MAX_QUERY_LEN);
2949 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2950 " package='%s' and package_locale='%s'", pkgid, locale);
2951 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2952 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2954 /*Also store the values corresponding to default locales*/
2955 memset(query, '\0', MAX_QUERY_LEN);
2956 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2957 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2958 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2959 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2961 if (pkginfo->manifest_info->label) {
2962 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2963 pkginfo->manifest_info->label = tmp1;
2965 if (pkginfo->manifest_info->icon) {
2966 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2967 pkginfo->manifest_info->icon = tmp2;
2969 if (pkginfo->manifest_info->description) {
2970 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2971 pkginfo->manifest_info->description = tmp3;
2973 if (pkginfo->manifest_info->author) {
2974 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2975 pkginfo->manifest_info->author = tmp4;
2977 if (pkginfo->manifest_info->privileges->privilege) {
2978 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2979 pkginfo->manifest_info->privileges->privilege = tmp5;
2983 if (ret == PMINFO_R_OK)
2984 *handle = (void*)pkginfo;
2987 __cleanup_pkginfo(pkginfo);
2989 sqlite3_close(pkginfo_db);
3002 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3004 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3007 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3009 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3010 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3011 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3012 if (info->manifest_info->package)
3013 *pkg_name = (char *)info->manifest_info->package;
3015 return PMINFO_R_ERROR;
3020 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3022 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3023 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3024 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3025 if (info->manifest_info->package)
3026 *pkgid = (char *)info->manifest_info->package;
3028 return PMINFO_R_ERROR;
3033 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3035 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3036 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3037 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3038 if (info->manifest_info->type)
3039 *type = (char *)info->manifest_info->type;
3045 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3047 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3048 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3049 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3050 *version = (char *)info->manifest_info->version;
3054 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3056 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3057 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3059 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3060 val = (char *)info->manifest_info->installlocation;
3062 if (strcmp(val, "internal-only") == 0)
3063 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3064 else if (strcmp(val, "prefer-external") == 0)
3065 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3067 *location = PMINFO_INSTALL_LOCATION_AUTO;
3072 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3074 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3075 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3077 char *location = NULL;
3078 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3079 location = (char *)info->manifest_info->installlocation;
3080 val = (char *)info->manifest_info->package_size;
3085 _LOGE("package size is not specified\n");
3086 return PMINFO_R_ERROR;
3091 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3093 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3094 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3097 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3098 long long rw_size = 0;
3099 long long ro_size= 0;
3100 long long tmp_size= 0;
3101 long long total_size= 0;
3102 struct stat fileinfo;
3105 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3107 return PMINFO_R_ERROR;
3110 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3111 if (lstat(device_path, &fileinfo) == 0) {
3112 if (!S_ISLNK(fileinfo.st_mode)) {
3113 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3115 rw_size += tmp_size;
3119 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3120 if (lstat(device_path, &fileinfo) == 0) {
3121 if (!S_ISLNK(fileinfo.st_mode)) {
3122 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3124 rw_size += tmp_size;
3128 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3129 if (lstat(device_path, &fileinfo) == 0) {
3130 if (!S_ISLNK(fileinfo.st_mode)) {
3131 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3133 rw_size += tmp_size;
3137 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3138 if (lstat(device_path, &fileinfo) == 0) {
3139 if (!S_ISLNK(fileinfo.st_mode)) {
3140 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3142 rw_size += tmp_size;
3146 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3147 if (lstat(device_path, &fileinfo) == 0) {
3148 if (!S_ISLNK(fileinfo.st_mode)) {
3149 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3151 rw_size += tmp_size;
3155 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3156 if (lstat(device_path, &fileinfo) == 0) {
3157 if (!S_ISLNK(fileinfo.st_mode)) {
3158 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3160 rw_size += tmp_size;
3165 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3166 if (lstat(device_path, &fileinfo) == 0) {
3167 if (!S_ISLNK(fileinfo.st_mode)) {
3168 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3170 ro_size += tmp_size;
3174 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3175 if (lstat(device_path, &fileinfo) == 0) {
3176 if (!S_ISLNK(fileinfo.st_mode)) {
3177 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3179 ro_size += tmp_size;
3183 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3184 if (lstat(device_path, &fileinfo) == 0) {
3185 if (!S_ISLNK(fileinfo.st_mode)) {
3186 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3188 ro_size += tmp_size;
3192 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3193 if (lstat(device_path, &fileinfo) == 0) {
3194 if (!S_ISLNK(fileinfo.st_mode)) {
3195 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3197 ro_size += tmp_size;
3201 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3202 if (lstat(device_path, &fileinfo) == 0) {
3203 if (!S_ISLNK(fileinfo.st_mode)) {
3204 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3206 ro_size += tmp_size;
3210 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3211 if (lstat(device_path, &fileinfo) == 0) {
3212 if (!S_ISLNK(fileinfo.st_mode)) {
3213 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3215 ro_size += tmp_size;
3220 total_size = rw_size + ro_size;
3221 *size = (int)total_size;
3226 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3228 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3229 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3232 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3233 long long total_size= 0;
3236 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3238 return PMINFO_R_ERROR;
3240 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3241 if (access(device_path, R_OK) == 0)
3242 total_size = _pkgmgr_calculate_dir_size(device_path);
3244 return PMINFO_R_ERROR;
3246 *size = (int)total_size;
3251 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3253 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3254 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3255 int ret = PMINFO_R_OK;
3256 char *locale = NULL;
3260 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3262 locale = info->locale;
3263 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3265 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3268 if (strcmp(ptr->lang, locale) == 0) {
3269 *icon = (char *)ptr->text;
3270 if (strcasecmp(*icon, "(null)") == 0) {
3271 locale = DEFAULT_LOCALE;
3275 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3276 *icon = (char *)ptr->text;
3285 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3287 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3288 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3289 int ret = PMINFO_R_OK;
3290 char *locale = NULL;
3291 label_x *ptr = NULL;
3294 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3295 locale = info->locale;
3296 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3298 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3301 if (strcmp(ptr->lang, locale) == 0) {
3302 *label = (char *)ptr->text;
3303 if (strcasecmp(*label, "(null)") == 0) {
3304 locale = DEFAULT_LOCALE;
3308 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3309 *label = (char *)ptr->text;
3318 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3320 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3321 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3322 char *locale = NULL;
3323 description_x *ptr = NULL;
3324 *description = NULL;
3326 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3327 locale = info->locale;
3328 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3330 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3333 if (strcmp(ptr->lang, locale) == 0) {
3334 *description = (char *)ptr->text;
3335 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3336 locale = DEFAULT_LOCALE;
3340 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3341 *description = (char *)ptr->text;
3349 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3351 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3352 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3353 char *locale = NULL;
3354 author_x *ptr = NULL;
3355 *author_name = NULL;
3357 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3358 locale = info->locale;
3359 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3361 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3364 if (strcmp(ptr->lang, locale) == 0) {
3365 *author_name = (char *)ptr->text;
3366 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3367 locale = DEFAULT_LOCALE;
3371 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3372 *author_name = (char *)ptr->text;
3380 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3382 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3383 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3384 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3385 *author_email = (char *)info->manifest_info->author->email;
3389 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3392 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3393 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3394 *author_href = (char *)info->manifest_info->author->href;
3398 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3400 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3401 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3403 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3405 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3406 *storage = PMINFO_INTERNAL_STORAGE;
3407 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3408 *storage = PMINFO_EXTERNAL_STORAGE;
3410 return PMINFO_R_ERROR;
3415 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3417 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3418 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3419 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3420 if (info->manifest_info->installed_time)
3421 *installed_time = atoi(info->manifest_info->installed_time);
3423 return PMINFO_R_ERROR;
3428 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3430 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3431 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3432 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3433 *storeclientid = (char *)info->manifest_info->storeclient_id;
3437 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3439 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3440 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3441 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3442 *mainappid = (char *)info->manifest_info->mainapp_id;
3446 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3448 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3449 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3450 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3451 *url = (char *)info->manifest_info->package_url;
3455 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3457 const char *val = NULL;
3458 const xmlChar *node;
3459 xmlTextReaderPtr reader;
3460 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3461 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3464 reader = xmlReaderForFile(manifest, NULL, 0);
3467 if (__child_element(reader, -1)) {
3468 node = xmlTextReaderConstName(reader);
3470 _LOGE("xmlTextReaderConstName value is NULL\n");
3471 xmlFreeTextReader(reader);
3473 return PMINFO_R_ERROR;
3476 if (!strcmp(ASC_CHAR(node), "manifest")) {
3477 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3478 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3484 _LOGE("package size is not specified\n");
3485 xmlFreeTextReader(reader);
3487 return PMINFO_R_ERROR;
3490 _LOGE("Unable to create xml reader\n");
3491 xmlFreeTextReader(reader);
3493 return PMINFO_R_ERROR;
3497 _LOGE("xmlReaderForFile value is NULL\n");
3499 return PMINFO_R_ERROR;
3502 xmlFreeTextReader(reader);
3508 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3510 const char *val = NULL;
3511 const xmlChar *node;
3512 xmlTextReaderPtr reader;
3513 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3514 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3517 reader = xmlReaderForFile(manifest, NULL, 0);
3520 if ( __child_element(reader, -1)) {
3521 node = xmlTextReaderConstName(reader);
3523 _LOGE("xmlTextReaderConstName value is NULL\n");
3524 xmlFreeTextReader(reader);
3526 return PMINFO_R_ERROR;
3529 if (!strcmp(ASC_CHAR(node), "manifest")) {
3530 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3531 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3534 if (strcmp(val, "internal-only") == 0)
3535 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3536 else if (strcmp(val, "prefer-external") == 0)
3537 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3539 *location = PMINFO_INSTALL_LOCATION_AUTO;
3542 _LOGE("Unable to create xml reader\n");
3543 xmlFreeTextReader(reader);
3545 return PMINFO_R_ERROR;
3549 _LOGE("xmlReaderForFile value is NULL\n");
3551 return PMINFO_R_ERROR;
3554 xmlFreeTextReader(reader);
3561 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3563 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3564 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3566 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3567 if (info->manifest_info->root_path)
3568 *path = (char *)info->manifest_info->root_path;
3570 return PMINFO_R_ERROR;
3575 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3577 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3578 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3580 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3581 if (info->manifest_info->csc_path)
3582 *path = (char *)info->manifest_info->csc_path;
3584 *path = (char *)info->manifest_info->csc_path;
3589 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)
3591 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3592 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3593 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3595 int ret = PMINFO_R_OK;
3596 char query[MAX_QUERY_LEN] = {'\0'};
3597 char *error_message = NULL;
3598 pkgmgr_cert_x *info= NULL;
3602 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3603 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3604 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3606 ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
3607 SQLITE_OPEN_READWRITE, NULL);
3608 if (ret != SQLITE_OK) {
3609 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
3610 ret = PMINFO_R_ERROR;
3613 _check_create_Cert_db(cert_db);
3614 _pkgmgr_parser_attach_create_view_certdb(cert_db,uid);
3615 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3617 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3618 _LOGE("Don't execute query = %s error message = %s\n", query,
3620 ret = PMINFO_R_ERROR;
3627 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3629 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3630 _LOGE("Don't execute query = %s error message = %s\n", query,
3632 ret = PMINFO_R_ERROR;
3635 lcert = info->cert_id;
3638 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3640 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3641 _LOGE("Don't execute query = %s error message = %s\n", query,
3643 ret = PMINFO_R_ERROR;
3650 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3652 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3653 _LOGE("Don't execute query = %s error message = %s\n", query,
3655 ret = PMINFO_R_ERROR;
3658 rcert = info->cert_id;
3661 if ((lcert == 0) || (rcert == 0))
3663 if ((lcert == 0) && (rcert == 0))
3664 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3665 else if (lcert == 0)
3666 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3667 else if (rcert == 0)
3668 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3671 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3673 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3677 sqlite3_free(error_message);
3678 sqlite3_close(cert_db);
3690 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)
3692 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3695 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)
3697 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3698 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3699 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3701 int ret = PMINFO_R_OK;
3702 char query[MAX_QUERY_LEN] = {'\0'};
3703 char *error_message = NULL;
3704 pkgmgr_cert_x *info= NULL;
3706 char *lpkgid = NULL;
3707 char *rpkgid = NULL;
3709 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3710 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3712 ret = db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
3713 SQLITE_OPEN_READONLY, NULL);
3714 if (ret != SQLITE_OK) {
3715 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPath());
3716 ret = PMINFO_R_ERROR;
3720 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3722 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3723 _LOGE("Don't execute query = %s error message = %s\n", query,
3725 ret = PMINFO_R_ERROR;
3732 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3734 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3735 _LOGE("Don't execute query = %s error message = %s\n", query,
3737 ret = PMINFO_R_ERROR;
3740 lpkgid = strdup(info->pkgid);
3741 if (lpkgid == NULL) {
3742 _LOGE("Out of Memory\n");
3743 ret = PMINFO_R_ERROR;
3750 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3752 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3753 _LOGE("Don't execute query = %s error message = %s\n", query,
3755 ret = PMINFO_R_ERROR;
3762 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3764 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3765 _LOGE("Don't execute query = %s error message = %s\n", query,
3767 ret = PMINFO_R_ERROR;
3770 rpkgid = strdup(info->pkgid);
3771 if (rpkgid == NULL) {
3772 _LOGE("Out of Memory\n");
3773 ret = PMINFO_R_ERROR;
3779 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3781 sqlite3_free(error_message);
3782 sqlite3_close(manifest_db);
3802 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)
3804 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3805 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3806 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3808 int ret = PMINFO_R_OK;
3809 char query[MAX_QUERY_LEN] = {'\0'};
3810 char *error_message = NULL;
3811 pkgmgr_cert_x *info= NULL;
3813 char *lpkgid = NULL;
3814 char *rpkgid = NULL;
3816 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3817 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3819 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
3820 SQLITE_OPEN_READONLY, NULL);
3821 if (ret != SQLITE_OK) {
3822 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3823 ret = PMINFO_R_ERROR;
3826 _pkgmgr_parser_attach_create_view_parserdb(manifest_db,uid);
3828 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3830 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3831 _LOGE("Don't execute query = %s error message = %s\n", query,
3833 ret = PMINFO_R_ERROR;
3840 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3842 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3843 _LOGE("Don't execute query = %s error message = %s\n", query,
3845 ret = PMINFO_R_ERROR;
3848 lpkgid = strdup(info->pkgid);
3849 if (lpkgid == NULL) {
3850 _LOGE("Out of Memory\n");
3851 ret = PMINFO_R_ERROR;
3858 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3860 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3861 _LOGE("Don't execute query = %s error message = %s\n", query,
3863 ret = PMINFO_R_ERROR;
3870 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3872 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3873 _LOGE("Don't execute query = %s error message = %s\n", query,
3875 ret = PMINFO_R_ERROR;
3878 rpkgid = strdup(info->pkgid);
3879 if (rpkgid == NULL) {
3880 _LOGE("Out of Memory\n");
3881 ret = PMINFO_R_ERROR;
3887 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3889 sqlite3_free(error_message);
3890 sqlite3_close(manifest_db);
3910 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3912 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3913 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3915 #if 0 //smack issue occured, check later
3917 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3919 _LOGD("invalid func parameters\n");
3920 return PMINFO_R_ERROR;
3922 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3925 char app_mmc_path[FILENAME_MAX] = { 0, };
3926 char app_dir_path[FILENAME_MAX] = { 0, };
3927 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3928 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3929 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3930 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3932 /*check whether application is in external memory or not */
3933 fp = fopen(app_mmc_path, "r");
3935 _LOGD(" app path in external memory not accesible\n");
3940 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3944 /*check whether application is in internal or not */
3945 fp = fopen(app_dir_path, "r");
3947 _LOGD(" app path in internal memory not accesible\n");
3949 return PMINFO_R_ERROR;
3952 /*check whether the application is installed in SD card
3953 but SD card is not present*/
3954 fp = fopen(app_mmc_internal_path, "r");
3957 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3962 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3967 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3974 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3976 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3977 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3979 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3980 val = (char *)info->manifest_info->removable;
3982 if (strcasecmp(val, "true") == 0)
3984 else if (strcasecmp(val, "false") == 0)
3992 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3994 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3995 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3998 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4000 val = (char *)info->manifest_info->installlocation;
4002 if (strcmp(val, "internal-only") == 0)
4004 else if (strcmp(val, "prefer-external") == 0)
4013 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4015 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4016 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4018 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4019 val = (char *)info->manifest_info->preload;
4021 if (strcasecmp(val, "true") == 0)
4023 else if (strcasecmp(val, "false") == 0)
4031 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4033 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4034 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4037 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4038 val = (char *)info->manifest_info->system;
4040 if (strcasecmp(val, "true") == 0)
4042 else if (strcasecmp(val, "false") == 0)
4051 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4053 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4054 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4056 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4057 val = (char *)info->manifest_info->readonly;
4059 if (strcasecmp(val, "true") == 0)
4061 else if (strcasecmp(val, "false") == 0)
4069 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4071 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4072 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4075 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4076 val = (char *)info->manifest_info->update;
4078 if (strcasecmp(val, "true") == 0)
4080 else if (strcasecmp(val, "false") == 0)
4088 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4090 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4091 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4092 __cleanup_pkginfo(info);
4096 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4098 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4100 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4101 if (filter == NULL) {
4102 _LOGE("Out of Memory!!!");
4103 return PMINFO_R_ERROR;
4109 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4111 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4112 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4114 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4115 g_slist_free(filter->list);
4122 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4123 const char *property, const int value)
4125 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4126 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4127 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4129 GSList *link = NULL;
4131 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4132 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4133 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4134 _LOGE("Invalid Integer Property\n");
4135 return PMINFO_R_EINVAL;
4137 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4138 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4140 _LOGE("Out of Memory!!!\n");
4141 return PMINFO_R_ERROR;
4143 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4144 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4146 _LOGE("Out of Memory\n");
4149 return PMINFO_R_ERROR;
4153 /*If API is called multiple times for same property, we should override the previous values.
4154 Last value set will be used for filtering.*/
4155 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4157 filter->list = g_slist_delete_link(filter->list, link);
4158 filter->list = g_slist_append(filter->list, (gpointer)node);
4163 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4164 const char *property, const bool value)
4166 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4167 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4169 GSList *link = NULL;
4171 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4172 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4173 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4174 _LOGE("Invalid Boolean Property\n");
4175 return PMINFO_R_EINVAL;
4177 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4178 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4180 _LOGE("Out of Memory!!!\n");
4181 return PMINFO_R_ERROR;
4184 val = strndup("('true','True')", 15);
4186 val = strndup("('false','False')", 17);
4188 _LOGE("Out of Memory\n");
4191 return PMINFO_R_ERROR;
4195 /*If API is called multiple times for same property, we should override the previous values.
4196 Last value set will be used for filtering.*/
4197 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4199 filter->list = g_slist_delete_link(filter->list, link);
4200 filter->list = g_slist_append(filter->list, (gpointer)node);
4205 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4206 const char *property, const char *value)
4208 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4209 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4210 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4212 GSList *link = NULL;
4214 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4215 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4216 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4217 _LOGE("Invalid String Property\n");
4218 return PMINFO_R_EINVAL;
4220 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4221 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4223 _LOGE("Out of Memory!!!\n");
4224 return PMINFO_R_ERROR;
4226 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4227 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4228 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4229 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4230 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4231 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4232 else if (strcmp(value, "installed_internal") == 0)
4233 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4234 else if (strcmp(value, "installed_external") == 0)
4235 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4237 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4239 _LOGE("Out of Memory\n");
4242 return PMINFO_R_ERROR;
4246 /*If API is called multiple times for same property, we should override the previous values.
4247 Last value set will be used for filtering.*/
4248 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4250 filter->list = g_slist_delete_link(filter->list, link);
4251 filter->list = g_slist_append(filter->list, (gpointer)node);
4256 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4258 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4259 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4260 char *syslocale = NULL;
4261 char *locale = NULL;
4262 char *condition = NULL;
4263 char *error_message = NULL;
4264 char query[MAX_QUERY_LEN] = {'\0'};
4265 char where[MAX_QUERY_LEN] = {'\0'};
4269 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4270 /*Get current locale*/
4271 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4272 if (syslocale == NULL) {
4273 _LOGE("current locale is NULL\n");
4274 return PMINFO_R_ERROR;
4276 locale = __convert_system_locale_to_manifest_locale(syslocale);
4277 if (locale == NULL) {
4278 _LOGE("manifest locale is NULL\n");
4280 return PMINFO_R_ERROR;
4283 ret = __open_manifest_db(uid);
4285 _LOGE("Fail to open manifest DB\n");
4288 return PMINFO_R_ERROR;
4291 /*Start constructing query*/
4292 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4294 /*Get where clause*/
4295 for (list = filter->list; list; list = g_slist_next(list)) {
4296 __get_filter_condition(list->data, &condition);
4298 strncat(where, condition, sizeof(where) - strlen(where) -1);
4299 where[sizeof(where) - 1] = '\0';
4303 if (g_slist_next(list)) {
4304 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4305 where[sizeof(where) - 1] = '\0';
4308 _LOGE("where = %s\n", where);
4309 if (strlen(where) > 0) {
4310 strncat(query, where, sizeof(query) - strlen(query) - 1);
4311 query[sizeof(query) - 1] = '\0';
4313 _LOGE("query = %s\n", query);
4317 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
4318 _LOGE("Don't execute query = %s error message = %s\n", query,
4320 sqlite3_free(error_message);
4321 sqlite3_close(manifest_db);
4322 ret = PMINFO_R_ERROR;
4336 sqlite3_close(manifest_db);
4340 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4342 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4345 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4346 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4348 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4349 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4350 char *syslocale = NULL;
4351 char *locale = NULL;
4352 char *condition = NULL;
4353 char *error_message = NULL;
4354 char query[MAX_QUERY_LEN] = {'\0'};
4355 char where[MAX_QUERY_LEN] = {'\0'};
4358 label_x *tmp1 = NULL;
4359 icon_x *tmp2 = NULL;
4360 description_x *tmp3 = NULL;
4361 author_x *tmp4 = NULL;
4362 privilege_x *tmp5 = NULL;
4363 pkgmgr_pkginfo_x *node = NULL;
4364 pkgmgr_pkginfo_x *tmphead = NULL;
4365 pkgmgr_pkginfo_x *pkginfo = NULL;
4367 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4368 /*Get current locale*/
4369 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4370 if (syslocale == NULL) {
4371 _LOGE("current locale is NULL\n");
4372 return PMINFO_R_ERROR;
4374 locale = __convert_system_locale_to_manifest_locale(syslocale);
4375 if (locale == NULL) {
4376 _LOGE("manifest locale is NULL\n");
4378 return PMINFO_R_ERROR;
4381 ret = __open_manifest_db(uid);
4383 _LOGE("Fail to open manifest DB\n");
4386 return PMINFO_R_ERROR;
4388 /*Start constructing query*/
4389 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4391 /*Get where clause*/
4392 for (list = filter->list; list; list = g_slist_next(list)) {
4393 __get_filter_condition(list->data, &condition);
4395 strncat(where, condition, sizeof(where) - strlen(where) -1);
4396 where[sizeof(where) - 1] = '\0';
4400 if (g_slist_next(list)) {
4401 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4402 where[sizeof(where) - 1] = '\0';
4405 _LOGE("where = %s\n", where);
4406 if (strlen(where) > 0) {
4407 strncat(query, where, sizeof(query) - strlen(query) - 1);
4408 query[sizeof(query) - 1] = '\0';
4410 _LOGE("query = %s\n", query);
4411 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4412 if (tmphead == NULL) {
4413 _LOGE("Out of Memory!!!\n");
4414 ret = PMINFO_R_ERROR;
4419 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4420 _LOGE("Don't execute query = %s error message = %s\n", query,
4422 sqlite3_free(error_message);
4423 ret = PMINFO_R_ERROR;
4427 LISTHEAD(tmphead, node);
4428 for(node = node->next ; node ; node = node->next) {
4430 pkginfo->locale = strdup(locale);
4431 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4432 if (pkginfo->manifest_info->privileges == NULL) {
4433 _LOGE("Failed to allocate memory for privileges info\n");
4434 ret = PMINFO_R_ERROR;
4438 /*populate manifest_info from DB*/
4439 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4440 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4442 _LOGE("Package Info DB Information retrieval failed\n");
4443 ret = PMINFO_R_ERROR;
4446 memset(query, '\0', MAX_QUERY_LEN);
4447 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4448 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4449 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4451 _LOGE("Package Info DB Information retrieval failed\n");
4452 ret = PMINFO_R_ERROR;
4455 /*Also store the values corresponding to default locales*/
4456 memset(query, '\0', MAX_QUERY_LEN);
4457 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4458 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4459 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4461 _LOGE("Package Info DB Information retrieval failed\n");
4462 ret = PMINFO_R_ERROR;
4465 if (pkginfo->manifest_info->label) {
4466 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4467 pkginfo->manifest_info->label = tmp1;
4469 if (pkginfo->manifest_info->icon) {
4470 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4471 pkginfo->manifest_info->icon = tmp2;
4473 if (pkginfo->manifest_info->description) {
4474 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4475 pkginfo->manifest_info->description = tmp3;
4477 if (pkginfo->manifest_info->author) {
4478 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4479 pkginfo->manifest_info->author = tmp4;
4481 if (pkginfo->manifest_info->privileges->privilege) {
4482 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4483 pkginfo->manifest_info->privileges->privilege = tmp5;
4487 LISTHEAD(tmphead, node);
4489 for(node = node->next ; node ; node = node->next) {
4491 ret = pkg_cb( (void *)pkginfo, user_data);
4506 sqlite3_close(manifest_db);
4507 __cleanup_pkginfo(tmphead);
4511 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4512 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4514 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4517 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4518 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4520 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4521 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4523 privilege_x *ptr = NULL;
4524 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4525 ptr = info->manifest_info->privileges->privilege;
4526 for (; ptr; ptr = ptr->next) {
4528 ret = privilege_func(ptr->text, user_data);
4536 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4537 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4539 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4540 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4541 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4543 char *syslocale = NULL;
4544 char *locale = NULL;
4546 char query[MAX_QUERY_LEN] = {'\0'};
4547 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4548 pkgmgr_pkginfo_x *allinfo = NULL;
4549 pkgmgr_appinfo_x *appinfo = NULL;
4550 icon_x *ptr1 = NULL;
4551 label_x *ptr2 = NULL;
4552 category_x *ptr3 = NULL;
4553 metadata_x *ptr4 = NULL;
4554 permission_x *ptr5 = NULL;
4555 image_x *ptr6 = NULL;
4556 sqlite3 *appinfo_db = NULL;
4558 /*get system locale*/
4559 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4560 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4562 /*get locale on db*/
4563 locale = __convert_system_locale_to_manifest_locale(syslocale);
4564 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4567 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4568 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4570 /*calloc manifest_info*/
4571 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4572 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4575 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4576 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4578 /*set component type*/
4579 if (component == PMINFO_UI_APP)
4580 appinfo->app_component = PMINFO_UI_APP;
4581 if (component == PMINFO_SVC_APP)
4582 appinfo->app_component = PMINFO_SVC_APP;
4583 if (component == PMINFO_ALL_APP)
4584 appinfo->app_component = PMINFO_ALL_APP;
4587 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4588 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4590 appinfo->package = strdup(info->manifest_info->package);
4591 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4592 "from package_app_info where " \
4593 "package='%s' and app_component='%s'",
4594 info->manifest_info->package,
4595 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4599 /*Populate ui app info */
4600 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
4601 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4603 uiapplication_x *tmp = NULL;
4604 if (info->manifest_info->uiapplication) {
4605 LISTHEAD(info->manifest_info->uiapplication, tmp);
4606 info->manifest_info->uiapplication = tmp;
4608 /*Populate localized info for default locales and call callback*/
4609 /*If the callback func return < 0 we break and no more call back is called*/
4612 appinfo->locale = strdup(locale);
4613 appinfo->uiapp_info = tmp;
4614 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4618 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
4621 memset(query, '\0', MAX_QUERY_LEN);
4622 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4623 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4624 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4626 memset(query, '\0', MAX_QUERY_LEN);
4627 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);
4628 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4629 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4631 /*store setting notification icon section*/
4632 memset(query, '\0', MAX_QUERY_LEN);
4633 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4634 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4635 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4637 /*store app preview image info*/
4638 memset(query, '\0', MAX_QUERY_LEN);
4639 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4640 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4641 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4643 if (appinfo->uiapp_info->label) {
4644 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4645 appinfo->uiapp_info->label = ptr2;
4647 if (appinfo->uiapp_info->icon) {
4648 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4649 appinfo->uiapp_info->icon = ptr1;
4651 if (appinfo->uiapp_info->category) {
4652 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4653 appinfo->uiapp_info->category = ptr3;
4655 if (appinfo->uiapp_info->metadata) {
4656 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4657 appinfo->uiapp_info->metadata = ptr4;
4659 if (appinfo->uiapp_info->permission) {
4660 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4661 appinfo->uiapp_info->permission = ptr5;
4663 if (appinfo->uiapp_info->image) {
4664 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4665 appinfo->uiapp_info->image = ptr6;
4667 ret = app_func((void *)appinfo, user_data);
4673 case PMINFO_SVC_APP:
4674 /*Populate svc app info */
4675 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
4676 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4678 serviceapplication_x *tmp1 = NULL;
4679 if (info->manifest_info->serviceapplication) {
4680 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4681 info->manifest_info->serviceapplication = tmp1;
4683 /*Populate localized info for default locales and call callback*/
4684 /*If the callback func return < 0 we break and no more call back is called*/
4687 appinfo->locale = strdup(locale);
4688 appinfo->svcapp_info = tmp1;
4689 memset(query, '\0', MAX_QUERY_LEN);
4690 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4691 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4692 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4694 memset(query, '\0', MAX_QUERY_LEN);
4695 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);
4696 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4697 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4699 if (appinfo->svcapp_info->label) {
4700 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4701 appinfo->svcapp_info->label = ptr2;
4703 if (appinfo->svcapp_info->icon) {
4704 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4705 appinfo->svcapp_info->icon = ptr1;
4707 if (appinfo->svcapp_info->category) {
4708 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4709 appinfo->svcapp_info->category = ptr3;
4711 if (appinfo->svcapp_info->metadata) {
4712 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4713 appinfo->svcapp_info->metadata = ptr4;
4715 if (appinfo->svcapp_info->permission) {
4716 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4717 appinfo->svcapp_info->permission = ptr5;
4719 ret = app_func((void *)appinfo, user_data);
4725 case PMINFO_ALL_APP:
4726 memset(query, '\0', MAX_QUERY_LEN);
4727 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4729 /*Populate all app info */
4730 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
4731 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4734 appinfo->app_component = PMINFO_UI_APP;
4735 uiapplication_x *tmp2 = NULL;
4736 if (allinfo->manifest_info->uiapplication) {
4737 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4738 allinfo->manifest_info->uiapplication = tmp2;
4740 /*Populate localized info for default locales and call callback*/
4741 /*If the callback func return < 0 we break and no more call back is called*/
4744 appinfo->locale = strdup(locale);
4745 appinfo->uiapp_info = tmp2;
4746 memset(query, '\0', MAX_QUERY_LEN);
4747 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4748 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4749 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4751 memset(query, '\0', MAX_QUERY_LEN);
4752 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
4753 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4754 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4756 /*store setting notification icon section*/
4757 memset(query, '\0', MAX_QUERY_LEN);
4758 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4759 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4760 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4762 /*store app preview image info*/
4763 memset(query, '\0', MAX_QUERY_LEN);
4764 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4765 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4766 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4768 if (appinfo->uiapp_info->label) {
4769 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4770 appinfo->uiapp_info->label = ptr2;
4772 if (appinfo->uiapp_info->icon) {
4773 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4774 appinfo->uiapp_info->icon = ptr1;
4776 if (appinfo->uiapp_info->category) {
4777 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4778 appinfo->uiapp_info->category = ptr3;
4780 if (appinfo->uiapp_info->metadata) {
4781 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4782 appinfo->uiapp_info->metadata = ptr4;
4784 if (appinfo->uiapp_info->permission) {
4785 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4786 appinfo->uiapp_info->permission = ptr5;
4788 if (appinfo->uiapp_info->image) {
4789 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4790 appinfo->uiapp_info->image = ptr6;
4792 ret = app_func((void *)appinfo, user_data);
4799 appinfo->app_component = PMINFO_SVC_APP;
4800 serviceapplication_x *tmp3 = NULL;
4801 if (allinfo->manifest_info->serviceapplication) {
4802 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4803 allinfo->manifest_info->serviceapplication = tmp3;
4805 /*Populate localized info for default locales and call callback*/
4806 /*If the callback func return < 0 we break and no more call back is called*/
4809 appinfo->locale = strdup(locale);
4810 appinfo->svcapp_info = tmp3;
4811 memset(query, '\0', MAX_QUERY_LEN);
4812 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4813 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4814 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4816 memset(query, '\0', MAX_QUERY_LEN);
4817 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);
4818 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4819 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4821 if (appinfo->svcapp_info->label) {
4822 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4823 appinfo->svcapp_info->label = ptr2;
4825 if (appinfo->svcapp_info->icon) {
4826 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4827 appinfo->svcapp_info->icon = ptr1;
4829 if (appinfo->svcapp_info->category) {
4830 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4831 appinfo->svcapp_info->category = ptr3;
4833 if (appinfo->svcapp_info->metadata) {
4834 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4835 appinfo->svcapp_info->metadata = ptr4;
4837 if (appinfo->svcapp_info->permission) {
4838 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4839 appinfo->svcapp_info->permission = ptr5;
4841 ret = app_func((void *)appinfo, user_data);
4846 appinfo->app_component = PMINFO_ALL_APP;
4862 if (appinfo->package) {
4863 free((void *)appinfo->package);
4864 appinfo->package = NULL;
4869 __cleanup_pkginfo(allinfo);
4871 sqlite3_close(appinfo_db);
4875 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4876 pkgmgrinfo_app_list_cb app_func, void *user_data)
4878 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4881 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4883 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4885 int ret = PMINFO_R_OK;
4886 char query[MAX_QUERY_LEN] = {'\0'};
4887 pkgmgr_appinfo_x *appinfo = NULL;
4888 uiapplication_x *ptr1 = NULL;
4889 serviceapplication_x *ptr2 = NULL;
4890 sqlite3 *appinfo_db = NULL;
4893 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4894 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4897 pkgmgr_pkginfo_x *info = NULL;
4898 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4899 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4901 /*calloc manifest_info*/
4902 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4903 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4906 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4907 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4909 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4910 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4911 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4913 if (info->manifest_info->uiapplication) {
4914 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4915 info->manifest_info->uiapplication = ptr1;
4917 if (info->manifest_info->serviceapplication) {
4918 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4919 info->manifest_info->serviceapplication = ptr2;
4923 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4925 appinfo->app_component = PMINFO_UI_APP;
4926 appinfo->package = strdup(ptr1->package);
4927 appinfo->uiapp_info = ptr1;
4929 ret = app_func((void *)appinfo, user_data);
4932 free((void *)appinfo->package);
4933 appinfo->package = NULL;
4936 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4938 appinfo->app_component = PMINFO_SVC_APP;
4939 appinfo->package = strdup(ptr2->package);
4940 appinfo->svcapp_info = ptr2;
4942 ret = app_func((void *)appinfo, user_data);
4945 free((void *)appinfo->package);
4946 appinfo->package = NULL;
4951 sqlite3_close(appinfo_db);
4957 __cleanup_pkginfo(info);
4961 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4963 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4966 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4968 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4970 int ret = PMINFO_R_OK;
4971 char query[MAX_QUERY_LEN] = {'\0'};
4972 char *syslocale = NULL;
4973 char *locale = NULL;
4974 pkgmgr_appinfo_x *appinfo = NULL;
4975 uiapplication_x *ptr1 = NULL;
4976 serviceapplication_x *ptr2 = NULL;
4977 label_x *tmp1 = NULL;
4978 icon_x *tmp2 = NULL;
4979 category_x *tmp3 = NULL;
4980 metadata_x *tmp4 = NULL;
4981 permission_x *tmp5 = NULL;
4982 image_x *tmp6 = NULL;
4983 sqlite3 *appinfo_db = NULL;
4985 /*get system locale*/
4986 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4987 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4989 /*get locale on db*/
4990 locale = __convert_system_locale_to_manifest_locale(syslocale);
4991 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4994 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4995 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4998 pkgmgr_pkginfo_x *info = NULL;
4999 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5000 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5002 /*calloc manifest_info*/
5003 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5004 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5007 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5008 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5010 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5011 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
5012 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5014 if (info->manifest_info->uiapplication) {
5015 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5016 info->manifest_info->uiapplication = ptr1;
5018 if (info->manifest_info->serviceapplication) {
5019 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5020 info->manifest_info->serviceapplication = ptr2;
5024 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5026 appinfo->locale = strdup(locale);
5027 appinfo->app_component = PMINFO_UI_APP;
5028 appinfo->package = strdup(ptr1->package);
5029 appinfo->uiapp_info = ptr1;
5030 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5031 "from package_app_info where " \
5032 "app_id='%s'", ptr1->appid);
5033 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5034 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5036 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5040 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
5043 memset(query, '\0', MAX_QUERY_LEN);
5044 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5045 "from package_app_localized_info where " \
5046 "app_id='%s' and app_locale='%s'",
5047 ptr1->appid, locale);
5048 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5049 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5051 memset(query, '\0', MAX_QUERY_LEN);
5052 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5053 "from package_app_localized_info where " \
5054 "app_id='%s' and app_locale='%s'",
5055 ptr1->appid, DEFAULT_LOCALE);
5057 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5058 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5060 /*store setting notification icon section*/
5061 memset(query, '\0', MAX_QUERY_LEN);
5062 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5063 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5064 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5066 /*store app preview image info*/
5067 memset(query, '\0', MAX_QUERY_LEN);
5068 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5069 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5070 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5072 if (appinfo->uiapp_info->label) {
5073 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5074 appinfo->uiapp_info->label = tmp1;
5076 if (appinfo->uiapp_info->icon) {
5077 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5078 appinfo->uiapp_info->icon= tmp2;
5080 if (appinfo->uiapp_info->category) {
5081 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5082 appinfo->uiapp_info->category = tmp3;
5084 if (appinfo->uiapp_info->metadata) {
5085 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5086 appinfo->uiapp_info->metadata = tmp4;
5088 if (appinfo->uiapp_info->permission) {
5089 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5090 appinfo->uiapp_info->permission = tmp5;
5092 if (appinfo->uiapp_info->image) {
5093 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5094 appinfo->uiapp_info->image = tmp6;
5096 ret = app_func((void *)appinfo, user_data);
5099 free((void *)appinfo->package);
5100 appinfo->package = NULL;
5103 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5105 appinfo->locale = strdup(locale);
5106 appinfo->app_component = PMINFO_SVC_APP;
5107 appinfo->package = strdup(ptr2->package);
5108 appinfo->svcapp_info = ptr2;
5109 memset(query, '\0', MAX_QUERY_LEN);
5110 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5111 "from package_app_info where " \
5112 "app_id='%s'", ptr2->appid);
5113 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5114 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5116 memset(query, '\0', MAX_QUERY_LEN);
5117 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5118 "from package_app_localized_info where " \
5119 "app_id='%s' and app_locale='%s'",
5120 ptr2->appid, locale);
5121 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5122 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5124 memset(query, '\0', MAX_QUERY_LEN);
5125 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5126 "from package_app_localized_info where " \
5127 "app_id='%s' and app_locale='%s'",
5128 ptr2->appid, DEFAULT_LOCALE);
5129 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5130 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5132 if (appinfo->svcapp_info->label) {
5133 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5134 appinfo->svcapp_info->label = tmp1;
5136 if (appinfo->svcapp_info->icon) {
5137 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5138 appinfo->svcapp_info->icon= tmp2;
5140 if (appinfo->svcapp_info->category) {
5141 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5142 appinfo->svcapp_info->category = tmp3;
5144 if (appinfo->svcapp_info->metadata) {
5145 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5146 appinfo->svcapp_info->metadata = tmp4;
5148 if (appinfo->svcapp_info->permission) {
5149 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5150 appinfo->svcapp_info->permission = tmp5;
5152 ret = app_func((void *)appinfo, user_data);
5155 free((void *)appinfo->package);
5156 appinfo->package = NULL;
5169 sqlite3_close(appinfo_db);
5174 __cleanup_pkginfo(info);
5178 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5180 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5183 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5185 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5186 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5188 pkgmgr_appinfo_x *appinfo = NULL;
5189 char *syslocale = NULL;
5190 char *locale = NULL;
5193 label_x *tmp1 = NULL;
5194 icon_x *tmp2 = NULL;
5195 category_x *tmp3 = NULL;
5196 metadata_x *tmp4 = NULL;
5197 permission_x *tmp5 = NULL;
5198 image_x *tmp6 = NULL;
5199 char query[MAX_QUERY_LEN] = {'\0'};
5200 sqlite3 *appinfo_db = NULL;
5203 _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
5204 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5205 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5208 /*check appid exist on db*/
5209 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5210 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
5211 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5212 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5214 /*get system locale*/
5215 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5216 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5218 /*get locale on db*/
5219 locale = __convert_system_locale_to_manifest_locale(syslocale);
5220 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5223 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5224 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5226 /*check app_component from DB*/
5227 memset(query, '\0', MAX_QUERY_LEN);
5228 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5229 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
5230 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5232 /*calloc app_component*/
5233 if (appinfo->app_component == PMINFO_UI_APP) {
5234 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5235 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5237 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5238 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5240 appinfo->locale = strdup(locale);
5242 /*populate app_info from DB*/
5243 memset(query, '\0', MAX_QUERY_LEN);
5244 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5245 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5246 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5248 memset(query, '\0', MAX_QUERY_LEN);
5249 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5250 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5251 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5253 /*Also store the values corresponding to default locales*/
5254 memset(query, '\0', MAX_QUERY_LEN);
5255 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5256 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5257 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5259 /*Populate app category*/
5260 memset(query, '\0', MAX_QUERY_LEN);
5261 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5262 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5263 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5265 /*Populate app metadata*/
5266 memset(query, '\0', MAX_QUERY_LEN);
5267 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5268 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5269 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5271 /*Populate app permission*/
5272 memset(query, '\0', MAX_QUERY_LEN);
5273 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5274 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5275 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5277 /*store setting notification icon section*/
5278 memset(query, '\0', MAX_QUERY_LEN);
5279 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5280 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5281 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5283 /*store app preview image info*/
5284 memset(query, '\0', MAX_QUERY_LEN);
5285 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5286 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5287 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5289 switch (appinfo->app_component) {
5291 if (appinfo->uiapp_info->label) {
5292 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5293 appinfo->uiapp_info->label = tmp1;
5295 if (appinfo->uiapp_info->icon) {
5296 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5297 appinfo->uiapp_info->icon = tmp2;
5299 if (appinfo->uiapp_info->category) {
5300 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5301 appinfo->uiapp_info->category = tmp3;
5303 if (appinfo->uiapp_info->metadata) {
5304 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5305 appinfo->uiapp_info->metadata = tmp4;
5307 if (appinfo->uiapp_info->permission) {
5308 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5309 appinfo->uiapp_info->permission = tmp5;
5311 if (appinfo->uiapp_info->image) {
5312 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5313 appinfo->uiapp_info->image = tmp6;
5316 case PMINFO_SVC_APP:
5317 if (appinfo->svcapp_info->label) {
5318 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5319 appinfo->svcapp_info->label = tmp1;
5321 if (appinfo->svcapp_info->icon) {
5322 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5323 appinfo->svcapp_info->icon = tmp2;
5325 if (appinfo->svcapp_info->category) {
5326 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5327 appinfo->svcapp_info->category = tmp3;
5329 if (appinfo->svcapp_info->metadata) {
5330 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5331 appinfo->svcapp_info->metadata = tmp4;
5333 if (appinfo->svcapp_info->permission) {
5334 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5335 appinfo->svcapp_info->permission = tmp5;
5345 if (ret == PMINFO_R_OK)
5346 *handle = (void*)appinfo;
5349 __cleanup_appinfo(appinfo);
5352 sqlite3_close(appinfo_db);
5364 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5366 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5369 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5371 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5372 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5373 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5375 if (info->app_component == PMINFO_UI_APP)
5376 *appid = (char *)info->uiapp_info->appid;
5377 else if (info->app_component == PMINFO_SVC_APP)
5378 *appid = (char *)info->svcapp_info->appid;
5383 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5385 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5386 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5387 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5389 *pkg_name = (char *)info->package;
5394 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5396 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5397 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5398 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5400 *pkgid = (char *)info->package;
5405 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5407 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5408 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5409 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5411 if (info->app_component == PMINFO_UI_APP)
5412 *exec = (char *)info->uiapp_info->exec;
5413 if (info->app_component == PMINFO_SVC_APP)
5414 *exec = (char *)info->svcapp_info->exec;
5420 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5422 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5423 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5424 char *locale = NULL;
5426 icon_x *start = NULL;
5429 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5430 locale = info->locale;
5431 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5433 if (info->app_component == PMINFO_UI_APP)
5434 start = info->uiapp_info->icon;
5435 if (info->app_component == PMINFO_SVC_APP)
5436 start = info->svcapp_info->icon;
5437 for(ptr = start; ptr != NULL; ptr = ptr->next)
5440 if (strcmp(ptr->lang, locale) == 0) {
5441 *icon = (char *)ptr->text;
5442 if (strcasecmp(*icon, "(null)") == 0) {
5443 locale = DEFAULT_LOCALE;
5447 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5448 *icon = (char *)ptr->text;
5457 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5459 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5460 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5461 char *locale = NULL;
5462 label_x *ptr = NULL;
5463 label_x *start = NULL;
5466 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5467 locale = info->locale;
5468 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5470 if (info->app_component == PMINFO_UI_APP)
5471 start = info->uiapp_info->label;
5472 if (info->app_component == PMINFO_SVC_APP)
5473 start = info->svcapp_info->label;
5474 for(ptr = start; ptr != NULL; ptr = ptr->next)
5477 if (strcmp(ptr->lang, locale) == 0) {
5478 *label = (char *)ptr->text;
5479 if (strcasecmp(*label, "(null)") == 0) {
5480 locale = DEFAULT_LOCALE;
5484 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5485 *label = (char *)ptr->text;
5486 if (strcasecmp(*label, "(null)") == 0) {
5487 locale = DEFAULT_LOCALE;
5491 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5492 *label = (char *)ptr->text;
5501 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5503 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5504 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5505 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5507 if (info->app_component == PMINFO_UI_APP)
5508 *component = PMINFO_UI_APP;
5509 else if (info->app_component == PMINFO_SVC_APP)
5510 *component = PMINFO_SVC_APP;
5512 return PMINFO_R_ERROR;
5517 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5519 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5520 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5521 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5523 if (info->app_component == PMINFO_UI_APP)
5524 *app_type = (char *)info->uiapp_info->type;
5525 if (info->app_component == PMINFO_SVC_APP)
5526 *app_type = (char *)info->svcapp_info->type;
5531 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5532 int *operation_count, char ***operation)
5534 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5535 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5536 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5537 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5538 *operation_count = data->operation_count;
5539 *operation = data->operation;
5543 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5544 int *uri_count, char ***uri)
5546 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5547 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5548 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5549 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5550 *uri_count = data->uri_count;
5555 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5556 int *mime_count, char ***mime)
5558 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5559 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5560 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5561 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5562 *mime_count = data->mime_count;
5567 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5568 int *subapp_count, char ***subapp)
5570 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5571 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5572 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5573 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5574 *subapp_count = data->subapp_count;
5575 *subapp = data->subapp;
5579 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5581 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5582 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5586 icon_x *start = NULL;
5587 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5589 start = info->uiapp_info->icon;
5591 for(ptr = start; ptr != NULL; ptr = ptr->next)
5594 val = (char *)ptr->section;
5595 if (strcmp(val, "setting") == 0){
5596 *icon = (char *)ptr->text;
5605 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5607 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5608 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5612 icon_x *start = NULL;
5613 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5615 start = info->uiapp_info->icon;
5617 for(ptr = start; ptr != NULL; ptr = ptr->next)
5620 val = (char *)ptr->section;
5622 if (strcmp(val, "notification") == 0){
5623 *icon = (char *)ptr->text;
5632 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5634 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5635 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5637 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5638 val = (char *)info->uiapp_info->recentimage;
5640 if (strcasecmp(val, "capture") == 0)
5641 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5642 else if (strcasecmp(val, "icon") == 0)
5643 *type = PMINFO_RECENTIMAGE_USE_ICON;
5645 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5651 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5653 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5654 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5657 image_x *ptr = NULL;
5658 image_x *start = NULL;
5659 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5661 start = info->uiapp_info->image;
5663 for(ptr = start; ptr != NULL; ptr = ptr->next)
5666 val = (char *)ptr->section;
5668 if (strcmp(val, "preview") == 0)
5669 *preview_img = (char *)ptr->text;
5677 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5679 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5680 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5683 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5685 if (info->app_component == PMINFO_UI_APP)
5686 val = info->uiapp_info->permission_type;
5687 else if (info->app_component == PMINFO_SVC_APP)
5688 val = info->svcapp_info->permission_type;
5690 return PMINFO_R_ERROR;
5692 if (strcmp(val, "signature") == 0)
5693 *permission = PMINFO_PERMISSION_SIGNATURE;
5694 else if (strcmp(val, "privilege") == 0)
5695 *permission = PMINFO_PERMISSION_PRIVILEGE;
5697 *permission = PMINFO_PERMISSION_NORMAL;
5702 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5704 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5705 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5706 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5708 *component_type = (char *)info->uiapp_info->component_type;
5713 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5715 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5716 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5718 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5719 val = (char *)info->uiapp_info->hwacceleration;
5721 if (strcasecmp(val, "not-use-GL") == 0)
5722 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5723 else if (strcasecmp(val, "use-GL") == 0)
5724 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5726 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5731 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5733 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5734 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5736 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5737 val = (char *)info->uiapp_info->screenreader;
5739 if (strcasecmp(val, "screenreader-off") == 0)
5740 *screenreader = PMINFO_SCREENREADER_OFF;
5741 else if (strcasecmp(val, "screenreader-on") == 0)
5742 *screenreader = PMINFO_SCREENREADER_ON;
5744 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5749 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5751 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5752 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5753 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5754 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5756 if (info->app_component == PMINFO_UI_APP){
5757 *portrait_img = (char *)info->uiapp_info->portraitimg;
5758 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5764 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5766 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5767 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5768 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5770 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5775 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5776 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5778 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5779 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5781 permission_x *ptr = NULL;
5782 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5783 if (info->app_component == PMINFO_UI_APP)
5784 ptr = info->uiapp_info->permission;
5785 else if (info->app_component == PMINFO_SVC_APP)
5786 ptr = info->svcapp_info->permission;
5788 return PMINFO_R_EINVAL;
5789 for (; ptr; ptr = ptr->next) {
5791 ret = permission_func(ptr->value, user_data);
5799 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5800 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5802 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5803 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5805 category_x *ptr = NULL;
5806 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5807 if (info->app_component == PMINFO_UI_APP)
5808 ptr = info->uiapp_info->category;
5809 else if (info->app_component == PMINFO_SVC_APP)
5810 ptr = info->svcapp_info->category;
5812 return PMINFO_R_EINVAL;
5813 for (; ptr; ptr = ptr->next) {
5815 ret = category_func(ptr->name, user_data);
5823 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5824 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5826 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5827 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5829 metadata_x *ptr = NULL;
5830 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5831 if (info->app_component == PMINFO_UI_APP)
5832 ptr = info->uiapp_info->metadata;
5833 else if (info->app_component == PMINFO_SVC_APP)
5834 ptr = info->svcapp_info->metadata;
5836 return PMINFO_R_EINVAL;
5837 for (; ptr; ptr = ptr->next) {
5839 ret = metadata_func(ptr->key, ptr->value, user_data);
5847 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5848 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5850 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5851 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5859 char *manifest = NULL;
5860 char **operation = NULL;
5863 char **subapp = NULL;
5864 appcontrol_x *appcontrol = NULL;
5865 manifest_x *mfx = NULL;
5866 operation_x *op = NULL;
5869 subapp_x *sa = NULL;
5870 pkgmgrinfo_app_component component;
5871 pkgmgrinfo_appcontrol_x *ptr = NULL;
5872 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5874 _LOGE("Failed to get package name\n");
5875 return PMINFO_R_ERROR;
5877 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5879 _LOGE("Failed to get app component name\n");
5880 return PMINFO_R_ERROR;
5882 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
5883 if (manifest == NULL) {
5884 _LOGE("Failed to fetch package manifest file\n");
5885 return PMINFO_R_ERROR;
5887 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
5889 _LOGE("Failed to parse package manifest file\n");
5892 return PMINFO_R_ERROR;
5895 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5897 _LOGE("Out of Memory!!!\n");
5898 pkgmgr_parser_free_manifest_xml(mfx);
5899 return PMINFO_R_ERROR;
5901 /*Get Operation, Uri, Mime*/
5902 switch (component) {
5904 if (mfx->uiapplication) {
5905 if (mfx->uiapplication->appsvc) {
5906 appcontrol = mfx->uiapplication->appsvc;
5910 case PMINFO_SVC_APP:
5911 if (mfx->serviceapplication) {
5912 if (mfx->serviceapplication->appsvc) {
5913 appcontrol = mfx->serviceapplication->appsvc;
5920 for (; appcontrol; appcontrol = appcontrol->next) {
5921 op = appcontrol->operation;
5922 for (; op; op = op->next)
5924 op = appcontrol->operation;
5926 ui = appcontrol->uri;
5927 for (; ui; ui = ui->next)
5929 ui = appcontrol->uri;
5931 mi = appcontrol->mime;
5932 for (; mi; mi = mi->next)
5934 mi = appcontrol->mime;
5936 sa = appcontrol->subapp;
5937 for (; sa; sa = sa->next)
5939 sa = appcontrol->subapp;
5941 operation = (char **)calloc(oc, sizeof(char *));
5942 for (i = 0; i < oc; i++) {
5943 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5947 uri = (char **)calloc(uc, sizeof(char *));
5948 for (i = 0; i < uc; i++) {
5949 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5953 mime = (char **)calloc(mc, sizeof(char *));
5954 for (i = 0; i < mc; i++) {
5955 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5959 subapp = (char **)calloc(sc, sizeof(char *));
5960 for (i = 0; i < sc; i++) {
5961 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5965 /*populate appcontrol handle*/
5966 ptr->operation_count = oc;
5967 ptr->uri_count = uc;
5968 ptr->mime_count = mc;
5969 ptr->subapp_count = sc;
5970 ptr->operation = operation;
5973 ptr->subapp = subapp;
5975 ret = appcontrol_func((void *)ptr, user_data);
5976 for (i = 0; i < oc; i++) {
5979 operation[i] = NULL;
5986 for (i = 0; i < uc; i++) {
5996 for (i = 0; i < mc; i++) {
6006 for (i = 0; i < sc; i++) {
6023 pkgmgr_parser_free_manifest_xml(mfx);
6031 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6032 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6034 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6035 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6043 char *manifest = NULL;
6044 char **operation = NULL;
6047 char **subapp = NULL;
6048 appcontrol_x *appcontrol = NULL;
6049 manifest_x *mfx = NULL;
6050 operation_x *op = NULL;
6053 subapp_x *sa = NULL;
6054 pkgmgrinfo_app_component component;
6055 pkgmgrinfo_appcontrol_x *ptr = NULL;
6056 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6058 _LOGE("Failed to get package name\n");
6059 return PMINFO_R_ERROR;
6061 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6063 _LOGE("Failed to get app component name\n");
6064 return PMINFO_R_ERROR;
6066 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6067 if (manifest == NULL) {
6068 _LOGE("Failed to fetch package manifest file\n");
6069 return PMINFO_R_ERROR;
6071 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6073 _LOGE("Failed to parse package manifest file\n");
6076 return PMINFO_R_ERROR;
6079 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6081 _LOGE("Out of Memory!!!\n");
6082 pkgmgr_parser_free_manifest_xml(mfx);
6083 return PMINFO_R_ERROR;
6085 /*Get Operation, Uri, Mime*/
6086 switch (component) {
6088 if (mfx->uiapplication) {
6089 if (mfx->uiapplication->appsvc) {
6090 appcontrol = mfx->uiapplication->appsvc;
6094 case PMINFO_SVC_APP:
6095 if (mfx->serviceapplication) {
6096 if (mfx->serviceapplication->appsvc) {
6097 appcontrol = mfx->serviceapplication->appsvc;
6104 for (; appcontrol; appcontrol = appcontrol->next) {
6105 op = appcontrol->operation;
6106 for (; op; op = op->next)
6108 op = appcontrol->operation;
6110 ui = appcontrol->uri;
6111 for (; ui; ui = ui->next)
6113 ui = appcontrol->uri;
6115 mi = appcontrol->mime;
6116 for (; mi; mi = mi->next)
6118 mi = appcontrol->mime;
6120 sa = appcontrol->subapp;
6121 for (; sa; sa = sa->next)
6123 sa = appcontrol->subapp;
6125 operation = (char **)calloc(oc, sizeof(char *));
6126 for (i = 0; i < oc; i++) {
6127 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6131 uri = (char **)calloc(uc, sizeof(char *));
6132 for (i = 0; i < uc; i++) {
6133 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6137 mime = (char **)calloc(mc, sizeof(char *));
6138 for (i = 0; i < mc; i++) {
6139 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6143 subapp = (char **)calloc(sc, sizeof(char *));
6144 for (i = 0; i < sc; i++) {
6145 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6149 /*populate appcontrol handle*/
6150 ptr->operation_count = oc;
6151 ptr->uri_count = uc;
6152 ptr->mime_count = mc;
6153 ptr->subapp_count = sc;
6154 ptr->operation = operation;
6157 ptr->subapp = subapp;
6159 ret = appcontrol_func((void *)ptr, user_data);
6160 for (i = 0; i < oc; i++) {
6163 operation[i] = NULL;
6170 for (i = 0; i < uc; i++) {
6180 for (i = 0; i < mc; i++) {
6190 for (i = 0; i < sc; i++) {
6207 pkgmgr_parser_free_manifest_xml(mfx);
6215 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6217 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6218 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6220 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6221 val = (char *)info->uiapp_info->nodisplay;
6223 if (strcasecmp(val, "true") == 0)
6225 else if (strcasecmp(val, "false") == 0)
6233 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6235 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6236 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6238 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6239 val = (char *)info->uiapp_info->multiple;
6241 if (strcasecmp(val, "true") == 0)
6243 else if (strcasecmp(val, "false") == 0)
6251 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6253 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6254 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6256 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6257 val = (char *)info->uiapp_info->indicatordisplay;
6259 if (strcasecmp(val, "true") == 0){
6260 *indicator_disp = 1;
6261 }else if (strcasecmp(val, "false") == 0){
6262 *indicator_disp = 0;
6264 *indicator_disp = 0;
6270 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6272 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6273 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6275 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6276 val = (char *)info->uiapp_info->taskmanage;
6278 if (strcasecmp(val, "true") == 0)
6280 else if (strcasecmp(val, "false") == 0)
6288 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6290 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6291 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6293 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6294 if (info->app_component == PMINFO_UI_APP)
6295 val = (char *)info->uiapp_info->enabled;
6296 else if (info->app_component == PMINFO_SVC_APP)
6297 val = (char *)info->uiapp_info->enabled;
6299 _LOGE("invalid component type\n");
6300 return PMINFO_R_EINVAL;
6304 if (strcasecmp(val, "true") == 0)
6306 else if (strcasecmp(val, "false") == 0)
6315 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6317 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6318 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6320 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6321 val = (char *)info->svcapp_info->onboot;
6323 if (strcasecmp(val, "true") == 0)
6325 else if (strcasecmp(val, "false") == 0)
6333 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6335 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6336 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6338 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6339 val = (char *)info->svcapp_info->autorestart;
6341 if (strcasecmp(val, "true") == 0)
6343 else if (strcasecmp(val, "false") == 0)
6351 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6353 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6354 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6356 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6357 val = (char *)info->uiapp_info->mainapp;
6359 if (strcasecmp(val, "true") == 0)
6361 else if (strcasecmp(val, "false") == 0)
6369 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6371 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6372 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6374 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6375 val = (char *)info->uiapp_info->preload;
6377 if (strcasecmp(val, "true") == 0)
6379 else if (strcasecmp(val, "false") == 0)
6387 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6389 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6390 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6392 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6393 val = (char *)info->uiapp_info->submode;
6395 if (strcasecmp(val, "true") == 0)
6397 else if (strcasecmp(val, "false") == 0)
6405 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6407 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6408 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6409 __cleanup_appinfo(info);
6413 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6415 return (pkgmgrinfo_pkginfo_filter_create(handle));
6418 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6420 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6423 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6424 const char *property, const int value)
6426 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6427 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6428 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6430 GSList *link = NULL;
6432 prop = _pminfo_appinfo_convert_to_prop_int(property);
6433 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6434 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6435 _LOGE("Invalid Integer Property\n");
6436 return PMINFO_R_EINVAL;
6438 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6439 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6441 _LOGE("Out of Memory!!!\n");
6442 return PMINFO_R_ERROR;
6444 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6445 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6447 _LOGE("Out of Memory\n");
6450 return PMINFO_R_ERROR;
6454 /*If API is called multiple times for same property, we should override the previous values.
6455 Last value set will be used for filtering.*/
6456 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6458 filter->list = g_slist_delete_link(filter->list, link);
6459 filter->list = g_slist_append(filter->list, (gpointer)node);
6464 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6465 const char *property, const bool value)
6467 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6468 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6470 GSList *link = NULL;
6472 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6473 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6474 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6475 _LOGE("Invalid Boolean Property\n");
6476 return PMINFO_R_EINVAL;
6478 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6479 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6481 _LOGE("Out of Memory!!!\n");
6482 return PMINFO_R_ERROR;
6485 val = strndup("('true','True')", 15);
6487 val = strndup("('false','False')", 17);
6489 _LOGE("Out of Memory\n");
6492 return PMINFO_R_ERROR;
6496 /*If API is called multiple times for same property, we should override the previous values.
6497 Last value set will be used for filtering.*/
6498 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6500 filter->list = g_slist_delete_link(filter->list, link);
6501 filter->list = g_slist_append(filter->list, (gpointer)node);
6506 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6507 const char *property, const char *value)
6509 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6510 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6511 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6513 pkgmgrinfo_node_x *ptr = NULL;
6514 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6515 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6516 GSList *link = NULL;
6518 prop = _pminfo_appinfo_convert_to_prop_str(property);
6519 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6520 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6521 _LOGE("Invalid String Property\n");
6522 return PMINFO_R_EINVAL;
6524 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6525 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6527 _LOGE("Out of Memory!!!\n");
6528 return PMINFO_R_ERROR;
6532 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6533 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6534 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6536 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6538 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6540 filter->list = g_slist_delete_link(filter->list, link);
6541 filter->list = g_slist_append(filter->list, (gpointer)node);
6543 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6544 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6545 case E_PMINFO_APPINFO_PROP_APP_URI:
6546 case E_PMINFO_APPINFO_PROP_APP_MIME:
6547 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6549 _LOGE("Out of Memory\n");
6552 return PMINFO_R_ERROR;
6554 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6556 ptr = (pkgmgrinfo_node_x *)link->data;
6557 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6558 _LOGE("Previous value is %s\n", prev);
6559 filter->list = g_slist_delete_link(filter->list, link);
6560 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6561 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6562 _LOGE("New value is %s\n", val);
6564 filter->list = g_slist_append(filter->list, (gpointer)node);
6565 memset(temp, '\0', PKG_STRING_LEN_MAX);
6567 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6568 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6569 _LOGE("First value is %s\n", val);
6571 filter->list = g_slist_append(filter->list, (gpointer)node);
6572 memset(temp, '\0', PKG_STRING_LEN_MAX);
6576 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6577 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6579 filter->list = g_slist_delete_link(filter->list, link);
6580 filter->list = g_slist_append(filter->list, (gpointer)node);
6586 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6588 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6589 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6590 char *syslocale = NULL;
6591 char *locale = NULL;
6592 char *condition = NULL;
6593 char *error_message = NULL;
6594 char query[MAX_QUERY_LEN] = {'\0'};
6595 char where[MAX_QUERY_LEN] = {'\0'};
6599 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6600 /*Get current locale*/
6601 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6602 if (syslocale == NULL) {
6603 _LOGE("current locale is NULL\n");
6604 return PMINFO_R_ERROR;
6606 locale = __convert_system_locale_to_manifest_locale(syslocale);
6607 if (locale == NULL) {
6608 _LOGE("manifest locale is NULL\n");
6610 return PMINFO_R_ERROR;
6613 ret = __open_manifest_db(uid);
6615 _LOGE("Fail to open manifest DB\n");
6618 return PMINFO_R_ERROR;
6621 /*Start constructing query*/
6622 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6624 /*Get where clause*/
6625 for (list = filter->list; list; list = g_slist_next(list)) {
6626 __get_filter_condition(list->data, &condition);
6628 strncat(where, condition, sizeof(where) - strlen(where) -1);
6629 where[sizeof(where) - 1] = '\0';
6633 if (g_slist_next(list)) {
6634 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6635 where[sizeof(where) - 1] = '\0';
6638 _LOGE("where = %s\n", where);
6639 if (strlen(where) > 0) {
6640 strncat(query, where, sizeof(query) - strlen(query) - 1);
6641 query[sizeof(query) - 1] = '\0';
6643 _LOGE("query = %s\n", query);
6647 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
6648 _LOGE("Don't execute query = %s error message = %s\n", query,
6650 sqlite3_free(error_message);
6651 sqlite3_close(manifest_db);
6652 ret = PMINFO_R_ERROR;
6666 sqlite3_close(manifest_db);
6670 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6672 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6675 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6676 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6678 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6679 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6680 char *syslocale = NULL;
6681 char *locale = NULL;
6682 char *condition = NULL;
6683 char *error_message = NULL;
6684 char query[MAX_QUERY_LEN] = {'\0'};
6685 char where[MAX_QUERY_LEN] = {'\0'};
6688 uiapplication_x *ptr1 = NULL;
6689 serviceapplication_x *ptr2 = NULL;
6690 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6691 /*Get current locale*/
6692 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6693 if (syslocale == NULL) {
6694 _LOGE("current locale is NULL\n");
6695 return PMINFO_R_ERROR;
6697 locale = __convert_system_locale_to_manifest_locale(syslocale);
6698 if (locale == NULL) {
6699 _LOGE("manifest locale is NULL\n");
6701 return PMINFO_R_ERROR;
6704 ret = __open_manifest_db(uid);
6706 _LOGE("Fail to open manifest DB\n");
6709 return PMINFO_R_ERROR;
6711 /*Start constructing query*/
6712 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6713 /*Get where clause*/
6714 for (list = filter->list; list; list = g_slist_next(list)) {
6715 __get_filter_condition(list->data, &condition);
6717 strncat(where, condition, sizeof(where) - strlen(where) -1);
6718 where[sizeof(where) - 1] = '\0';
6722 if (g_slist_next(list)) {
6723 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6724 where[sizeof(where) - 1] = '\0';
6727 _LOGE("where = %s\n", where);
6728 if (strlen(where) > 0) {
6729 strncat(query, where, sizeof(query) - strlen(query) - 1);
6730 query[sizeof(query) - 1] = '\0';
6732 _LOGE("query = %s\n", query);
6733 /*To get filtered list*/
6734 pkgmgr_pkginfo_x *info = NULL;
6735 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6737 _LOGE("Out of Memory!!!\n");
6738 ret = PMINFO_R_ERROR;
6741 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6742 if (info->manifest_info == NULL) {
6743 _LOGE("Out of Memory!!!\n");
6744 ret = PMINFO_R_ERROR;
6747 /*To get detail app info for each member of filtered list*/
6748 pkgmgr_pkginfo_x *filtinfo = NULL;
6749 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6750 if (filtinfo == NULL) {
6751 _LOGE("Out of Memory!!!\n");
6752 ret = PMINFO_R_ERROR;
6755 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6756 if (filtinfo->manifest_info == NULL) {
6757 _LOGE("Out of Memory!!!\n");
6758 ret = PMINFO_R_ERROR;
6761 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6762 if (appinfo == NULL) {
6763 _LOGE("Out of Memory!!!\n");
6764 ret = PMINFO_R_ERROR;
6768 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
6769 _LOGE("Don't execute query = %s error message = %s\n", query,
6771 sqlite3_free(error_message);
6772 sqlite3_close(manifest_db);
6773 ret = PMINFO_R_ERROR;
6776 memset(query, '\0', MAX_QUERY_LEN);
6777 if (info->manifest_info->uiapplication) {
6778 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6779 info->manifest_info->uiapplication = ptr1;
6781 if (info->manifest_info->serviceapplication) {
6782 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6783 info->manifest_info->serviceapplication = ptr2;
6785 /*Filtered UI Apps*/
6786 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6788 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6789 ptr1->appid, "uiapp");
6791 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6792 _LOGE("Don't execute query = %s error message = %s\n", query,
6794 sqlite3_free(error_message);
6795 sqlite3_close(manifest_db);
6796 ret = PMINFO_R_ERROR;
6800 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6802 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6803 ptr2->appid, "svcapp");
6805 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6806 _LOGE("Don't execute query = %s error message = %s\n", query,
6808 sqlite3_free(error_message);
6809 sqlite3_close(manifest_db);
6810 ret = PMINFO_R_ERROR;
6814 if (filtinfo->manifest_info->uiapplication) {
6815 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6816 filtinfo->manifest_info->uiapplication = ptr1;
6818 /*If the callback func return < 0 we break and no more call back is called*/
6821 appinfo->locale = strdup(locale);
6822 appinfo->uiapp_info = ptr1;
6823 appinfo->app_component = PMINFO_UI_APP;
6824 ret = app_cb((void *)appinfo, user_data);
6829 /*Filtered Service Apps*/
6830 if (filtinfo->manifest_info->serviceapplication) {
6831 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6832 filtinfo->manifest_info->serviceapplication = ptr2;
6834 /*If the callback func return < 0 we break and no more call back is called*/
6837 appinfo->locale = strdup(locale);
6838 appinfo->svcapp_info = ptr2;
6839 appinfo->app_component = PMINFO_SVC_APP;
6840 ret = app_cb((void *)appinfo, user_data);
6855 sqlite3_close(manifest_db);
6860 __cleanup_pkginfo(info);
6861 __cleanup_pkginfo(filtinfo);
6865 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6866 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6868 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6871 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6873 return (pkgmgrinfo_pkginfo_filter_create(handle));
6876 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6878 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6881 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6882 const char *key, const char *value)
6884 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6885 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6886 /*value can be NULL. In that case all apps with specified key should be displayed*/
6890 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6891 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6892 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6894 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6898 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6901 /*If API is called multiple times, we should OR all conditions.*/
6902 filter->list = g_slist_append(filter->list, (gpointer)node);
6903 /*All memory will be freed in destroy API*/
6921 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6922 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6924 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6925 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6926 char *syslocale = NULL;
6927 char *locale = NULL;
6928 char *condition = NULL;
6929 char *error_message = NULL;
6930 char query[MAX_QUERY_LEN] = {'\0'};
6931 char where[MAX_QUERY_LEN] = {'\0'};
6934 pkgmgr_pkginfo_x *info = NULL;
6935 pkgmgr_pkginfo_x *filtinfo = NULL;
6936 pkgmgr_appinfo_x *appinfo = NULL;
6937 uiapplication_x *ptr1 = NULL;
6938 serviceapplication_x *ptr2 = NULL;
6939 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6941 /*Get current locale*/
6942 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6943 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
6944 locale = __convert_system_locale_to_manifest_locale(syslocale);
6945 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6947 ret = __open_manifest_db(uid);
6949 _LOGE("Fail to open manifest DB\n");
6952 return PMINFO_R_ERROR;
6954 /*Start constructing query*/
6955 memset(where, '\0', MAX_QUERY_LEN);
6956 memset(query, '\0', MAX_QUERY_LEN);
6957 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6958 /*Get where clause*/
6959 for (list = filter->list; list; list = g_slist_next(list)) {
6960 __get_metadata_filter_condition(list->data, &condition);
6962 strncat(where, condition, sizeof(where) - strlen(where) -1);
6966 if (g_slist_next(list)) {
6967 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6970 _LOGE("where = %s (%d)\n", where, strlen(where));
6971 if (strlen(where) > 0) {
6972 strncat(query, where, sizeof(query) - strlen(query) - 1);
6974 _LOGE("query = %s (%d)\n", query, strlen(query));
6975 /*To get filtered list*/
6976 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6977 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6979 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6980 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6982 /*To get detail app info for each member of filtered list*/
6983 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6984 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6986 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6987 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6989 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6990 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6992 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
6993 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6994 memset(query, '\0', MAX_QUERY_LEN);
6996 if (info->manifest_info->uiapplication) {
6997 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6998 info->manifest_info->uiapplication = ptr1;
7000 if (info->manifest_info->serviceapplication) {
7001 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7002 info->manifest_info->serviceapplication = ptr2;
7006 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7008 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7009 ptr1->appid, "uiapp");
7010 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7011 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7012 memset(query, '\0', MAX_QUERY_LEN);
7015 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7017 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7018 ptr2->appid, "svcapp");
7019 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7020 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7021 memset(query, '\0', MAX_QUERY_LEN);
7023 /*Filtered UI Apps*/
7024 if (filtinfo->manifest_info->uiapplication) {
7025 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7026 filtinfo->manifest_info->uiapplication = ptr1;
7028 /*If the callback func return < 0 we break and no more call back is called*/
7031 appinfo->locale = strdup(locale);
7032 appinfo->uiapp_info = ptr1;
7033 appinfo->app_component = PMINFO_UI_APP;
7034 ret = app_cb((void *)appinfo, user_data);
7039 /*Filtered Service Apps*/
7040 if (filtinfo->manifest_info->serviceapplication) {
7041 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7042 filtinfo->manifest_info->serviceapplication = ptr2;
7044 /*If the callback func return < 0 we break and no more call back is called*/
7047 appinfo->locale = strdup(locale);
7048 appinfo->svcapp_info = ptr2;
7049 appinfo->app_component = PMINFO_SVC_APP;
7050 ret = app_cb((void *)appinfo, user_data);
7065 sqlite3_free(error_message);
7066 sqlite3_close(manifest_db);
7071 __cleanup_pkginfo(info);
7072 __cleanup_pkginfo(filtinfo);
7076 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7077 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7079 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7082 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7084 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7085 pkgmgr_certinfo_x *certinfo = NULL;
7086 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7087 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7088 *handle = (void *)certinfo;
7092 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
7094 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7095 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7096 pkgmgr_certinfo_x *certinfo = NULL;
7097 char *error_message = NULL;
7098 int ret = PMINFO_R_OK;
7099 char query[MAX_QUERY_LEN] = {'\0'};
7104 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7105 SQLITE_OPEN_READWRITE, NULL);
7106 if (ret != SQLITE_OK) {
7107 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7108 return PMINFO_R_ERROR;
7110 _check_create_Cert_db(cert_db);
7112 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7114 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7115 _LOGE("Don't execute query = %s error message = %s\n", query,
7117 sqlite3_free(error_message);
7118 ret = PMINFO_R_ERROR;
7122 _LOGE("Package not found in DB\n");
7123 ret = PMINFO_R_ERROR;
7126 certinfo = (pkgmgr_certinfo_x *)handle;
7127 /*populate certinfo from DB*/
7128 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7129 ret = __exec_certinfo_query(query, (void *)certinfo);
7131 _LOGE("Package Cert Info DB Information retrieval failed\n");
7132 ret = PMINFO_R_ERROR;
7135 for (i = 0; i < MAX_CERT_TYPE; i++) {
7136 memset(query, '\0', MAX_QUERY_LEN);
7137 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7138 ret = __exec_certinfo_query(query, (void *)certinfo);
7140 _LOGE("Cert Info DB Information retrieval failed\n");
7141 ret = PMINFO_R_ERROR;
7144 if (certinfo->cert_value) {
7145 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7146 free(certinfo->cert_value);
7147 certinfo->cert_value = NULL;
7151 sqlite3_close(cert_db);
7155 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7157 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7158 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7159 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7160 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7161 pkgmgr_certinfo_x *certinfo = NULL;
7162 certinfo = (pkgmgr_certinfo_x *)handle;
7163 if ((certinfo->cert_info)[cert_type])
7164 *cert_value = (certinfo->cert_info)[cert_type];
7170 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7172 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7174 pkgmgr_certinfo_x *certinfo = NULL;
7175 certinfo = (pkgmgr_certinfo_x *)handle;
7176 if (certinfo->pkgid) {
7177 free(certinfo->pkgid);
7178 certinfo->pkgid = NULL;
7180 for (i = 0; i < MAX_CERT_TYPE; i++) {
7181 if ((certinfo->cert_info)[i]) {
7182 free((certinfo->cert_info)[i]);
7183 (certinfo->cert_info)[i] = NULL;
7191 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7193 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7194 pkgmgr_instcertinfo_x *certinfo = NULL;
7195 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7196 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7197 *handle = (void *)certinfo;
7201 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7203 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7204 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7205 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7206 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7207 pkgmgr_instcertinfo_x *certinfo = NULL;
7208 certinfo = (pkgmgr_instcertinfo_x *)handle;
7209 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7213 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
7215 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7216 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7217 char *error_message = NULL;
7218 char query[MAX_QUERY_LEN] = {'\0'};
7219 char *vquery = NULL;
7224 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7231 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7232 pkgmgr_certindexinfo_x *indexinfo = NULL;
7233 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7234 if (indexinfo == NULL) {
7235 _LOGE("Out of Memory!!!");
7236 return PMINFO_R_ERROR;
7238 info->pkgid = strdup(pkgid);
7241 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7242 SQLITE_OPEN_READWRITE, NULL);
7243 if (ret != SQLITE_OK) {
7244 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7245 ret = PMINFO_R_ERROR;
7248 _check_create_Cert_db(cert_db);
7249 /*Begin Transaction*/
7250 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7251 if (ret != SQLITE_OK) {
7252 _LOGE("Failed to begin transaction\n");
7253 ret = PMINFO_R_ERROR;
7256 _LOGE("Transaction Begin\n");
7257 /*Check if request is to insert/update*/
7258 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7260 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7261 _LOGE("Don't execute query = %s error message = %s\n", query,
7263 sqlite3_free(error_message);
7264 ret = PMINFO_R_ERROR;
7269 We cant just issue update query directly. We need to manage index table also.
7270 Hence it is better to delete and insert again in case of update*/
7271 ret = __delete_certinfo(pkgid);
7273 _LOGE("Certificate Deletion Failed\n");
7275 for (i = 0; i < MAX_CERT_TYPE; i++) {
7276 if ((info->cert_info)[i]) {
7277 for (j = 0; j < i; j++) {
7278 if ( (info->cert_info)[j]) {
7279 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7280 (info->cert_id)[i] = (info->cert_id)[j];
7281 (info->is_new)[i] = 0;
7282 (info->ref_count)[i] = (info->ref_count)[j];
7289 memset(query, '\0', MAX_QUERY_LEN);
7290 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7291 "where cert_info='%s'",(info->cert_info)[i]);
7292 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7294 _LOGE("Cert Info DB Information retrieval failed\n");
7295 ret = PMINFO_R_ERROR;
7298 if (indexinfo->cert_id == 0) {
7299 /*New certificate. Get newid*/
7300 memset(query, '\0', MAX_QUERY_LEN);
7301 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7303 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
7304 _LOGE("Don't execute query = %s error message = %s\n", query,
7306 sqlite3_free(error_message);
7307 ret = PMINFO_R_ERROR;
7315 indexinfo->cert_id = maxid;
7316 indexinfo->cert_ref_count = 1;
7320 (info->cert_id)[i] = indexinfo->cert_id;
7321 (info->is_new)[i] = is_new;
7322 (info->ref_count)[i] = indexinfo->cert_ref_count;
7323 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
7324 indexinfo->cert_id = 0;
7325 indexinfo->cert_ref_count = 0;
7329 len = MAX_QUERY_LEN;
7330 for (i = 0; i < MAX_CERT_TYPE; i++) {
7331 if ((info->cert_info)[i])
7332 len+= strlen((info->cert_info)[i]);
7334 vquery = (char *)calloc(1, len);
7336 snprintf(vquery, len,
7337 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7338 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7339 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7340 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7341 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7342 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7343 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7344 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7346 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7347 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7349 sqlite3_free(error_message);
7350 ret = PMINFO_R_ERROR;
7353 /*Update index table info*/
7354 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7355 for (i = 0; i < MAX_CERT_TYPE; i++) {
7356 if ((info->cert_info)[i]) {
7357 memset(vquery, '\0', len);
7358 if ((info->is_new)[i]) {
7359 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7360 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7361 unique_id[c++] = (info->cert_id)[i];
7364 for (j = 0; j < MAX_CERT_TYPE; j++) {
7365 if ((info->cert_id)[i] == unique_id[j]) {
7366 /*Ref count has already been increased. Just continue*/
7370 if (j == MAX_CERT_TYPE)
7371 unique_id[c++] = (info->cert_id)[i];
7374 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7375 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7378 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7379 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7381 sqlite3_free(error_message);
7382 ret = PMINFO_R_ERROR;
7387 /*Commit transaction*/
7388 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7389 if (ret != SQLITE_OK) {
7390 _LOGE("Failed to commit transaction, Rollback now\n");
7391 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7392 ret = PMINFO_R_ERROR;
7395 _LOGE("Transaction Commit and End\n");
7398 sqlite3_close(cert_db);
7410 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7412 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7414 pkgmgr_instcertinfo_x *certinfo = NULL;
7415 certinfo = (pkgmgr_instcertinfo_x *)handle;
7416 if (certinfo->pkgid) {
7417 free(certinfo->pkgid);
7418 certinfo->pkgid = NULL;
7420 for (i = 0; i < MAX_CERT_TYPE; i++) {
7421 if ((certinfo->cert_info)[i]) {
7422 free((certinfo->cert_info)[i]);
7423 (certinfo->cert_info)[i] = NULL;
7431 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7433 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7436 ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
7437 SQLITE_OPEN_READWRITE, NULL);
7438 if (ret != SQLITE_OK) {
7439 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7440 ret = PMINFO_R_ERROR;
7443 _check_create_Cert_db(cert_db);
7444 /*Begin Transaction*/
7445 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7446 if (ret != SQLITE_OK) {
7447 _LOGE("Failed to begin transaction\n");
7448 ret = PMINFO_R_ERROR;
7451 _LOGE("Transaction Begin\n");
7452 ret = __delete_certinfo(pkgid);
7454 _LOGE("Certificate Deletion Failed\n");
7456 _LOGE("Certificate Deletion Success\n");
7458 /*Commit transaction*/
7459 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7460 if (ret != SQLITE_OK) {
7461 _LOGE("Failed to commit transaction, Rollback now\n");
7462 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7463 ret = PMINFO_R_ERROR;
7466 _LOGE("Transaction Commit and End\n");
7469 sqlite3_close(cert_db);
7474 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7476 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7479 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7481 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7482 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7484 char *manifest = NULL;
7485 manifest_x *mfx = NULL;
7487 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7488 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7490 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7495 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7497 *handle = (void *)mfx;
7502 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7504 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7505 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7507 char *manifest = NULL;
7508 manifest_x *mfx = NULL;
7510 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7511 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7513 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7518 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7520 *handle = (void *)mfx;
7525 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7527 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7528 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7530 int len = strlen(type);
7531 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7533 manifest_x *mfx = (manifest_x *)handle;
7535 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7539 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7541 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7542 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7544 int len = strlen(version);
7545 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7547 manifest_x *mfx = (manifest_x *)handle;
7549 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7553 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7555 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7556 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7558 manifest_x *mfx = (manifest_x *)handle;
7560 if (location == INSTALL_INTERNAL)
7561 strcpy(mfx->installlocation, "internal-only");
7562 else if (location == INSTALL_EXTERNAL)
7563 strcpy(mfx->installlocation, "prefer-external");
7568 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7570 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7571 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7573 manifest_x *mfx = (manifest_x *)handle;
7575 mfx->package_size = strdup(size);
7580 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7582 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7583 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7585 int len = strlen(label_txt);
7586 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7588 manifest_x *mfx = (manifest_x *)handle;
7590 label_x *label = calloc(1, sizeof(label_x));
7591 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7593 LISTADD(mfx->label, label);
7595 mfx->label->lang = strdup(locale);
7597 mfx->label->lang = strdup(DEFAULT_LOCALE);
7598 mfx->label->text = strdup(label_txt);
7603 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7605 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7606 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7608 int len = strlen(icon_txt);
7609 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7611 manifest_x *mfx = (manifest_x *)handle;
7613 icon_x *icon = calloc(1, sizeof(icon_x));
7614 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7616 LISTADD(mfx->icon, icon);
7618 mfx->icon->lang = strdup(locale);
7620 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7621 mfx->icon->text = strdup(icon_txt);
7626 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7628 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7629 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7631 int len = strlen(desc_txt);
7632 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7634 manifest_x *mfx = (manifest_x *)handle;
7636 description_x *description = calloc(1, sizeof(description_x));
7637 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7639 LISTADD(mfx->description, description);
7641 mfx->description->lang = strdup(locale);
7643 mfx->description->lang = strdup(DEFAULT_LOCALE);
7644 mfx->description->text = strdup(desc_txt);
7649 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7650 const char *author_email, const char *author_href, const char *locale)
7652 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7653 manifest_x *mfx = (manifest_x *)handle;
7654 author_x *author = calloc(1, sizeof(author_x));
7655 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7657 LISTADD(mfx->author, author);
7659 mfx->author->text = strdup(author_name);
7661 mfx->author->email = strdup(author_email);
7663 mfx->author->href = strdup(author_href);
7665 mfx->author->lang = strdup(locale);
7667 mfx->author->lang = strdup(DEFAULT_LOCALE);
7671 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7673 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7674 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7676 manifest_x *mfx = (manifest_x *)handle;
7679 strcpy(mfx->removable, "false");
7680 else if (removable == 1)
7681 strcpy(mfx->removable, "true");
7686 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7688 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7689 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7691 manifest_x *mfx = (manifest_x *)handle;
7694 strcpy(mfx->preload, "false");
7695 else if (preload == 1)
7696 strcpy(mfx->preload, "true");
7701 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7703 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7704 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7706 manifest_x *mfx = (manifest_x *)handle;
7708 if (location == INSTALL_INTERNAL)
7709 strcpy(mfx->installed_storage, "installed_internal");
7710 else if (location == INSTALL_EXTERNAL)
7711 strcpy(mfx->installed_storage, "installed_external");
7716 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7718 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7721 manifest_x *mfx = NULL;
7722 mfx = (manifest_x *)handle;
7724 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7726 _LOGE("Successfully stored info in DB\n");
7729 _LOGE("Failed to store info in DB\n");
7730 return PMINFO_R_ERROR;
7734 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7736 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7739 manifest_x *mfx = NULL;
7740 mfx = (manifest_x *)handle;
7742 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7744 _LOGE("Successfully stored info in DB\n");
7747 _LOGE("Failed to store info in DB\n");
7748 return PMINFO_R_ERROR;
7752 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7754 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7756 manifest_x *mfx = NULL;
7757 mfx = (manifest_x *)handle;
7758 pkgmgr_parser_free_manifest_xml(mfx);
7762 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7764 /* Should be implemented later */
7768 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7770 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7772 char query[MAX_QUERY_LEN] = {'\0'};
7773 ret = __open_manifest_db(uid);
7775 /*Begin transaction*/
7776 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7777 if (ret != SQLITE_OK) {
7778 _LOGE("Failed to begin transaction\n");
7779 sqlite3_close(manifest_db);
7780 return PMINFO_R_ERROR;
7782 _LOGD("Transaction Begin\n");
7784 memset(query, '\0', MAX_QUERY_LEN);
7785 snprintf(query, MAX_QUERY_LEN,
7786 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7788 char *error_message = NULL;
7790 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7791 _LOGE("Don't execute query = %s error message = %s\n", query,
7793 sqlite3_free(error_message);
7794 return PMINFO_R_ERROR;
7796 sqlite3_free(error_message);
7798 /*Commit transaction*/
7799 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7800 if (ret != SQLITE_OK) {
7801 _LOGE("Failed to commit transaction. Rollback now\n");
7802 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7803 sqlite3_close(manifest_db);
7804 return PMINFO_R_ERROR;
7806 _LOGD("Transaction Commit and End\n");
7807 sqlite3_close(manifest_db);
7812 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7814 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7817 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7819 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7820 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7821 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7822 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7823 int ret = PMINFO_R_OK;
7824 char query[MAX_QUERY_LEN] = {'\0'};
7825 char *error_message = NULL;
7826 pkgmgr_datacontrol_x *data = NULL;
7828 ret = __open_datacontrol_db();
7830 _LOGE("Fail to open datacontrol DB\n");
7831 return PMINFO_R_ERROR;
7834 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7836 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7837 sqlite3_close(datacontrol_db);
7838 return PMINFO_R_ERROR;
7841 snprintf(query, MAX_QUERY_LEN,
7842 "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",
7846 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
7847 _LOGE("Don't execute query = %s error message = %s\n", query,
7849 sqlite3_free(error_message);
7850 sqlite3_close(datacontrol_db);
7851 return PMINFO_R_ERROR;
7854 *appid = (char *)data->appid;
7855 *access = (char *)data->access;
7857 sqlite3_close(datacontrol_db);
7862 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7864 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7866 char query[MAX_QUERY_LEN] = {'\0'};
7867 char *error_message = NULL;
7868 ret = __open_manifest_db(uid);
7871 /*Begin transaction*/
7872 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7873 if (ret != SQLITE_OK) {
7874 _LOGE("Failed to begin transaction\n");
7875 sqlite3_close(manifest_db);
7876 return PMINFO_R_ERROR;
7878 _LOGD("Transaction Begin\n");
7880 memset(query, '\0', MAX_QUERY_LEN);
7881 snprintf(query, MAX_QUERY_LEN,
7882 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7885 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7886 _LOGE("Don't execute query = %s error message = %s\n", query,
7888 sqlite3_free(error_message);
7889 return PMINFO_R_ERROR;
7892 /*Commit transaction*/
7893 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7894 if (ret != SQLITE_OK) {
7895 _LOGE("Failed to commit transaction. Rollback now\n");
7896 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7897 sqlite3_close(manifest_db);
7898 return PMINFO_R_ERROR;
7900 _LOGD("Transaction Commit and End\n");
7901 sqlite3_close(manifest_db);
7906 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7908 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7911 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7913 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7914 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7916 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7917 val = (char *)info->uiapp_info->guestmode_visibility;
7919 if (strcasecmp(val, "true") == 0){
7921 }else if (strcasecmp(val, "false") == 0){
7930 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
7932 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7935 char *noti_string = NULL;
7937 char query[MAX_QUERY_LEN] = {'\0'};
7938 char *errmsg = NULL;
7939 sqlite3 *pkgmgr_parser_db;
7941 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7942 val = (char *)info->uiapp_info->guestmode_visibility;
7945 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
7946 SQLITE_OPEN_READWRITE, NULL);
7948 if (ret != SQLITE_OK) {
7949 _LOGE("DB Open Failed\n");
7950 return PMINFO_R_ERROR;
7953 /*TODO: Write to DB here*/
7955 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7957 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7959 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7960 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7962 sqlite3_close(pkgmgr_parser_db);
7963 return PMINFO_R_ERROR;
7965 sqlite3_close(pkgmgr_parser_db);
7966 len = strlen((char *)info->uiapp_info->appid) + 8;
7967 noti_string = calloc(1, len);
7968 if (noti_string == NULL){
7969 return PMINFO_R_ERROR;
7971 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7972 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7973 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
7980 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7982 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
7985 /* pkgmgrinfo client start*/
7986 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7989 char *errmsg = NULL;
7991 void *handle = NULL;
7992 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7994 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7995 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
7997 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
7999 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8001 pc = __pkgmgr_client_new(ctype);
8002 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8006 return (pkgmgrinfo_client *) pc;
8009 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8012 char *errmsg = NULL;
8013 void *handle = NULL;
8014 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8016 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8017 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8019 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8021 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8023 ret = __pkgmgr_client_set_status_type(pc, status_type);
8024 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8028 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8030 * The lib dependency chain like below
8031 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8033 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8034 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8035 * on libpkgmgr-installer-client.
8037 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8040 * However, when the libdbus call into the callback function, it suddenly fond that the
8041 * function address is gone (unmapped), then we receive a SIGSEGV.
8043 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8044 * robust if we just link to the well-known lib.
8046 * See https://bugs.tizen.org/jira/browse/PTREL-591
8052 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8055 char *errmsg = NULL;
8056 void *handle = NULL;
8057 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8059 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8060 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8062 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8064 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8066 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8067 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8070 /* same as pkgmgrinfo_client_new */
8074 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8077 char *errmsg = NULL;
8078 void *handle = NULL;
8079 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8081 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8082 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8084 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8086 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8088 ret = __pkgmgr_client_free(pc);
8089 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8092 /* same as pkgmgrinfo_client_new */
8096 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8099 DBusConnection *bus;
8100 DBusMessage *message;
8102 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8104 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8107 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8108 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8110 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8111 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8113 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8115 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8116 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8118 dbus_connection_flush(bus);
8119 dbus_message_unref(message);
8124 /* pkgmgrinfo client end*/