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.
30 #include <libxml/parser.h>
31 #include <libxml/xmlreader.h>
32 #include <libxml/xmlschemas.h>
38 #include <sys/types.h>
43 #include "pkgmgr-info.h"
44 #include "pkgmgr_parser.h"
45 #include "pkgmgr_parser_internal.h"
46 #include "pkgmgr_parser_db.h"
47 #include "pkgmgr_parser_db_util.h"
48 #include "pkgmgr_parser_plugin.h"
50 #include "pkgmgrinfo_debug.h"
51 #include "pkgmgr_parser_feature.h"
56 #define LOG_TAG "PKGMGR_PARSER"
58 #define MAX_QUERY_LEN 4096
60 sqlite3 *pkgmgr_parser_db;
61 sqlite3 *pkgmgr_cert_db;
63 #define QUERY_CREATE_TABLE_DISABLED_PACKAGE_INFO "create table if not exists disabled_package_info " \
64 "(package text primary key not null, " \
65 "package_type text DEFAULT 'rpm', " \
66 "package_version text, " \
67 "install_location text, " \
68 "package_size text, " \
69 "package_removable text DEFAULT 'true', " \
70 "package_preload text DEFAULT 'false', " \
71 "package_readonly text DEFAULT 'false', " \
72 "package_update text DEFAULT 'false', " \
73 "package_appsetting text DEFAULT 'false', " \
74 "package_nodisplay text DEFAULT 'false', " \
75 "package_system text DEFAULT 'false', " \
76 "author_name text, " \
77 "author_email text, " \
79 "installed_time text," \
80 "installed_storage text," \
81 "storeclient_id text," \
87 #define QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_INFO "create table if not exists disabled_package_app_info " \
88 "(app_id text primary key not null, " \
89 "app_component text, " \
91 "app_nodisplay text DEFAULT 'false', " \
93 "app_onboot text DEFAULT 'false', " \
94 "app_multiple text DEFAULT 'false', " \
95 "app_autorestart text DEFAULT 'false', " \
96 "app_taskmanage text DEFAULT 'false', " \
97 "app_enabled text DEFAULT 'true', " \
98 "app_hwacceleration text DEFAULT 'use-system-setting', " \
99 "app_screenreader text DEFAULT 'use-system-setting', " \
100 "app_mainapp text, " \
101 "app_recentimage text, " \
102 "app_launchcondition text, " \
103 "app_indicatordisplay text DEFAULT 'true', " \
104 "app_portraitimg text, " \
105 "app_landscapeimg text, " \
106 "app_guestmodevisibility text DEFAULT 'true', " \
107 "app_permissiontype text DEFAULT 'normal', " \
108 "app_preload text DEFAULT 'false', " \
109 "app_submode text DEFAULT 'false', " \
110 "app_submode_mainid text, " \
111 "app_installed_storage text, " \
112 "component_type text, " \
113 "package text not null, " \
114 "FOREIGN KEY(package) " \
115 "REFERENCES package_info(package) " \
118 #define QUERY_CREATE_TABLE_DISABLED_PACKAGE_LOCALIZED_INFO "create table if not exists disabled_package_localized_info " \
119 "(package text not null, " \
120 "package_locale text DEFAULT 'No Locale', " \
121 "package_label text, " \
122 "package_icon text, " \
123 "package_description text, " \
124 "package_license text, " \
126 "PRIMARY KEY(package, package_locale), " \
127 "FOREIGN KEY(package) " \
128 "REFERENCES package_info(package) " \
131 #define QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_LOCALIZED_INFO "create table if not exists disabled_package_app_localized_info " \
132 "(app_id text not null, " \
133 "app_locale text DEFAULT 'No Locale', " \
136 "package text not null, " \
137 "PRIMARY KEY(app_id,app_locale) " \
138 "FOREIGN KEY(app_id) " \
139 "REFERENCES package_app_info(app_id) " \
142 #define QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_APP_CATEGORY "create table if not exists disabled_package_app_app_category " \
143 "(app_id text not null, " \
144 "category text not null, " \
145 "package text not null, " \
146 "PRIMARY KEY(app_id,category) " \
147 "FOREIGN KEY(app_id) " \
148 "REFERENCES package_app_info(app_id) " \
152 #define QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_APP_METADATA "create table if not exists disabled_package_app_app_metadata " \
153 "(app_id text not null, " \
154 "md_key text not null, " \
155 "md_value text not null, " \
156 "package text not null, " \
157 "PRIMARY KEY(app_id, md_key, md_value) " \
158 "FOREIGN KEY(app_id) " \
159 "REFERENCES package_app_info(app_id) " \
162 int __init_tables_for_wearable(void)
166 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_DISABLED_PACKAGE_INFO);
168 _LOGD("package pkg reserve info DB initialization failed\n");
172 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_INFO);
174 _LOGD("package pkg reserve info DB initialization failed\n");
178 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_DISABLED_PACKAGE_LOCALIZED_INFO);
180 _LOGD("package pkg reserve info DB initialization failed\n");
184 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_LOCALIZED_INFO);
186 _LOGD("package pkg reserve info DB initialization failed\n");
190 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_APP_CATEGORY);
192 _LOGD("package pkg reserve info DB initialization failed\n");
196 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_DISABLED_PACKAGE_APP_APP_METADATA);
199 _LOGD("package pkg reserve info DB initialization failed\n");
206 static int __insert_disabled_ui_mainapp_info(manifest_x *mfx)
208 uiapplication_x *up = mfx->uiapplication;
213 query = sqlite3_mprintf("update disabled_package_app_info set app_mainapp=%Q where app_id=%Q", up->mainapp, up->appid);
215 ret = __exec_query(query);
218 _LOGD("Package UiApp Info DB Insert Failed\n");
221 if (strcasecmp(up->mainapp, "True") == 0) {
222 FREE_AND_NULL(mfx->mainapp_id);
223 mfx->mainapp_id = strdup(up->appid);
229 if (mfx->mainapp_id == NULL){
230 if (mfx->uiapplication && mfx->uiapplication->appid) {
231 query = sqlite3_mprintf("update disabled_package_app_info set app_mainapp='true' where app_id=%Q", mfx->uiapplication->appid);
233 _LOGD("Not valid appid\n");
237 ret = __exec_query(query);
240 _LOGD("Package UiApp Info DB Insert Failed\n");
244 free((void *)mfx->uiapplication->mainapp);
245 mfx->uiapplication->mainapp= strdup("true");
246 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
249 query = sqlite3_mprintf("update disabled_package_info set mainapp_id=%Q where package=%Q", mfx->mainapp_id, mfx->package);
250 ret = __exec_query(query);
253 _LOGD("Package Info DB update Failed\n");
260 static int __insert_disabled_uiapplication_info(manifest_x *mfx)
262 uiapplication_x *up = mfx->uiapplication;
267 query = sqlite3_mprintf("insert into disabled_package_app_info(app_id, app_component, app_exec, app_ambient_support, app_nodisplay, app_type, app_onboot, " \
268 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
269 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
270 "app_preload, app_submode, app_submode_mainid, app_installed_storage, component_type, package) " \
271 "values(%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
278 PKGMGR_PARSER_EMPTY_STR,
280 PKGMGR_PARSER_EMPTY_STR,
286 __get_str(up->recentimage),
288 up->indicatordisplay,
289 __get_str(up->portraitimg),
290 __get_str(up->landscapeimg),
291 up->guestmode_visibility,
295 __get_str(up->submode_mainid),
296 mfx->installed_storage,
300 ret = __exec_query(query);
303 _LOGD("Package UiApp Info DB Insert Failed\n");
311 static void __insert_disabled_uiapplication_locale_info(gpointer data, gpointer userdata)
318 uiapplication_x *up = (uiapplication_x*)userdata;
319 label_x *lbl = up->label;
320 icon_x *icn = up->icon;
322 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
325 query = sqlite3_mprintf("insert into disabled_package_app_localized_info(app_id, app_locale, " \
326 "app_label, app_icon, package) values " \
327 "(%Q, %Q, %Q, %Q, %Q)", up->appid, (char*)data,
328 label, icon, up->package);
329 ret = __exec_query(query);
332 _LOGD("Package UiApp Localized Info DB Insert failed\n");
334 /*insert ui app locale info to pkg locale to get mainapp data */
335 if (strcasecmp(up->mainapp, "true")==0) {
336 char *update_query = NULL;
337 update_query = sqlite3_mprintf("insert into disabled_package_localized_info(package, package_locale, " \
338 "package_label, package_icon, package_description, package_license, package_author) values " \
339 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
344 PKGMGR_PARSER_EMPTY_STR,
345 PKGMGR_PARSER_EMPTY_STR,
346 PKGMGR_PARSER_EMPTY_STR);
348 ret = __exec_query_no_msg(update_query);
349 sqlite3_free(update_query);
352 update_query = sqlite3_mprintf("update package_localized_info set package_icon=%Q " \
353 "where package=%Q and package_locale=%Q", icon, up->package, (char*)data);
354 ret = __exec_query_no_msg(update_query);
355 sqlite3_free(update_query);
360 static int __insert_disabled_uiapplication_appcategory_info(manifest_x *mfx)
362 uiapplication_x *up = mfx->uiapplication;
363 category_x *ct = NULL;
371 query = sqlite3_mprintf("insert into disabled_package_app_app_category(app_id, category, package) " \
372 "values(%Q, %Q, %Q)",\
373 up->appid, ct->name, up->package);
374 ret = __exec_query(query);
377 _LOGD("Package UiApp Category Info DB Insert Failed\n");
387 static int __insert_disabled_uiapplication_appmetadata_info(manifest_x *mfx)
389 uiapplication_x *up = mfx->uiapplication;
390 metadata_x *md = NULL;
399 query = sqlite3_mprintf("insert into disabled_package_app_app_metadata(app_id, md_key, md_value, package) " \
400 "values(%Q, %Q, %Q, %Q)",\
401 up->appid, md->key, md->value, up->package);
402 ret = __exec_query(query);
405 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
416 static void __insert_disabled_pkglocale_info(gpointer data, gpointer userdata)
421 char *description = NULL;
422 char *license = NULL;
426 manifest_x *mfx = (manifest_x *)userdata;
427 label_x *lbl = mfx->label;
428 license_x *lcn = mfx->license;
429 icon_x *icn = mfx->icon;
430 description_x *dcn = mfx->description;
431 author_x *ath = mfx->author;
433 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
434 if (!label && !description && !icon && !license && !author)
437 query = sqlite3_mprintf("insert into disabled_package_localized_info(package, package_locale, " \
438 "package_label, package_icon, package_description, package_license, package_author) values " \
439 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
444 __get_str(description),
448 ret = __exec_query(query);
451 _LOGD("Package Localized Info DB Insert failed\n");
454 static int __insert_disabled_pkg_info_in_db(manifest_x *mfx)
456 label_x *lbl = mfx->label;
457 license_x *lcn = mfx->license;
458 icon_x *icn = mfx->icon;
459 description_x *dcn = mfx->description;
460 author_x *ath = mfx->author;
461 uiapplication_x *up = mfx->uiapplication;
464 char root[MAX_QUERY_LEN] = { '\0' };
468 const char *auth_name = NULL;
469 const char *auth_email = NULL;
470 const char *auth_href = NULL;
472 GList *pkglocale = NULL;
473 GList *applocale = NULL;
477 auth_name = ath->text;
479 auth_email = ath->email;
481 auth_href = ath->href;
484 /*Insert in the package_info DB*/
486 type = strdup(mfx->type);
488 type = strdup("rpm");
489 /*Insert in the package_info DB*/
491 path = strdup(mfx->root_path);
493 if (type && strcmp(type,"rpm")==0)
494 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package);
496 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
500 query = sqlite3_mprintf("insert into disabled_package_info(package, package_type, package_version, install_location, package_size, " \
501 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
502 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
503 "values(%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
507 __get_str(mfx->installlocation),
508 __get_str(mfx->package_size),
514 mfx->nodisplay_setting,
516 __get_str(auth_name),
517 __get_str(auth_email),
518 __get_str(auth_href),
520 mfx->installed_storage,
521 __get_str(mfx->storeclient_id),
523 __get_str(mfx->package_url),
525 __get_str(mfx->csc_path));
527 ret = __exec_query(query);
530 _LOGD("Package Info DB Insert Failed\n");
551 ret = __insert_disabled_ui_mainapp_info(mfx);
555 /*Insert the package locale*/
556 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
557 /*remove duplicated data in pkglocale*/
558 __trimfunc(pkglocale);
560 /*Insert the app locale info */
563 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
567 /*remove duplicated data in applocale*/
568 __trimfunc(applocale);
570 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
572 /*g_list_foreach(applocale, __printfunc, NULL);*/
574 g_list_foreach(pkglocale, __insert_disabled_pkglocale_info, (gpointer)mfx);
576 /*native app locale info*/
577 up = mfx->uiapplication;
580 g_list_foreach(applocale, __insert_disabled_uiapplication_locale_info, (gpointer)up);
584 g_list_free(pkglocale);
586 g_list_free(applocale);
589 /*Insert in the package_app_info DB*/
590 ret = __insert_disabled_uiapplication_info(mfx);
594 /*Insert in the package_app_app_category DB*/
595 ret = __insert_disabled_uiapplication_appcategory_info(mfx);
599 /*Insert in the package_app_app_metadata DB*/
600 ret = __insert_disabled_uiapplication_appmetadata_info(mfx);
607 static int __delete_disabled_pkg_info_from_pkgid(const char *pkgid)
612 /*Delete from Package Info DB*/
613 query = sqlite3_mprintf("delete from disabled_package_info where package=%Q", pkgid);
614 ret = __exec_query(query);
615 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
617 /*Delete from Package Localized Info*/
619 query = sqlite3_mprintf("delete from disabled_package_localized_info where package=%Q", pkgid);
620 ret = __exec_query(query);
621 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Localized Info DB Delete Failed\n");
623 /*Delete from app Info*/
625 query = sqlite3_mprintf("delete from disabled_package_app_info where package=%Q", pkgid);
626 ret = __exec_query(query);
627 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "app Info DB Delete Failed\n");
629 /*Delete from app Localized Info*/
631 query = sqlite3_mprintf("delete from disabled_package_app_localized_info where package=%Q", pkgid);
632 ret = __exec_query(query);
633 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "app Localized Info DB Delete Failed\n");
635 /*Delete from app category Info*/
637 query = sqlite3_mprintf("delete from disabled_package_app_app_category where package=%Q", pkgid);
638 ret = __exec_query(query);
639 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "app category Info DB Delete Failed\n");
641 /*Delete from app metadata Info*/
643 query = sqlite3_mprintf("delete from disabled_package_app_app_metadata where package=%Q", pkgid);
644 ret = __exec_query(query);
645 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "app metadata Info DB Delete Failed\n");
652 API int pkgmgr_parser_insert_disabled_pkg_info_in_db(manifest_x *mfx)
655 _LOGD("manifest pointer is NULL\n");
659 ret = pkgmgr_parser_check_and_create_db();
661 _LOGD("Failed to open DB\n");
664 ret = pkgmgr_parser_initialize_db();
667 /*Begin transaction*/
668 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
669 if (ret != SQLITE_OK) {
670 _LOGD("Failed to begin transaction[%d]\n", ret);
674 _LOGD("Transaction Begin\n");
675 ret = __insert_disabled_pkg_info_in_db(mfx);
677 _LOGE("Insert into DB failed. Rollback now\n");
678 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
679 if (ret != SQLITE_OK)
680 _LOGE("ROLLBACK is fail after insert_disabled_pkg_info_in_db\n");
685 /*Commit transaction*/
686 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
687 if (ret != SQLITE_OK) {
688 _LOGE("Failed to commit transaction. Rollback now\n");
689 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
690 if (ret != SQLITE_OK)
691 _LOGE("Failed to commit transaction. Rollback now\n");
696 _LOGD("Transaction Commit and End\n");
698 pkgmgr_parser_close_db();
702 API int pkgmgr_parser_delete_disabled_pkgid_info_from_db(const char *pkgid)
704 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
709 ret = pkgmgr_parser_check_and_create_db();
710 retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
712 /*Begin transaction*/
713 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
714 if (ret != SQLITE_OK) {
715 _LOGE("Failed to begin transaction\n");
720 _LOGD("Start to Delete pkgid[%s] info from db\n", pkgid);
723 ret = __delete_disabled_pkg_info_from_pkgid(pkgid);
725 _LOGD("Delete from DB failed. Rollback now\n");
726 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
727 if (ret != SQLITE_OK)
728 _LOGE("Failed to begin transaction\n");
732 /*Commit transaction*/
733 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
734 if (ret != SQLITE_OK) {
735 _LOGD("Failed to commit transaction, Rollback now\n");
736 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
737 if (ret != SQLITE_OK)
738 _LOGE("Failed to commit transaction, Rollback now\n");
745 pkgmgr_parser_close_db();
749 API int pkgmgr_parser_insert_disabled_pkg(const char *pkgid, char *const tagv[])
751 retvm_if(pkgid == NULL, PM_PARSER_R_ERROR, "argument supplied is NULL");
753 char *manifest = NULL;
754 manifest_x *mfx = NULL;
757 _LOGD("parsing manifest for installation: %s\n", pkgid);
759 manifest = pkgmgr_parser_get_manifest_file(pkgid);
760 if (manifest == NULL) {
761 _LOGE("can not get the manifest.xml\n");
766 mfx = pkgmgr_parser_process_manifest_xml(manifest);
767 retvm_if(mfx == NULL, PM_PARSER_R_ERROR, "argument supplied is NULL");
769 _LOGD("Parsing Finished\n");
771 __add_preload_info(mfx, manifest);
773 _LOGD("Added preload infomation\n");
775 FREE_AND_NULL(manifest);
777 ret = pkgmgr_parser_insert_disabled_pkg_info_in_db(mfx);
778 retvm_if(ret == PM_PARSER_R_ERROR, PM_PARSER_R_ERROR, "DB Insert failed");
780 _LOGD("DB Insert Success\n");
782 pkgmgr_parser_free_manifest_xml(mfx);
783 _LOGD("Free Done\n");
786 return PM_PARSER_R_OK;
789 API int pkgmgr_parser_delete_disabled_pkg(const char *pkgid, char *const tagv[])
791 retvm_if(pkgid == NULL, PM_PARSER_R_ERROR, "argument supplied is NULL");
795 _LOGD("Start uninstall for pkgid : delete pkgid[%s]\n", pkgid);
797 /* delete pkgmgr db */
798 ret = pkgmgr_parser_delete_disabled_pkgid_info_from_db(pkgid);
800 _LOGD("DB pkgid info Delete failed\n");
802 _LOGD("DB pkgid info Delete Success\n");
804 _LOGD("Finish : uninstall for pkgid\n");
806 return PM_PARSER_R_OK;