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;
2909 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkginfo_db, SQLITE_OPEN_READONLY, NULL);
2910 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
2912 /*check pkgid exist on db*/
2913 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_info where package='%s')", pkgid);
2914 ret = __exec_db_query(pkginfo_db, query, __validate_cb, (void *)&exist);
2915 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
2916 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
2918 /*get system locale*/
2919 syslocale = vconf_get_str(VCONFKEY_LANGSET);
2920 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
2922 /*get locale on db*/
2923 locale = __convert_system_locale_to_manifest_locale(syslocale);
2924 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
2926 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2927 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
2929 pkginfo->locale = strdup(locale);
2931 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
2932 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
2934 pkginfo->manifest_info->package = strdup(pkgid);
2935 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
2936 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
2938 /*populate manifest_info from DB*/
2939 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkgid);
2940 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2941 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2943 memset(query, '\0', MAX_QUERY_LEN);
2944 /*populate privilege_info from DB*/
2945 snprintf(query, MAX_QUERY_LEN, "select * from package_privilege_info where package='%s' ", pkgid);
2946 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2947 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
2949 memset(query, '\0', MAX_QUERY_LEN);
2950 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2951 " package='%s' and package_locale='%s'", pkgid, locale);
2952 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2953 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2955 /*Also store the values corresponding to default locales*/
2956 memset(query, '\0', MAX_QUERY_LEN);
2957 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
2958 " package='%s' and package_locale='%s'", pkgid, DEFAULT_LOCALE);
2959 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
2960 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
2962 if (pkginfo->manifest_info->label) {
2963 LISTHEAD(pkginfo->manifest_info->label, tmp1);
2964 pkginfo->manifest_info->label = tmp1;
2966 if (pkginfo->manifest_info->icon) {
2967 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
2968 pkginfo->manifest_info->icon = tmp2;
2970 if (pkginfo->manifest_info->description) {
2971 LISTHEAD(pkginfo->manifest_info->description, tmp3);
2972 pkginfo->manifest_info->description = tmp3;
2974 if (pkginfo->manifest_info->author) {
2975 LISTHEAD(pkginfo->manifest_info->author, tmp4);
2976 pkginfo->manifest_info->author = tmp4;
2978 if (pkginfo->manifest_info->privileges->privilege) {
2979 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
2980 pkginfo->manifest_info->privileges->privilege = tmp5;
2984 if (ret == PMINFO_R_OK)
2985 *handle = (void*)pkginfo;
2988 __cleanup_pkginfo(pkginfo);
2990 sqlite3_close(pkginfo_db);
3003 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
3005 return pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, GLOBAL_USER, handle);
3008 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
3010 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3011 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3012 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3013 if (info->manifest_info->package)
3014 *pkg_name = (char *)info->manifest_info->package;
3016 return PMINFO_R_ERROR;
3021 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
3023 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3024 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3025 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3026 if (info->manifest_info->package)
3027 *pkgid = (char *)info->manifest_info->package;
3029 return PMINFO_R_ERROR;
3034 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
3036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3037 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3038 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3039 if (info->manifest_info->type)
3040 *type = (char *)info->manifest_info->type;
3046 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
3048 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3049 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3050 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3051 *version = (char *)info->manifest_info->version;
3055 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
3057 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3058 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3060 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3061 val = (char *)info->manifest_info->installlocation;
3063 if (strcmp(val, "internal-only") == 0)
3064 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3065 else if (strcmp(val, "prefer-external") == 0)
3066 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3068 *location = PMINFO_INSTALL_LOCATION_AUTO;
3073 API int pkgmgrinfo_pkginfo_get_package_size(pkgmgrinfo_pkginfo_h handle, int *size)
3075 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3076 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3078 char *location = NULL;
3079 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3080 location = (char *)info->manifest_info->installlocation;
3081 val = (char *)info->manifest_info->package_size;
3086 _LOGE("package size is not specified\n");
3087 return PMINFO_R_ERROR;
3092 API int pkgmgrinfo_pkginfo_get_total_size(pkgmgrinfo_pkginfo_h handle, int *size)
3094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3095 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3098 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3099 long long rw_size = 0;
3100 long long ro_size= 0;
3101 long long tmp_size= 0;
3102 long long total_size= 0;
3103 struct stat fileinfo;
3106 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3108 return PMINFO_R_ERROR;
3111 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RW_PATH, pkgid);
3112 if (lstat(device_path, &fileinfo) == 0) {
3113 if (!S_ISLNK(fileinfo.st_mode)) {
3114 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3116 rw_size += tmp_size;
3120 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RW_PATH, pkgid);
3121 if (lstat(device_path, &fileinfo) == 0) {
3122 if (!S_ISLNK(fileinfo.st_mode)) {
3123 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3125 rw_size += tmp_size;
3129 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RW_PATH, pkgid);
3130 if (lstat(device_path, &fileinfo) == 0) {
3131 if (!S_ISLNK(fileinfo.st_mode)) {
3132 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3134 rw_size += tmp_size;
3138 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3139 if (lstat(device_path, &fileinfo) == 0) {
3140 if (!S_ISLNK(fileinfo.st_mode)) {
3141 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3143 rw_size += tmp_size;
3147 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RW_PATH, pkgid);
3148 if (lstat(device_path, &fileinfo) == 0) {
3149 if (!S_ISLNK(fileinfo.st_mode)) {
3150 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3152 rw_size += tmp_size;
3156 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RW_PATH, pkgid);
3157 if (lstat(device_path, &fileinfo) == 0) {
3158 if (!S_ISLNK(fileinfo.st_mode)) {
3159 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3161 rw_size += tmp_size;
3166 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/bin", PKG_RO_PATH, pkgid);
3167 if (lstat(device_path, &fileinfo) == 0) {
3168 if (!S_ISLNK(fileinfo.st_mode)) {
3169 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3171 ro_size += tmp_size;
3175 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/info", PKG_RO_PATH, pkgid);
3176 if (lstat(device_path, &fileinfo) == 0) {
3177 if (!S_ISLNK(fileinfo.st_mode)) {
3178 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3180 ro_size += tmp_size;
3184 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/res", PKG_RO_PATH, pkgid);
3185 if (lstat(device_path, &fileinfo) == 0) {
3186 if (!S_ISLNK(fileinfo.st_mode)) {
3187 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3189 ro_size += tmp_size;
3193 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RO_PATH, pkgid);
3194 if (lstat(device_path, &fileinfo) == 0) {
3195 if (!S_ISLNK(fileinfo.st_mode)) {
3196 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3198 ro_size += tmp_size;
3202 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/shared", PKG_RO_PATH, pkgid);
3203 if (lstat(device_path, &fileinfo) == 0) {
3204 if (!S_ISLNK(fileinfo.st_mode)) {
3205 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3207 ro_size += tmp_size;
3211 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/setting", PKG_RO_PATH, pkgid);
3212 if (lstat(device_path, &fileinfo) == 0) {
3213 if (!S_ISLNK(fileinfo.st_mode)) {
3214 tmp_size = _pkgmgr_calculate_dir_size(device_path);
3216 ro_size += tmp_size;
3221 total_size = rw_size + ro_size;
3222 *size = (int)total_size;
3227 API int pkgmgrinfo_pkginfo_get_data_size(pkgmgrinfo_pkginfo_h handle, int *size)
3229 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3230 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3233 char device_path[PKG_STRING_LEN_MAX] = { '\0', };
3234 long long total_size= 0;
3237 ret = pkgmgrinfo_pkginfo_get_pkgid(handle,&pkgid);
3239 return PMINFO_R_ERROR;
3241 snprintf(device_path, PKG_STRING_LEN_MAX, "%s%s/data", PKG_RW_PATH, pkgid);
3242 if (access(device_path, R_OK) == 0)
3243 total_size = _pkgmgr_calculate_dir_size(device_path);
3245 return PMINFO_R_ERROR;
3247 *size = (int)total_size;
3252 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
3254 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3255 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3256 int ret = PMINFO_R_OK;
3257 char *locale = NULL;
3261 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3263 locale = info->locale;
3264 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3266 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
3269 if (strcmp(ptr->lang, locale) == 0) {
3270 *icon = (char *)ptr->text;
3271 if (strcasecmp(*icon, "(null)") == 0) {
3272 locale = DEFAULT_LOCALE;
3276 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3277 *icon = (char *)ptr->text;
3286 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
3288 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
3289 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3290 int ret = PMINFO_R_OK;
3291 char *locale = NULL;
3292 label_x *ptr = NULL;
3295 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3296 locale = info->locale;
3297 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3299 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
3302 if (strcmp(ptr->lang, locale) == 0) {
3303 *label = (char *)ptr->text;
3304 if (strcasecmp(*label, "(null)") == 0) {
3305 locale = DEFAULT_LOCALE;
3309 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3310 *label = (char *)ptr->text;
3319 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
3321 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3322 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3323 char *locale = NULL;
3324 description_x *ptr = NULL;
3325 *description = NULL;
3327 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3328 locale = info->locale;
3329 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3331 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
3334 if (strcmp(ptr->lang, locale) == 0) {
3335 *description = (char *)ptr->text;
3336 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
3337 locale = DEFAULT_LOCALE;
3341 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3342 *description = (char *)ptr->text;
3350 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
3352 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3353 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3354 char *locale = NULL;
3355 author_x *ptr = NULL;
3356 *author_name = NULL;
3358 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3359 locale = info->locale;
3360 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
3362 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
3365 if (strcmp(ptr->lang, locale) == 0) {
3366 *author_name = (char *)ptr->text;
3367 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
3368 locale = DEFAULT_LOCALE;
3372 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
3373 *author_name = (char *)ptr->text;
3381 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
3383 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3384 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3385 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3386 *author_email = (char *)info->manifest_info->author->email;
3390 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
3392 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3393 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3394 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3395 *author_href = (char *)info->manifest_info->author->href;
3399 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
3401 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3402 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3404 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3406 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
3407 *storage = PMINFO_INTERNAL_STORAGE;
3408 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
3409 *storage = PMINFO_EXTERNAL_STORAGE;
3411 return PMINFO_R_ERROR;
3416 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
3418 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3419 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3420 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3421 if (info->manifest_info->installed_time)
3422 *installed_time = atoi(info->manifest_info->installed_time);
3424 return PMINFO_R_ERROR;
3429 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
3431 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3432 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3433 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3434 *storeclientid = (char *)info->manifest_info->storeclient_id;
3438 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
3440 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3441 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3442 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3443 *mainappid = (char *)info->manifest_info->mainapp_id;
3447 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
3449 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3450 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3451 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3452 *url = (char *)info->manifest_info->package_url;
3456 API int pkgmgrinfo_pkginfo_get_size_from_xml(const char *manifest, int *size)
3458 const char *val = NULL;
3459 const xmlChar *node;
3460 xmlTextReaderPtr reader;
3461 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3462 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3465 reader = xmlReaderForFile(manifest, NULL, 0);
3468 if (__child_element(reader, -1)) {
3469 node = xmlTextReaderConstName(reader);
3471 _LOGE("xmlTextReaderConstName value is NULL\n");
3472 xmlFreeTextReader(reader);
3474 return PMINFO_R_ERROR;
3477 if (!strcmp(ASC_CHAR(node), "manifest")) {
3478 if (xmlTextReaderGetAttribute(reader, XML_CHAR("size")))
3479 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("size")));
3485 _LOGE("package size is not specified\n");
3486 xmlFreeTextReader(reader);
3488 return PMINFO_R_ERROR;
3491 _LOGE("Unable to create xml reader\n");
3492 xmlFreeTextReader(reader);
3494 return PMINFO_R_ERROR;
3498 _LOGE("xmlReaderForFile value is NULL\n");
3500 return PMINFO_R_ERROR;
3503 xmlFreeTextReader(reader);
3509 API int pkgmgrinfo_pkginfo_get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
3511 const char *val = NULL;
3512 const xmlChar *node;
3513 xmlTextReaderPtr reader;
3514 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "Input argument is NULL\n");
3515 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3518 reader = xmlReaderForFile(manifest, NULL, 0);
3521 if ( __child_element(reader, -1)) {
3522 node = xmlTextReaderConstName(reader);
3524 _LOGE("xmlTextReaderConstName value is NULL\n");
3525 xmlFreeTextReader(reader);
3527 return PMINFO_R_ERROR;
3530 if (!strcmp(ASC_CHAR(node), "manifest")) {
3531 if (xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")))
3532 val = ASC_CHAR(xmlTextReaderGetAttribute(reader, XML_CHAR("install-location")));
3535 if (strcmp(val, "internal-only") == 0)
3536 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
3537 else if (strcmp(val, "prefer-external") == 0)
3538 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
3540 *location = PMINFO_INSTALL_LOCATION_AUTO;
3543 _LOGE("Unable to create xml reader\n");
3544 xmlFreeTextReader(reader);
3546 return PMINFO_R_ERROR;
3550 _LOGE("xmlReaderForFile value is NULL\n");
3552 return PMINFO_R_ERROR;
3555 xmlFreeTextReader(reader);
3562 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
3564 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3565 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3567 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3568 if (info->manifest_info->root_path)
3569 *path = (char *)info->manifest_info->root_path;
3571 return PMINFO_R_ERROR;
3576 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
3578 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3579 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3581 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3582 if (info->manifest_info->csc_path)
3583 *path = (char *)info->manifest_info->csc_path;
3585 *path = (char *)info->manifest_info->csc_path;
3590 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)
3592 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
3593 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
3594 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3596 int ret = PMINFO_R_OK;
3597 char query[MAX_QUERY_LEN] = {'\0'};
3598 char *error_message = NULL;
3599 pkgmgr_cert_x *info= NULL;
3603 *compare_result = PMINFO_CERT_COMPARE_ERROR;
3604 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3605 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3607 ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
3608 SQLITE_OPEN_READWRITE, NULL);
3609 if (ret != SQLITE_OK) {
3610 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
3611 ret = PMINFO_R_ERROR;
3614 _check_create_Cert_db(cert_db);
3615 _pkgmgr_parser_attach_create_view_certdb(cert_db,uid);
3616 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", lhs_package_id);
3618 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3619 _LOGE("Don't execute query = %s error message = %s\n", query,
3621 ret = PMINFO_R_ERROR;
3628 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", lhs_package_id);
3630 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3631 _LOGE("Don't execute query = %s error message = %s\n", query,
3633 ret = PMINFO_R_ERROR;
3636 lcert = info->cert_id;
3639 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", rhs_package_id);
3641 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
3642 _LOGE("Don't execute query = %s error message = %s\n", query,
3644 ret = PMINFO_R_ERROR;
3651 snprintf(query, MAX_QUERY_LEN, "select author_signer_cert from package_cert_info where package='%s'", rhs_package_id);
3653 sqlite3_exec(cert_db, query, __cert_cb, (void *)info, &error_message)) {
3654 _LOGE("Don't execute query = %s error message = %s\n", query,
3656 ret = PMINFO_R_ERROR;
3659 rcert = info->cert_id;
3662 if ((lcert == 0) || (rcert == 0))
3664 if ((lcert == 0) && (rcert == 0))
3665 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
3666 else if (lcert == 0)
3667 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
3668 else if (rcert == 0)
3669 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
3672 *compare_result = PMINFO_CERT_COMPARE_MATCH;
3674 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
3678 sqlite3_free(error_message);
3679 sqlite3_close(cert_db);
3691 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)
3693 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
3696 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)
3698 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3699 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3700 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3702 int ret = PMINFO_R_OK;
3703 char query[MAX_QUERY_LEN] = {'\0'};
3704 char *error_message = NULL;
3705 pkgmgr_cert_x *info= NULL;
3707 char *lpkgid = NULL;
3708 char *rpkgid = NULL;
3710 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3711 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3713 ret = db_util_open_with_options(getUserPkgParserDBPath(), &manifest_db,
3714 SQLITE_OPEN_READONLY, NULL);
3715 if (ret != SQLITE_OK) {
3716 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPath());
3717 ret = PMINFO_R_ERROR;
3721 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3723 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3724 _LOGE("Don't execute query = %s error message = %s\n", query,
3726 ret = PMINFO_R_ERROR;
3733 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3735 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3736 _LOGE("Don't execute query = %s error message = %s\n", query,
3738 ret = PMINFO_R_ERROR;
3741 lpkgid = strdup(info->pkgid);
3742 if (lpkgid == NULL) {
3743 _LOGE("Out of Memory\n");
3744 ret = PMINFO_R_ERROR;
3751 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3753 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3754 _LOGE("Don't execute query = %s error message = %s\n", query,
3756 ret = PMINFO_R_ERROR;
3763 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3765 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3766 _LOGE("Don't execute query = %s error message = %s\n", query,
3768 ret = PMINFO_R_ERROR;
3771 rpkgid = strdup(info->pkgid);
3772 if (rpkgid == NULL) {
3773 _LOGE("Out of Memory\n");
3774 ret = PMINFO_R_ERROR;
3780 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
3782 sqlite3_free(error_message);
3783 sqlite3_close(manifest_db);
3803 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)
3805 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
3806 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
3807 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
3809 int ret = PMINFO_R_OK;
3810 char query[MAX_QUERY_LEN] = {'\0'};
3811 char *error_message = NULL;
3812 pkgmgr_cert_x *info= NULL;
3814 char *lpkgid = NULL;
3815 char *rpkgid = NULL;
3817 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
3818 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
3820 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &manifest_db,
3821 SQLITE_OPEN_READONLY, NULL);
3822 if (ret != SQLITE_OK) {
3823 _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
3824 ret = PMINFO_R_ERROR;
3827 _pkgmgr_parser_attach_create_view_parserdb(manifest_db,uid);
3829 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", lhs_app_id);
3831 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3832 _LOGE("Don't execute query = %s error message = %s\n", query,
3834 ret = PMINFO_R_ERROR;
3841 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", lhs_app_id);
3843 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3844 _LOGE("Don't execute query = %s error message = %s\n", query,
3846 ret = PMINFO_R_ERROR;
3849 lpkgid = strdup(info->pkgid);
3850 if (lpkgid == NULL) {
3851 _LOGE("Out of Memory\n");
3852 ret = PMINFO_R_ERROR;
3859 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", rhs_app_id);
3861 sqlite3_exec(manifest_db, query, __validate_cb, (void *)&exist, &error_message)) {
3862 _LOGE("Don't execute query = %s error message = %s\n", query,
3864 ret = PMINFO_R_ERROR;
3871 snprintf(query, MAX_QUERY_LEN, "select package from package_app_info where app_id='%s' ", rhs_app_id);
3873 sqlite3_exec(manifest_db, query, __cert_cb, (void *)info, &error_message)) {
3874 _LOGE("Don't execute query = %s error message = %s\n", query,
3876 ret = PMINFO_R_ERROR;
3879 rpkgid = strdup(info->pkgid);
3880 if (rpkgid == NULL) {
3881 _LOGE("Out of Memory\n");
3882 ret = PMINFO_R_ERROR;
3888 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lpkgid, rpkgid, uid, compare_result);
3890 sqlite3_free(error_message);
3891 sqlite3_close(manifest_db);
3911 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
3913 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3914 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3916 #if 0 //smack issue occured, check later
3918 pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
3920 _LOGD("invalid func parameters\n");
3921 return PMINFO_R_ERROR;
3923 _LOGD("pkgmgr_get_pkg_external_validation() called\n");
3926 char app_mmc_path[FILENAME_MAX] = { 0, };
3927 char app_dir_path[FILENAME_MAX] = { 0, };
3928 char app_mmc_internal_path[FILENAME_MAX] = { 0, };
3929 snprintf(app_dir_path, FILENAME_MAX,"%s%s", PKG_INSTALLATION_PATH, pkgid);
3930 snprintf(app_mmc_path, FILENAME_MAX,"%s%s", PKG_SD_PATH, pkgid);
3931 snprintf(app_mmc_internal_path, FILENAME_MAX,"%s%s/.mmc", PKG_INSTALLATION_PATH, pkgid);
3933 /*check whether application is in external memory or not */
3934 fp = fopen(app_mmc_path, "r");
3936 _LOGD(" app path in external memory not accesible\n");
3941 _LOGD("pkgmgr_get_pkg_external_validation() : SD_CARD \n");
3945 /*check whether application is in internal or not */
3946 fp = fopen(app_dir_path, "r");
3948 _LOGD(" app path in internal memory not accesible\n");
3950 return PMINFO_R_ERROR;
3953 /*check whether the application is installed in SD card
3954 but SD card is not present*/
3955 fp = fopen(app_mmc_internal_path, "r");
3958 _LOGD("pkgmgr_get_pkg_external_validation() : INTERNAL_MEM \n");
3963 _LOGD("pkgmgr_get_pkg_external_validation() : ERROR_MMC_STATUS \n");
3968 _LOGD("pkgmgr_get_pkg_external_validation() end\n");
3975 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
3977 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3978 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3980 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
3981 val = (char *)info->manifest_info->removable;
3983 if (strcasecmp(val, "true") == 0)
3985 else if (strcasecmp(val, "false") == 0)
3993 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
3995 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
3996 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
3999 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4001 val = (char *)info->manifest_info->installlocation;
4003 if (strcmp(val, "internal-only") == 0)
4005 else if (strcmp(val, "prefer-external") == 0)
4014 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
4016 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4017 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4019 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4020 val = (char *)info->manifest_info->preload;
4022 if (strcasecmp(val, "true") == 0)
4024 else if (strcasecmp(val, "false") == 0)
4032 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
4034 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4035 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4038 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4039 val = (char *)info->manifest_info->system;
4041 if (strcasecmp(val, "true") == 0)
4043 else if (strcasecmp(val, "false") == 0)
4052 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
4054 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4055 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4057 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4058 val = (char *)info->manifest_info->readonly;
4060 if (strcasecmp(val, "true") == 0)
4062 else if (strcasecmp(val, "false") == 0)
4070 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
4072 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4073 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
4076 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4077 val = (char *)info->manifest_info->update;
4079 if (strcasecmp(val, "true") == 0)
4081 else if (strcasecmp(val, "false") == 0)
4089 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
4091 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
4092 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4093 __cleanup_pkginfo(info);
4097 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
4099 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
4101 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
4102 if (filter == NULL) {
4103 _LOGE("Out of Memory!!!");
4104 return PMINFO_R_ERROR;
4110 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
4112 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4113 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4115 g_slist_foreach(filter->list, __destroy_each_node, NULL);
4116 g_slist_free(filter->list);
4123 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
4124 const char *property, const int value)
4126 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4127 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4128 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
4130 GSList *link = NULL;
4132 prop = _pminfo_pkginfo_convert_to_prop_int(property);
4133 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
4134 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
4135 _LOGE("Invalid Integer Property\n");
4136 return PMINFO_R_EINVAL;
4138 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4139 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4141 _LOGE("Out of Memory!!!\n");
4142 return PMINFO_R_ERROR;
4144 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
4145 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
4147 _LOGE("Out of Memory\n");
4150 return PMINFO_R_ERROR;
4154 /*If API is called multiple times for same property, we should override the previous values.
4155 Last value set will be used for filtering.*/
4156 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4158 filter->list = g_slist_delete_link(filter->list, link);
4159 filter->list = g_slist_append(filter->list, (gpointer)node);
4164 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
4165 const char *property, const bool value)
4167 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4168 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4170 GSList *link = NULL;
4172 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
4173 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
4174 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
4175 _LOGE("Invalid Boolean Property\n");
4176 return PMINFO_R_EINVAL;
4178 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4179 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4181 _LOGE("Out of Memory!!!\n");
4182 return PMINFO_R_ERROR;
4185 val = strndup("('true','True')", 15);
4187 val = strndup("('false','False')", 17);
4189 _LOGE("Out of Memory\n");
4192 return PMINFO_R_ERROR;
4196 /*If API is called multiple times for same property, we should override the previous values.
4197 Last value set will be used for filtering.*/
4198 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4200 filter->list = g_slist_delete_link(filter->list, link);
4201 filter->list = g_slist_append(filter->list, (gpointer)node);
4206 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
4207 const char *property, const char *value)
4209 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4210 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4211 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4213 GSList *link = NULL;
4215 prop = _pminfo_pkginfo_convert_to_prop_str(property);
4216 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
4217 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
4218 _LOGE("Invalid String Property\n");
4219 return PMINFO_R_EINVAL;
4221 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4222 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
4224 _LOGE("Out of Memory!!!\n");
4225 return PMINFO_R_ERROR;
4227 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
4228 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
4229 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
4230 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
4231 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
4232 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
4233 else if (strcmp(value, "installed_internal") == 0)
4234 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
4235 else if (strcmp(value, "installed_external") == 0)
4236 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
4238 val = strndup(value, PKG_STRING_LEN_MAX - 1);
4240 _LOGE("Out of Memory\n");
4243 return PMINFO_R_ERROR;
4247 /*If API is called multiple times for same property, we should override the previous values.
4248 Last value set will be used for filtering.*/
4249 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
4251 filter->list = g_slist_delete_link(filter->list, link);
4252 filter->list = g_slist_append(filter->list, (gpointer)node);
4257 API int pkgmgrinfo_pkginfo_usr_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count, uid_t uid)
4259 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4260 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4261 char *syslocale = NULL;
4262 char *locale = NULL;
4263 char *condition = NULL;
4264 char *error_message = NULL;
4265 char query[MAX_QUERY_LEN] = {'\0'};
4266 char where[MAX_QUERY_LEN] = {'\0'};
4270 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4271 /*Get current locale*/
4272 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4273 if (syslocale == NULL) {
4274 _LOGE("current locale is NULL\n");
4275 return PMINFO_R_ERROR;
4277 locale = __convert_system_locale_to_manifest_locale(syslocale);
4278 if (locale == NULL) {
4279 _LOGE("manifest locale is NULL\n");
4281 return PMINFO_R_ERROR;
4284 ret = __open_manifest_db(uid);
4286 _LOGE("Fail to open manifest DB\n");
4289 return PMINFO_R_ERROR;
4292 /*Start constructing query*/
4293 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_PACKAGE, locale);
4295 /*Get where clause*/
4296 for (list = filter->list; list; list = g_slist_next(list)) {
4297 __get_filter_condition(list->data, &condition);
4299 strncat(where, condition, sizeof(where) - strlen(where) -1);
4300 where[sizeof(where) - 1] = '\0';
4304 if (g_slist_next(list)) {
4305 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4306 where[sizeof(where) - 1] = '\0';
4309 _LOGE("where = %s\n", where);
4310 if (strlen(where) > 0) {
4311 strncat(query, where, sizeof(query) - strlen(query) - 1);
4312 query[sizeof(query) - 1] = '\0';
4314 _LOGE("query = %s\n", query);
4318 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
4319 _LOGE("Don't execute query = %s error message = %s\n", query,
4321 sqlite3_free(error_message);
4322 sqlite3_close(manifest_db);
4323 ret = PMINFO_R_ERROR;
4337 sqlite3_close(manifest_db);
4341 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
4343 return pkgmgrinfo_pkginfo_usr_filter_count(handle, count, GLOBAL_USER);
4346 API int pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4347 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
4349 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4350 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
4351 char *syslocale = NULL;
4352 char *locale = NULL;
4353 char *condition = NULL;
4354 char *error_message = NULL;
4355 char query[MAX_QUERY_LEN] = {'\0'};
4356 char where[MAX_QUERY_LEN] = {'\0'};
4359 label_x *tmp1 = NULL;
4360 icon_x *tmp2 = NULL;
4361 description_x *tmp3 = NULL;
4362 author_x *tmp4 = NULL;
4363 privilege_x *tmp5 = NULL;
4364 pkgmgr_pkginfo_x *node = NULL;
4365 pkgmgr_pkginfo_x *tmphead = NULL;
4366 pkgmgr_pkginfo_x *pkginfo = NULL;
4368 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
4369 /*Get current locale*/
4370 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4371 if (syslocale == NULL) {
4372 _LOGE("current locale is NULL\n");
4373 return PMINFO_R_ERROR;
4375 locale = __convert_system_locale_to_manifest_locale(syslocale);
4376 if (locale == NULL) {
4377 _LOGE("manifest locale is NULL\n");
4379 return PMINFO_R_ERROR;
4382 ret = __open_manifest_db(uid);
4384 _LOGE("Fail to open manifest DB\n");
4387 return PMINFO_R_ERROR;
4389 /*Start constructing query*/
4390 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, locale);
4392 /*Get where clause*/
4393 for (list = filter->list; list; list = g_slist_next(list)) {
4394 __get_filter_condition(list->data, &condition);
4396 strncat(where, condition, sizeof(where) - strlen(where) -1);
4397 where[sizeof(where) - 1] = '\0';
4401 if (g_slist_next(list)) {
4402 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
4403 where[sizeof(where) - 1] = '\0';
4406 _LOGE("where = %s\n", where);
4407 if (strlen(where) > 0) {
4408 strncat(query, where, sizeof(query) - strlen(query) - 1);
4409 query[sizeof(query) - 1] = '\0';
4411 _LOGE("query = %s\n", query);
4412 tmphead = calloc(1, sizeof(pkgmgr_pkginfo_x));
4413 if (tmphead == NULL) {
4414 _LOGE("Out of Memory!!!\n");
4415 ret = PMINFO_R_ERROR;
4420 sqlite3_exec(manifest_db, query, __pkg_list_cb, (void *)tmphead, &error_message)) {
4421 _LOGE("Don't execute query = %s error message = %s\n", query,
4423 sqlite3_free(error_message);
4424 ret = PMINFO_R_ERROR;
4428 LISTHEAD(tmphead, node);
4429 for(node = node->next ; node ; node = node->next) {
4431 pkginfo->locale = strdup(locale);
4432 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
4433 if (pkginfo->manifest_info->privileges == NULL) {
4434 _LOGE("Failed to allocate memory for privileges info\n");
4435 ret = PMINFO_R_ERROR;
4439 /*populate manifest_info from DB*/
4440 snprintf(query, MAX_QUERY_LEN, "select * from package_info where package='%s' ", pkginfo->manifest_info->package);
4441 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4443 _LOGE("Package Info DB Information retrieval failed\n");
4444 ret = PMINFO_R_ERROR;
4447 memset(query, '\0', MAX_QUERY_LEN);
4448 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4449 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, locale);
4450 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4452 _LOGE("Package Info DB Information retrieval failed\n");
4453 ret = PMINFO_R_ERROR;
4456 /*Also store the values corresponding to default locales*/
4457 memset(query, '\0', MAX_QUERY_LEN);
4458 snprintf(query, MAX_QUERY_LEN, "select * from package_localized_info where" \
4459 " package='%s' and package_locale='%s'", pkginfo->manifest_info->package, DEFAULT_LOCALE);
4460 ret = __exec_pkginfo_query(query, (void *)pkginfo);
4462 _LOGE("Package Info DB Information retrieval failed\n");
4463 ret = PMINFO_R_ERROR;
4466 if (pkginfo->manifest_info->label) {
4467 LISTHEAD(pkginfo->manifest_info->label, tmp1);
4468 pkginfo->manifest_info->label = tmp1;
4470 if (pkginfo->manifest_info->icon) {
4471 LISTHEAD(pkginfo->manifest_info->icon, tmp2);
4472 pkginfo->manifest_info->icon = tmp2;
4474 if (pkginfo->manifest_info->description) {
4475 LISTHEAD(pkginfo->manifest_info->description, tmp3);
4476 pkginfo->manifest_info->description = tmp3;
4478 if (pkginfo->manifest_info->author) {
4479 LISTHEAD(pkginfo->manifest_info->author, tmp4);
4480 pkginfo->manifest_info->author = tmp4;
4482 if (pkginfo->manifest_info->privileges->privilege) {
4483 LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
4484 pkginfo->manifest_info->privileges->privilege = tmp5;
4488 LISTHEAD(tmphead, node);
4490 for(node = node->next ; node ; node = node->next) {
4492 ret = pkg_cb( (void *)pkginfo, user_data);
4507 sqlite3_close(manifest_db);
4508 __cleanup_pkginfo(tmphead);
4512 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
4513 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
4515 return pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, pkg_cb, user_data, GLOBAL_USER);
4518 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
4519 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
4521 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4522 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
4524 privilege_x *ptr = NULL;
4525 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4526 ptr = info->manifest_info->privileges->privilege;
4527 for (; ptr; ptr = ptr->next) {
4529 ret = privilege_func(ptr->text, user_data);
4537 API int pkgmgrinfo_appinfo_get_usr_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4538 pkgmgrinfo_app_list_cb app_func, void *user_data, uid_t uid)
4540 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
4541 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback pointer is NULL");
4542 retvm_if((component != PMINFO_UI_APP) && (component != PMINFO_SVC_APP) && (component != PMINFO_ALL_APP), PMINFO_R_EINVAL, "Invalid App Component Type");
4544 char *syslocale = NULL;
4545 char *locale = NULL;
4547 char query[MAX_QUERY_LEN] = {'\0'};
4548 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
4549 pkgmgr_pkginfo_x *allinfo = NULL;
4550 pkgmgr_appinfo_x *appinfo = NULL;
4551 icon_x *ptr1 = NULL;
4552 label_x *ptr2 = NULL;
4553 category_x *ptr3 = NULL;
4554 metadata_x *ptr4 = NULL;
4555 permission_x *ptr5 = NULL;
4556 image_x *ptr6 = NULL;
4557 sqlite3 *appinfo_db = NULL;
4559 /*get system locale*/
4560 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4561 retvm_if(syslocale == NULL, PMINFO_R_EINVAL, "current locale is NULL");
4563 /*get locale on db*/
4564 locale = __convert_system_locale_to_manifest_locale(syslocale);
4565 tryvm_if(locale == NULL, ret = PMINFO_R_EINVAL, "manifest locale is NULL");
4568 allinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4569 tryvm_if(allinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4571 /*calloc manifest_info*/
4572 allinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4573 tryvm_if(allinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4576 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4577 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
4579 /*set component type*/
4580 if (component == PMINFO_UI_APP)
4581 appinfo->app_component = PMINFO_UI_APP;
4582 if (component == PMINFO_SVC_APP)
4583 appinfo->app_component = PMINFO_SVC_APP;
4584 if (component == PMINFO_ALL_APP)
4585 appinfo->app_component = PMINFO_ALL_APP;
4588 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4589 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4591 appinfo->package = strdup(info->manifest_info->package);
4592 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
4593 "from package_app_info where " \
4594 "package='%s' and app_component='%s'",
4595 info->manifest_info->package,
4596 (appinfo->app_component==PMINFO_UI_APP ? "uiapp" : "svcapp"));
4600 /*Populate ui app info */
4601 ret = __exec_db_query(appinfo_db, query, __uiapp_list_cb, (void *)info);
4602 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4604 uiapplication_x *tmp = NULL;
4605 if (info->manifest_info->uiapplication) {
4606 LISTHEAD(info->manifest_info->uiapplication, tmp);
4607 info->manifest_info->uiapplication = tmp;
4609 /*Populate localized info for default locales and call callback*/
4610 /*If the callback func return < 0 we break and no more call back is called*/
4613 appinfo->locale = strdup(locale);
4614 appinfo->uiapp_info = tmp;
4615 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
4619 locale = __get_app_locale_by_fallback(appinfo_db, appinfo->uiapp_info->appid, syslocale);
4622 memset(query, '\0', MAX_QUERY_LEN);
4623 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4624 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4625 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4627 memset(query, '\0', MAX_QUERY_LEN);
4628 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);
4629 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4630 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4632 /*store setting notification icon section*/
4633 memset(query, '\0', MAX_QUERY_LEN);
4634 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4635 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4636 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4638 /*store app preview image info*/
4639 memset(query, '\0', MAX_QUERY_LEN);
4640 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4641 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4642 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4644 if (appinfo->uiapp_info->label) {
4645 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4646 appinfo->uiapp_info->label = ptr2;
4648 if (appinfo->uiapp_info->icon) {
4649 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4650 appinfo->uiapp_info->icon = ptr1;
4652 if (appinfo->uiapp_info->category) {
4653 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4654 appinfo->uiapp_info->category = ptr3;
4656 if (appinfo->uiapp_info->metadata) {
4657 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4658 appinfo->uiapp_info->metadata = ptr4;
4660 if (appinfo->uiapp_info->permission) {
4661 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4662 appinfo->uiapp_info->permission = ptr5;
4664 if (appinfo->uiapp_info->image) {
4665 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4666 appinfo->uiapp_info->image = ptr6;
4668 ret = app_func((void *)appinfo, user_data);
4674 case PMINFO_SVC_APP:
4675 /*Populate svc app info */
4676 ret = __exec_db_query(appinfo_db, query, __svcapp_list_cb, (void *)info);
4677 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4679 serviceapplication_x *tmp1 = NULL;
4680 if (info->manifest_info->serviceapplication) {
4681 LISTHEAD(info->manifest_info->serviceapplication, tmp1);
4682 info->manifest_info->serviceapplication = tmp1;
4684 /*Populate localized info for default locales and call callback*/
4685 /*If the callback func return < 0 we break and no more call back is called*/
4688 appinfo->locale = strdup(locale);
4689 appinfo->svcapp_info = tmp1;
4690 memset(query, '\0', MAX_QUERY_LEN);
4691 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4692 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4693 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4695 memset(query, '\0', MAX_QUERY_LEN);
4696 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);
4697 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4698 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4700 if (appinfo->svcapp_info->label) {
4701 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4702 appinfo->svcapp_info->label = ptr2;
4704 if (appinfo->svcapp_info->icon) {
4705 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4706 appinfo->svcapp_info->icon = ptr1;
4708 if (appinfo->svcapp_info->category) {
4709 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4710 appinfo->svcapp_info->category = ptr3;
4712 if (appinfo->svcapp_info->metadata) {
4713 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4714 appinfo->svcapp_info->metadata = ptr4;
4716 if (appinfo->svcapp_info->permission) {
4717 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4718 appinfo->svcapp_info->permission = ptr5;
4720 ret = app_func((void *)appinfo, user_data);
4726 case PMINFO_ALL_APP:
4727 memset(query, '\0', MAX_QUERY_LEN);
4728 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where package='%s'", info->manifest_info->package);
4730 /*Populate all app info */
4731 ret = __exec_db_query(appinfo_db, query, __allapp_list_cb, (void *)allinfo);
4732 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info list retrieval failed");
4735 appinfo->app_component = PMINFO_UI_APP;
4736 uiapplication_x *tmp2 = NULL;
4737 if (allinfo->manifest_info->uiapplication) {
4738 LISTHEAD(allinfo->manifest_info->uiapplication, tmp2);
4739 allinfo->manifest_info->uiapplication = tmp2;
4741 /*Populate localized info for default locales and call callback*/
4742 /*If the callback func return < 0 we break and no more call back is called*/
4745 appinfo->locale = strdup(locale);
4746 appinfo->uiapp_info = tmp2;
4747 memset(query, '\0', MAX_QUERY_LEN);
4748 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, locale);
4749 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4750 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4752 memset(query, '\0', MAX_QUERY_LEN);
4753 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->uiapp_info->appid, DEFAULT_LOCALE);
4754 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4755 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4757 /*store setting notification icon section*/
4758 memset(query, '\0', MAX_QUERY_LEN);
4759 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appinfo->uiapp_info->appid);
4760 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4761 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
4763 /*store app preview image info*/
4764 memset(query, '\0', MAX_QUERY_LEN);
4765 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appinfo->uiapp_info->appid);
4766 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4767 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
4769 if (appinfo->uiapp_info->label) {
4770 LISTHEAD(appinfo->uiapp_info->label, ptr2);
4771 appinfo->uiapp_info->label = ptr2;
4773 if (appinfo->uiapp_info->icon) {
4774 LISTHEAD(appinfo->uiapp_info->icon, ptr1);
4775 appinfo->uiapp_info->icon = ptr1;
4777 if (appinfo->uiapp_info->category) {
4778 LISTHEAD(appinfo->uiapp_info->category, ptr3);
4779 appinfo->uiapp_info->category = ptr3;
4781 if (appinfo->uiapp_info->metadata) {
4782 LISTHEAD(appinfo->uiapp_info->metadata, ptr4);
4783 appinfo->uiapp_info->metadata = ptr4;
4785 if (appinfo->uiapp_info->permission) {
4786 LISTHEAD(appinfo->uiapp_info->permission, ptr5);
4787 appinfo->uiapp_info->permission = ptr5;
4789 if (appinfo->uiapp_info->image) {
4790 LISTHEAD(appinfo->uiapp_info->image, ptr6);
4791 appinfo->uiapp_info->image = ptr6;
4793 ret = app_func((void *)appinfo, user_data);
4800 appinfo->app_component = PMINFO_SVC_APP;
4801 serviceapplication_x *tmp3 = NULL;
4802 if (allinfo->manifest_info->serviceapplication) {
4803 LISTHEAD(allinfo->manifest_info->serviceapplication, tmp3);
4804 allinfo->manifest_info->serviceapplication = tmp3;
4806 /*Populate localized info for default locales and call callback*/
4807 /*If the callback func return < 0 we break and no more call back is called*/
4810 appinfo->locale = strdup(locale);
4811 appinfo->svcapp_info = tmp3;
4812 memset(query, '\0', MAX_QUERY_LEN);
4813 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appinfo->svcapp_info->appid, locale);
4814 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4815 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4817 memset(query, '\0', MAX_QUERY_LEN);
4818 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);
4819 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
4820 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
4822 if (appinfo->svcapp_info->label) {
4823 LISTHEAD(appinfo->svcapp_info->label, ptr2);
4824 appinfo->svcapp_info->label = ptr2;
4826 if (appinfo->svcapp_info->icon) {
4827 LISTHEAD(appinfo->svcapp_info->icon, ptr1);
4828 appinfo->svcapp_info->icon = ptr1;
4830 if (appinfo->svcapp_info->category) {
4831 LISTHEAD(appinfo->svcapp_info->category, ptr3);
4832 appinfo->svcapp_info->category = ptr3;
4834 if (appinfo->svcapp_info->metadata) {
4835 LISTHEAD(appinfo->svcapp_info->metadata, ptr4);
4836 appinfo->svcapp_info->metadata = ptr4;
4838 if (appinfo->svcapp_info->permission) {
4839 LISTHEAD(appinfo->svcapp_info->permission, ptr5);
4840 appinfo->svcapp_info->permission = ptr5;
4842 ret = app_func((void *)appinfo, user_data);
4847 appinfo->app_component = PMINFO_ALL_APP;
4863 if (appinfo->package) {
4864 free((void *)appinfo->package);
4865 appinfo->package = NULL;
4870 __cleanup_pkginfo(allinfo);
4872 sqlite3_close(appinfo_db);
4876 API int pkgmgrinfo_appinfo_get_list(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_app_component component,
4877 pkgmgrinfo_app_list_cb app_func, void *user_data)
4879 return pkgmgrinfo_appinfo_get_usr_list(handle, component, app_func, user_data, GLOBAL_USER);
4882 API int pkgmgrinfo_appinfo_get_usr_install_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4884 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4886 int ret = PMINFO_R_OK;
4887 char query[MAX_QUERY_LEN] = {'\0'};
4888 pkgmgr_appinfo_x *appinfo = NULL;
4889 uiapplication_x *ptr1 = NULL;
4890 serviceapplication_x *ptr2 = NULL;
4891 sqlite3 *appinfo_db = NULL;
4894 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4895 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4898 pkgmgr_pkginfo_x *info = NULL;
4899 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
4900 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4902 /*calloc manifest_info*/
4903 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
4904 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4907 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
4908 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
4910 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
4911 ret = __exec_db_query(appinfo_db, query, __mini_appinfo_cb, (void *)info);
4912 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
4914 if (info->manifest_info->uiapplication) {
4915 LISTHEAD(info->manifest_info->uiapplication, ptr1);
4916 info->manifest_info->uiapplication = ptr1;
4918 if (info->manifest_info->serviceapplication) {
4919 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
4920 info->manifest_info->serviceapplication = ptr2;
4924 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
4926 appinfo->app_component = PMINFO_UI_APP;
4927 appinfo->package = strdup(ptr1->package);
4928 appinfo->uiapp_info = ptr1;
4930 ret = app_func((void *)appinfo, user_data);
4933 free((void *)appinfo->package);
4934 appinfo->package = NULL;
4937 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
4939 appinfo->app_component = PMINFO_SVC_APP;
4940 appinfo->package = strdup(ptr2->package);
4941 appinfo->svcapp_info = ptr2;
4943 ret = app_func((void *)appinfo, user_data);
4946 free((void *)appinfo->package);
4947 appinfo->package = NULL;
4952 sqlite3_close(appinfo_db);
4958 __cleanup_pkginfo(info);
4962 API int pkgmgrinfo_appinfo_get_install_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
4964 return pkgmgrinfo_appinfo_get_usr_install_list(app_func, GLOBAL_USER, user_data);
4967 API int pkgmgrinfo_appinfo_get_usr_installed_list(pkgmgrinfo_app_list_cb app_func, uid_t uid, void *user_data)
4969 retvm_if(app_func == NULL, PMINFO_R_EINVAL, "callback function is NULL");
4971 int ret = PMINFO_R_OK;
4972 char query[MAX_QUERY_LEN] = {'\0'};
4973 char *syslocale = NULL;
4974 char *locale = NULL;
4975 pkgmgr_appinfo_x *appinfo = NULL;
4976 uiapplication_x *ptr1 = NULL;
4977 serviceapplication_x *ptr2 = NULL;
4978 label_x *tmp1 = NULL;
4979 icon_x *tmp2 = NULL;
4980 category_x *tmp3 = NULL;
4981 metadata_x *tmp4 = NULL;
4982 permission_x *tmp5 = NULL;
4983 image_x *tmp6 = NULL;
4984 sqlite3 *appinfo_db = NULL;
4986 /*get system locale*/
4987 syslocale = vconf_get_str(VCONFKEY_LANGSET);
4988 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
4990 /*get locale on db*/
4991 locale = __convert_system_locale_to_manifest_locale(syslocale);
4992 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
4995 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
4996 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
4999 pkgmgr_pkginfo_x *info = NULL;
5000 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
5001 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5003 /*calloc manifest_info*/
5004 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
5005 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5008 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5009 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!");
5011 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info");
5012 ret = __exec_db_query(appinfo_db, query, __app_list_cb, (void *)info);
5013 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5015 if (info->manifest_info->uiapplication) {
5016 LISTHEAD(info->manifest_info->uiapplication, ptr1);
5017 info->manifest_info->uiapplication = ptr1;
5019 if (info->manifest_info->serviceapplication) {
5020 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
5021 info->manifest_info->serviceapplication = ptr2;
5025 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
5027 appinfo->locale = strdup(locale);
5028 appinfo->app_component = PMINFO_UI_APP;
5029 appinfo->package = strdup(ptr1->package);
5030 appinfo->uiapp_info = ptr1;
5031 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5032 "from package_app_info where " \
5033 "app_id='%s'", ptr1->appid);
5034 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5035 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5037 if (strcmp(appinfo->uiapp_info->type,"c++app") == 0){
5041 locale = __get_app_locale_by_fallback(appinfo_db, ptr1->appid, syslocale);
5044 memset(query, '\0', MAX_QUERY_LEN);
5045 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5046 "from package_app_localized_info where " \
5047 "app_id='%s' and app_locale='%s'",
5048 ptr1->appid, locale);
5049 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5050 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5052 memset(query, '\0', MAX_QUERY_LEN);
5053 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5054 "from package_app_localized_info where " \
5055 "app_id='%s' and app_locale='%s'",
5056 ptr1->appid, DEFAULT_LOCALE);
5058 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5059 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5061 /*store setting notification icon section*/
5062 memset(query, '\0', MAX_QUERY_LEN);
5063 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", ptr1->appid);
5064 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5065 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5067 /*store app preview image info*/
5068 memset(query, '\0', MAX_QUERY_LEN);
5069 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", ptr1->appid);
5070 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5071 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5073 if (appinfo->uiapp_info->label) {
5074 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5075 appinfo->uiapp_info->label = tmp1;
5077 if (appinfo->uiapp_info->icon) {
5078 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5079 appinfo->uiapp_info->icon= tmp2;
5081 if (appinfo->uiapp_info->category) {
5082 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5083 appinfo->uiapp_info->category = tmp3;
5085 if (appinfo->uiapp_info->metadata) {
5086 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5087 appinfo->uiapp_info->metadata = tmp4;
5089 if (appinfo->uiapp_info->permission) {
5090 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5091 appinfo->uiapp_info->permission = tmp5;
5093 if (appinfo->uiapp_info->image) {
5094 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5095 appinfo->uiapp_info->image = tmp6;
5097 ret = app_func((void *)appinfo, user_data);
5100 free((void *)appinfo->package);
5101 appinfo->package = NULL;
5104 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
5106 appinfo->locale = strdup(locale);
5107 appinfo->app_component = PMINFO_SVC_APP;
5108 appinfo->package = strdup(ptr2->package);
5109 appinfo->svcapp_info = ptr2;
5110 memset(query, '\0', MAX_QUERY_LEN);
5111 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5112 "from package_app_info where " \
5113 "app_id='%s'", ptr2->appid);
5114 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5115 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5117 memset(query, '\0', MAX_QUERY_LEN);
5118 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5119 "from package_app_localized_info where " \
5120 "app_id='%s' and app_locale='%s'",
5121 ptr2->appid, locale);
5122 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5123 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5125 memset(query, '\0', MAX_QUERY_LEN);
5126 snprintf(query, MAX_QUERY_LEN, "select DISTINCT * " \
5127 "from package_app_localized_info where " \
5128 "app_id='%s' and app_locale='%s'",
5129 ptr2->appid, DEFAULT_LOCALE);
5130 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5131 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5133 if (appinfo->svcapp_info->label) {
5134 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5135 appinfo->svcapp_info->label = tmp1;
5137 if (appinfo->svcapp_info->icon) {
5138 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5139 appinfo->svcapp_info->icon= tmp2;
5141 if (appinfo->svcapp_info->category) {
5142 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5143 appinfo->svcapp_info->category = tmp3;
5145 if (appinfo->svcapp_info->metadata) {
5146 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5147 appinfo->svcapp_info->metadata = tmp4;
5149 if (appinfo->svcapp_info->permission) {
5150 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5151 appinfo->svcapp_info->permission = tmp5;
5153 ret = app_func((void *)appinfo, user_data);
5156 free((void *)appinfo->package);
5157 appinfo->package = NULL;
5170 sqlite3_close(appinfo_db);
5175 __cleanup_pkginfo(info);
5179 API int pkgmgrinfo_appinfo_get_installed_list(pkgmgrinfo_app_list_cb app_func, void *user_data)
5181 return pkgmgrinfo_appinfo_get_usr_installed_list(app_func, GLOBAL_USER, user_data);
5184 API int pkgmgrinfo_appinfo_get_usr_appinfo(const char *appid, uid_t uid, pkgmgrinfo_appinfo_h *handle)
5186 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL");
5187 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5189 pkgmgr_appinfo_x *appinfo = NULL;
5190 char *syslocale = NULL;
5191 char *locale = NULL;
5194 label_x *tmp1 = NULL;
5195 icon_x *tmp2 = NULL;
5196 category_x *tmp3 = NULL;
5197 metadata_x *tmp4 = NULL;
5198 permission_x *tmp5 = NULL;
5199 image_x *tmp6 = NULL;
5200 char query[MAX_QUERY_LEN] = {'\0'};
5201 sqlite3 *appinfo_db = NULL;
5205 _LOGD("getUserPkgParserDBPathUID(%d) returns: [%s]", uid, getUserPkgParserDBPathUID(uid));
5206 ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &appinfo_db, SQLITE_OPEN_READONLY, NULL);
5207 retvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", getUserPkgParserDBPathUID(uid));
5210 /*check appid exist on db*/
5211 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_app_info where app_id='%s')", appid);
5212 ret = __exec_db_query(appinfo_db, query, __validate_cb, (void *)&exist);
5213 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec fail");
5214 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "Appid[%s] not found in DB", appid);
5216 /*get system locale*/
5217 syslocale = vconf_get_str(VCONFKEY_LANGSET);
5218 tryvm_if(syslocale == NULL, ret = PMINFO_R_ERROR, "current locale is NULL");
5220 /*get locale on db*/
5221 locale = __convert_system_locale_to_manifest_locale(syslocale);
5222 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
5225 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
5226 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for appinfo");
5228 /*check app_component from DB*/
5229 memset(query, '\0', MAX_QUERY_LEN);
5230 snprintf(query, MAX_QUERY_LEN, "select app_component, package from package_app_info where app_id='%s' ", appid);
5231 ret = __exec_db_query(appinfo_db, query, __appcomponent_cb, (void *)appinfo);
5232 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5234 /*calloc app_component*/
5235 if (appinfo->app_component == PMINFO_UI_APP) {
5236 appinfo->uiapp_info = (uiapplication_x *)calloc(1, sizeof(uiapplication_x));
5237 tryvm_if(appinfo->uiapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for uiapp info");
5239 appinfo->svcapp_info = (serviceapplication_x *)calloc(1, sizeof(serviceapplication_x));
5240 tryvm_if(appinfo->svcapp_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for svcapp info");
5242 appinfo->locale = strdup(locale);
5244 /*populate app_info from DB*/
5245 memset(query, '\0', MAX_QUERY_LEN);
5246 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' ", appid);
5247 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5248 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5250 memset(query, '\0', MAX_QUERY_LEN);
5251 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, locale);
5252 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5253 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Info DB Information retrieval failed");
5255 /*Also store the values corresponding to default locales*/
5256 memset(query, '\0', MAX_QUERY_LEN);
5257 snprintf(query, MAX_QUERY_LEN, "select * from package_app_localized_info where app_id='%s' and app_locale='%s'", appid, DEFAULT_LOCALE);
5258 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5259 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Localized Info DB Information retrieval failed");
5261 /*Populate app category*/
5262 memset(query, '\0', MAX_QUERY_LEN);
5263 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_category where app_id='%s'", appid);
5264 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5265 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Category Info DB Information retrieval failed");
5267 /*Populate app metadata*/
5268 memset(query, '\0', MAX_QUERY_LEN);
5269 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_metadata where app_id='%s'", appid);
5270 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5271 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App Metadata Info DB Information retrieval failed");
5273 /*Populate app permission*/
5274 memset(query, '\0', MAX_QUERY_LEN);
5275 snprintf(query, MAX_QUERY_LEN, "select * from package_app_app_permission where app_id='%s'", appid);
5276 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5277 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App permission Info DB Information retrieval failed");
5279 /*store setting notification icon section*/
5280 memset(query, '\0', MAX_QUERY_LEN);
5281 snprintf(query, MAX_QUERY_LEN, "select * from package_app_icon_section_info where app_id='%s'", appid);
5282 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5283 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App icon section Info DB Information retrieval failed");
5285 /*store app preview image info*/
5286 memset(query, '\0', MAX_QUERY_LEN);
5287 snprintf(query, MAX_QUERY_LEN, "select app_image_section, app_image from package_app_image_info where app_id='%s'", appid);
5288 ret = __exec_db_query(appinfo_db, query, __appinfo_cb, (void *)appinfo);
5289 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "App image Info DB Information retrieval failed");
5291 switch (appinfo->app_component) {
5293 if (appinfo->uiapp_info->label) {
5294 LISTHEAD(appinfo->uiapp_info->label, tmp1);
5295 appinfo->uiapp_info->label = tmp1;
5297 if (appinfo->uiapp_info->icon) {
5298 LISTHEAD(appinfo->uiapp_info->icon, tmp2);
5299 appinfo->uiapp_info->icon = tmp2;
5301 if (appinfo->uiapp_info->category) {
5302 LISTHEAD(appinfo->uiapp_info->category, tmp3);
5303 appinfo->uiapp_info->category = tmp3;
5305 if (appinfo->uiapp_info->metadata) {
5306 LISTHEAD(appinfo->uiapp_info->metadata, tmp4);
5307 appinfo->uiapp_info->metadata = tmp4;
5309 if (appinfo->uiapp_info->permission) {
5310 LISTHEAD(appinfo->uiapp_info->permission, tmp5);
5311 appinfo->uiapp_info->permission = tmp5;
5313 if (appinfo->uiapp_info->image) {
5314 LISTHEAD(appinfo->uiapp_info->image, tmp6);
5315 appinfo->uiapp_info->image = tmp6;
5318 case PMINFO_SVC_APP:
5319 if (appinfo->svcapp_info->label) {
5320 LISTHEAD(appinfo->svcapp_info->label, tmp1);
5321 appinfo->svcapp_info->label = tmp1;
5323 if (appinfo->svcapp_info->icon) {
5324 LISTHEAD(appinfo->svcapp_info->icon, tmp2);
5325 appinfo->svcapp_info->icon = tmp2;
5327 if (appinfo->svcapp_info->category) {
5328 LISTHEAD(appinfo->svcapp_info->category, tmp3);
5329 appinfo->svcapp_info->category = tmp3;
5331 if (appinfo->svcapp_info->metadata) {
5332 LISTHEAD(appinfo->svcapp_info->metadata, tmp4);
5333 appinfo->svcapp_info->metadata = tmp4;
5335 if (appinfo->svcapp_info->permission) {
5336 LISTHEAD(appinfo->svcapp_info->permission, tmp5);
5337 appinfo->svcapp_info->permission = tmp5;
5347 if (ret == PMINFO_R_OK)
5348 *handle = (void*)appinfo;
5351 __cleanup_appinfo(appinfo);
5354 sqlite3_close(appinfo_db);
5366 API int pkgmgrinfo_appinfo_get_appinfo(const char *appid, pkgmgrinfo_appinfo_h *handle)
5368 return pkgmgrinfo_appinfo_get_usr_appinfo(appid, GLOBAL_USER, handle);
5371 API int pkgmgrinfo_appinfo_get_appid(pkgmgrinfo_appinfo_h handle, char **appid)
5373 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5374 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5375 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5377 if (info->app_component == PMINFO_UI_APP)
5378 *appid = (char *)info->uiapp_info->appid;
5379 else if (info->app_component == PMINFO_SVC_APP)
5380 *appid = (char *)info->svcapp_info->appid;
5385 API int pkgmgrinfo_appinfo_get_pkgname(pkgmgrinfo_appinfo_h handle, char **pkg_name)
5387 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5388 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5389 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5391 *pkg_name = (char *)info->package;
5396 API int pkgmgrinfo_appinfo_get_pkgid(pkgmgrinfo_appinfo_h handle, char **pkgid)
5398 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5399 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5400 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5402 *pkgid = (char *)info->package;
5407 API int pkgmgrinfo_appinfo_get_exec(pkgmgrinfo_appinfo_h handle, char **exec)
5409 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5410 retvm_if(exec == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5411 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5413 if (info->app_component == PMINFO_UI_APP)
5414 *exec = (char *)info->uiapp_info->exec;
5415 if (info->app_component == PMINFO_SVC_APP)
5416 *exec = (char *)info->svcapp_info->exec;
5422 API int pkgmgrinfo_appinfo_get_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5424 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5425 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5426 char *locale = NULL;
5428 icon_x *start = NULL;
5431 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5432 locale = info->locale;
5433 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5435 if (info->app_component == PMINFO_UI_APP)
5436 start = info->uiapp_info->icon;
5437 if (info->app_component == PMINFO_SVC_APP)
5438 start = info->svcapp_info->icon;
5439 for(ptr = start; ptr != NULL; ptr = ptr->next)
5442 if (strcmp(ptr->lang, locale) == 0) {
5443 *icon = (char *)ptr->text;
5444 if (strcasecmp(*icon, "(null)") == 0) {
5445 locale = DEFAULT_LOCALE;
5449 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5450 *icon = (char *)ptr->text;
5459 API int pkgmgrinfo_appinfo_get_label(pkgmgrinfo_appinfo_h handle, char **label)
5461 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5462 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5463 char *locale = NULL;
5464 label_x *ptr = NULL;
5465 label_x *start = NULL;
5468 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5469 locale = info->locale;
5470 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
5472 if (info->app_component == PMINFO_UI_APP)
5473 start = info->uiapp_info->label;
5474 if (info->app_component == PMINFO_SVC_APP)
5475 start = info->svcapp_info->label;
5476 for(ptr = start; ptr != NULL; ptr = ptr->next)
5479 if (strcmp(ptr->lang, locale) == 0) {
5480 *label = (char *)ptr->text;
5481 if (strcasecmp(*label, "(null)") == 0) {
5482 locale = DEFAULT_LOCALE;
5486 } else if (strncasecmp(ptr->lang, locale, 2) == 0) {
5487 *label = (char *)ptr->text;
5488 if (strcasecmp(*label, "(null)") == 0) {
5489 locale = DEFAULT_LOCALE;
5493 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
5494 *label = (char *)ptr->text;
5503 API int pkgmgrinfo_appinfo_get_component(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_component *component)
5505 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5506 retvm_if(component == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5507 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5509 if (info->app_component == PMINFO_UI_APP)
5510 *component = PMINFO_UI_APP;
5511 else if (info->app_component == PMINFO_SVC_APP)
5512 *component = PMINFO_SVC_APP;
5514 return PMINFO_R_ERROR;
5519 API int pkgmgrinfo_appinfo_get_apptype(pkgmgrinfo_appinfo_h handle, char **app_type)
5521 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5522 retvm_if(app_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5523 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5525 if (info->app_component == PMINFO_UI_APP)
5526 *app_type = (char *)info->uiapp_info->type;
5527 if (info->app_component == PMINFO_SVC_APP)
5528 *app_type = (char *)info->svcapp_info->type;
5533 API int pkgmgrinfo_appinfo_get_operation(pkgmgrinfo_appcontrol_h handle,
5534 int *operation_count, char ***operation)
5536 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5537 retvm_if(operation == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5538 retvm_if(operation_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5539 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5540 *operation_count = data->operation_count;
5541 *operation = data->operation;
5545 API int pkgmgrinfo_appinfo_get_uri(pkgmgrinfo_appcontrol_h handle,
5546 int *uri_count, char ***uri)
5548 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5549 retvm_if(uri == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5550 retvm_if(uri_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5551 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5552 *uri_count = data->uri_count;
5557 API int pkgmgrinfo_appinfo_get_mime(pkgmgrinfo_appcontrol_h handle,
5558 int *mime_count, char ***mime)
5560 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5561 retvm_if(mime == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5562 retvm_if(mime_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5563 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5564 *mime_count = data->mime_count;
5569 API int pkgmgrinfo_appinfo_get_subapp(pkgmgrinfo_appcontrol_h handle,
5570 int *subapp_count, char ***subapp)
5572 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5573 retvm_if(subapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5574 retvm_if(subapp_count == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5575 pkgmgrinfo_appcontrol_x *data = (pkgmgrinfo_appcontrol_x *)handle;
5576 *subapp_count = data->subapp_count;
5577 *subapp = data->subapp;
5581 API int pkgmgrinfo_appinfo_get_setting_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5583 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5584 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5588 icon_x *start = NULL;
5589 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5591 start = info->uiapp_info->icon;
5593 for(ptr = start; ptr != NULL; ptr = ptr->next)
5596 val = (char *)ptr->section;
5597 if (strcmp(val, "setting") == 0){
5598 *icon = (char *)ptr->text;
5607 API int pkgmgrinfo_appinfo_get_notification_icon(pkgmgrinfo_appinfo_h handle, char **icon)
5609 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5610 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5614 icon_x *start = NULL;
5615 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5617 start = info->uiapp_info->icon;
5619 for(ptr = start; ptr != NULL; ptr = ptr->next)
5622 val = (char *)ptr->section;
5624 if (strcmp(val, "notification") == 0){
5625 *icon = (char *)ptr->text;
5634 API int pkgmgrinfo_appinfo_get_recent_image_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_recentimage *type)
5636 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5637 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5639 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5640 val = (char *)info->uiapp_info->recentimage;
5642 if (strcasecmp(val, "capture") == 0)
5643 *type = PMINFO_RECENTIMAGE_USE_CAPTURE;
5644 else if (strcasecmp(val, "icon") == 0)
5645 *type = PMINFO_RECENTIMAGE_USE_ICON;
5647 *type = PMINFO_RECENTIMAGE_USE_NOTHING;
5653 API int pkgmgrinfo_appinfo_get_preview_image(pkgmgrinfo_appinfo_h handle, char **preview_img)
5655 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5656 retvm_if(preview_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5659 image_x *ptr = NULL;
5660 image_x *start = NULL;
5661 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5663 start = info->uiapp_info->image;
5665 for(ptr = start; ptr != NULL; ptr = ptr->next)
5668 val = (char *)ptr->section;
5670 if (strcmp(val, "preview") == 0)
5671 *preview_img = (char *)ptr->text;
5679 API int pkgmgrinfo_appinfo_get_permission_type(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_permission_type *permission)
5681 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
5682 retvm_if(permission == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
5685 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5687 if (info->app_component == PMINFO_UI_APP)
5688 val = info->uiapp_info->permission_type;
5689 else if (info->app_component == PMINFO_SVC_APP)
5690 val = info->svcapp_info->permission_type;
5692 return PMINFO_R_ERROR;
5694 if (strcmp(val, "signature") == 0)
5695 *permission = PMINFO_PERMISSION_SIGNATURE;
5696 else if (strcmp(val, "privilege") == 0)
5697 *permission = PMINFO_PERMISSION_PRIVILEGE;
5699 *permission = PMINFO_PERMISSION_NORMAL;
5704 API int pkgmgrinfo_appinfo_get_component_type(pkgmgrinfo_appinfo_h handle, char **component_type)
5706 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5707 retvm_if(component_type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5708 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5710 *component_type = (char *)info->uiapp_info->component_type;
5715 API int pkgmgrinfo_appinfo_get_hwacceleration(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_hwacceleration *hwacceleration)
5717 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5718 retvm_if(hwacceleration == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5720 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5721 val = (char *)info->uiapp_info->hwacceleration;
5723 if (strcasecmp(val, "not-use-GL") == 0)
5724 *hwacceleration = PMINFO_HWACCELERATION_NOT_USE_GL;
5725 else if (strcasecmp(val, "use-GL") == 0)
5726 *hwacceleration = PMINFO_HWACCELERATION_USE_GL;
5728 *hwacceleration = PMINFO_HWACCELERATION_USE_SYSTEM_SETTING;
5733 API int pkgmgrinfo_appinfo_get_screenreader(pkgmgrinfo_appinfo_h handle, pkgmgrinfo_app_screenreader *screenreader)
5735 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5736 retvm_if(screenreader == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5738 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5739 val = (char *)info->uiapp_info->screenreader;
5741 if (strcasecmp(val, "screenreader-off") == 0)
5742 *screenreader = PMINFO_SCREENREADER_OFF;
5743 else if (strcasecmp(val, "screenreader-on") == 0)
5744 *screenreader = PMINFO_SCREENREADER_ON;
5746 *screenreader = PMINFO_SCREENREADER_USE_SYSTEM_SETTING;
5751 API int pkgmgrinfo_appinfo_get_effectimage(pkgmgrinfo_appinfo_h handle, char **portrait_img, char **landscape_img)
5753 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5754 retvm_if(portrait_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5755 retvm_if(landscape_img == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5756 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5758 if (info->app_component == PMINFO_UI_APP){
5759 *portrait_img = (char *)info->uiapp_info->portraitimg;
5760 *landscape_img = (char *)info->uiapp_info->landscapeimg;
5766 API int pkgmgrinfo_appinfo_get_submode_mainid(pkgmgrinfo_appinfo_h handle, char **submode_mainid)
5768 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5769 retvm_if(submode_mainid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
5770 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5772 *submode_mainid = (char *)info->uiapp_info->submode_mainid;
5777 API int pkgmgrinfo_appinfo_foreach_permission(pkgmgrinfo_appinfo_h handle,
5778 pkgmgrinfo_app_permission_list_cb permission_func, void *user_data)
5780 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5781 retvm_if(permission_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5783 permission_x *ptr = NULL;
5784 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5785 if (info->app_component == PMINFO_UI_APP)
5786 ptr = info->uiapp_info->permission;
5787 else if (info->app_component == PMINFO_SVC_APP)
5788 ptr = info->svcapp_info->permission;
5790 return PMINFO_R_EINVAL;
5791 for (; ptr; ptr = ptr->next) {
5793 ret = permission_func(ptr->value, user_data);
5801 API int pkgmgrinfo_appinfo_foreach_category(pkgmgrinfo_appinfo_h handle,
5802 pkgmgrinfo_app_category_list_cb category_func, void *user_data)
5804 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5805 retvm_if(category_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5807 category_x *ptr = NULL;
5808 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5809 if (info->app_component == PMINFO_UI_APP)
5810 ptr = info->uiapp_info->category;
5811 else if (info->app_component == PMINFO_SVC_APP)
5812 ptr = info->svcapp_info->category;
5814 return PMINFO_R_EINVAL;
5815 for (; ptr; ptr = ptr->next) {
5817 ret = category_func(ptr->name, user_data);
5825 API int pkgmgrinfo_appinfo_foreach_metadata(pkgmgrinfo_appinfo_h handle,
5826 pkgmgrinfo_app_metadata_list_cb metadata_func, void *user_data)
5828 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5829 retvm_if(metadata_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5831 metadata_x *ptr = NULL;
5832 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
5833 if (info->app_component == PMINFO_UI_APP)
5834 ptr = info->uiapp_info->metadata;
5835 else if (info->app_component == PMINFO_SVC_APP)
5836 ptr = info->svcapp_info->metadata;
5838 return PMINFO_R_EINVAL;
5839 for (; ptr; ptr = ptr->next) {
5841 ret = metadata_func(ptr->key, ptr->value, user_data);
5849 API int pkgmgrinfo_usr_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
5850 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data, uid_t uid)
5852 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
5853 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
5861 char *manifest = NULL;
5862 char **operation = NULL;
5865 char **subapp = NULL;
5866 appcontrol_x *appcontrol = NULL;
5867 manifest_x *mfx = NULL;
5868 operation_x *op = NULL;
5871 subapp_x *sa = NULL;
5872 pkgmgrinfo_app_component component;
5873 pkgmgrinfo_appcontrol_x *ptr = NULL;
5874 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
5876 _LOGE("Failed to get package name\n");
5877 return PMINFO_R_ERROR;
5879 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
5881 _LOGE("Failed to get app component name\n");
5882 return PMINFO_R_ERROR;
5884 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
5885 if (manifest == NULL) {
5886 _LOGE("Failed to fetch package manifest file\n");
5887 return PMINFO_R_ERROR;
5889 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
5891 _LOGE("Failed to parse package manifest file\n");
5894 return PMINFO_R_ERROR;
5897 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
5899 _LOGE("Out of Memory!!!\n");
5900 pkgmgr_parser_free_manifest_xml(mfx);
5901 return PMINFO_R_ERROR;
5903 /*Get Operation, Uri, Mime*/
5904 switch (component) {
5906 if (mfx->uiapplication) {
5907 if (mfx->uiapplication->appsvc) {
5908 appcontrol = mfx->uiapplication->appsvc;
5912 case PMINFO_SVC_APP:
5913 if (mfx->serviceapplication) {
5914 if (mfx->serviceapplication->appsvc) {
5915 appcontrol = mfx->serviceapplication->appsvc;
5922 for (; appcontrol; appcontrol = appcontrol->next) {
5923 op = appcontrol->operation;
5924 for (; op; op = op->next)
5926 op = appcontrol->operation;
5928 ui = appcontrol->uri;
5929 for (; ui; ui = ui->next)
5931 ui = appcontrol->uri;
5933 mi = appcontrol->mime;
5934 for (; mi; mi = mi->next)
5936 mi = appcontrol->mime;
5938 sa = appcontrol->subapp;
5939 for (; sa; sa = sa->next)
5941 sa = appcontrol->subapp;
5943 operation = (char **)calloc(oc, sizeof(char *));
5944 for (i = 0; i < oc; i++) {
5945 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
5949 uri = (char **)calloc(uc, sizeof(char *));
5950 for (i = 0; i < uc; i++) {
5951 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
5955 mime = (char **)calloc(mc, sizeof(char *));
5956 for (i = 0; i < mc; i++) {
5957 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
5961 subapp = (char **)calloc(sc, sizeof(char *));
5962 for (i = 0; i < sc; i++) {
5963 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
5967 /*populate appcontrol handle*/
5968 ptr->operation_count = oc;
5969 ptr->uri_count = uc;
5970 ptr->mime_count = mc;
5971 ptr->subapp_count = sc;
5972 ptr->operation = operation;
5975 ptr->subapp = subapp;
5977 ret = appcontrol_func((void *)ptr, user_data);
5978 for (i = 0; i < oc; i++) {
5981 operation[i] = NULL;
5988 for (i = 0; i < uc; i++) {
5998 for (i = 0; i < mc; i++) {
6008 for (i = 0; i < sc; i++) {
6025 pkgmgr_parser_free_manifest_xml(mfx);
6033 API int pkgmgrinfo_appinfo_foreach_appcontrol(pkgmgrinfo_appinfo_h handle,
6034 pkgmgrinfo_app_control_list_cb appcontrol_func, void *user_data)
6036 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6037 retvm_if(appcontrol_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
6045 char *manifest = NULL;
6046 char **operation = NULL;
6049 char **subapp = NULL;
6050 appcontrol_x *appcontrol = NULL;
6051 manifest_x *mfx = NULL;
6052 operation_x *op = NULL;
6055 subapp_x *sa = NULL;
6056 pkgmgrinfo_app_component component;
6057 pkgmgrinfo_appcontrol_x *ptr = NULL;
6058 ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
6060 _LOGE("Failed to get package name\n");
6061 return PMINFO_R_ERROR;
6063 ret = pkgmgrinfo_appinfo_get_component(handle, &component);
6065 _LOGE("Failed to get app component name\n");
6066 return PMINFO_R_ERROR;
6068 manifest = pkgmgr_parser_get_manifest_file(pkgid);
6069 if (manifest == NULL) {
6070 _LOGE("Failed to fetch package manifest file\n");
6071 return PMINFO_R_ERROR;
6073 mfx = pkgmgr_parser_process_manifest_xml(manifest);
6075 _LOGE("Failed to parse package manifest file\n");
6078 return PMINFO_R_ERROR;
6081 ptr = calloc(1, sizeof(pkgmgrinfo_appcontrol_x));
6083 _LOGE("Out of Memory!!!\n");
6084 pkgmgr_parser_free_manifest_xml(mfx);
6085 return PMINFO_R_ERROR;
6087 /*Get Operation, Uri, Mime*/
6088 switch (component) {
6090 if (mfx->uiapplication) {
6091 if (mfx->uiapplication->appsvc) {
6092 appcontrol = mfx->uiapplication->appsvc;
6096 case PMINFO_SVC_APP:
6097 if (mfx->serviceapplication) {
6098 if (mfx->serviceapplication->appsvc) {
6099 appcontrol = mfx->serviceapplication->appsvc;
6106 for (; appcontrol; appcontrol = appcontrol->next) {
6107 op = appcontrol->operation;
6108 for (; op; op = op->next)
6110 op = appcontrol->operation;
6112 ui = appcontrol->uri;
6113 for (; ui; ui = ui->next)
6115 ui = appcontrol->uri;
6117 mi = appcontrol->mime;
6118 for (; mi; mi = mi->next)
6120 mi = appcontrol->mime;
6122 sa = appcontrol->subapp;
6123 for (; sa; sa = sa->next)
6125 sa = appcontrol->subapp;
6127 operation = (char **)calloc(oc, sizeof(char *));
6128 for (i = 0; i < oc; i++) {
6129 operation[i] = strndup(op->name, PKG_STRING_LEN_MAX - 1);
6133 uri = (char **)calloc(uc, sizeof(char *));
6134 for (i = 0; i < uc; i++) {
6135 uri[i] = strndup(ui->name, PKG_STRING_LEN_MAX - 1);
6139 mime = (char **)calloc(mc, sizeof(char *));
6140 for (i = 0; i < mc; i++) {
6141 mime[i] = strndup(mi->name, PKG_STRING_LEN_MAX - 1);
6145 subapp = (char **)calloc(sc, sizeof(char *));
6146 for (i = 0; i < sc; i++) {
6147 subapp[i] = strndup(sa->name, PKG_STRING_LEN_MAX - 1);
6151 /*populate appcontrol handle*/
6152 ptr->operation_count = oc;
6153 ptr->uri_count = uc;
6154 ptr->mime_count = mc;
6155 ptr->subapp_count = sc;
6156 ptr->operation = operation;
6159 ptr->subapp = subapp;
6161 ret = appcontrol_func((void *)ptr, user_data);
6162 for (i = 0; i < oc; i++) {
6165 operation[i] = NULL;
6172 for (i = 0; i < uc; i++) {
6182 for (i = 0; i < mc; i++) {
6192 for (i = 0; i < sc; i++) {
6209 pkgmgr_parser_free_manifest_xml(mfx);
6217 API int pkgmgrinfo_appinfo_is_nodisplay(pkgmgrinfo_appinfo_h handle, bool *nodisplay)
6219 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6220 retvm_if(nodisplay == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6222 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6223 val = (char *)info->uiapp_info->nodisplay;
6225 if (strcasecmp(val, "true") == 0)
6227 else if (strcasecmp(val, "false") == 0)
6235 API int pkgmgrinfo_appinfo_is_multiple(pkgmgrinfo_appinfo_h handle, bool *multiple)
6237 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6238 retvm_if(multiple == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6240 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6241 val = (char *)info->uiapp_info->multiple;
6243 if (strcasecmp(val, "true") == 0)
6245 else if (strcasecmp(val, "false") == 0)
6253 API int pkgmgrinfo_appinfo_is_indicator_display_allowed(pkgmgrinfo_appinfo_h handle, bool *indicator_disp)
6255 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6256 retvm_if(indicator_disp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6258 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6259 val = (char *)info->uiapp_info->indicatordisplay;
6261 if (strcasecmp(val, "true") == 0){
6262 *indicator_disp = 1;
6263 }else if (strcasecmp(val, "false") == 0){
6264 *indicator_disp = 0;
6266 *indicator_disp = 0;
6272 API int pkgmgrinfo_appinfo_is_taskmanage(pkgmgrinfo_appinfo_h handle, bool *taskmanage)
6274 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6275 retvm_if(taskmanage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6277 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6278 val = (char *)info->uiapp_info->taskmanage;
6280 if (strcasecmp(val, "true") == 0)
6282 else if (strcasecmp(val, "false") == 0)
6290 API int pkgmgrinfo_appinfo_is_enabled(pkgmgrinfo_appinfo_h handle, bool *enabled)
6292 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6293 retvm_if(enabled == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6295 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6296 if (info->app_component == PMINFO_UI_APP)
6297 val = (char *)info->uiapp_info->enabled;
6298 else if (info->app_component == PMINFO_SVC_APP)
6299 val = (char *)info->uiapp_info->enabled;
6301 _LOGE("invalid component type\n");
6302 return PMINFO_R_EINVAL;
6306 if (strcasecmp(val, "true") == 0)
6308 else if (strcasecmp(val, "false") == 0)
6317 API int pkgmgrinfo_appinfo_is_onboot(pkgmgrinfo_appinfo_h handle, bool *onboot)
6319 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6320 retvm_if(onboot == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6322 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6323 val = (char *)info->svcapp_info->onboot;
6325 if (strcasecmp(val, "true") == 0)
6327 else if (strcasecmp(val, "false") == 0)
6335 API int pkgmgrinfo_appinfo_is_autorestart(pkgmgrinfo_appinfo_h handle, bool *autorestart)
6337 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6338 retvm_if(autorestart == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6340 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6341 val = (char *)info->svcapp_info->autorestart;
6343 if (strcasecmp(val, "true") == 0)
6345 else if (strcasecmp(val, "false") == 0)
6353 API int pkgmgrinfo_appinfo_is_mainapp(pkgmgrinfo_appinfo_h handle, bool *mainapp)
6355 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6356 retvm_if(mainapp == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
6358 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6359 val = (char *)info->uiapp_info->mainapp;
6361 if (strcasecmp(val, "true") == 0)
6363 else if (strcasecmp(val, "false") == 0)
6371 API int pkgmgrinfo_appinfo_is_preload(pkgmgrinfo_appinfo_h handle, bool *preload)
6373 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6374 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6376 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6377 val = (char *)info->uiapp_info->preload;
6379 if (strcasecmp(val, "true") == 0)
6381 else if (strcasecmp(val, "false") == 0)
6389 API int pkgmgrinfo_appinfo_is_submode(pkgmgrinfo_appinfo_h handle, bool *submode)
6391 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
6392 retvm_if(submode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
6394 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6395 val = (char *)info->uiapp_info->submode;
6397 if (strcasecmp(val, "true") == 0)
6399 else if (strcasecmp(val, "false") == 0)
6407 API int pkgmgrinfo_appinfo_destroy_appinfo(pkgmgrinfo_appinfo_h handle)
6409 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL");
6410 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
6411 __cleanup_appinfo(info);
6415 API int pkgmgrinfo_appinfo_filter_create(pkgmgrinfo_appinfo_filter_h *handle)
6417 return (pkgmgrinfo_pkginfo_filter_create(handle));
6420 API int pkgmgrinfo_appinfo_filter_destroy(pkgmgrinfo_appinfo_filter_h handle)
6422 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6425 API int pkgmgrinfo_appinfo_filter_add_int(pkgmgrinfo_appinfo_filter_h handle,
6426 const char *property, const int value)
6428 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6429 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6430 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
6432 GSList *link = NULL;
6434 prop = _pminfo_appinfo_convert_to_prop_int(property);
6435 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_INT ||
6436 prop > E_PMINFO_APPINFO_PROP_APP_MAX_INT) {
6437 _LOGE("Invalid Integer Property\n");
6438 return PMINFO_R_EINVAL;
6440 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6441 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6443 _LOGE("Out of Memory!!!\n");
6444 return PMINFO_R_ERROR;
6446 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
6447 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
6449 _LOGE("Out of Memory\n");
6452 return PMINFO_R_ERROR;
6456 /*If API is called multiple times for same property, we should override the previous values.
6457 Last value set will be used for filtering.*/
6458 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6460 filter->list = g_slist_delete_link(filter->list, link);
6461 filter->list = g_slist_append(filter->list, (gpointer)node);
6466 API int pkgmgrinfo_appinfo_filter_add_bool(pkgmgrinfo_appinfo_filter_h handle,
6467 const char *property, const bool value)
6469 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6470 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6472 GSList *link = NULL;
6474 prop = _pminfo_appinfo_convert_to_prop_bool(property);
6475 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_BOOL ||
6476 prop > E_PMINFO_APPINFO_PROP_APP_MAX_BOOL) {
6477 _LOGE("Invalid Boolean Property\n");
6478 return PMINFO_R_EINVAL;
6480 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6481 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6483 _LOGE("Out of Memory!!!\n");
6484 return PMINFO_R_ERROR;
6487 val = strndup("('true','True')", 15);
6489 val = strndup("('false','False')", 17);
6491 _LOGE("Out of Memory\n");
6494 return PMINFO_R_ERROR;
6498 /*If API is called multiple times for same property, we should override the previous values.
6499 Last value set will be used for filtering.*/
6500 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6502 filter->list = g_slist_delete_link(filter->list, link);
6503 filter->list = g_slist_append(filter->list, (gpointer)node);
6508 API int pkgmgrinfo_appinfo_filter_add_string(pkgmgrinfo_appinfo_filter_h handle,
6509 const char *property, const char *value)
6511 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6512 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6513 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6515 pkgmgrinfo_node_x *ptr = NULL;
6516 char prev[PKG_STRING_LEN_MAX] = {'\0'};
6517 char temp[PKG_STRING_LEN_MAX] = {'\0'};
6518 GSList *link = NULL;
6520 prop = _pminfo_appinfo_convert_to_prop_str(property);
6521 if (prop < E_PMINFO_APPINFO_PROP_APP_MIN_STR ||
6522 prop > E_PMINFO_APPINFO_PROP_APP_MAX_STR) {
6523 _LOGE("Invalid String Property\n");
6524 return PMINFO_R_EINVAL;
6526 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6527 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6529 _LOGE("Out of Memory!!!\n");
6530 return PMINFO_R_ERROR;
6534 case E_PMINFO_APPINFO_PROP_APP_COMPONENT:
6535 if (strcmp(value, PMINFO_APPINFO_UI_APP) == 0)
6536 val = strndup("uiapp", PKG_STRING_LEN_MAX - 1);
6538 val = strndup("svcapp", PKG_STRING_LEN_MAX - 1);
6540 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6542 filter->list = g_slist_delete_link(filter->list, link);
6543 filter->list = g_slist_append(filter->list, (gpointer)node);
6545 case E_PMINFO_APPINFO_PROP_APP_CATEGORY:
6546 case E_PMINFO_APPINFO_PROP_APP_OPERATION:
6547 case E_PMINFO_APPINFO_PROP_APP_URI:
6548 case E_PMINFO_APPINFO_PROP_APP_MIME:
6549 val = (char *)calloc(1, PKG_STRING_LEN_MAX);
6551 _LOGE("Out of Memory\n");
6554 return PMINFO_R_ERROR;
6556 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6558 ptr = (pkgmgrinfo_node_x *)link->data;
6559 strncpy(prev, ptr->value, PKG_STRING_LEN_MAX - 1);
6560 _LOGE("Previous value is %s\n", prev);
6561 filter->list = g_slist_delete_link(filter->list, link);
6562 snprintf(temp, PKG_STRING_LEN_MAX - 1, "%s , '%s'", prev, value);
6563 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6564 _LOGE("New value is %s\n", val);
6566 filter->list = g_slist_append(filter->list, (gpointer)node);
6567 memset(temp, '\0', PKG_STRING_LEN_MAX);
6569 snprintf(temp, PKG_STRING_LEN_MAX - 1, "'%s'", value);
6570 strncpy(val, temp, PKG_STRING_LEN_MAX - 1);
6571 _LOGE("First value is %s\n", val);
6573 filter->list = g_slist_append(filter->list, (gpointer)node);
6574 memset(temp, '\0', PKG_STRING_LEN_MAX);
6578 node->value = strndup(value, PKG_STRING_LEN_MAX - 1);
6579 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
6581 filter->list = g_slist_delete_link(filter->list, link);
6582 filter->list = g_slist_append(filter->list, (gpointer)node);
6588 API int pkgmgrinfo_appinfo_usr_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count, uid_t uid)
6590 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6591 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6592 char *syslocale = NULL;
6593 char *locale = NULL;
6594 char *condition = NULL;
6595 char *error_message = NULL;
6596 char query[MAX_QUERY_LEN] = {'\0'};
6597 char where[MAX_QUERY_LEN] = {'\0'};
6601 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6602 /*Get current locale*/
6603 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6604 if (syslocale == NULL) {
6605 _LOGE("current locale is NULL\n");
6606 return PMINFO_R_ERROR;
6608 locale = __convert_system_locale_to_manifest_locale(syslocale);
6609 if (locale == NULL) {
6610 _LOGE("manifest locale is NULL\n");
6612 return PMINFO_R_ERROR;
6615 ret = __open_manifest_db(uid);
6617 _LOGE("Fail to open manifest DB\n");
6620 return PMINFO_R_ERROR;
6623 /*Start constructing query*/
6624 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_COUNT_APP, locale);
6626 /*Get where clause*/
6627 for (list = filter->list; list; list = g_slist_next(list)) {
6628 __get_filter_condition(list->data, &condition);
6630 strncat(where, condition, sizeof(where) - strlen(where) -1);
6631 where[sizeof(where) - 1] = '\0';
6635 if (g_slist_next(list)) {
6636 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6637 where[sizeof(where) - 1] = '\0';
6640 _LOGE("where = %s\n", where);
6641 if (strlen(where) > 0) {
6642 strncat(query, where, sizeof(query) - strlen(query) - 1);
6643 query[sizeof(query) - 1] = '\0';
6645 _LOGE("query = %s\n", query);
6649 sqlite3_exec(manifest_db, query, __count_cb, (void *)count, &error_message)) {
6650 _LOGE("Don't execute query = %s error message = %s\n", query,
6652 sqlite3_free(error_message);
6653 sqlite3_close(manifest_db);
6654 ret = PMINFO_R_ERROR;
6668 sqlite3_close(manifest_db);
6672 API int pkgmgrinfo_appinfo_filter_count(pkgmgrinfo_appinfo_filter_h handle, int *count)
6674 return pkgmgrinfo_appinfo_usr_filter_count(handle, count, GLOBAL_USER);
6677 API int pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6678 pkgmgrinfo_app_list_cb app_cb, void * user_data, uid_t uid)
6680 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6681 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
6682 char *syslocale = NULL;
6683 char *locale = NULL;
6684 char *condition = NULL;
6685 char *error_message = NULL;
6686 char query[MAX_QUERY_LEN] = {'\0'};
6687 char where[MAX_QUERY_LEN] = {'\0'};
6690 uiapplication_x *ptr1 = NULL;
6691 serviceapplication_x *ptr2 = NULL;
6692 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6693 /*Get current locale*/
6694 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6695 if (syslocale == NULL) {
6696 _LOGE("current locale is NULL\n");
6697 return PMINFO_R_ERROR;
6699 locale = __convert_system_locale_to_manifest_locale(syslocale);
6700 if (locale == NULL) {
6701 _LOGE("manifest locale is NULL\n");
6703 return PMINFO_R_ERROR;
6706 ret = __open_manifest_db(uid);
6708 _LOGE("Fail to open manifest DB\n");
6711 return PMINFO_R_ERROR;
6713 /*Start constructing query*/
6714 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_APP, locale);
6715 /*Get where clause*/
6716 for (list = filter->list; list; list = g_slist_next(list)) {
6717 __get_filter_condition(list->data, &condition);
6719 strncat(where, condition, sizeof(where) - strlen(where) -1);
6720 where[sizeof(where) - 1] = '\0';
6724 if (g_slist_next(list)) {
6725 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
6726 where[sizeof(where) - 1] = '\0';
6729 _LOGE("where = %s\n", where);
6730 if (strlen(where) > 0) {
6731 strncat(query, where, sizeof(query) - strlen(query) - 1);
6732 query[sizeof(query) - 1] = '\0';
6734 _LOGE("query = %s\n", query);
6735 /*To get filtered list*/
6736 pkgmgr_pkginfo_x *info = NULL;
6737 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6739 _LOGE("Out of Memory!!!\n");
6740 ret = PMINFO_R_ERROR;
6743 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6744 if (info->manifest_info == NULL) {
6745 _LOGE("Out of Memory!!!\n");
6746 ret = PMINFO_R_ERROR;
6749 /*To get detail app info for each member of filtered list*/
6750 pkgmgr_pkginfo_x *filtinfo = NULL;
6751 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6752 if (filtinfo == NULL) {
6753 _LOGE("Out of Memory!!!\n");
6754 ret = PMINFO_R_ERROR;
6757 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6758 if (filtinfo->manifest_info == NULL) {
6759 _LOGE("Out of Memory!!!\n");
6760 ret = PMINFO_R_ERROR;
6763 pkgmgr_appinfo_x *appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6764 if (appinfo == NULL) {
6765 _LOGE("Out of Memory!!!\n");
6766 ret = PMINFO_R_ERROR;
6770 sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message)) {
6771 _LOGE("Don't execute query = %s error message = %s\n", query,
6773 sqlite3_free(error_message);
6774 sqlite3_close(manifest_db);
6775 ret = PMINFO_R_ERROR;
6778 memset(query, '\0', MAX_QUERY_LEN);
6779 if (info->manifest_info->uiapplication) {
6780 LISTHEAD(info->manifest_info->uiapplication, ptr1);
6781 info->manifest_info->uiapplication = ptr1;
6783 if (info->manifest_info->serviceapplication) {
6784 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
6785 info->manifest_info->serviceapplication = ptr2;
6787 /*Filtered UI Apps*/
6788 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
6790 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6791 ptr1->appid, "uiapp");
6793 sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message)) {
6794 _LOGE("Don't execute query = %s error message = %s\n", query,
6796 sqlite3_free(error_message);
6797 sqlite3_close(manifest_db);
6798 ret = PMINFO_R_ERROR;
6802 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
6804 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
6805 ptr2->appid, "svcapp");
6807 sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message)) {
6808 _LOGE("Don't execute query = %s error message = %s\n", query,
6810 sqlite3_free(error_message);
6811 sqlite3_close(manifest_db);
6812 ret = PMINFO_R_ERROR;
6816 if (filtinfo->manifest_info->uiapplication) {
6817 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
6818 filtinfo->manifest_info->uiapplication = ptr1;
6820 /*If the callback func return < 0 we break and no more call back is called*/
6823 appinfo->locale = strdup(locale);
6824 appinfo->uiapp_info = ptr1;
6825 appinfo->app_component = PMINFO_UI_APP;
6826 ret = app_cb((void *)appinfo, user_data);
6831 /*Filtered Service Apps*/
6832 if (filtinfo->manifest_info->serviceapplication) {
6833 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
6834 filtinfo->manifest_info->serviceapplication = ptr2;
6836 /*If the callback func return < 0 we break and no more call back is called*/
6839 appinfo->locale = strdup(locale);
6840 appinfo->svcapp_info = ptr2;
6841 appinfo->app_component = PMINFO_SVC_APP;
6842 ret = app_cb((void *)appinfo, user_data);
6857 sqlite3_close(manifest_db);
6862 __cleanup_pkginfo(info);
6863 __cleanup_pkginfo(filtinfo);
6867 API int pkgmgrinfo_appinfo_filter_foreach_appinfo(pkgmgrinfo_appinfo_filter_h handle,
6868 pkgmgrinfo_app_list_cb app_cb, void * user_data)
6870 return pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_cb, user_data, GLOBAL_USER);
6873 API int pkgmgrinfo_appinfo_metadata_filter_create(pkgmgrinfo_appinfo_metadata_filter_h *handle)
6875 return (pkgmgrinfo_pkginfo_filter_create(handle));
6878 API int pkgmgrinfo_appinfo_metadata_filter_destroy(pkgmgrinfo_appinfo_metadata_filter_h handle)
6880 return (pkgmgrinfo_pkginfo_filter_destroy(handle));
6883 API int pkgmgrinfo_appinfo_metadata_filter_add(pkgmgrinfo_appinfo_metadata_filter_h handle,
6884 const char *key, const char *value)
6886 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6887 retvm_if(key == NULL, PMINFO_R_EINVAL, "metadata key supplied is NULL\n");
6888 /*value can be NULL. In that case all apps with specified key should be displayed*/
6892 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6893 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
6894 retvm_if(node == NULL, PMINFO_R_ERROR, "Out of Memory!!!\n");
6896 tryvm_if(k == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6900 tryvm_if(v == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6903 /*If API is called multiple times, we should OR all conditions.*/
6904 filter->list = g_slist_append(filter->list, (gpointer)node);
6905 /*All memory will be freed in destroy API*/
6923 API int pkgmgrinfo_appinfo_usr_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
6924 pkgmgrinfo_app_list_cb app_cb, void *user_data, uid_t uid)
6926 retvm_if(handle == NULL, PMINFO_R_EINVAL, "filter handle is NULL\n");
6927 retvm_if(app_cb == NULL, PMINFO_R_EINVAL, "Callback function supplied is NULL\n");
6928 char *syslocale = NULL;
6929 char *locale = NULL;
6930 char *condition = NULL;
6931 char *error_message = NULL;
6932 char query[MAX_QUERY_LEN] = {'\0'};
6933 char where[MAX_QUERY_LEN] = {'\0'};
6936 pkgmgr_pkginfo_x *info = NULL;
6937 pkgmgr_pkginfo_x *filtinfo = NULL;
6938 pkgmgr_appinfo_x *appinfo = NULL;
6939 uiapplication_x *ptr1 = NULL;
6940 serviceapplication_x *ptr2 = NULL;
6941 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
6943 /*Get current locale*/
6944 syslocale = vconf_get_str(VCONFKEY_LANGSET);
6945 retvm_if(syslocale == NULL, PMINFO_R_ERROR, "current locale is NULL\n");
6946 locale = __convert_system_locale_to_manifest_locale(syslocale);
6947 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL\n");
6949 ret = __open_manifest_db(uid);
6951 _LOGE("Fail to open manifest DB\n");
6954 return PMINFO_R_ERROR;
6956 /*Start constructing query*/
6957 memset(where, '\0', MAX_QUERY_LEN);
6958 memset(query, '\0', MAX_QUERY_LEN);
6959 snprintf(query, MAX_QUERY_LEN - 1, METADATA_FILTER_QUERY_SELECT_CLAUSE);
6960 /*Get where clause*/
6961 for (list = filter->list; list; list = g_slist_next(list)) {
6962 __get_metadata_filter_condition(list->data, &condition);
6964 strncat(where, condition, sizeof(where) - strlen(where) -1);
6968 if (g_slist_next(list)) {
6969 strncat(where, METADATA_FILTER_QUERY_UNION_CLAUSE, sizeof(where) - strlen(where) - 1);
6972 _LOGE("where = %s (%d)\n", where, strlen(where));
6973 if (strlen(where) > 0) {
6974 strncat(query, where, sizeof(query) - strlen(query) - 1);
6976 _LOGE("query = %s (%d)\n", query, strlen(query));
6977 /*To get filtered list*/
6978 info = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6979 tryvm_if(info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6981 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6982 tryvm_if(info->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6984 /*To get detail app info for each member of filtered list*/
6985 filtinfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
6986 tryvm_if(filtinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6988 filtinfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
6989 tryvm_if(filtinfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6991 appinfo = (pkgmgr_appinfo_x *)calloc(1, sizeof(pkgmgr_appinfo_x));
6992 tryvm_if(appinfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
6994 ret = sqlite3_exec(manifest_db, query, __app_list_cb, (void *)info, &error_message);
6995 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
6996 memset(query, '\0', MAX_QUERY_LEN);
6998 if (info->manifest_info->uiapplication) {
6999 LISTHEAD(info->manifest_info->uiapplication, ptr1);
7000 info->manifest_info->uiapplication = ptr1;
7002 if (info->manifest_info->serviceapplication) {
7003 LISTHEAD(info->manifest_info->serviceapplication, ptr2);
7004 info->manifest_info->serviceapplication = ptr2;
7008 for(ptr1 = info->manifest_info->uiapplication; ptr1; ptr1 = ptr1->next)
7010 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7011 ptr1->appid, "uiapp");
7012 ret = sqlite3_exec(manifest_db, query, __uiapp_list_cb, (void *)filtinfo, &error_message);
7013 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7014 memset(query, '\0', MAX_QUERY_LEN);
7017 for(ptr2 = info->manifest_info->serviceapplication; ptr2; ptr2 = ptr2->next)
7019 snprintf(query, MAX_QUERY_LEN, "select * from package_app_info where app_id='%s' and app_component='%s'",
7020 ptr2->appid, "svcapp");
7021 ret = sqlite3_exec(manifest_db, query, __svcapp_list_cb, (void *)filtinfo, &error_message);
7022 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s error message = %s\n", query, error_message);
7023 memset(query, '\0', MAX_QUERY_LEN);
7025 /*Filtered UI Apps*/
7026 if (filtinfo->manifest_info->uiapplication) {
7027 LISTHEAD(filtinfo->manifest_info->uiapplication, ptr1);
7028 filtinfo->manifest_info->uiapplication = ptr1;
7030 /*If the callback func return < 0 we break and no more call back is called*/
7033 appinfo->locale = strdup(locale);
7034 appinfo->uiapp_info = ptr1;
7035 appinfo->app_component = PMINFO_UI_APP;
7036 ret = app_cb((void *)appinfo, user_data);
7041 /*Filtered Service Apps*/
7042 if (filtinfo->manifest_info->serviceapplication) {
7043 LISTHEAD(filtinfo->manifest_info->serviceapplication, ptr2);
7044 filtinfo->manifest_info->serviceapplication = ptr2;
7046 /*If the callback func return < 0 we break and no more call back is called*/
7049 appinfo->locale = strdup(locale);
7050 appinfo->svcapp_info = ptr2;
7051 appinfo->app_component = PMINFO_SVC_APP;
7052 ret = app_cb((void *)appinfo, user_data);
7067 sqlite3_free(error_message);
7068 sqlite3_close(manifest_db);
7073 __cleanup_pkginfo(info);
7074 __cleanup_pkginfo(filtinfo);
7078 API int pkgmgrinfo_appinfo_metadata_filter_foreach(pkgmgrinfo_appinfo_metadata_filter_h handle,
7079 pkgmgrinfo_app_list_cb app_cb, void *user_data)
7081 return pkgmgrinfo_appinfo_usr_metadata_filter_foreach(handle, app_cb, user_data, GLOBAL_USER);
7084 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle)
7086 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7087 pkgmgr_certinfo_x *certinfo = NULL;
7088 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
7090 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7091 *handle = (void *)certinfo;
7095 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid, pkgmgrinfo_certinfo_h handle)
7097 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7098 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7099 pkgmgr_certinfo_x *certinfo = NULL;
7100 char *error_message = NULL;
7101 int ret = PMINFO_R_OK;
7102 char query[MAX_QUERY_LEN] = {'\0'};
7107 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7108 SQLITE_OPEN_READWRITE, NULL);
7109 if (ret != SQLITE_OK) {
7110 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7111 return PMINFO_R_ERROR;
7113 _check_create_Cert_db(cert_db);
7115 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7117 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7118 _LOGE("Don't execute query = %s error message = %s\n", query,
7120 sqlite3_free(error_message);
7121 ret = PMINFO_R_ERROR;
7125 _LOGE("Package not found in DB\n");
7126 ret = PMINFO_R_ERROR;
7129 certinfo = (pkgmgr_certinfo_x *)handle;
7130 /*populate certinfo from DB*/
7131 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_info where package='%s' ", pkgid);
7132 ret = __exec_certinfo_query(query, (void *)certinfo);
7134 _LOGE("Package Cert Info DB Information retrieval failed\n");
7135 ret = PMINFO_R_ERROR;
7138 for (i = 0; i < MAX_CERT_TYPE; i++) {
7139 memset(query, '\0', MAX_QUERY_LEN);
7140 snprintf(query, MAX_QUERY_LEN, "select cert_info from package_cert_index_info where cert_id=%d ", (certinfo->cert_id)[i]);
7141 ret = __exec_certinfo_query(query, (void *)certinfo);
7143 _LOGE("Cert Info DB Information retrieval failed\n");
7144 ret = PMINFO_R_ERROR;
7147 if (certinfo->cert_value) {
7148 (certinfo->cert_info)[i] = strdup(certinfo->cert_value);
7149 free(certinfo->cert_value);
7150 certinfo->cert_value = NULL;
7154 sqlite3_close(cert_db);
7158 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle, pkgmgrinfo_cert_type cert_type, const char **cert_value)
7160 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7161 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7162 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7163 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7164 pkgmgr_certinfo_x *certinfo = NULL;
7165 certinfo = (pkgmgr_certinfo_x *)handle;
7166 if ((certinfo->cert_info)[cert_type])
7167 *cert_value = (certinfo->cert_info)[cert_type];
7173 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle)
7175 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7177 pkgmgr_certinfo_x *certinfo = NULL;
7178 certinfo = (pkgmgr_certinfo_x *)handle;
7179 if (certinfo->pkgid) {
7180 free(certinfo->pkgid);
7181 certinfo->pkgid = NULL;
7183 for (i = 0; i < MAX_CERT_TYPE; i++) {
7184 if ((certinfo->cert_info)[i]) {
7185 free((certinfo->cert_info)[i]);
7186 (certinfo->cert_info)[i] = NULL;
7194 API int pkgmgrinfo_create_certinfo_set_handle(pkgmgrinfo_instcertinfo_h *handle)
7196 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7197 pkgmgr_instcertinfo_x *certinfo = NULL;
7199 certinfo = calloc(1, sizeof(pkgmgr_instcertinfo_x));
7200 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
7201 *handle = (void *)certinfo;
7205 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle, pkgmgrinfo_instcert_type cert_type, char *cert_value)
7207 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7208 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7209 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7210 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL, "Invalid certificate type\n");
7211 pkgmgr_instcertinfo_x *certinfo = NULL;
7212 certinfo = (pkgmgr_instcertinfo_x *)handle;
7213 (certinfo->cert_info)[cert_type] = strdup(cert_value);
7217 API int pkgmgrinfo_save_certinfo(const char *pkgid, pkgmgrinfo_instcertinfo_h handle)
7219 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "package ID is NULL\n");
7220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Certinfo handle is NULL\n");
7221 char *error_message = NULL;
7222 char query[MAX_QUERY_LEN] = {'\0'};
7223 char *vquery = NULL;
7228 int unique_id[MAX_CERT_TYPE] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
7235 pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
7236 pkgmgr_certindexinfo_x *indexinfo = NULL;
7237 indexinfo = calloc(1, sizeof(pkgmgr_certindexinfo_x));
7238 if (indexinfo == NULL) {
7239 _LOGE("Out of Memory!!!");
7240 return PMINFO_R_ERROR;
7242 info->pkgid = strdup(pkgid);
7245 ret = db_util_open_with_options(getUserPkgCertDBPath(), &cert_db,
7246 SQLITE_OPEN_READWRITE, NULL);
7247 if (ret != SQLITE_OK) {
7248 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPath());
7249 ret = PMINFO_R_ERROR;
7252 _check_create_Cert_db(cert_db);
7253 /*Begin Transaction*/
7254 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7255 if (ret != SQLITE_OK) {
7256 _LOGE("Failed to begin transaction\n");
7257 ret = PMINFO_R_ERROR;
7260 _LOGE("Transaction Begin\n");
7261 /*Check if request is to insert/update*/
7262 snprintf(query, MAX_QUERY_LEN, "select exists(select * from package_cert_info where package='%s')", pkgid);
7264 sqlite3_exec(cert_db, query, __validate_cb, (void *)&exist, &error_message)) {
7265 _LOGE("Don't execute query = %s error message = %s\n", query,
7267 sqlite3_free(error_message);
7268 ret = PMINFO_R_ERROR;
7273 We cant just issue update query directly. We need to manage index table also.
7274 Hence it is better to delete and insert again in case of update*/
7275 ret = __delete_certinfo(pkgid);
7277 _LOGE("Certificate Deletion Failed\n");
7279 for (i = 0; i < MAX_CERT_TYPE; i++) {
7280 if ((info->cert_info)[i]) {
7281 for (j = 0; j < i; j++) {
7282 if ( (info->cert_info)[j]) {
7283 if (strcmp((info->cert_info)[i], (info->cert_info)[j]) == 0) {
7284 (info->cert_id)[i] = (info->cert_id)[j];
7285 (info->is_new)[i] = 0;
7286 (info->ref_count)[i] = (info->ref_count)[j];
7293 memset(query, '\0', MAX_QUERY_LEN);
7294 snprintf(query, MAX_QUERY_LEN, "select * from package_cert_index_info " \
7295 "where cert_info='%s'",(info->cert_info)[i]);
7296 ret = __exec_certindexinfo_query(query, (void *)indexinfo);
7298 _LOGE("Cert Info DB Information retrieval failed\n");
7299 ret = PMINFO_R_ERROR;
7302 if (indexinfo->cert_id == 0) {
7303 /*New certificate. Get newid*/
7304 memset(query, '\0', MAX_QUERY_LEN);
7305 snprintf(query, MAX_QUERY_LEN, "select MAX(cert_id) from package_cert_index_info ");
7307 sqlite3_exec(cert_db, query, __maxid_cb, (void *)&newid, &error_message)) {
7308 _LOGE("Don't execute query = %s error message = %s\n", query,
7310 sqlite3_free(error_message);
7311 ret = PMINFO_R_ERROR;
7319 indexinfo->cert_id = maxid;
7320 indexinfo->cert_ref_count = 1;
7324 (info->cert_id)[i] = indexinfo->cert_id;
7325 (info->is_new)[i] = is_new;
7326 (info->ref_count)[i] = indexinfo->cert_ref_count;
7327 _LOGE("Id:Count = %d %d\n", indexinfo->cert_id, indexinfo->cert_ref_count);
7328 indexinfo->cert_id = 0;
7329 indexinfo->cert_ref_count = 0;
7333 len = MAX_QUERY_LEN;
7334 for (i = 0; i < MAX_CERT_TYPE; i++) {
7335 if ((info->cert_info)[i])
7336 len+= strlen((info->cert_info)[i]);
7338 vquery = (char *)calloc(1, len);
7340 snprintf(vquery, len,
7341 "insert into package_cert_info(package, author_root_cert, author_im_cert, author_signer_cert, dist_root_cert, " \
7342 "dist_im_cert, dist_signer_cert, dist2_root_cert, dist2_im_cert, dist2_signer_cert) " \
7343 "values('%s', %d, %d, %d, %d, %d, %d, %d, %d, %d)",\
7344 info->pkgid,(info->cert_id)[PMINFO_SET_AUTHOR_ROOT_CERT],(info->cert_id)[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT],
7345 (info->cert_id)[PMINFO_SET_AUTHOR_SIGNER_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_ROOT_CERT],
7346 (info->cert_id)[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT], (info->cert_id)[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT],
7347 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT],(info->cert_id)[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT],
7348 (info->cert_id)[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT]);
7350 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7351 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7353 sqlite3_free(error_message);
7354 ret = PMINFO_R_ERROR;
7357 /*Update index table info*/
7358 /*If cert_id exists and is repeated for current package, ref count should only be increased once*/
7359 for (i = 0; i < MAX_CERT_TYPE; i++) {
7360 if ((info->cert_info)[i]) {
7361 memset(vquery, '\0', len);
7362 if ((info->is_new)[i]) {
7363 snprintf(vquery, len, "insert into package_cert_index_info(cert_info, cert_id, cert_ref_count) " \
7364 "values('%s', '%d', '%d') ", (info->cert_info)[i], (info->cert_id)[i], 1);
7365 unique_id[c++] = (info->cert_id)[i];
7368 for (j = 0; j < MAX_CERT_TYPE; j++) {
7369 if ((info->cert_id)[i] == unique_id[j]) {
7370 /*Ref count has already been increased. Just continue*/
7374 if (j == MAX_CERT_TYPE)
7375 unique_id[c++] = (info->cert_id)[i];
7378 snprintf(vquery, len, "update package_cert_index_info set cert_ref_count=%d " \
7379 "where cert_id=%d", (info->ref_count)[i] + 1, (info->cert_id)[i]);
7382 sqlite3_exec(cert_db, vquery, NULL, NULL, &error_message)) {
7383 _LOGE("Don't execute query = %s error message = %s\n", vquery,
7385 sqlite3_free(error_message);
7386 ret = PMINFO_R_ERROR;
7391 /*Commit transaction*/
7392 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7393 if (ret != SQLITE_OK) {
7394 _LOGE("Failed to commit transaction, Rollback now\n");
7395 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7396 ret = PMINFO_R_ERROR;
7399 _LOGE("Transaction Commit and End\n");
7402 sqlite3_close(cert_db);
7414 API int pkgmgrinfo_destroy_certinfo_set_handle(pkgmgrinfo_instcertinfo_h handle)
7416 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7418 pkgmgr_instcertinfo_x *certinfo = NULL;
7419 certinfo = (pkgmgr_instcertinfo_x *)handle;
7420 if (certinfo->pkgid) {
7421 free(certinfo->pkgid);
7422 certinfo->pkgid = NULL;
7424 for (i = 0; i < MAX_CERT_TYPE; i++) {
7425 if ((certinfo->cert_info)[i]) {
7426 free((certinfo->cert_info)[i]);
7427 (certinfo->cert_info)[i] = NULL;
7435 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid)
7437 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7440 ret = db_util_open_with_options(getUserPkgCertDBPathUID(uid), &cert_db,
7441 SQLITE_OPEN_READWRITE, NULL);
7442 if (ret != SQLITE_OK) {
7443 _LOGE("connect db [%s] failed!\n", getUserPkgCertDBPathUID(uid));
7444 ret = PMINFO_R_ERROR;
7447 _check_create_Cert_db(cert_db);
7448 /*Begin Transaction*/
7449 ret = sqlite3_exec(cert_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7450 if (ret != SQLITE_OK) {
7451 _LOGE("Failed to begin transaction\n");
7452 ret = PMINFO_R_ERROR;
7455 _LOGE("Transaction Begin\n");
7456 ret = __delete_certinfo(pkgid);
7458 _LOGE("Certificate Deletion Failed\n");
7460 _LOGE("Certificate Deletion Success\n");
7462 /*Commit transaction*/
7463 ret = sqlite3_exec(cert_db, "COMMIT", NULL, NULL, NULL);
7464 if (ret != SQLITE_OK) {
7465 _LOGE("Failed to commit transaction, Rollback now\n");
7466 sqlite3_exec(cert_db, "ROLLBACK", NULL, NULL, NULL);
7467 ret = PMINFO_R_ERROR;
7470 _LOGE("Transaction Commit and End\n");
7473 sqlite3_close(cert_db);
7478 API int pkgmgrinfo_delete_certinfo(const char *pkgid)
7480 return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
7483 API int pkgmgrinfo_create_pkgusrdbinfo(const char *pkgid, uid_t uid, pkgmgrinfo_pkgdbinfo_h *handle)
7485 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7486 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7488 char *manifest = NULL;
7489 manifest_x *mfx = NULL;
7491 manifest = pkgmgr_parser_get_usr_manifest_file(pkgid, uid);
7492 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7494 mfx = pkgmgr_parser_usr_process_manifest_xml(manifest, uid);
7499 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7501 *handle = (void *)mfx;
7506 API int pkgmgrinfo_create_pkgdbinfo(const char *pkgid, pkgmgrinfo_pkgdbinfo_h *handle)
7508 retvm_if(!pkgid, PMINFO_R_EINVAL, "pkgid is NULL");
7509 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7511 char *manifest = NULL;
7512 manifest_x *mfx = NULL;
7514 manifest = pkgmgr_parser_get_manifest_file(pkgid);
7515 retvm_if(manifest == NULL, PMINFO_R_EINVAL, "pkg[%s] dont have manifest file", pkgid);
7517 mfx = pkgmgr_parser_process_manifest_xml(manifest);
7522 retvm_if(mfx == NULL, PMINFO_R_EINVAL, "pkg[%s] parsing fail", pkgid);
7524 *handle = (void *)mfx;
7529 API int pkgmgrinfo_set_type_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *type)
7531 retvm_if(!type, PMINFO_R_EINVAL, "Argument supplied is NULL");
7532 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7534 int len = strlen(type);
7535 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7537 manifest_x *mfx = (manifest_x *)handle;
7539 mfx->type = strndup(type, PKG_TYPE_STRING_LEN_MAX);
7543 API int pkgmgrinfo_set_version_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *version)
7545 retvm_if(!version, PMINFO_R_EINVAL, "Argument supplied is NULL");
7546 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7548 int len = strlen(version);
7549 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7551 manifest_x *mfx = (manifest_x *)handle;
7553 mfx->version = strndup(version, PKG_VERSION_STRING_LEN_MAX);
7557 API int pkgmgrinfo_set_install_location_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7559 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7560 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7562 manifest_x *mfx = (manifest_x *)handle;
7564 if (location == INSTALL_INTERNAL)
7565 strcpy(mfx->installlocation, "internal-only");
7566 else if (location == INSTALL_EXTERNAL)
7567 strcpy(mfx->installlocation, "prefer-external");
7572 API int pkgmgrinfo_set_size_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *size)
7574 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7575 retvm_if(size == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7577 manifest_x *mfx = (manifest_x *)handle;
7579 mfx->package_size = strdup(size);
7584 API int pkgmgrinfo_set_label_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *label_txt, const char *locale)
7586 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7587 retvm_if(!label_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7589 int len = strlen(label_txt);
7590 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7592 manifest_x *mfx = (manifest_x *)handle;
7594 label_x *label = calloc(1, sizeof(label_x));
7595 retvm_if(label == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7597 LISTADD(mfx->label, label);
7599 mfx->label->lang = strdup(locale);
7601 mfx->label->lang = strdup(DEFAULT_LOCALE);
7602 mfx->label->text = strdup(label_txt);
7607 API int pkgmgrinfo_set_icon_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *icon_txt, const char *locale)
7609 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7610 retvm_if(!icon_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7612 int len = strlen(icon_txt);
7613 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7615 manifest_x *mfx = (manifest_x *)handle;
7617 icon_x *icon = calloc(1, sizeof(icon_x));
7618 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7620 LISTADD(mfx->icon, icon);
7622 mfx->icon->lang = strdup(locale);
7624 mfx->icon->lang = strdup(DEFAULT_LOCALE);
7625 mfx->icon->text = strdup(icon_txt);
7630 API int pkgmgrinfo_set_description_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *desc_txt, const char *locale)
7632 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7633 retvm_if(!desc_txt, PMINFO_R_EINVAL, "Argument supplied is NULL");
7635 int len = strlen(desc_txt);
7636 retvm_if(len > PKG_TYPE_STRING_LEN_MAX, PMINFO_R_EINVAL, "pkg type length exceeds the max limit");
7638 manifest_x *mfx = (manifest_x *)handle;
7640 description_x *description = calloc(1, sizeof(description_x));
7641 retvm_if(description == NULL, PMINFO_R_EINVAL, "Malloc Failed");
7643 LISTADD(mfx->description, description);
7645 mfx->description->lang = strdup(locale);
7647 mfx->description->lang = strdup(DEFAULT_LOCALE);
7648 mfx->description->text = strdup(desc_txt);
7653 API int pkgmgrinfo_set_author_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, const char *author_name,
7654 const char *author_email, const char *author_href, const char *locale)
7656 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7657 manifest_x *mfx = (manifest_x *)handle;
7658 author_x *author = calloc(1, sizeof(author_x));
7659 retvm_if(author == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL");
7661 LISTADD(mfx->author, author);
7663 mfx->author->text = strdup(author_name);
7665 mfx->author->email = strdup(author_email);
7667 mfx->author->href = strdup(author_href);
7669 mfx->author->lang = strdup(locale);
7671 mfx->author->lang = strdup(DEFAULT_LOCALE);
7675 API int pkgmgrinfo_set_removable_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int removable)
7677 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7678 retvm_if((removable < 0) || (removable > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7680 manifest_x *mfx = (manifest_x *)handle;
7683 strcpy(mfx->removable, "false");
7684 else if (removable == 1)
7685 strcpy(mfx->removable, "true");
7690 API int pkgmgrinfo_set_preload_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, int preload)
7692 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7693 retvm_if((preload < 0) || (preload > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7695 manifest_x *mfx = (manifest_x *)handle;
7698 strcpy(mfx->preload, "false");
7699 else if (preload == 1)
7700 strcpy(mfx->preload, "true");
7705 API int pkgmgrinfo_set_installed_storage_to_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle, INSTALL_LOCATION location)
7707 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7708 retvm_if((location < 0) || (location > 1), PMINFO_R_EINVAL, "Argument supplied is NULL");
7710 manifest_x *mfx = (manifest_x *)handle;
7712 if (location == INSTALL_INTERNAL)
7713 strcpy(mfx->installed_storage, "installed_internal");
7714 else if (location == INSTALL_EXTERNAL)
7715 strcpy(mfx->installed_storage, "installed_external");
7720 API int pkgmgrinfo_save_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7722 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7725 manifest_x *mfx = NULL;
7726 mfx = (manifest_x *)handle;
7728 ret = pkgmgr_parser_update_manifest_info_in_db(mfx);
7730 _LOGE("Successfully stored info in DB\n");
7733 _LOGE("Failed to store info in DB\n");
7734 return PMINFO_R_ERROR;
7738 API int pkgmgrinfo_save_pkgusrdbinfo(pkgmgrinfo_pkgdbinfo_h handle, uid_t uid)
7740 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7743 manifest_x *mfx = NULL;
7744 mfx = (manifest_x *)handle;
7746 ret = pkgmgr_parser_update_manifest_info_in_usr_db(mfx, uid);
7748 _LOGE("Successfully stored info in DB\n");
7751 _LOGE("Failed to store info in DB\n");
7752 return PMINFO_R_ERROR;
7756 API int pkgmgrinfo_destroy_pkgdbinfo(pkgmgrinfo_pkgdbinfo_h handle)
7758 retvm_if(!handle, PMINFO_R_EINVAL, "Argument supplied is NULL");
7760 manifest_x *mfx = NULL;
7761 mfx = (manifest_x *)handle;
7762 pkgmgr_parser_free_manifest_xml(mfx);
7766 API int pkgmgrinfo_pkginfo_set_state_enabled(const char *pkgid, bool enabled)
7768 /* Should be implemented later */
7772 API int pkgmgrinfo_appinfo_set_usr_state_enabled(const char *appid, bool enabled, uid_t uid)
7774 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7776 char query[MAX_QUERY_LEN] = {'\0'};
7777 ret = __open_manifest_db(uid);
7779 /*Begin transaction*/
7780 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7781 if (ret != SQLITE_OK) {
7782 _LOGE("Failed to begin transaction\n");
7783 sqlite3_close(manifest_db);
7784 return PMINFO_R_ERROR;
7786 _LOGD("Transaction Begin\n");
7788 memset(query, '\0', MAX_QUERY_LEN);
7789 snprintf(query, MAX_QUERY_LEN,
7790 "update package_app_info set app_enabled='%s' where app_id='%s'", enabled?"true":"false", appid);
7792 char *error_message = NULL;
7794 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7795 _LOGE("Don't execute query = %s error message = %s\n", query,
7797 sqlite3_free(error_message);
7798 return PMINFO_R_ERROR;
7800 sqlite3_free(error_message);
7802 /*Commit transaction*/
7803 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7804 if (ret != SQLITE_OK) {
7805 _LOGE("Failed to commit transaction. Rollback now\n");
7806 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7807 sqlite3_close(manifest_db);
7808 return PMINFO_R_ERROR;
7810 _LOGD("Transaction Commit and End\n");
7811 sqlite3_close(manifest_db);
7816 API int pkgmgrinfo_appinfo_set_state_enabled(const char *appid, bool enabled)
7818 return pkgmgrinfo_appinfo_set_usr_state_enabled(appid, enabled, GLOBAL_USER);
7821 API int pkgmgrinfo_datacontrol_get_info(const char *providerid, const char * type, char **appid, char **access)
7823 retvm_if(providerid == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7824 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
7825 retvm_if(appid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7826 retvm_if(access == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7827 int ret = PMINFO_R_OK;
7828 char query[MAX_QUERY_LEN] = {'\0'};
7829 char *error_message = NULL;
7830 pkgmgr_datacontrol_x *data = NULL;
7832 ret = __open_datacontrol_db();
7834 _LOGE("Fail to open datacontrol DB\n");
7835 return PMINFO_R_ERROR;
7838 data = (pkgmgr_datacontrol_x *)calloc(1, sizeof(pkgmgr_datacontrol_x));
7840 _LOGE("Failed to allocate memory for pkgmgr_datacontrol_x\n");
7841 sqlite3_close(datacontrol_db);
7842 return PMINFO_R_ERROR;
7845 snprintf(query, MAX_QUERY_LEN,
7846 "select appinfo.package_name, datacontrol.access from appinfo, datacontrol where datacontrol.id=appinfo.unique_id and datacontrol.provider_id = '%s' and datacontrol.type='%s' COLLATE NOCASE",
7850 sqlite3_exec(datacontrol_db, query, __datacontrol_cb, (void *)data, &error_message)) {
7851 _LOGE("Don't execute query = %s error message = %s\n", query,
7853 sqlite3_free(error_message);
7854 sqlite3_close(datacontrol_db);
7855 return PMINFO_R_ERROR;
7858 *appid = (char *)data->appid;
7859 *access = (char *)data->access;
7861 sqlite3_close(datacontrol_db);
7866 API int pkgmgrinfo_appinfo_set_usr_default_label(const char *appid, const char *label, uid_t uid)
7868 retvm_if(appid == NULL, PMINFO_R_EINVAL, "appid is NULL\n");
7870 char query[MAX_QUERY_LEN] = {'\0'};
7871 char *error_message = NULL;
7872 ret = __open_manifest_db(uid);
7875 /*Begin transaction*/
7876 ret = sqlite3_exec(manifest_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
7877 if (ret != SQLITE_OK) {
7878 _LOGE("Failed to begin transaction\n");
7879 sqlite3_close(manifest_db);
7880 return PMINFO_R_ERROR;
7882 _LOGD("Transaction Begin\n");
7884 memset(query, '\0', MAX_QUERY_LEN);
7885 snprintf(query, MAX_QUERY_LEN,
7886 "update package_app_localized_info set app_label='%s' where app_id='%s' and app_locale='No Locale'", label, appid);
7889 sqlite3_exec(manifest_db, query, NULL, NULL, &error_message)) {
7890 _LOGE("Don't execute query = %s error message = %s\n", query,
7892 sqlite3_free(error_message);
7893 return PMINFO_R_ERROR;
7896 /*Commit transaction*/
7897 ret = sqlite3_exec(manifest_db, "COMMIT", NULL, NULL, NULL);
7898 if (ret != SQLITE_OK) {
7899 _LOGE("Failed to commit transaction. Rollback now\n");
7900 sqlite3_exec(manifest_db, "ROLLBACK", NULL, NULL, NULL);
7901 sqlite3_close(manifest_db);
7902 return PMINFO_R_ERROR;
7904 _LOGD("Transaction Commit and End\n");
7905 sqlite3_close(manifest_db);
7910 API int pkgmgrinfo_appinfo_set_default_label(const char *appid, const char *label)
7912 return pkgmgrinfo_appinfo_set_usr_default_label(appid, label, GLOBAL_USER);
7915 API int pkgmgrinfo_appinfo_is_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool *status)
7917 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7918 retvm_if(status == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
7920 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7921 val = (char *)info->uiapp_info->guestmode_visibility;
7923 if (strcasecmp(val, "true") == 0){
7925 }else if (strcasecmp(val, "false") == 0){
7934 API int pkgmgrinfo_appinfo_set_usr_guestmode_visibility(pkgmgrinfo_appinfo_h handle, uid_t uid, bool status)
7936 retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
7939 char *noti_string = NULL;
7941 char query[MAX_QUERY_LEN] = {'\0'};
7942 char *errmsg = NULL;
7943 sqlite3 *pkgmgr_parser_db;
7945 pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
7946 val = (char *)info->uiapp_info->guestmode_visibility;
7949 db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
7950 SQLITE_OPEN_READWRITE, NULL);
7952 if (ret != SQLITE_OK) {
7953 _LOGE("DB Open Failed\n");
7954 return PMINFO_R_ERROR;
7957 /*TODO: Write to DB here*/
7959 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'true' where app_id = '%s'", (char *)info->uiapp_info->appid);
7961 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_guestmodevisibility = 'false' where app_id = '%s'", (char *)info->uiapp_info->appid);
7963 if (SQLITE_OK != sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &errmsg)) {
7964 _LOGE("DB update [%s] failed, error message = %s\n", query, errmsg);
7966 sqlite3_close(pkgmgr_parser_db);
7967 return PMINFO_R_ERROR;
7969 sqlite3_close(pkgmgr_parser_db);
7970 len = strlen((char *)info->uiapp_info->appid) + 8;
7971 noti_string = calloc(1, len);
7972 if (noti_string == NULL){
7973 return PMINFO_R_ERROR;
7975 snprintf(noti_string, len, "update:%s", (char *)info->uiapp_info->appid);
7976 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
7977 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
7984 API int pkgmgrinfo_appinfo_set_guestmode_visibility(pkgmgrinfo_appinfo_h handle, bool status)
7986 return pkgmgrinfo_appinfo_set_usr_guestmode_visibility(handle, GLOBAL_USER, status);
7989 /* pkgmgrinfo client start*/
7990 API pkgmgrinfo_client *pkgmgrinfo_client_new(pkgmgrinfo_client_type ctype)
7993 char *errmsg = NULL;
7995 void *handle = NULL;
7996 pkgmgrinfo_client *(*__pkgmgr_client_new)(pkgmgrinfo_client_type ctype) = NULL;
7998 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
7999 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8001 __pkgmgr_client_new = dlsym(handle, "pkgmgr_client_new");
8003 tryvm_if((errmsg != NULL) || (__pkgmgr_client_new == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8005 pc = __pkgmgr_client_new(ctype);
8006 tryvm_if(pc == NULL, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8010 return (pkgmgrinfo_client *) pc;
8013 API int pkgmgrinfo_client_set_status_type(pkgmgrinfo_client *pc, int status_type)
8016 char *errmsg = NULL;
8017 void *handle = NULL;
8018 int (*__pkgmgr_client_set_status_type)(pkgmgrinfo_client *pc, int status_type) = NULL;
8020 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8021 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8023 __pkgmgr_client_set_status_type = dlsym(handle, "pkgmgr_client_set_status_type");
8025 tryvm_if((errmsg != NULL) || (__pkgmgr_client_set_status_type == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8027 ret = __pkgmgr_client_set_status_type(pc, status_type);
8028 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8032 * Do not close libpkgmgr-client.so.0 to avoid munmap registered callback
8034 * The lib dependency chain like below
8035 * amd --> pkgmgr-info -- dlopen --> libpkgmgr-client --> libpkgmgr-installer-client
8037 * And there is a function in libpkgmgr-installer-client named _on_signal_handle_filter()
8038 * which will registered to dbus callback in amd though in fact amd doesn't direct depends
8039 * on libpkgmgr-installer-client.
8041 * So when the dlcose happen, then libpkgmgr-installer-client been closed too since no one
8044 * However, when the libdbus call into the callback function, it suddenly fond that the
8045 * function address is gone (unmapped), then we receive a SIGSEGV.
8047 * I'm not sure why we're using dlopen/dlclose in this case, I think it's much simple and
8048 * robust if we just link to the well-known lib.
8050 * See https://bugs.tizen.org/jira/browse/PTREL-591
8056 API int pkgmgrinfo_client_listen_status(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data)
8059 char *errmsg = NULL;
8060 void *handle = NULL;
8061 int (*__pkgmgr_client_listen_status)(pkgmgrinfo_client *pc, pkgmgrinfo_handler event_cb, void *data) = NULL;
8063 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8064 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8066 __pkgmgr_client_listen_status = dlsym(handle, "pkgmgr_client_listen_status");
8068 tryvm_if((errmsg != NULL) || (__pkgmgr_client_listen_status == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8070 ret = __pkgmgr_client_listen_status(pc, event_cb, data);
8071 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8074 /* same as pkgmgrinfo_client_new */
8078 API int pkgmgrinfo_client_free(pkgmgrinfo_client *pc)
8081 char *errmsg = NULL;
8082 void *handle = NULL;
8083 int (*__pkgmgr_client_free)(pkgmgrinfo_client *pc) = NULL;
8085 handle = dlopen("libpkgmgr-client.so.0", RTLD_LAZY | RTLD_GLOBAL);
8086 retvm_if(!handle, PMINFO_R_ERROR, "dlopen() failed. [%s]", dlerror());
8088 __pkgmgr_client_free = dlsym(handle, "pkgmgr_client_free");
8090 tryvm_if((errmsg != NULL) || (__pkgmgr_client_free == NULL), ret = PMINFO_R_ERROR, "dlsym() failed. [%s]", errmsg);
8092 ret = __pkgmgr_client_free(pc);
8093 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_client_new failed.");
8096 /* same as pkgmgrinfo_client_new */
8100 API int pkgmgrinfo_client_request_enable_external_pkg(char *pkgid)
8103 DBusConnection *bus;
8104 DBusMessage *message;
8106 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
8108 if(__get_pkg_location(pkgid) != PMINFO_EXTERNAL_STORAGE)
8111 bus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
8112 retvm_if(bus == NULL, PMINFO_R_EINVAL, "dbus_bus_get() failed.");
8114 message = dbus_message_new_method_call (SERVICE_NAME, PATH_NAME, INTERFACE_NAME, METHOD_NAME);
8115 retvm_if(message == NULL, PMINFO_R_EINVAL, "dbus_message_new_method_call() failed.");
8117 dbus_message_append_args(message, DBUS_TYPE_STRING, &pkgid, DBUS_TYPE_INVALID);
8119 ret = dbus_connection_send_with_reply_and_block(bus, message, -1, NULL);
8120 retvm_if(!ret, ret = PMINFO_R_EINVAL, "connection_send dbus fail");
8122 dbus_connection_flush(bus);
8123 dbus_message_unref(message);
8128 /* pkgmgrinfo client end*/