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.
23 #include "pkgmgrinfo_private.h"
28 #define LOG_TAG "PKGMGR_INFO"
30 #define FILTER_QUERY_LIST_PACKAGE "select * from package_info LEFT OUTER JOIN package_localized_info " \
31 "ON package_info.package=package_localized_info.package " \
32 "and package_localized_info.package_locale IN ('%s', '%s') where "
35 typedef struct _pkgmgr_cert_x {
40 static void __destroy_each_node(gpointer data, gpointer user_data)
43 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)data;
44 FREE_AND_NULL(node->value);
45 FREE_AND_NULL(node->key);
49 static void __get_pkginfo_from_db(char *colname, char *coltxt, manifest_x *manifest_info)
51 if (colname == NULL || manifest_info == NULL)
54 if (strcmp(colname, "package") == 0) {
55 if (manifest_info->package)
59 manifest_info->package = strdup(coltxt);
60 } else if (strcmp(colname, "package_type") == 0) {
62 manifest_info->type = strdup(coltxt);
64 manifest_info->type = NULL;
65 } else if (strcmp(colname, "package_version") == 0) {
67 manifest_info->version = strdup(coltxt);
69 manifest_info->version = NULL;
70 } else if (strcmp(colname, "install_location") == 0) {
72 manifest_info->installlocation = strdup(coltxt);
74 manifest_info->installlocation = NULL;
75 } else if (strcmp(colname, "package_size") == 0) {
77 manifest_info->package_size = strdup(coltxt);
79 manifest_info->package_size = NULL;
80 } else if (strcmp(colname, "package_removable") == 0 ){
82 manifest_info->removable = strdup(coltxt);
84 manifest_info->removable = NULL;
85 } else if (strcmp(colname, "package_preload") == 0 ){
87 manifest_info->preload = strdup(coltxt);
89 manifest_info->preload = NULL;
90 } else if (strcmp(colname, "package_readonly") == 0 ){
92 manifest_info->readonly = strdup(coltxt);
94 manifest_info->readonly = NULL;
95 } else if (strcmp(colname, "package_update") == 0 ){
97 manifest_info->update= strdup(coltxt);
99 manifest_info->update = NULL;
100 } else if (strcmp(colname, "package_system") == 0 ){
102 manifest_info->system= strdup(coltxt);
104 manifest_info->system = NULL;
105 } else if (strcmp(colname, "package_appsetting") == 0 ){
107 manifest_info->appsetting = strdup(coltxt);
109 manifest_info->appsetting = NULL;
110 } else if (strcmp(colname, "installed_time") == 0 ){
112 manifest_info->installed_time = strdup(coltxt);
114 manifest_info->installed_time = NULL;
115 } else if (strcmp(colname, "installed_storage") == 0 ){
117 manifest_info->installed_storage = strdup(coltxt);
119 manifest_info->installed_storage = NULL;
120 } else if (strcmp(colname, "mainapp_id") == 0 ){
122 manifest_info->mainapp_id = strdup(coltxt);
124 manifest_info->mainapp_id = NULL;
125 } else if (strcmp(colname, "storeclient_id") == 0 ){
127 manifest_info->storeclient_id = strdup(coltxt);
129 manifest_info->storeclient_id = NULL;
130 } else if (strcmp(colname, "package_url") == 0 ){
132 manifest_info->package_url = strdup(coltxt);
134 manifest_info->package_url = NULL;
135 } else if (strcmp(colname, "root_path") == 0 ){
137 manifest_info->root_path = strdup(coltxt);
139 manifest_info->root_path = NULL;
140 } else if (strcmp(colname, "csc_path") == 0 ){
142 manifest_info->csc_path = strdup(coltxt);
144 manifest_info->csc_path = NULL;
145 } else if (strcmp(colname, "package_support_disable") == 0 ){
147 manifest_info->support_disable = strdup(coltxt);
149 manifest_info->support_disable = NULL;
150 } else if (strcmp(colname, "package_mother_package") == 0 ){
152 manifest_info->mother_package = strdup(coltxt);
154 manifest_info->mother_package = NULL;
155 } else if (strcmp(colname, "package_support_mode") == 0 ){
157 manifest_info->support_mode = strdup(coltxt);
159 manifest_info->support_mode = NULL;
160 } else if (strcmp(colname, "package_reserve1") == 0 ){
162 manifest_info->support_reset = strdup(coltxt);
164 manifest_info->support_reset = NULL;
165 } else if (strcmp(colname, "package_reserve2") == 0 ){
167 manifest_info->use_reset = strdup(coltxt);
169 manifest_info->use_reset = NULL;
170 } else if (strcmp(colname, "package_hash") == 0 ){
172 manifest_info->hash = strdup(coltxt);
174 manifest_info->hash = NULL;
175 } else if (strcmp(colname, "package_reserve3") == 0 ){
177 manifest_info->groupid = strdup(coltxt);
179 manifest_info->groupid = NULL;
181 /*end package_info table*/
183 } else if (strcmp(colname, "author_email") == 0 ){
185 manifest_info->author->email = strdup(coltxt);
187 manifest_info->author->email = NULL;
188 } else if (strcmp(colname, "author_href") == 0 ){
190 manifest_info->author->href = strdup(coltxt);
192 manifest_info->author->href = NULL;
193 } else if (strcmp(colname, "package_label") == 0 ){
195 manifest_info->label->text = strdup(coltxt);
197 manifest_info->label->text = NULL;
198 } else if (strcmp(colname, "package_icon") == 0 ){
200 manifest_info->icon->text = strdup(coltxt);
202 manifest_info->icon->text = NULL;
203 } else if (strcmp(colname, "package_description") == 0 ){
205 manifest_info->description->text = strdup(coltxt);
207 manifest_info->description->text = NULL;
208 } else if (strcmp(colname, "package_author") == 0 ){
210 manifest_info->author->text = strdup(coltxt);
212 manifest_info->author->text = NULL;
213 } else if (strcmp(colname, "package_locale") == 0 ){
215 manifest_info->author->lang = strdup(coltxt);
216 manifest_info->icon->lang = strdup(coltxt);
217 manifest_info->label->lang = strdup(coltxt);
218 manifest_info->description->lang = strdup(coltxt);
221 manifest_info->author->lang = NULL;
222 manifest_info->icon->lang = NULL;
223 manifest_info->label->lang = NULL;
224 manifest_info->description->lang = NULL;
226 /*end package_localized_info table*/
228 } else if (strcmp(colname, "privilege") == 0 ){
230 manifest_info->privileges->privilege->text = strdup(coltxt);
232 manifest_info->privileges->privilege->text = NULL;
235 /*end package_privilege_info table*/
239 static void __get_pkginfo_for_list(sqlite3_stmt *stmt, pkgmgr_pkginfo_x *udata)
243 char *colname = NULL;
245 pkgmgr_pkginfo_x *info = NULL;
247 info = calloc(1, sizeof(pkgmgr_pkginfo_x));
249 _LOGE("out of memory");
253 info->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
254 if (info->manifest_info == NULL) {
255 _LOGE("out of memory");
260 info->manifest_info->icon= (icon_x *)calloc(1, sizeof(icon_x));
261 if (info->manifest_info->icon == NULL) {
262 _LOGE("out of memory");
263 free(info->manifest_info);
268 info->manifest_info->label= (label_x *)calloc(1, sizeof(label_x));
269 if (info->manifest_info->label == NULL) {
270 _LOGE("out of memory");
271 free(info->manifest_info->icon);
272 free(info->manifest_info);
277 info->manifest_info->author= (author_x *)calloc(1, sizeof(author_x));
278 if (info->manifest_info->author == NULL) {
279 _LOGE("out of memory");
280 free(info->manifest_info->label);
281 free(info->manifest_info->icon);
282 free(info->manifest_info);
287 info->manifest_info->description= (description_x *)calloc(1, sizeof(description_x));
288 if (info->manifest_info->description == NULL) {
289 _LOGE("out of memory");
290 free(info->manifest_info->author);
291 free(info->manifest_info->label);
292 free(info->manifest_info->icon);
293 free(info->manifest_info);
298 ncols = sqlite3_column_count(stmt);
300 LISTADD(udata, info);
302 for(i = 0; i < ncols; i++)
304 colname = (char *)sqlite3_column_name(stmt, i);
305 coltxt = (char *)sqlite3_column_text(stmt, i);
307 // _LOGE("field value :: %s = %s \n", colname, coltxt);
308 __get_pkginfo_from_db(colname, coltxt, info->manifest_info);
312 static void __update_localed_label_for_list(sqlite3_stmt *stmt, pkgmgr_pkginfo_x *list_pkginfo)
316 char *colname = NULL;
319 pkgmgr_pkginfo_x *node = NULL;
320 pkgmgr_pkginfo_x *pkginfo = NULL;
322 LISTHEAD(list_pkginfo, node);
323 pkginfo = node->next;
325 ncols = sqlite3_column_count(stmt);
327 for(i = 0; i < ncols; i++)
329 colname = (char *)sqlite3_column_name(stmt, i);
330 if (colname && strcmp(colname, "package_label") == 0 ){
331 coltxt = (char *)sqlite3_column_text(stmt, i);
332 FREE_AND_STRDUP(coltxt, pkginfo->manifest_info->label->text);
337 int __pkginfo_cb(void *data, int ncols, char **coltxt, char **colname)
339 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)data;
341 author_x *author = NULL;
343 label_x *label = NULL;
344 description_x *description = NULL;
345 privilege_x *privilege = NULL;
347 author = calloc(1, sizeof(author_x));
348 retvm_if(author == NULL, PMINFO_R_ERROR, "out of memory");
349 LISTADD(info->manifest_info->author, author);
350 icon = calloc(1, sizeof(icon_x));
351 retvm_if(icon == NULL, PMINFO_R_ERROR, "out of memory");
352 LISTADD(info->manifest_info->icon, icon);
353 label = calloc(1, sizeof(label_x));
354 retvm_if(label == NULL, PMINFO_R_ERROR, "out of memory");
355 LISTADD(info->manifest_info->label, label);
356 description = calloc(1, sizeof(description_x));
357 retvm_if(description == NULL, PMINFO_R_ERROR, "out of memory");
358 LISTADD(info->manifest_info->description, description);
359 privilege = calloc(1, sizeof(privilege_x));
360 retvm_if(privilege == NULL, PMINFO_R_ERROR, "out of memory");
361 LISTADD(info->manifest_info->privileges->privilege, privilege);
363 for(i = 0; i < ncols; i++)
365 __get_pkginfo_from_db(colname[i], coltxt[i], info->manifest_info);
370 static int __cert_cb(void *data, int ncols, char **coltxt, char **colname)
372 pkgmgr_cert_x *info = (pkgmgr_cert_x *)data;
375 for(i = 0; i < ncols; i++)
377 if (strcmp(colname[i], "author_signer_cert") == 0) {
379 info->cert_id = atoi(coltxt[i]);
382 } else if (strcmp(colname[i], "package") == 0) {
383 if (coltxt[i] && info->pkgid == NULL) {
384 info->pkgid= strdup(coltxt[i]);
397 API int pkgmgrinfo_pkginfo_get_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
399 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
401 int ret = PMINFO_R_OK;
405 char pkgid[MAX_QUERY_LEN] = {0,};
406 char pre_pkgid[MAX_QUERY_LEN] = {0,};
408 sqlite3 *pkginfo_db = NULL;
409 sqlite3_stmt *stmt = NULL;
411 pkgmgr_pkginfo_x *node = NULL;
412 pkgmgr_pkginfo_x *pkginfo = NULL;
413 pkgmgr_pkginfo_x *list_pkginfo = NULL;
416 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
417 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
419 /*Start constructing query*/
420 locale = __convert_system_locale_to_manifest_locale();
421 retvm_if(locale == NULL, PMINFO_R_ERROR, "locale is NULL");
422 query = sqlite3_mprintf("select * from package_info LEFT OUTER JOIN package_localized_info " \
423 "ON package_info.package=package_localized_info.package "\
424 "where package_info.package_disable='false' and package_localized_info.package_locale IN (%Q, %Q)", DEFAULT_LOCALE, locale);
427 ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
428 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
431 list_pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
432 tryvm_if(list_pkginfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
436 ret = sqlite3_step(stmt);
437 if(ret == SQLITE_ROW) {
439 memset(pkgid, 0, MAX_QUERY_LEN);
440 strncpy(pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
442 if (strlen(pre_pkgid) != 0) {
443 if (strcmp(pre_pkgid, pkgid) == 0) {
444 __update_localed_label_for_list(stmt, list_pkginfo);
446 memset(pre_pkgid, 0, MAX_QUERY_LEN);
447 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
451 memset(pre_pkgid, 0, MAX_QUERY_LEN);
452 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
455 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
458 __get_pkginfo_for_list(stmt, list_pkginfo);
465 LISTHEAD(list_pkginfo, node);
467 for(node = node->next; node ; node = node->next) {
469 pkginfo->locale = strdup(locale);
471 ret = __pkginfo_check_installed_storage(pkginfo);
475 ret = pkg_list_cb( (void *)pkginfo, user_data);
482 sqlite3_finalize(stmt);
483 sqlite3_close(pkginfo_db);
484 FREE_AND_NULL(locale);
486 __cleanup_list_pkginfo(list_pkginfo, node);
491 API int pkgmgrinfo_pkginfo_get_mounted_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
493 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
495 int ret = PMINFO_R_OK;
499 char pkgid[MAX_QUERY_LEN] = {0,};
500 char pre_pkgid[MAX_QUERY_LEN] = {0,};
502 sqlite3 *pkginfo_db = NULL;
503 sqlite3_stmt *stmt = NULL;
505 pkgmgr_pkginfo_x *node = NULL;
506 pkgmgr_pkginfo_x *pkginfo = NULL;
507 pkgmgr_pkginfo_x *list_pkginfo = NULL;
510 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
511 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
513 /*Start constructing query*/
514 locale = __convert_system_locale_to_manifest_locale();
515 retvm_if(locale == NULL, PMINFO_R_ERROR, "locale is NULL");
516 query = sqlite3_mprintf("select * from package_info LEFT OUTER JOIN package_localized_info " \
517 "ON package_info.package=package_localized_info.package "\
518 "where installed_storage='installed_external' and package_info.package_disable='false' and package_localized_info.package_locale IN (%Q, %Q)", DEFAULT_LOCALE, locale);
521 ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
522 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
525 list_pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
526 tryvm_if(list_pkginfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
530 ret = sqlite3_step(stmt);
531 if(ret == SQLITE_ROW) {
533 memset(pkgid, 0, MAX_QUERY_LEN);
534 strncpy(pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
536 if (strlen(pre_pkgid) != 0) {
537 if (strcmp(pre_pkgid, pkgid) == 0) {
538 __update_localed_label_for_list(stmt, list_pkginfo);
540 memset(pre_pkgid, 0, MAX_QUERY_LEN);
541 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
544 memset(pre_pkgid, 0, MAX_QUERY_LEN);
545 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
548 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
551 __get_pkginfo_for_list(stmt, list_pkginfo);
558 LISTHEAD(list_pkginfo, node);
560 for(node = node->next; node ; node = node->next) {
562 pkginfo->locale = strdup(locale);
564 ret = __pkginfo_check_installed_storage(pkginfo);
568 ret = pkg_list_cb( (void *)pkginfo, user_data);
575 sqlite3_finalize(stmt);
576 sqlite3_close(pkginfo_db);
577 FREE_AND_NULL(locale);
579 __cleanup_list_pkginfo(list_pkginfo, node);
585 API int pkgmgrinfo_pkginfo_get_unmounted_list(pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
587 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
589 int ret = PMINFO_R_OK;
593 char pkgid[MAX_QUERY_LEN] = {0,};
594 char pre_pkgid[MAX_QUERY_LEN] = {0,};
596 sqlite3 *pkginfo_db = NULL;
597 sqlite3_stmt *stmt = NULL;
599 pkgmgr_pkginfo_x *node = NULL;
600 pkgmgr_pkginfo_x *pkginfo = NULL;
601 pkgmgr_pkginfo_x *list_pkginfo = NULL;
604 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
605 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
607 /*Start constructing query*/
608 locale = __convert_system_locale_to_manifest_locale();
609 retvm_if(locale == NULL, PMINFO_R_ERROR, "locale is NULL");
610 query = sqlite3_mprintf("select * from package_info LEFT OUTER JOIN package_localized_info " \
611 "ON package_info.package=package_localized_info.package "\
612 "where installed_storage='installed_external' and package_info.package_disable='false' and package_localized_info.package_locale IN (%Q, %Q)", DEFAULT_LOCALE, locale);
615 ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
616 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
619 list_pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
620 tryvm_if(list_pkginfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
624 ret = sqlite3_step(stmt);
625 if(ret == SQLITE_ROW) {
627 memset(pkgid, 0, MAX_QUERY_LEN);
628 strncpy(pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
630 if (strlen(pre_pkgid) != 0) {
631 if (strcmp(pre_pkgid, pkgid) == 0) {
632 __update_localed_label_for_list(stmt, list_pkginfo);
634 memset(pre_pkgid, 0, MAX_QUERY_LEN);
635 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
639 memset(pre_pkgid, 0, MAX_QUERY_LEN);
640 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
643 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
646 __get_pkginfo_for_list(stmt, list_pkginfo);
653 LISTHEAD(list_pkginfo, node);
655 for(node = node->next; node ; node = node->next) {
657 pkginfo->locale = strdup(locale);
659 ret = pkg_list_cb( (void *)pkginfo, user_data);
666 sqlite3_finalize(stmt);
667 sqlite3_close(pkginfo_db);
668 FREE_AND_NULL(locale);
670 __cleanup_list_pkginfo(list_pkginfo, node);
675 API int pkgmgrinfo_pkginfo_get_unmounted_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
677 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
678 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
679 pkgmgr_pkginfo_x *pkginfo = NULL;
680 int ret = PMINFO_R_OK;
684 label_x *tmp1 = NULL;
686 description_x *tmp3 = NULL;
687 author_x *tmp4 = NULL;
688 privilege_x *tmp5 = NULL;
689 sqlite3 *pkginfo_db = NULL;
692 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
693 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
695 /*check pkgid exist on db*/
696 query= sqlite3_mprintf("select exists(select * from package_info where package=%Q and package_disable='false')", pkgid);
697 ret = __exec_db_query(pkginfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist);
699 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
700 tryvm_if(exist == 0, ret = PMINFO_R_ERROR, "pkgid[%s] not found in DB", pkgid);
702 /*get system locale*/
703 locale = __convert_system_locale_to_manifest_locale();
704 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
706 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
707 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
709 pkginfo->locale = strdup(locale);
711 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
712 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
714 pkginfo->manifest_info->package = strdup(pkgid);
715 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
716 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
718 /*populate manifest_info from DB*/
719 query= sqlite3_mprintf("select * from package_info where package=%Q and package_disable='false'", pkgid);
720 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
722 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
724 /*populate privilege_info from DB*/
725 query= sqlite3_mprintf("select * from package_privilege_info where package=%Q ", pkgid);
726 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
728 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
730 query= sqlite3_mprintf("select * from package_localized_info where package=%Q and package_locale=%Q", pkgid, locale);
731 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
733 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
735 /*Also store the values corresponding to default locales*/
736 query= sqlite3_mprintf("select * from package_localized_info where package=%Q and package_locale=%Q", pkgid, DEFAULT_LOCALE);
737 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
739 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
741 SAFE_LISTHEAD(pkginfo->manifest_info->label, tmp1);
742 SAFE_LISTHEAD(pkginfo->manifest_info->icon, tmp2);
743 SAFE_LISTHEAD(pkginfo->manifest_info->description, tmp3);
744 SAFE_LISTHEAD(pkginfo->manifest_info->author, tmp4);
745 SAFE_LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
748 if (ret == PMINFO_R_OK)
749 *handle = (void*)pkginfo;
752 __cleanup_pkginfo(pkginfo);
754 sqlite3_close(pkginfo_db);
756 FREE_AND_NULL(locale);
760 API int pkgmgrinfo_pkginfo_get_pkginfo(const char *pkgid, pkgmgrinfo_pkginfo_h *handle)
762 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
763 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
764 pkgmgr_pkginfo_x *pkginfo = NULL;
765 int ret = PMINFO_R_OK;
769 label_x *tmp1 = NULL;
771 description_x *tmp3 = NULL;
772 author_x *tmp4 = NULL;
773 privilege_x *tmp5 = NULL;
774 sqlite3 *pkginfo_db = NULL;
777 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
778 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
780 /*check pkgid exist on db*/
781 query= sqlite3_mprintf("select exists(select * from package_info where package=%Q and package_disable='false')", pkgid);
782 ret = __exec_db_query(pkginfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist);
784 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "sqlite3_exec[%s] fail", pkgid);
786 _LOGS("pkgid[%s] not found in DB", pkgid);
787 ret = PMINFO_R_ERROR;
791 /*get system locale*/
792 locale = __convert_system_locale_to_manifest_locale();
793 tryvm_if(locale == NULL, ret = PMINFO_R_ERROR, "manifest locale is NULL");
795 pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
796 tryvm_if(pkginfo == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for pkginfo");
798 pkginfo->locale = strdup(locale);
800 pkginfo->manifest_info = (manifest_x *)calloc(1, sizeof(manifest_x));
801 tryvm_if(pkginfo->manifest_info == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for manifest info");
803 pkginfo->manifest_info->package = strdup(pkgid);
804 pkginfo->manifest_info->privileges = (privileges_x *)calloc(1, sizeof(privileges_x));
805 tryvm_if(pkginfo->manifest_info->privileges == NULL, ret = PMINFO_R_ERROR, "Failed to allocate memory for privileges info");
807 /*populate manifest_info from DB*/
808 query= sqlite3_mprintf("select * from package_info where package=%Q and package_disable='false'", pkgid);
809 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
811 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
813 /*populate privilege_info from DB*/
814 query= sqlite3_mprintf("select * from package_privilege_info where package=%Q ", pkgid);
815 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
817 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Privilege Info DB Information retrieval failed");
819 query= sqlite3_mprintf("select * from package_localized_info where package=%Q and package_locale=%Q", pkgid, locale);
820 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
822 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
824 /*Also store the values corresponding to default locales*/
825 query= sqlite3_mprintf("select * from package_localized_info where package=%Q and package_locale=%Q", pkgid, DEFAULT_LOCALE);
826 ret = __exec_db_query(pkginfo_db, query, __pkginfo_cb, (void *)pkginfo);
828 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "Package Info DB Information retrieval failed");
830 SAFE_LISTHEAD(pkginfo->manifest_info->label, tmp1);
831 SAFE_LISTHEAD(pkginfo->manifest_info->icon, tmp2);
832 SAFE_LISTHEAD(pkginfo->manifest_info->description, tmp3);
833 SAFE_LISTHEAD(pkginfo->manifest_info->author, tmp4);
834 SAFE_LISTHEAD(pkginfo->manifest_info->privileges->privilege, tmp5);
836 ret = __pkginfo_check_installed_storage(pkginfo);
837 tryvm_if(ret == -1, ret = PMINFO_R_ERROR, "[%s] is installed external, but is not in mmc", pkgid);
840 if (ret == PMINFO_R_OK)
841 *handle = (void*)pkginfo;
844 __cleanup_pkginfo(pkginfo);
846 sqlite3_close(pkginfo_db);
848 FREE_AND_NULL(locale);
853 API int pkgmgrinfo_pkginfo_get_pkgname(pkgmgrinfo_pkginfo_h handle, char **pkg_name)
855 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
856 retvm_if(pkg_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
857 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
858 if (info->manifest_info->package)
859 *pkg_name = (char *)info->manifest_info->package;
861 return PMINFO_R_ERROR;
866 API int pkgmgrinfo_pkginfo_get_pkgid(pkgmgrinfo_pkginfo_h handle, char **pkgid)
868 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
869 retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
870 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
871 if (info->manifest_info->package)
872 *pkgid = (char *)info->manifest_info->package;
874 return PMINFO_R_ERROR;
879 API int pkgmgrinfo_pkginfo_get_type(pkgmgrinfo_pkginfo_h handle, char **type)
881 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
882 retvm_if(type == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
883 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
884 if (info->manifest_info->type)
885 *type = (char *)info->manifest_info->type;
891 API int pkgmgrinfo_pkginfo_get_version(pkgmgrinfo_pkginfo_h handle, char **version)
893 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
894 retvm_if(version == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
895 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
896 *version = (char *)info->manifest_info->version;
900 API int pkgmgrinfo_pkginfo_get_install_location(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_install_location *location)
902 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
903 retvm_if(location == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
905 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
906 val = (char *)info->manifest_info->installlocation;
908 if (strcmp(val, "internal-only") == 0)
909 *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
910 else if (strcmp(val, "prefer-external") == 0)
911 *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
913 *location = PMINFO_INSTALL_LOCATION_AUTO;
918 API int pkgmgrinfo_pkginfo_get_icon(pkgmgrinfo_pkginfo_h handle, char **icon)
920 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
921 retvm_if(icon == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
922 int ret = PMINFO_R_OK;
927 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
929 locale = info->locale;
930 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
932 for(ptr = info->manifest_info->icon; ptr != NULL; ptr = ptr->next)
935 if (strcmp(ptr->lang, locale) == 0) {
937 *icon = (char *)ptr->text;
938 if (strcasecmp(*icon, PKGMGR_PARSER_EMPTY_STR) == 0) {
939 locale = DEFAULT_LOCALE;
944 locale = DEFAULT_LOCALE;
947 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
948 *icon = (char *)ptr->text;
957 API int pkgmgrinfo_pkginfo_get_label(pkgmgrinfo_pkginfo_h handle, char **label)
959 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
960 retvm_if(label == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
961 int ret = PMINFO_R_OK;
966 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
967 locale = info->locale;
968 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
970 for(ptr = info->manifest_info->label; ptr != NULL; ptr = ptr->next)
973 if (strcmp(ptr->lang, locale) == 0) {
975 *label = (char *)ptr->text;
976 if (strcasecmp(*label, PKGMGR_PARSER_EMPTY_STR) == 0) {
977 locale = DEFAULT_LOCALE;
982 locale = DEFAULT_LOCALE;
985 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
986 *label = (char *)ptr->text;
995 API int pkgmgrinfo_pkginfo_get_description(pkgmgrinfo_pkginfo_h handle, char **description)
997 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
998 retvm_if(description == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1000 description_x *ptr = NULL;
1001 *description = NULL;
1003 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1004 locale = info->locale;
1005 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1007 for(ptr = info->manifest_info->description; ptr != NULL; ptr = ptr->next)
1010 if (strcmp(ptr->lang, locale) == 0) {
1011 *description = (char *)ptr->text;
1012 if (strcasecmp(*description, PKGMGR_PARSER_EMPTY_STR) == 0) {
1013 locale = DEFAULT_LOCALE;
1017 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1018 *description = (char *)ptr->text;
1026 API int pkgmgrinfo_pkginfo_get_author_name(pkgmgrinfo_pkginfo_h handle, char **author_name)
1028 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1029 retvm_if(author_name == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1030 char *locale = NULL;
1031 author_x *ptr = NULL;
1032 *author_name = NULL;
1034 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1035 locale = info->locale;
1036 retvm_if(locale == NULL, PMINFO_R_ERROR, "manifest locale is NULL");
1038 for(ptr = info->manifest_info->author; ptr != NULL; ptr = ptr->next)
1041 if (strcmp(ptr->lang, locale) == 0) {
1042 *author_name = (char *)ptr->text;
1043 if (strcasecmp(*author_name, PKGMGR_PARSER_EMPTY_STR) == 0) {
1044 locale = DEFAULT_LOCALE;
1048 } else if (strcmp(ptr->lang, DEFAULT_LOCALE) == 0) {
1049 *author_name = (char *)ptr->text;
1057 API int pkgmgrinfo_pkginfo_get_author_email(pkgmgrinfo_pkginfo_h handle, char **author_email)
1059 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1060 retvm_if(author_email == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1061 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1062 *author_email = (char *)info->manifest_info->author->email;
1066 API int pkgmgrinfo_pkginfo_get_author_href(pkgmgrinfo_pkginfo_h handle, char **author_href)
1068 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1069 retvm_if(author_href == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1070 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1071 *author_href = (char *)info->manifest_info->author->href;
1075 API int pkgmgrinfo_pkginfo_get_installed_storage(pkgmgrinfo_pkginfo_h handle, pkgmgrinfo_installed_storage *storage)
1077 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1078 retvm_if(storage == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1080 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1082 if (strcmp(info->manifest_info->installed_storage,"installed_internal") == 0)
1083 *storage = PMINFO_INTERNAL_STORAGE;
1084 else if (strcmp(info->manifest_info->installed_storage,"installed_external") == 0)
1085 *storage = PMINFO_EXTERNAL_STORAGE;
1087 return PMINFO_R_ERROR;
1092 API int pkgmgrinfo_pkginfo_get_installed_time(pkgmgrinfo_pkginfo_h handle, int *installed_time)
1094 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1095 retvm_if(installed_time == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1096 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1097 if (info->manifest_info->installed_time)
1098 *installed_time = atoi(info->manifest_info->installed_time);
1100 return PMINFO_R_ERROR;
1105 API int pkgmgrinfo_pkginfo_get_storeclientid(pkgmgrinfo_pkginfo_h handle, char **storeclientid)
1107 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1108 retvm_if(storeclientid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1109 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1110 *storeclientid = (char *)info->manifest_info->storeclient_id;
1114 API int pkgmgrinfo_pkginfo_get_mainappid(pkgmgrinfo_pkginfo_h handle, char **mainappid)
1116 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1117 retvm_if(mainappid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1118 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1119 *mainappid = (char *)info->manifest_info->mainapp_id;
1123 API int pkgmgrinfo_pkginfo_get_url(pkgmgrinfo_pkginfo_h handle, char **url)
1125 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1126 retvm_if(url == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1127 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1128 *url = (char *)info->manifest_info->package_url;
1132 API int pkgmgrinfo_pkginfo_get_root_path(pkgmgrinfo_pkginfo_h handle, char **path)
1134 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1135 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1137 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1138 if (info->manifest_info->root_path)
1139 *path = (char *)info->manifest_info->root_path;
1141 return PMINFO_R_ERROR;
1146 API int pkgmgrinfo_pkginfo_get_csc_path(pkgmgrinfo_pkginfo_h handle, char **path)
1148 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1149 retvm_if(path == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1151 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1152 if (info->manifest_info->csc_path)
1153 *path = (char *)info->manifest_info->csc_path;
1155 return PMINFO_R_ERROR;
1160 API int pkgmgrinfo_pkginfo_get_support_mode(pkgmgrinfo_pkginfo_h handle, int *support_mode)
1162 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1163 retvm_if(support_mode == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1165 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1166 if (info->manifest_info->support_mode)
1167 *support_mode = atoi(info->manifest_info->support_mode);
1174 API int pkgmgrinfo_pkginfo_get_hash(pkgmgrinfo_pkginfo_h handle, char **hash)
1176 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1177 retvm_if(hash == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1179 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1180 if (info->manifest_info->hash)
1181 *hash = (char *)info->manifest_info->hash;
1189 API int pkgmgrinfo_pkginfo_get_groupid(pkgmgrinfo_pkginfo_h handle, char **groupid)
1191 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1192 retvm_if(groupid == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1194 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1195 if (info->manifest_info->groupid)
1196 *groupid = (char *)info->manifest_info->groupid;
1198 return PMINFO_R_ERROR;
1203 API int pkgmgrinfo_pkginfo_get_support_reset(pkgmgrinfo_pkginfo_h handle, char **support_reset)
1205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1206 retvm_if(support_reset == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1208 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1209 if (info->manifest_info->support_reset)
1210 *support_reset = (char *)info->manifest_info->support_reset;
1212 return PMINFO_R_ERROR;
1217 API int pkgmgrinfo_pkginfo_foreach_privilege(pkgmgrinfo_pkginfo_h handle,
1218 pkgmgrinfo_pkg_privilege_list_cb privilege_func, void *user_data)
1220 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL");
1221 retvm_if(privilege_func == NULL, PMINFO_R_EINVAL, "Callback function is NULL");
1223 privilege_x *ptr = NULL;
1224 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1225 ptr = info->manifest_info->privileges->privilege;
1226 for (; ptr; ptr = ptr->next) {
1228 ret = privilege_func(ptr->text, user_data);
1236 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)
1238 retvm_if(lhs_package_id == NULL, PMINFO_R_EINVAL, "lhs package ID is NULL");
1239 retvm_if(rhs_package_id == NULL, PMINFO_R_EINVAL, "rhs package ID is NULL");
1240 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1242 int ret = PMINFO_R_OK;
1244 char *error_message = NULL;
1245 pkgmgr_cert_x *info= NULL;
1249 sqlite3 *pkgmgr_cert_db = NULL;
1251 *compare_result = PMINFO_CERT_COMPARE_ERROR;
1252 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
1253 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
1255 ret = db_util_open_with_options(CERT_DB, &pkgmgr_cert_db, SQLITE_OPEN_READONLY, NULL);
1256 if (ret != SQLITE_OK) {
1257 _LOGE("connect db [%s] failed!\n", CERT_DB);
1258 ret = PMINFO_R_ERROR;
1262 query = sqlite3_mprintf("select exists(select * from package_cert_info where package=%Q)", lhs_package_id);
1264 sqlite3_exec(pkgmgr_cert_db, query, _pkgmgrinfo_validate_cb, (void *)&exist, &error_message)) {
1265 _LOGE("Don't execute query = %s error message = %s\n", query,
1267 ret = PMINFO_R_ERROR;
1268 sqlite3_free(query);
1275 sqlite3_free(query);
1276 query = sqlite3_mprintf("select author_signer_cert from package_cert_info where package=%Q", lhs_package_id);
1278 sqlite3_exec(pkgmgr_cert_db, query, __cert_cb, (void *)info, &error_message)) {
1279 _LOGE("Don't execute query = %s error message = %s\n", query,
1281 ret = PMINFO_R_ERROR;
1282 sqlite3_free(query);
1285 lcert = info->cert_id;
1288 sqlite3_free(query);
1289 query = sqlite3_mprintf("select exists(select * from package_cert_info where package=%Q)", rhs_package_id);
1291 sqlite3_exec(pkgmgr_cert_db, query, _pkgmgrinfo_validate_cb, (void *)&exist, &error_message)) {
1292 _LOGE("Don't execute query = %s error message = %s\n", query,
1294 ret = PMINFO_R_ERROR;
1295 sqlite3_free(query);
1302 sqlite3_free(query);
1303 query = sqlite3_mprintf("select author_signer_cert from package_cert_info where package=%Q", rhs_package_id);
1305 sqlite3_exec(pkgmgr_cert_db, query, __cert_cb, (void *)info, &error_message)) {
1306 _LOGE("Don't execute query = %s error message = %s\n", query,
1308 ret = PMINFO_R_ERROR;
1309 sqlite3_free(query);
1312 rcert = info->cert_id;
1313 sqlite3_free(query);
1316 if ((lcert == 0) || (rcert == 0))
1318 if ((lcert == 0) && (rcert == 0))
1319 *compare_result = PMINFO_CERT_COMPARE_BOTH_NO_CERT;
1320 else if (lcert == 0)
1321 *compare_result = PMINFO_CERT_COMPARE_LHS_NO_CERT;
1322 else if (rcert == 0)
1323 *compare_result = PMINFO_CERT_COMPARE_RHS_NO_CERT;
1326 *compare_result = PMINFO_CERT_COMPARE_MATCH;
1328 *compare_result = PMINFO_CERT_COMPARE_MISMATCH;
1332 sqlite3_free(error_message);
1333 sqlite3_close(pkgmgr_cert_db);
1335 FREE_AND_NULL(info->pkgid);
1336 FREE_AND_NULL(info);
1342 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)
1344 retvm_if(lhs_app_id == NULL, PMINFO_R_EINVAL, "lhs app ID is NULL");
1345 retvm_if(rhs_app_id == NULL, PMINFO_R_EINVAL, "rhs app ID is NULL");
1346 retvm_if(compare_result == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL");
1348 int ret = PMINFO_R_OK;
1350 char *error_message = NULL;
1351 pkgmgr_cert_x *info= NULL;
1353 char *lpkgid = NULL;
1354 char *rpkgid = NULL;
1355 sqlite3 *pkginfo_db = NULL;
1357 info = (pkgmgr_cert_x *)calloc(1, sizeof(pkgmgr_cert_x));
1358 retvm_if(info == NULL, PMINFO_R_ERROR, "Out of Memory!!!");
1360 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
1361 tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "connect db [%s] failed!", MANIFEST_DB);
1363 query = sqlite3_mprintf("select exists(select * from package_app_info where app_id=%Q and app_disable='false')", lhs_app_id);
1365 sqlite3_exec(pkginfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist, &error_message)) {
1366 _LOGE("Don't execute query = %s error message = %s\n", query,
1368 ret = PMINFO_R_ERROR;
1369 sqlite3_free(query);
1376 sqlite3_free(query);
1377 query = sqlite3_mprintf("select package from package_app_info where app_id=%Q and app_disable='false'", lhs_app_id);
1379 sqlite3_exec(pkginfo_db, query, __cert_cb, (void *)info, &error_message)) {
1380 _LOGE("Don't execute query = %s error message = %s\n", query,
1382 ret = PMINFO_R_ERROR;
1383 sqlite3_free(query);
1386 lpkgid = strdup(info->pkgid);
1387 if (lpkgid == NULL) {
1388 _LOGE("Out of Memory\n");
1389 ret = PMINFO_R_ERROR;
1390 sqlite3_free(query);
1397 sqlite3_free(query);
1398 query = sqlite3_mprintf("select exists(select * from package_app_info where app_id=%Q and app_disable='false')", rhs_app_id);
1400 sqlite3_exec(pkginfo_db, query, _pkgmgrinfo_validate_cb, (void *)&exist, &error_message)) {
1401 _LOGE("Don't execute query = %s error message = %s\n", query,
1403 ret = PMINFO_R_ERROR;
1404 sqlite3_free(query);
1411 sqlite3_free(query);
1412 query = sqlite3_mprintf("select package from package_app_info where app_id=%Q and app_disable='false'", rhs_app_id);
1414 sqlite3_exec(pkginfo_db, query, __cert_cb, (void *)info, &error_message)) {
1415 _LOGE("Don't execute query = %s error message = %s\n", query,
1417 ret = PMINFO_R_ERROR;
1418 sqlite3_free(query);
1421 rpkgid = strdup(info->pkgid);
1422 if (rpkgid == NULL) {
1423 _LOGE("Out of Memory\n");
1424 ret = PMINFO_R_ERROR;
1425 sqlite3_free(query);
1428 sqlite3_free(query);
1429 FREE_AND_NULL(info->pkgid);
1431 ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lpkgid, rpkgid, compare_result);
1434 sqlite3_free(error_message);
1435 sqlite3_close(pkginfo_db);
1437 FREE_AND_NULL(info->pkgid);
1438 FREE_AND_NULL(info);
1440 FREE_AND_NULL(lpkgid);
1441 FREE_AND_NULL(rpkgid);
1445 API int pkgmgrinfo_pkginfo_is_accessible(pkgmgrinfo_pkginfo_h handle, bool *accessible)
1447 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1448 retvm_if(accessible == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1454 API int pkgmgrinfo_pkginfo_is_removable(pkgmgrinfo_pkginfo_h handle, bool *removable)
1456 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1457 retvm_if(removable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1459 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1460 val = (char *)info->manifest_info->removable;
1462 if (strcasecmp(val, "true") == 0)
1464 else if (strcasecmp(val, "false") == 0)
1472 API int pkgmgrinfo_pkginfo_is_movable(pkgmgrinfo_pkginfo_h handle, bool *movable)
1474 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1475 retvm_if(movable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1478 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1480 val = (char *)info->manifest_info->installlocation;
1482 if (strcmp(val, "internal-only") == 0)
1484 else if (strcmp(val, "prefer-external") == 0)
1493 API int pkgmgrinfo_pkginfo_is_preload(pkgmgrinfo_pkginfo_h handle, bool *preload)
1495 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1496 retvm_if(preload == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1498 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1499 val = (char *)info->manifest_info->preload;
1501 if (strcasecmp(val, "true") == 0)
1503 else if (strcasecmp(val, "false") == 0)
1511 API int pkgmgrinfo_pkginfo_is_system(pkgmgrinfo_pkginfo_h handle, bool *system)
1513 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1514 retvm_if(system == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1517 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1518 val = (char *)info->manifest_info->system;
1520 if (strcasecmp(val, "true") == 0)
1522 else if (strcasecmp(val, "false") == 0)
1531 API int pkgmgrinfo_pkginfo_is_readonly(pkgmgrinfo_pkginfo_h handle, bool *readonly)
1533 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1534 retvm_if(readonly == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1536 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1537 val = (char *)info->manifest_info->readonly;
1539 if (strcasecmp(val, "true") == 0)
1541 else if (strcasecmp(val, "false") == 0)
1549 API int pkgmgrinfo_pkginfo_is_update(pkgmgrinfo_pkginfo_h handle, bool *update)
1551 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1552 retvm_if(update == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1555 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1556 val = (char *)info->manifest_info->update;
1558 if (strcasecmp(val, "true") == 0)
1560 else if (strcasecmp(val, "false") == 0)
1568 API int pkgmgrinfo_pkginfo_is_support_disable(pkgmgrinfo_pkginfo_h handle, bool *support_disable)
1570 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1571 retvm_if(support_disable == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1574 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1575 val = (char *)info->manifest_info->support_disable;
1577 if (strcasecmp(val, "true") == 0)
1578 *support_disable = 1;
1579 else if (strcasecmp(val, "false") == 0)
1580 *support_disable = 0;
1582 *support_disable = 1;
1587 API int pkgmgrinfo_pkginfo_is_mother_package(pkgmgrinfo_pkginfo_h handle, bool *mother_package)
1589 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1590 retvm_if(mother_package == NULL, PMINFO_R_EINVAL, "Argument supplied to hold return value is NULL\n");
1593 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1594 val = (char *)info->manifest_info->mother_package;
1596 if (strcasecmp(val, "true") == 0)
1597 *mother_package = 1;
1598 else if (strcasecmp(val, "false") == 0)
1599 *mother_package = 0;
1601 *mother_package = 1;
1606 API int pkgmgrinfo_pkginfo_destroy_pkginfo(pkgmgrinfo_pkginfo_h handle)
1608 retvm_if(handle == NULL, PMINFO_R_EINVAL, "pkginfo handle is NULL\n");
1609 pkgmgr_pkginfo_x *info = (pkgmgr_pkginfo_x *)handle;
1610 __cleanup_pkginfo(info);
1614 API int pkgmgrinfo_pkginfo_filter_create(pkgmgrinfo_pkginfo_filter_h *handle)
1616 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle output parameter is NULL\n");
1618 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)calloc(1, sizeof(pkgmgrinfo_filter_x));
1619 if (filter == NULL) {
1620 _LOGE("Out of Memory!!!");
1621 return PMINFO_R_ERROR;
1627 API int pkgmgrinfo_pkginfo_filter_destroy(pkgmgrinfo_pkginfo_filter_h handle)
1629 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1630 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1632 g_slist_foreach(filter->list, __destroy_each_node, NULL);
1633 g_slist_free(filter->list);
1635 FREE_AND_NULL(filter);
1640 API int pkgmgrinfo_pkginfo_filter_add_int(pkgmgrinfo_pkginfo_filter_h handle,
1641 const char *property, const int value)
1643 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1644 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1645 char buf[PKG_VALUE_STRING_LEN_MAX] = {'\0'};
1647 GSList *link = NULL;
1649 prop = _pminfo_pkginfo_convert_to_prop_int(property);
1650 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_INT ||
1651 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_INT) {
1652 _LOGE("Invalid Integer Property\n");
1653 return PMINFO_R_EINVAL;
1655 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1656 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1658 _LOGE("Out of Memory!!!\n");
1659 return PMINFO_R_ERROR;
1661 snprintf(buf, PKG_VALUE_STRING_LEN_MAX - 1, "%d", value);
1662 val = strndup(buf, PKG_VALUE_STRING_LEN_MAX - 1);
1664 _LOGE("Out of Memory\n");
1665 FREE_AND_NULL(node);
1666 return PMINFO_R_ERROR;
1670 /*If API is called multiple times for same property, we should override the previous values.
1671 Last value set will be used for filtering.*/
1672 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1674 filter->list = g_slist_delete_link(filter->list, link);
1675 filter->list = g_slist_append(filter->list, (gpointer)node);
1680 API int pkgmgrinfo_pkginfo_filter_add_bool(pkgmgrinfo_pkginfo_filter_h handle,
1681 const char *property, const bool value)
1683 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1684 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1686 GSList *link = NULL;
1688 prop = _pminfo_pkginfo_convert_to_prop_bool(property);
1689 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_BOOL ||
1690 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_BOOL) {
1691 _LOGE("Invalid Boolean Property\n");
1692 return PMINFO_R_EINVAL;
1694 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1695 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1697 _LOGE("Out of Memory!!!\n");
1698 return PMINFO_R_ERROR;
1701 val = strndup("('true','True')", 15);
1703 val = strndup("('false','False')", 17);
1705 _LOGE("Out of Memory\n");
1706 FREE_AND_NULL(node);
1707 return PMINFO_R_ERROR;
1711 /*If API is called multiple times for same property, we should override the previous values.
1712 Last value set will be used for filtering.*/
1713 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1715 filter->list = g_slist_delete_link(filter->list, link);
1716 filter->list = g_slist_append(filter->list, (gpointer)node);
1721 API int pkgmgrinfo_pkginfo_filter_add_string(pkgmgrinfo_pkginfo_filter_h handle,
1722 const char *property, const char *value)
1724 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1725 retvm_if(property == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1726 retvm_if(value == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1728 GSList *link = NULL;
1730 prop = _pminfo_pkginfo_convert_to_prop_str(property);
1731 if (prop < E_PMINFO_PKGINFO_PROP_PACKAGE_MIN_STR ||
1732 prop > E_PMINFO_PKGINFO_PROP_PACKAGE_MAX_STR) {
1733 _LOGE("Invalid String Property\n");
1734 return PMINFO_R_EINVAL;
1736 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1737 pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x*)calloc(1, sizeof(pkgmgrinfo_node_x));
1739 _LOGE("Out of Memory!!!\n");
1740 return PMINFO_R_ERROR;
1742 if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_AUTO) == 0)
1743 val = strndup("auto", PKG_STRING_LEN_MAX - 1);
1744 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_INTERNAL) == 0)
1745 val = strndup("internal-only", PKG_STRING_LEN_MAX - 1);
1746 else if (strcmp(value, PMINFO_PKGINFO_INSTALL_LOCATION_EXTERNAL) == 0)
1747 val = strndup("prefer-external", PKG_STRING_LEN_MAX - 1);
1748 else if (strcmp(value, "installed_internal") == 0)
1749 val = strndup("installed_internal", PKG_STRING_LEN_MAX - 1);
1750 else if (strcmp(value, "installed_external") == 0)
1751 val = strndup("installed_external", PKG_STRING_LEN_MAX - 1);
1753 val = strndup(value, PKG_STRING_LEN_MAX - 1);
1755 _LOGE("Out of Memory\n");
1756 FREE_AND_NULL(node);
1757 return PMINFO_R_ERROR;
1761 /*If API is called multiple times for same property, we should override the previous values.
1762 Last value set will be used for filtering.*/
1763 link = g_slist_find_custom(filter->list, (gconstpointer)node, __compare_func);
1765 filter->list = g_slist_delete_link(filter->list, link);
1766 filter->list = g_slist_append(filter->list, (gpointer)node);
1771 API int pkgmgrinfo_pkginfo_filter_count(pkgmgrinfo_pkginfo_filter_h handle, int *count)
1773 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1774 retvm_if(count == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1777 int filter_count = 0;
1779 char pkgid[MAX_QUERY_LEN] = {0,};
1780 char pre_pkgid[MAX_QUERY_LEN] = {0,};
1782 char *locale = NULL;
1783 char *condition = NULL;
1784 char query[MAX_QUERY_LEN] = {'\0'};
1785 char where[MAX_QUERY_LEN] = {'\0'};
1788 pkgmgr_pkginfo_x *node = NULL;
1789 pkgmgr_pkginfo_x *pkginfo = NULL;
1790 pkgmgr_pkginfo_x *list_pkginfo = NULL;
1791 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1793 sqlite3 *pkginfo_db = NULL;
1794 sqlite3_stmt *stmt = NULL;
1798 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
1799 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
1801 /*Start constructing query*/
1802 locale = __convert_system_locale_to_manifest_locale();
1803 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, DEFAULT_LOCALE, locale);
1805 /*Get where clause*/
1806 for (list = filter->list; list; list = g_slist_next(list)) {
1807 __get_filter_condition(list->data, &condition);
1809 strncat(where, condition, sizeof(where) - strlen(where) -1);
1810 where[sizeof(where) - 1] = '\0';
1811 FREE_AND_NULL(condition);
1813 if (g_slist_next(list)) {
1814 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1815 where[sizeof(where) - 1] = '\0';
1819 if (strstr(where, "package_info.package_disable") == NULL) {
1820 if (strlen(where) > 0) {
1821 strncat(where, " and package_info.package_disable IN ('false','False')", sizeof(where) - strlen(where) - 1);
1822 where[sizeof(where) - 1] = '\0';
1826 _LOGE("where = %s\n", where);
1827 if (strlen(where) > 0) {
1828 strncat(query, where, sizeof(query) - strlen(query) - 1);
1829 query[sizeof(query) - 1] = '\0';
1831 _LOGE("query = %s\n", query);
1833 list_pkginfo = calloc(1, sizeof(pkgmgr_pkginfo_x));
1834 tryvm_if(list_pkginfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1836 ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
1837 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1840 ret = sqlite3_step(stmt);
1841 if(ret == SQLITE_ROW) {
1843 memset(pkgid, 0, MAX_QUERY_LEN);
1844 strncpy(pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1846 if (strlen(pre_pkgid) != 0) {
1847 if (strcmp(pre_pkgid, pkgid) == 0) {
1848 __update_localed_label_for_list(stmt, list_pkginfo);
1850 memset(pre_pkgid, 0, MAX_QUERY_LEN);
1851 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1855 memset(pre_pkgid, 0, MAX_QUERY_LEN);
1856 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1859 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1862 __get_pkginfo_for_list(stmt, list_pkginfo);
1868 LISTHEAD(list_pkginfo, node);
1870 for(node = node->next ; node ; node = node->next) {
1872 ret = __pkginfo_check_installed_storage(pkginfo);
1878 *count = filter_count;
1882 FREE_AND_NULL(locale);
1883 sqlite3_finalize(stmt);
1884 sqlite3_close(pkginfo_db);
1886 __cleanup_list_pkginfo(list_pkginfo, node);
1891 API int pkgmgrinfo_pkginfo_filter_foreach_pkginfo(pkgmgrinfo_pkginfo_filter_h handle,
1892 pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
1894 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1895 retvm_if(pkg_cb == NULL, PMINFO_R_EINVAL, "Filter handle input parameter is NULL\n");
1896 char *locale = NULL;
1897 char *condition = NULL;
1898 char query[MAX_QUERY_LEN] = {'\0'};
1899 char where[MAX_QUERY_LEN] = {'\0'};
1903 char pkgid[MAX_QUERY_LEN] = {0,};
1904 char pre_pkgid[MAX_QUERY_LEN] = {0,};
1906 pkgmgr_pkginfo_x *node = NULL;
1907 pkgmgr_pkginfo_x *pkginfo = NULL;
1908 pkgmgr_pkginfo_x *list_pkginfo = NULL;
1909 pkgmgrinfo_filter_x *filter = (pkgmgrinfo_filter_x*)handle;
1911 sqlite3 *pkginfo_db = NULL;
1912 sqlite3_stmt *stmt = NULL;
1915 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
1916 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
1918 /*Start constructing query*/
1919 locale = __convert_system_locale_to_manifest_locale();
1920 retvm_if(locale == NULL, PMINFO_R_ERROR, "locale is NULL");
1921 snprintf(query, MAX_QUERY_LEN - 1, FILTER_QUERY_LIST_PACKAGE, DEFAULT_LOCALE, locale);
1923 /*Get where clause*/
1924 for (list = filter->list; list; list = g_slist_next(list)) {
1925 __get_filter_condition(list->data, &condition);
1927 strncat(where, condition, sizeof(where) - strlen(where) -1);
1928 where[sizeof(where) - 1] = '\0';
1930 FREE_AND_NULL(condition);
1932 if (g_slist_next(list)) {
1933 strncat(where, " and ", sizeof(where) - strlen(where) - 1);
1934 where[sizeof(where) - 1] = '\0';
1938 if (strstr(where, "package_info.package_disable") == NULL) {
1939 if (strlen(where) > 0) {
1940 strncat(where, " and package_info.package_disable IN ('false','False')", sizeof(where) - strlen(where) - 1);
1941 where[sizeof(where) - 1] = '\0';
1945 _LOGE("where = %s\n", where);
1947 if (strlen(where) > 0) {
1948 strncat(query, where, sizeof(query) - strlen(query) - 1);
1949 query[sizeof(query) - 1] = '\0';
1951 _LOGE("query = %s\n", query);
1953 list_pkginfo = calloc(1, sizeof(pkgmgr_pkginfo_x));
1954 tryvm_if(list_pkginfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
1956 ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
1957 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
1960 ret = sqlite3_step(stmt);
1961 if(ret == SQLITE_ROW) {
1963 memset(pkgid, 0, MAX_QUERY_LEN);
1964 strncpy(pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1966 if (strlen(pre_pkgid) != 0) {
1967 if (strcmp(pre_pkgid, pkgid) == 0) {
1968 __update_localed_label_for_list(stmt, list_pkginfo);
1970 memset(pre_pkgid, 0, MAX_QUERY_LEN);
1971 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1975 memset(pre_pkgid, 0, MAX_QUERY_LEN);
1976 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1979 strncpy(pre_pkgid, (const char *)sqlite3_column_text(stmt, 0), MAX_QUERY_LEN - 1);
1982 __get_pkginfo_for_list(stmt, list_pkginfo);
1988 LISTHEAD(list_pkginfo, node);
1990 for(node = node->next ; node ; node = node->next) {
1992 pkginfo->locale = strdup(locale);
1994 ret = __pkginfo_check_installed_storage(pkginfo);
1998 ret = pkg_cb( (void *)pkginfo, user_data);
2005 FREE_AND_NULL(locale);
2006 sqlite3_finalize(stmt);
2007 sqlite3_close(pkginfo_db);
2008 __cleanup_list_pkginfo(list_pkginfo, node);
2013 API int pkgmgrinfo_pkginfo_privilege_filter_foreach(const char *privilege,
2014 pkgmgrinfo_pkg_list_cb pkg_list_cb, void *user_data)
2016 retvm_if(privilege == NULL, PMINFO_R_EINVAL, "privilege is NULL\n");
2017 retvm_if(pkg_list_cb == NULL, PMINFO_R_EINVAL, "callback function is NULL\n");
2019 int ret = PMINFO_R_OK;
2022 sqlite3 *pkginfo_db = NULL;
2023 sqlite3_stmt *stmt = NULL;
2025 pkgmgr_pkginfo_x *node = NULL;
2026 pkgmgr_pkginfo_x *pkginfo = NULL;
2027 pkgmgr_pkginfo_x *list_pkginfo = NULL;
2030 ret = db_util_open(MANIFEST_DB, &pkginfo_db, 0);
2031 retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "db_util_open[%s] failed!", MANIFEST_DB);
2033 /*Start constructing query*/
2034 query = sqlite3_mprintf("select package_info.* from package_info LEFT OUTER JOIN package_privilege_info " \
2035 "ON package_privilege_info.package=package_info.package " \
2036 "where package_privilege_info.privilege=%Q and package_info.package_disable='false'", privilege);
2039 ret = sqlite3_prepare_v2(pkginfo_db, query, strlen(query), &stmt, NULL);
2040 tryvm_if(ret != PMINFO_R_OK, ret = PMINFO_R_ERROR, "sqlite3_prepare_v2 failed[%s]\n", query);
2042 /*calloc pkginfo_x*/
2043 list_pkginfo = (pkgmgr_pkginfo_x *)calloc(1, sizeof(pkgmgr_pkginfo_x));
2044 tryvm_if(list_pkginfo == NULL, ret = PMINFO_R_ERROR, "Out of Memory!!!\n");
2048 ret = sqlite3_step(stmt);
2049 if(ret == SQLITE_ROW) {
2050 __get_pkginfo_for_list(stmt, list_pkginfo);
2056 LISTHEAD(list_pkginfo, node);
2058 for(node = node->next; node ; node = node->next) {
2060 ret = pkg_list_cb( (void *)pkginfo, user_data);
2067 sqlite3_free(query);
2068 sqlite3_finalize(stmt);
2069 sqlite3_close(pkginfo_db);
2071 __cleanup_list_pkginfo(list_pkginfo, node);