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.
26 #include <sys/types.h>
33 #include "pkgmgr_parser_internal.h"
34 #include "pkgmgr_parser_db.h"
36 #include "pkgmgrinfo_debug.h"
37 #include "pkgmgrinfo_type.h"
42 #define LOG_TAG "PKGMGR_PARSER"
44 #define MAX_QUERY_LEN 4096
45 #define MAX_PACKAGE_STR_SIZE 512
46 #define MAX_ALIAS_INI_ENTRY (2 * MAX_PACKAGE_STR_SIZE) + 1
47 #define USR_APPSVC_ALIAS_INI "/usr/share/appsvc/alias.ini"
48 #define OPT_APPSVC_ALIAS_INI "/opt/usr/share/appsvc/alias.ini"
49 #define MANIFEST_DB "/opt/dbspace/.pkgmgr_parser.db"
50 typedef int (*sqlite_query_callback)(void *data, int ncols, char **coltxt, char **colname);
52 sqlite3 *pkgmgr_parser_db;
53 sqlite3 *pkgmgr_cert_db;
56 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
57 "(package text primary key not null, " \
58 "package_type text DEFAULT 'rpm', " \
59 "package_version text, " \
60 "install_location text, " \
61 "package_size text, " \
62 "package_removable text DEFAULT 'true', " \
63 "package_preload text DEFAULT 'false', " \
64 "package_readonly text DEFAULT 'false', " \
65 "package_update text DEFAULT 'false', " \
66 "package_appsetting text DEFAULT 'false', " \
67 "package_nodisplay text DEFAULT 'false', " \
68 "package_system text DEFAULT 'false', " \
69 "author_name text, " \
70 "author_email text, " \
72 "installed_time text," \
73 "installed_storage text," \
74 "storeclient_id text," \
79 "package_support_disable text DEFAULT 'false', " \
80 "package_mother_package text DEFAULT 'false', " \
81 "package_disable text DEFAULT 'false', " \
82 "package_support_mode text, " \
83 "package_hash text, " \
84 "package_reserve1 text," \
85 "package_reserve2 text," \
86 "package_reserve3 text," \
87 "package_reserve4 text," \
88 "package_reserve5 text)"
90 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
91 "(package text not null, " \
92 "package_locale text DEFAULT 'No Locale', " \
93 "package_label text, " \
94 "package_icon text, " \
95 "package_description text, " \
96 "package_license text, " \
98 "PRIMARY KEY(package, package_locale), " \
99 "FOREIGN KEY(package) " \
100 "REFERENCES package_info(package) " \
103 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
104 "(package text not null, " \
105 "privilege text not null, " \
106 "PRIMARY KEY(package, privilege) " \
107 "FOREIGN KEY(package) " \
108 "REFERENCES package_info(package) " \
111 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
112 "(app_id text primary key not null, " \
113 "app_component text, " \
115 "app_ambient_support text DEFAULT 'false', " \
116 "app_nodisplay text DEFAULT 'false', " \
118 "app_onboot text DEFAULT 'false', " \
119 "app_multiple text DEFAULT 'false', " \
120 "app_autorestart text DEFAULT 'false', " \
121 "app_taskmanage text DEFAULT 'false', " \
122 "app_enabled text DEFAULT 'true', " \
123 "app_hwacceleration text DEFAULT 'default', " \
124 "app_screenreader text DEFAULT 'use-system-setting', " \
125 "app_mainapp text, " \
126 "app_recentimage text, " \
127 "app_launchcondition text, " \
128 "app_indicatordisplay text DEFAULT 'true', " \
129 "app_portraitimg text, " \
130 "app_landscapeimg text, " \
131 "app_effectimage_type text, " \
132 "app_guestmodevisibility text DEFAULT 'true', " \
133 "app_permissiontype text DEFAULT 'normal', " \
134 "app_preload text DEFAULT 'false', " \
135 "app_submode text DEFAULT 'false', " \
136 "app_submode_mainid text, " \
137 "app_installed_storage text, " \
138 "app_process_pool text DEFAULT 'false', " \
139 "app_multi_instance text DEFAULT 'false', " \
140 "app_multi_instance_mainid text, " \
141 "app_multi_window text DEFAULT 'false', " \
142 "app_support_disable text DEFAULT 'false', " \
143 "app_disable text DEFAULT 'false', " \
144 "app_ui_gadget text DEFAULT 'false', " \
145 "app_removable text DEFAULT 'false', " \
146 "app_support_mode text, " \
147 "app_support_feature text, " \
148 "component_type text, " \
149 "package text not null, " \
150 "app_package_type text DEFAULT 'rpm', " \
151 "app_package_system text, " \
152 "app_package_installed_time text, " \
153 "app_reserve1 text, " \
154 "app_reserve2 text, " \
155 "app_reserve3 text, " \
156 "app_reserve4 text, " \
157 "app_reserve5 text, " \
158 "FOREIGN KEY(package) " \
159 "REFERENCES package_info(package) " \
162 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
163 "(app_id text not null, " \
164 "app_locale text DEFAULT 'No Locale', " \
167 "PRIMARY KEY(app_id,app_locale) " \
168 "FOREIGN KEY(app_id) " \
169 "REFERENCES package_app_info(app_id) " \
172 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
173 "(app_id text not null, " \
175 "app_icon_section text, " \
176 "app_icon_resolution text, " \
177 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
178 "FOREIGN KEY(app_id) " \
179 "REFERENCES package_app_info(app_id) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
183 "(app_id text not null, " \
184 "app_locale text DEFAULT 'No Locale', " \
185 "app_image_section text, " \
187 "PRIMARY KEY(app_id,app_image_section) " \
188 "FOREIGN KEY(app_id) " \
189 "REFERENCES package_app_info(app_id) " \
192 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
193 "(app_id text not null, " \
194 "app_control text not null, " \
195 "PRIMARY KEY(app_id,app_control) " \
196 "FOREIGN KEY(app_id) " \
197 "REFERENCES package_app_info(app_id) " \
200 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
201 "(app_id text not null, " \
202 "operation text not null, " \
203 "uri_scheme text, " \
205 "subapp_name text, " \
206 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
207 "FOREIGN KEY(app_id) " \
208 "REFERENCES package_app_info(app_id) " \
211 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
212 "(app_id text not null, " \
213 "category text not null, " \
214 "PRIMARY KEY(app_id,category) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
220 "(app_id text not null, " \
221 "md_key text not null, " \
222 "md_value text not null, " \
223 "PRIMARY KEY(app_id, md_key, md_value) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
229 "(app_id text not null, " \
230 "pm_type text not null, " \
231 "pm_value text not null, " \
232 "PRIMARY KEY(app_id, pm_type, pm_value) " \
233 "FOREIGN KEY(app_id) " \
234 "REFERENCES package_app_info(app_id) " \
237 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
238 "(app_id text not null, " \
239 "data_share_path text not null, " \
240 "data_share_allowed text not null, " \
241 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
242 "FOREIGN KEY(app_id) " \
243 "REFERENCES package_app_info(app_id) " \
246 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
247 "(app_id text not null, " \
248 "data_share_request text not null, " \
249 "PRIMARY KEY(app_id,data_share_request) " \
250 "FOREIGN KEY(app_id) " \
251 "REFERENCES package_app_info(app_id) " \
254 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
255 "(cert_info text not null, " \
256 "cert_id integer, " \
257 "cert_ref_count integer, " \
258 "PRIMARY KEY(cert_id)) "
260 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
261 "(package text not null, " \
262 "author_root_cert integer, " \
263 "author_im_cert integer, " \
264 "author_signer_cert integer, " \
265 "dist_root_cert integer, " \
266 "dist_im_cert integer, " \
267 "dist_signer_cert integer, " \
268 "dist2_root_cert integer, " \
269 "dist2_im_cert integer, " \
270 "dist2_signer_cert integer, " \
271 "PRIMARY KEY(package)) "
273 #define QUERY_CREATE_TABLE_PACKAGE_PKG_RESERVE "create table if not exists package_pkg_reserve " \
274 "(pkgid text not null, " \
280 "PRIMARY KEY(pkgid)) "
282 #define QUERY_CREATE_TABLE_PACKAGE_APP_RESERVE "create table if not exists package_app_reserve " \
283 "(app_id text not null, " \
289 "PRIMARY KEY(app_id)) "
291 #define QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO "create table if not exists package_plugin_info " \
292 "(pkgid text primary key not null, " \
293 "enabled_plugin INTEGER DEFAULT 0)"
295 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
296 "(app_id text not null, " \
297 "providerid text not null, " \
298 "access text not null, " \
299 "type text not null, " \
300 "PRIMARY KEY(app_id, providerid, access, type) " \
301 "FOREIGN KEY(app_id) " \
302 "REFERENCES package_app_info(app_id) " \
305 #define QUERY_CREATE_TABLE_PACKAGE_APP_ALIASID "create table if not exists package_app_aliasid" \
306 "(app_id text primary key not null, "\
307 "alias_id text not null)"
309 static int __insert_uiapplication_info(manifest_x *mfx);
310 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
311 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
312 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
313 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
314 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
315 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
316 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
317 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
318 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
319 static int __delete_manifest_info_from_pkgid(const char *pkgid);
320 static int __delete_manifest_info_from_appid(const char *appid);
321 static int __insert_manifest_info_in_db(manifest_x *mfx);
322 static int __delete_manifest_info_from_db(manifest_x *mfx);
323 static int __delete_appinfo_from_db(char *db_table, const char *appid);
324 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
325 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
327 static void __str_trim(char *input)
329 char *trim_str = input;
334 while (*input != 0) {
335 if (!isspace(*input)) {
346 const char *__get_str(const char *str)
350 return PKGMGR_PARSER_EMPTY_STR;
356 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
360 if (access(db_path, F_OK) == 0) {
362 db_util_open(db_path, &handle,
363 DB_UTIL_REGISTER_HOOK_METHOD);
364 if (ret != SQLITE_OK) {
365 _LOGD("connect db [%s] failed!\n",
372 _LOGD("%s DB does not exists. Create one!!\n", db_path);
375 db_util_open(db_path, &handle,
376 DB_UTIL_REGISTER_HOOK_METHOD);
378 if (ret != SQLITE_OK) {
379 _LOGD("connect db [%s] failed!\n", db_path);
386 int __evaluate_query(sqlite3 *db_handle, char *query)
388 sqlite3_stmt* p_statement;
390 result = sqlite3_prepare_v2(db_handle, query, strlen(query), &p_statement, NULL);
391 if (result != SQLITE_OK) {
392 _LOGE("Sqlite3 error [%d] : <%s> preparing <%s> querry\n", result, sqlite3_errmsg(db_handle), query);
396 result = sqlite3_step(p_statement);
397 if (result != SQLITE_DONE) {
398 _LOGE("Sqlite3 error [%d] : <%s> executing <%s> statement\n", result, sqlite3_errmsg(db_handle), query);
402 result = sqlite3_finalize(p_statement);
403 if (result != SQLITE_OK) {
404 _LOGE("Sqlite3 error [%d] : <%s> finalizing <%s> statement\n", result, sqlite3_errmsg(db_handle), query);
410 int __initialize_db(sqlite3 *db_handle, char *db_query)
412 return (__evaluate_query(db_handle, db_query));
415 int __exec_query(char *query)
417 return (__evaluate_query(pkgmgr_parser_db, query));
420 int __exec_query_no_msg(char *query)
422 char *error_message = NULL;
424 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
425 sqlite3_free(error_message);
428 sqlite3_free(error_message);
432 static int __exec_db_query(sqlite3 *db, char *query, sqlite_query_callback callback, void *data)
434 char *error_message = NULL;
436 sqlite3_exec(db, query, callback, data, &error_message)) {
437 _LOGE("Don't execute query = %s error message = %s\n", query,
439 sqlite3_free(error_message);
442 sqlite3_free(error_message);
446 GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
452 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
458 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
464 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
470 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
476 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
483 static GList *__create_icon_list(GList *locale, icon_x *icn)
488 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
494 static GList *__create_image_list(GList *locale, image_x *image)
499 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
505 void __trimfunc(GList* trim_list)
507 char *trim_data = NULL;
511 list = g_list_first(trim_list);
514 trim_data = (char *)list->data;
517 if (strcmp(trim_data, prev) == 0) {
518 trim_list = g_list_remove(trim_list, trim_data);
519 list = g_list_first(trim_list);
528 list = g_list_next(list);
532 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
534 if (a == NULL || b == NULL)
536 if (strcmp((char*)a, (char*)b) == 0)
538 if (strcmp((char*)a, (char*)b) < 0)
540 if (strcmp((char*)a, (char*)b) > 0)
545 void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
546 char **label, char **license, char **icon, char **description, char **author)
551 if (strcmp(lbl->lang, (char *)data) == 0) {
552 *label = (char*)lbl->text;
561 if (strcmp(lcn->lang, (char *)data) == 0) {
562 *license = (char*)lcn->text;
570 if (icn->section == NULL) {
572 if (strcmp(icn->lang, (char *)data) == 0) {
573 *icon = (char*)icn->text;
583 if (strcmp(dcn->lang, (char *)data) == 0) {
584 *description = (char*)dcn->text;
593 if (strcmp(ath->lang, (char *)data) == 0) {
594 *author = (char*)ath->text;
603 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
608 if (strcmp(icn->section, (char *)data) == 0) {
609 *icon = (char*)icn->text;
610 *resolution = (char*)icn->resolution;
618 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
622 if (image->section) {
623 if (strcmp(image->section, (char *)data) == 0) {
624 *lang = (char*)image->lang;
625 *img = (char*)image->text;
633 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
638 char *description = NULL;
639 char *license = NULL;
643 manifest_x *mfx = (manifest_x *)userdata;
644 label_x *lbl = mfx->label;
645 license_x *lcn = mfx->license;
646 icon_x *icn = mfx->icon;
647 description_x *dcn = mfx->description;
648 author_x *ath = mfx->author;
650 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
651 if (!label && !description && !icon && !license && !author)
654 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
655 "package_label, package_icon, package_description, package_license, package_author) values " \
656 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
661 __get_str(description),
665 ret = __exec_query(query);
667 _LOGD("Package Localized Info DB Insert failed\n");
672 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
674 uiapplication_x *up = mfx->uiapplication;
675 datacontrol_x *dc = NULL;
681 dc = up->datacontrol;
683 query = sqlite3_mprintf("insert into package_app_data_control(app_id, providerid, access, type) " \
684 "values(%Q, %Q, %Q, %Q)", \
690 ret = __exec_query(query);
693 _LOGD("Package UiApp Data Control DB Insert Failed\n");
703 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
710 uiapplication_x *up = (uiapplication_x*)userdata;
711 label_x *lbl = up->label;
712 icon_x *icn = up->icon;
714 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
718 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
719 "app_label, app_icon) values " \
720 "(%Q, %Q, %Q, %Q)", up->appid, (char*)data,
721 __get_str(label), __get_str(icon));
722 ret = __exec_query(query);
724 _LOGD("Package UiApp Localized Info DB Insert failed\n");
728 /*insert ui app locale info to pkg locale to get mainapp data */
729 if (strcasecmp(up->mainapp, "true")==0) {
730 char *update_query = NULL;
731 update_query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
732 "package_label, package_icon, package_description, package_license, package_author) values " \
733 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
738 PKGMGR_PARSER_EMPTY_STR,
739 PKGMGR_PARSER_EMPTY_STR,
740 PKGMGR_PARSER_EMPTY_STR);
742 ret = __exec_query_no_msg(update_query);
743 sqlite3_free(update_query);
746 update_query = sqlite3_mprintf("update package_localized_info set package_icon=%Q " \
747 "where package=%Q and package_locale=%Q", icon, up->package, (char*)data);
748 ret = __exec_query_no_msg(update_query);
749 sqlite3_free(update_query);
754 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
758 char *resolution = NULL;
761 uiapplication_x *up = (uiapplication_x*)userdata;
762 icon_x *icn = up->icon;
764 __extract_icon_data(data, icn, &icon, &resolution);
765 if (!icon && !resolution)
768 query = sqlite3_mprintf("insert into package_app_icon_section_info(app_id, " \
769 "app_icon, app_icon_section, app_icon_resolution) values " \
770 "(%Q, %Q, %Q, %Q)", up->appid,
771 icon, (char*)data, resolution);
773 ret = __exec_query(query);
775 _LOGD("Package UiApp Localized Info DB Insert failed\n");
780 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
787 uiapplication_x *up = (uiapplication_x*)userdata;
788 image_x *image = up->image;
790 __extract_image_data(data, image, &lang, &img);
794 query = sqlite3_mprintf("insert into package_app_image_info(app_id, app_locale, " \
795 "app_image_section, app_image) values " \
796 "(%Q, %Q, %Q, %Q)", up->appid, lang, (char*)data, img);
798 ret = __exec_query(query);
800 _LOGD("Package UiApp image Info DB Insert failed\n");
805 static int __insert_ui_mainapp_info(manifest_x *mfx)
807 uiapplication_x *up = mfx->uiapplication;
812 query = sqlite3_mprintf("update package_app_info set app_mainapp=%Q where app_id=%Q", up->mainapp, up->appid);
814 ret = __exec_query(query);
817 _LOGD("Package UiApp Info DB Insert Failed\n");
820 if (strcasecmp(up->mainapp, "True") == 0) {
821 FREE_AND_NULL(mfx->mainapp_id);
822 mfx->mainapp_id = strdup(up->appid);
828 if (mfx->mainapp_id == NULL){
829 if (mfx->uiapplication && mfx->uiapplication->appid) {
830 query = sqlite3_mprintf("update package_app_info set app_mainapp='true' where app_id=%Q", mfx->uiapplication->appid);
832 _LOGD("Not valid appid\n");
836 ret = __exec_query(query);
839 _LOGD("Package UiApp Info DB Insert Failed\n");
843 FREE_AND_NULL(mfx->uiapplication->mainapp);
844 mfx->uiapplication->mainapp= strdup("true");
845 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
848 query = sqlite3_mprintf("update package_info set mainapp_id=%Q where package=%Q", mfx->mainapp_id, mfx->package);
849 ret = __exec_query(query);
852 _LOGD("Package Info DB update Failed\n");
858 /* _PRODUCT_LAUNCHING_ENHANCED_
859 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
861 static int __insert_uiapplication_info(manifest_x *mfx)
863 uiapplication_x *up = mfx->uiapplication;
869 type = strdup(mfx->type);
871 type = strdup("rpm");
875 query = sqlite3_mprintf("insert into package_app_info(app_id, app_component, app_exec, app_ambient_support, app_nodisplay, app_type, app_onboot, " \
876 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
877 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_effectimage_type, app_guestmodevisibility, app_permissiontype, "\
878 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, app_multi_instance, app_multi_instance_mainid, app_multi_window, app_support_disable, "\
879 "app_ui_gadget, app_removable, app_support_mode, app_support_feature, component_type, package, "\
880 "app_package_type, app_package_system, app_package_installed_time"\
882 "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, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q)",\
897 __get_str(up->recentimage),
899 up->indicatordisplay,
900 __get_str(up->portraitimg),
901 __get_str(up->landscapeimg),
902 __get_str(up->effectimage_type),
903 up->guestmode_visibility,
907 __get_str(up->submode_mainid),
908 mfx->installed_storage,
911 __get_str(up->multi_instance_mainid),
913 mfx->support_disable,
925 ret = __exec_query(query);
928 _LOGD("Package UiApp Info DB Insert Failed\n");
938 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
940 uiapplication_x *up = mfx->uiapplication;
941 category_x *ct = NULL;
949 query = sqlite3_mprintf("insert into package_app_app_category(app_id, category) " \
951 up->appid, ct->name);
952 ret = __exec_query(query);
955 _LOGD("Package UiApp Category Info DB Insert Failed\n");
965 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
967 uiapplication_x *up = mfx->uiapplication;
968 metadata_x *md = NULL;
977 query = sqlite3_mprintf("insert into package_app_app_metadata(app_id, md_key, md_value) " \
978 "values(%Q, %Q, %Q)",\
979 up->appid, md->key, __get_str(md->value));
980 ret = __exec_query(query);
983 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
994 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
996 uiapplication_x *up = mfx->uiapplication;
997 permission_x *pm = NULL;
1002 pm = up->permission;
1005 query = sqlite3_mprintf("insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1006 "values(%Q, %Q, %Q)",\
1007 up->appid, pm->type, pm->value);
1008 ret = __exec_query(query);
1009 sqlite3_free(query);
1011 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1021 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1025 char *buftemp = NULL;
1027 uiapplication_x *up = mfx->uiapplication;
1029 buf = (char *)calloc(1, BUFMAX);
1030 retvm_if(!buf, PMINFO_R_ERROR, "Malloc Failed\n");
1032 buftemp = (char *)calloc(1, BUFMAX);
1033 tryvm_if(!buftemp, ret = PMINFO_R_ERROR, "Malloc Failed\n");
1035 for(; up; up=up->next) {
1037 appsvc_x *asvc = NULL;
1038 operation_x *op = NULL;
1041 subapp_x *sub = NULL;
1042 const char *operation = NULL;
1043 const char *mime = NULL;
1044 const char *uri = NULL;
1045 const char *subapp = NULL;
1047 memset(buf, '\0', BUFMAX);
1048 memset(buftemp, '\0', BUFMAX);
1051 while(asvc != NULL) {
1052 op = asvc->operation;
1055 operation = op->name;
1074 strncpy(buftemp, buf, BUFMAX);
1075 snprintf(buf, BUFMAX, "%s;", buftemp);
1078 strncpy(buftemp, buf, BUFMAX);
1079 snprintf(buf, BUFMAX, "%s%s|%s|%s|%s", buftemp, operation?operation:"NULL", uri?uri:"NULL", mime?mime:"NULL", subapp?subapp:"NULL");
1080 // _LOGD("buf[%s]\n", buf);
1085 } while(ui != NULL);
1089 }while(sub != NULL);
1101 query= sqlite3_mprintf("insert into package_app_app_control(app_id, app_control) values(%Q, %Q)", up->appid, buf);
1102 ret = __exec_query(query);
1104 _LOGD("Package UiApp app_control DB Insert Failed\n");
1106 sqlite3_free(query);
1112 FREE_AND_NULL(buftemp);
1117 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1119 uiapplication_x *up = mfx->uiapplication;
1120 appsvc_x *asvc = NULL;
1121 operation_x *op = NULL;
1124 subapp_x *sub = NULL;
1127 const char *operation = NULL;
1128 const char *mime = NULL;
1129 const char *uri = NULL;
1130 const char *subapp = NULL;
1136 op = asvc->operation;
1140 operation = op->name;
1157 query = sqlite3_mprintf("insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1158 "values(%Q, %Q, %Q, %Q, %Q)",\
1165 ret = __exec_query(query);
1166 sqlite3_free(query);
1168 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1174 } while(ui != NULL);
1178 }while(sub != NULL);
1194 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1196 uiapplication_x *up = mfx->uiapplication;
1197 datashare_x *ds = NULL;
1198 request_x *rq = NULL;
1209 query = sqlite3_mprintf("insert into package_app_share_request(app_id, data_share_request) " \
1211 up->appid, rq->text);
1212 ret = __exec_query(query);
1213 sqlite3_free(query);
1215 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1227 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1229 uiapplication_x *up = mfx->uiapplication;
1230 datashare_x *ds = NULL;
1231 define_x *df = NULL;
1232 allowed_x *al = NULL;
1246 query = sqlite3_mprintf("insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1247 "values(%Q, %Q, %Q)",\
1248 up->appid, df->path, al->text);
1249 ret = __exec_query(query);
1250 sqlite3_free(query);
1252 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1266 static int __insert_manifest_info_in_db(manifest_x *mfx)
1268 label_x *lbl = mfx->label;
1269 license_x *lcn = mfx->license;
1270 icon_x *icn = mfx->icon;
1271 description_x *dcn = mfx->description;
1272 author_x *ath = mfx->author;
1273 uiapplication_x *up = mfx->uiapplication;
1274 uiapplication_x *up_icn = mfx->uiapplication;
1275 uiapplication_x *up_image = mfx->uiapplication;
1276 privileges_x *pvs = NULL;
1277 privilege_x *pv = NULL;
1279 char root[MAX_QUERY_LEN] = { '\0' };
1283 const char *auth_name = NULL;
1284 const char *auth_email = NULL;
1285 const char *auth_href = NULL;
1287 GList *pkglocale = NULL;
1288 GList *applocale = NULL;
1289 GList *appicon = NULL;
1290 GList *appimage = NULL;
1294 auth_name = ath->text;
1296 auth_email = ath->email;
1298 auth_href = ath->href;
1301 /*Insert in the package_info DB*/
1303 type = strdup(mfx->type);
1305 type = strdup("rpm");
1306 /*Insert in the package_info DB*/
1307 if (mfx->root_path) {
1308 path = strdup(mfx->root_path);
1310 if (type && strcmp(type,"rpm")==0) {
1311 snprintf(root, MAX_QUERY_LEN - 1, "/opt/share/packages/%s.xml", mfx->package);
1312 if (access(root, F_OK) == 0) {
1313 memset(root, '\0', MAX_QUERY_LEN);
1314 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1316 memset(root, '\0', MAX_QUERY_LEN);
1317 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->package);
1320 snprintf(root, MAX_QUERY_LEN - 1, "/opt/usr/apps/%s", mfx->package);
1323 path = strdup(root);
1326 query = sqlite3_mprintf("insert into package_info(package, package_type, package_version, install_location, package_size, " \
1327 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1328 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path, package_support_disable, " \
1329 "package_mother_package, package_support_mode, package_reserve1, package_reserve2, package_hash) " \
1330 "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, %Q)",\
1334 __get_str(mfx->installlocation),
1335 __get_str(mfx->package_size),
1341 mfx->nodisplay_setting,
1343 __get_str(auth_name),
1344 __get_str(auth_email),
1345 __get_str(auth_href),
1346 mfx->installed_time,
1347 mfx->installed_storage,
1348 __get_str(mfx->storeclient_id),
1350 __get_str(mfx->package_url),
1352 __get_str(mfx->csc_path),
1353 mfx->support_disable,
1354 mfx->mother_package,
1356 __get_str(mfx->support_reset),
1361 ret = __exec_query(query);
1362 sqlite3_free(query);
1364 _LOGD("Package Info DB Insert Failed\n");
1365 FREE_AND_NULL(type);
1366 FREE_AND_NULL(path);
1370 FREE_AND_NULL(type);
1371 FREE_AND_NULL(path);
1373 /*Insert in the package_privilege_info DB*/
1374 pvs = mfx->privileges;
1375 while (pvs != NULL) {
1376 pv = pvs->privilege;
1377 while (pv != NULL) {
1378 query = sqlite3_mprintf("insert into package_privilege_info(package, privilege) " \
1380 mfx->package, pv->text);
1381 ret = __exec_query(query);
1382 sqlite3_free(query);
1384 _LOGD("Package Privilege Info DB Insert Failed\n");
1392 ret = __insert_ui_mainapp_info(mfx);
1396 /*Insert the package locale*/
1397 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1398 /*remove duplicated data in pkglocale*/
1399 __trimfunc(pkglocale);
1401 /*Insert the app locale info */
1404 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1407 /*remove duplicated data in applocale*/
1408 __trimfunc(applocale);
1410 /*Insert the app icon info */
1411 while(up_icn != NULL)
1413 appicon = __create_icon_list(appicon, up_icn->icon);
1414 up_icn = up_icn->next;
1416 /*remove duplicated data in appicon*/
1417 __trimfunc(appicon);
1419 /*Insert the image info */
1420 while(up_image != NULL)
1422 appimage = __create_image_list(appimage, up_image->image);
1423 up_image = up_image->next;
1425 /*remove duplicated data in appimage*/
1426 __trimfunc(appimage);
1428 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1430 /*g_list_foreach(applocale, __printfunc, NULL);*/
1432 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1434 /*native app locale info*/
1435 up = mfx->uiapplication;
1438 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1442 /*app icon locale info*/
1443 up_icn = mfx->uiapplication;
1444 while(up_icn != NULL)
1446 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1447 up_icn = up_icn->next;
1451 up_image = mfx->uiapplication;
1452 while(up_image != NULL)
1454 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1455 up_image = up_image->next;
1458 g_list_free(pkglocale);
1460 g_list_free(applocale);
1462 g_list_free(appicon);
1464 g_list_free(appimage);
1468 /*Insert in the package_app_info DB*/
1469 ret = __insert_uiapplication_info(mfx);
1473 /*Insert in the package_app_app_control DB*/
1474 ret = __insert_uiapplication_appcontrol_info(mfx);
1478 /*Insert in the package_app_app_category DB*/
1479 ret = __insert_uiapplication_appcategory_info(mfx);
1483 /*Insert in the package_app_app_metadata DB*/
1484 ret = __insert_uiapplication_appmetadata_info(mfx);
1488 /*Insert in the package_app_app_permission DB*/
1489 ret = __insert_uiapplication_apppermission_info(mfx);
1493 /*Insert in the package_app_app_svc DB*/
1494 ret = __insert_uiapplication_appsvc_info(mfx);
1498 /*Insert in the package_app_share_allowed DB*/
1499 ret = __insert_uiapplication_share_allowed_info(mfx);
1503 /*Insert in the package_app_share_request DB*/
1504 ret = __insert_uiapplication_share_request_info(mfx);
1508 /*Insert in the package_app_data_control DB*/
1509 ret = __insert_uiapplication_datacontrol_info(mfx);
1517 static int __update_pkg_info_for_disable(const char *pkgid, bool disable)
1522 /*Update from package info*/
1523 query = sqlite3_mprintf("update package_info set package_disable=%Q where package=%Q", disable?"true":"false", pkgid);
1524 ret = __exec_query(query);
1525 sqlite3_free(query);
1526 retvm_if(ret < 0, PMINFO_R_ERROR, "__exec_query() failed.\n");
1528 /*Update from app info*/
1529 query = sqlite3_mprintf("update package_app_info set app_disable=%Q where package=%Q", disable?"true":"false", pkgid);
1530 ret = __exec_query(query);
1531 sqlite3_free(query);
1532 retvm_if(ret < 0, PMINFO_R_ERROR, "__exec_query() failed.\n");
1537 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1540 char *query = sqlite3_mprintf("delete from %Q where app_id=%Q", db_table, appid);
1541 ret = __exec_query(query);
1542 sqlite3_free(query);
1544 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1551 static int __delete_manifest_info_from_db(manifest_x *mfx)
1554 uiapplication_x *up = mfx->uiapplication;
1556 /* Delete package info DB */
1557 ret = __delete_manifest_info_from_pkgid(mfx->package);
1558 retvm_if(ret < 0, PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
1560 while (up != NULL) {
1561 ret = __delete_manifest_info_from_appid(up->appid);
1562 retvm_if(ret < 0, PMINFO_R_ERROR, "App Info DB Delete Failed\n");
1570 static int __delete_appsvc_db(const char *appid)
1573 void *lib_handle = NULL;
1574 int (*appsvc_operation) (const char *);
1576 if ((lib_handle = dlopen(LIBAPPSVC_PATH, RTLD_LAZY)) == NULL) {
1577 _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAPPSVC_PATH);
1580 if ((appsvc_operation =
1581 dlsym(lib_handle, "appsvc_unset_defapp")) == NULL || dlerror() != NULL) {
1582 _LOGE("can not find symbol \n");
1586 ret = appsvc_operation(appid);
1590 dlclose(lib_handle);
1595 static int __delete_appsvc_info_from_db(manifest_x *mfx)
1598 uiapplication_x *uiapplication = mfx->uiapplication;
1600 for(; uiapplication; uiapplication=uiapplication->next) {
1601 ret = __delete_appsvc_db(uiapplication->appid);
1603 _LOGE("can not remove_appsvc_db\n");
1609 static int __delete_manifest_info_from_pkgid(const char *pkgid)
1614 /*Delete from cert table*/
1615 ret = pkgmgrinfo_delete_certinfo(pkgid);
1616 retvm_if(ret < 0, PMINFO_R_ERROR, "Cert Info DB Delete Failed\n");
1618 /*Delete from Package Info DB*/
1619 query = sqlite3_mprintf("delete from package_info where package=%Q", pkgid);
1620 ret = __exec_query(query);
1621 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Info DB Delete Failed\n");
1623 /*Delete from Package Localized Info*/
1624 sqlite3_free(query);
1625 query = sqlite3_mprintf("delete from package_localized_info where package=%Q", pkgid);
1626 ret = __exec_query(query);
1627 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Localized Info DB Delete Failed\n");
1629 /*Delete from Package Privilege Info*/
1630 sqlite3_free(query);
1631 query = sqlite3_mprintf("delete from package_privilege_info where package=%Q", pkgid);
1632 ret = __exec_query(query);
1633 tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "Package Privilege Info DB Delete Failed\n");
1636 sqlite3_free(query);
1641 static int __delete_manifest_info_from_appid(const char *appid)
1645 ret = __delete_appinfo_from_db("package_app_info", appid);
1646 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1648 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1649 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1651 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1652 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1654 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1655 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1657 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1658 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1660 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1661 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1663 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1664 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1666 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1667 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1669 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1670 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1672 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1673 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1675 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1676 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1678 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1679 retvm_if(ret < 0, PMINFO_R_ERROR, "Fail to get handle");
1685 static int __update_preload_condition_in_db()
1690 query = sqlite3_mprintf("update package_info set package_preload='true'");
1692 ret = __exec_query(query);
1693 sqlite3_free(query);
1695 _LOGD("Package preload_condition update failed\n");
1700 int pkgmgr_parser_initialize_db()
1704 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
1706 _LOGD("package info DB initialization failed\n");
1709 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
1711 _LOGD("package localized info DB initialization failed\n");
1714 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
1716 _LOGD("package app app privilege DB initialization failed\n");
1719 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
1721 _LOGD("package app info DB initialization failed\n");
1724 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
1726 _LOGD("package app localized info DB initialization failed\n");
1729 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
1731 _LOGD("package app icon localized info DB initialization failed\n");
1734 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
1736 _LOGD("package app image info DB initialization failed\n");
1739 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
1741 _LOGD("package app app control DB initialization failed\n");
1744 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
1746 _LOGD("package app app category DB initialization failed\n");
1749 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
1751 _LOGD("package app app category DB initialization failed\n");
1754 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
1756 _LOGD("package app app permission DB initialization failed\n");
1759 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
1761 _LOGD("package app app svc DB initialization failed\n");
1764 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
1766 _LOGD("package app share allowed DB initialization failed\n");
1769 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
1771 _LOGD("package app share request DB initialization failed\n");
1774 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
1776 _LOGD("package app data control DB initialization failed\n");
1780 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
1782 _LOGD("package cert info DB initialization failed\n");
1785 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
1787 _LOGD("package cert index info DB initialization failed\n");
1791 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PKG_RESERVE);
1793 _LOGD("package pkg reserve info DB initialization failed\n");
1796 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_RESERVE);
1798 _LOGD("package pkg reserve info DB initialization failed\n");
1802 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PLUGIN_INFO);
1804 _LOGD("package pkg reserve info DB initialization failed\n");
1807 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ALIASID);
1809 _LOGD("package app aliasId DB initialization failed\n");
1812 #ifdef _APPFW_FEATURE_PROFILE_WEARABLE
1813 ret = __init_tables_for_wearable();
1815 _LOGD("package pkg reserve info DB initialization failed\n");
1823 int pkgmgr_parser_check_and_create_db()
1827 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, PKGMGR_PARSER_DB_FILE);
1829 _LOGD("Manifest DB creation Failed\n");
1833 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, PKGMGR_CERT_DB_FILE);
1835 _LOGD("Cert DB creation Failed\n");
1841 void pkgmgr_parser_close_db()
1843 sqlite3_close(pkgmgr_parser_db);
1844 sqlite3_close(pkgmgr_cert_db);
1847 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
1850 _LOGD("manifest pointer is NULL\n");
1854 ret = pkgmgr_parser_check_and_create_db();
1856 _LOGD("Failed to open DB\n");
1859 ret = pkgmgr_parser_initialize_db();
1862 /*Begin transaction*/
1863 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1864 if (ret != SQLITE_OK) {
1865 _LOGD("Failed to begin transaction[%d]\n", ret);
1869 _LOGD("Transaction Begin\n");
1870 ret = __insert_manifest_info_in_db(mfx);
1872 _LOGD("Insert into DB failed. Rollback now\n");
1873 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1874 if (ret != SQLITE_OK)
1875 _LOGD("ROLLBACK is fail after insert_disabled_pkg_info_in_db\n");
1880 /*Commit transaction*/
1881 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1882 if (ret != SQLITE_OK) {
1883 _LOGD("Failed to commit transaction. Rollback now\n");
1884 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1885 if (ret != SQLITE_OK)
1886 _LOGE("Failed to commit transaction. Rollback now\n");
1891 _LOGD("Transaction Commit and End\n");
1893 pkgmgr_parser_close_db();
1897 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
1900 _LOGD("manifest pointer is NULL\n");
1904 ret = pkgmgr_parser_check_and_create_db();
1906 _LOGD("Failed to open DB\n");
1909 ret = pkgmgr_parser_initialize_db();
1913 /*Begin transaction*/
1914 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1915 if (ret != SQLITE_OK) {
1916 _LOGD("Failed to begin transaction\n");
1920 _LOGD("Transaction Begin\n");
1921 ret = __delete_manifest_info_from_db(mfx);
1923 _LOGD("Delete from DB failed. Rollback now\n");
1924 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1925 if (ret != SQLITE_OK)
1926 _LOGD("Failed to commit transaction. Rollback now\n");
1929 ret = __insert_manifest_info_in_db(mfx);
1931 _LOGD("Insert into DB failed. Rollback now\n");
1932 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1933 if (ret != SQLITE_OK)
1934 _LOGD("Failed to commit transaction. Rollback now\n");
1938 /*Commit transaction*/
1939 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1940 if (ret != SQLITE_OK) {
1941 _LOGD("Failed to commit transaction. Rollback now\n");
1942 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1943 if (ret != SQLITE_OK)
1944 _LOGD("Failed to commit transaction. Rollback now\n");
1949 _LOGD("Transaction Commit and End\n");
1951 pkgmgr_parser_close_db();
1955 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
1958 _LOGD("manifest pointer is NULL\n");
1962 ret = pkgmgr_parser_check_and_create_db();
1964 _LOGD("Failed to open DB\n");
1967 /*Begin transaction*/
1968 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
1969 if (ret != SQLITE_OK) {
1970 _LOGD("Failed to begin transaction\n");
1974 _LOGD("Transaction Begin\n");
1975 ret = __delete_manifest_info_from_db(mfx);
1977 _LOGD("Delete from DB failed. Rollback now\n");
1978 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1979 if (ret != SQLITE_OK)
1980 _LOGE("Failed to commit transaction, Rollback now\n");
1984 /*Commit transaction*/
1985 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
1986 if (ret != SQLITE_OK) {
1987 _LOGD("Failed to commit transaction, Rollback now\n");
1988 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
1989 if (ret != SQLITE_OK)
1990 _LOGE("Failed to commit transaction, Rollback now\n");
1996 ret = __delete_appsvc_info_from_db(mfx);
1998 _LOGD("Removing appsvc_db failed\n");
2000 _LOGD("Removing appsvc_db Success\n");
2002 _LOGD("Transaction Commit and End\n");
2004 pkgmgr_parser_close_db();
2008 API int pkgmgr_parser_update_preload_info_in_db()
2011 ret = pkgmgr_parser_check_and_create_db();
2013 _LOGD("Failed to open DB\n");
2016 /*Begin transaction*/
2017 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2018 if (ret != SQLITE_OK) {
2019 _LOGD("Failed to begin transaction\n");
2023 _LOGD("Transaction Begin\n");
2024 ret = __update_preload_condition_in_db();
2026 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2027 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2028 if (ret != SQLITE_OK)
2029 _LOGE("Failed to commit transaction, Rollback now\n");
2033 /*Commit transaction*/
2034 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2035 if (ret != SQLITE_OK) {
2036 _LOGD("Failed to commit transaction, Rollback now\n");
2037 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2038 if (ret != SQLITE_OK)
2039 _LOGE("Failed to commit transaction, Rollback now\n");
2044 _LOGD("Transaction Commit and End\n");
2046 pkgmgr_parser_close_db();
2050 API int pkgmgr_parser_delete_pkgid_info_from_db(const char *pkgid)
2052 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2057 ret = pkgmgr_parser_check_and_create_db();
2058 retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
2060 /*Begin transaction*/
2061 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2062 if (ret != SQLITE_OK) {
2063 _LOGE("Failed to begin transaction\n");
2068 _LOGD("Start to Delete pkgid[%s] info from db\n", pkgid);
2071 ret = __delete_manifest_info_from_pkgid(pkgid);
2073 _LOGD("Delete from DB failed. Rollback now\n");
2074 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2075 if (ret != SQLITE_OK)
2076 _LOGE("Failed to begin transaction\n");
2080 /*Commit transaction*/
2081 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2082 if (ret != SQLITE_OK) {
2083 _LOGD("Failed to commit transaction, Rollback now\n");
2084 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2085 if (ret != SQLITE_OK)
2086 _LOGE("Failed to commit transaction, Rollback now\n");
2093 pkgmgr_parser_close_db();
2097 API int pkgmgr_parser_delete_appid_info_from_db(const char *appid)
2099 retvm_if(appid == NULL, PMINFO_R_ERROR, "argument supplied is NULL");
2104 ret = pkgmgr_parser_check_and_create_db();
2105 retvm_if(ret < 0, PMINFO_R_ERROR, "Failed to open DB\n");
2107 /*Begin transaction*/
2108 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2109 if (ret != SQLITE_OK) {
2110 _LOGE("Failed to begin transaction\n");
2115 _LOGD("Start to Delete appid[%s] info from db\n", appid);
2117 /*delete appinfo db*/
2118 ret = __delete_manifest_info_from_appid(appid);
2120 _LOGE("Fail to delete appid[%s] info from pkgmgr db\n", appid);
2122 /*delete appsvc db*/
2123 ret = __delete_appsvc_db(appid);
2125 _LOGE("Fail to delete appid[%s] info from appsvc db\n", appid);
2127 /*Commit transaction*/
2128 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2129 if (ret != SQLITE_OK) {
2130 _LOGD("Failed to commit transaction, Rollback now\n");
2131 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2132 if (ret != SQLITE_OK)
2133 _LOGE("Failed to commit transaction, Rollback now\n");
2140 pkgmgr_parser_close_db();
2144 API int pkgmgr_parser_update_enabled_pkg_info_in_db(const char *pkgid)
2146 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL.");
2150 _LOGD("pkgmgr_parser_update_enabled_pkg_info_in_db(%s)\n", pkgid);
2153 ret = pkgmgr_parser_check_and_create_db();
2154 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_parser_check_and_create_db(%s) failed.\n", pkgid);
2156 /*Begin transaction*/
2157 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2158 if (ret != SQLITE_OK) {
2159 _LOGE("sqlite3_exec(BEGIN EXCLUSIVE) failed.\n");
2165 ret = __update_pkg_info_for_disable(pkgid, false);
2167 _LOGD("__update_pkg_info_for_disable(%s) failed.\n", pkgid);
2168 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2169 if (ret != SQLITE_OK)
2170 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2174 /*Commit transaction*/
2175 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2176 if (ret != SQLITE_OK) {
2177 _LOGD("sqlite3_exec(COMMIT) failed.\n");
2178 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2179 if (ret != SQLITE_OK)
2180 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2187 pkgmgr_parser_close_db();
2191 API int pkgmgr_parser_update_disabled_pkg_info_in_db(const char *pkgid)
2193 retvm_if(pkgid == NULL, PMINFO_R_ERROR, "pkgid is NULL.");
2197 _LOGD("pkgmgr_parser_update_disabled_pkg_info_in_db(%s)\n", pkgid);
2200 ret = pkgmgr_parser_check_and_create_db();
2201 retvm_if(ret < 0, PMINFO_R_ERROR, "pkgmgr_parser_check_and_create_db(%s) failed.\n", pkgid);
2203 /*Begin transaction*/
2204 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2205 if (ret != SQLITE_OK) {
2206 _LOGE("sqlite3_exec(BEGIN EXCLUSIVE) failed.\n");
2212 ret = __update_pkg_info_for_disable(pkgid, true);
2214 _LOGD("__update_pkg_info_for_disable(%s) failed.\n", pkgid);
2215 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2216 if (ret != SQLITE_OK)
2217 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2221 /*Commit transaction*/
2222 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2223 if (ret != SQLITE_OK) {
2224 _LOGD("sqlite3_exec(COMMIT) failed.\n");
2225 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2226 if (ret != SQLITE_OK)
2227 _LOGE("sqlite3_exec(ROLLBACK) failed.\n");
2234 pkgmgr_parser_close_db();
2238 int pkgmgr_parser_insert_app_aliasid_info_in_db(void)
2240 FILE *ini_file = NULL;
2242 char *tizen_id = NULL;
2243 char *app_id = NULL;
2245 char buf[ MAX_ALIAS_INI_ENTRY ] = {0};
2246 int ret = PM_PARSER_R_OK;
2247 sqlite3 *pkgmgr_db = NULL;
2250 /*Open the alias.ini file*/
2251 ini_file = fopen(USR_APPSVC_ALIAS_INI,"r");
2253 /*Open the pkgmgr DB*/
2254 ret = db_util_open_with_options(MANIFEST_DB, &pkgmgr_db, SQLITE_OPEN_READWRITE, NULL);
2255 if (ret != SQLITE_OK) {
2256 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2258 return PM_PARSER_R_ERROR;
2261 /*Begin Transaction*/
2262 ret = sqlite3_exec(pkgmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2263 tryvm_if(ret != SQLITE_OK, ret = PM_PARSER_R_ERROR, "Failed to begin transaction");
2265 _LOGD("Transaction Begin\n");
2267 /*delete all the previous entries from package_app_aliasid tables*/
2268 query = sqlite3_mprintf("delete from package_app_aliasid");
2269 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2270 sqlite3_free(query);
2271 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR,"sqlite exec failed to delete entries from package_app_aliasid!!");
2273 while ( fgets ( buf, sizeof(buf), ini_file ) != NULL ) /* read a line */
2275 match = strstr(buf,"=");
2278 /*format of alias.ini entry is 'tizen_app_id=alias_id'*/
2279 /*get the tizen appid id*/
2280 len = strlen(buf)-strlen(match);
2281 tizen_id = malloc(len + 1);
2282 tryvm_if(tizen_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2283 memset(tizen_id,'\0',len +1);
2284 strncpy(tizen_id,buf,len);
2286 __str_trim(tizen_id);
2288 /*get the corresponding alias id*/
2289 len = strlen(match)-1;
2290 app_id = malloc(len + 1);
2291 tryvm_if(app_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2292 memset(app_id,'\0',len + 1);
2293 strncpy(app_id, match + 1, len);
2297 /* Insert the data into DB*/
2298 query = sqlite3_mprintf("insert into package_app_aliasid(app_id, alias_id) values(%Q ,%Q)",tizen_id,app_id);
2299 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2300 sqlite3_free(query);
2301 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR, "sqlite exec failed to insert entries into package_app_aliasid table!!");
2303 FREE_AND_NULL(tizen_id);
2304 FREE_AND_NULL(app_id);
2305 memset(buf,'\0',MAX_ALIAS_INI_ENTRY);
2308 /*Commit transaction*/
2309 ret = sqlite3_exec(pkgmgr_db, "COMMIT", NULL, NULL, NULL);
2310 if (ret != SQLITE_OK) {
2311 _LOGE("Failed to commit transaction, Rollback now\n");
2312 ret = sqlite3_exec(pkgmgr_db, "ROLLBACK", NULL, NULL, NULL);
2313 if (ret != SQLITE_OK)
2314 _LOGE("Failed to Rollback\n");
2316 ret = PM_PARSER_R_ERROR;
2319 _LOGE("Transaction Commit and End\n");
2320 ret = PM_PARSER_R_OK;
2322 perror(USR_APPSVC_ALIAS_INI);
2330 FREE_AND_NULL(tizen_id);
2331 FREE_AND_NULL(app_id);
2332 sqlite3_close(pkgmgr_db);
2338 int pkgmgr_parser_update_app_aliasid_info_in_db(void)
2340 FILE *ini_file = NULL;
2342 char *tizen_id = NULL;
2343 char *app_id = NULL;
2345 char buf[ MAX_ALIAS_INI_ENTRY ] = {0};
2346 int ret = PM_PARSER_R_OK;
2347 sqlite3 *pkgmgr_db = NULL;
2350 /*Open the alias.ini file*/
2351 ini_file = fopen(OPT_APPSVC_ALIAS_INI,"r");
2353 /*Open the pkgmgr DB*/
2354 ret = db_util_open_with_options(MANIFEST_DB, &pkgmgr_db, SQLITE_OPEN_READWRITE, NULL);
2355 if (ret != SQLITE_OK) {
2356 _LOGE("connect db [%s] failed!\n", MANIFEST_DB);
2358 return PM_PARSER_R_ERROR;
2361 /*Begin Transaction*/
2362 ret = sqlite3_exec(pkgmgr_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2363 tryvm_if(ret != SQLITE_OK, ret = PM_PARSER_R_ERROR, "Failed to begin transaction");
2365 _LOGD("Transaction Begin\n");
2367 while ( fgets ( buf, sizeof(buf), ini_file ) != NULL ) /* read a line */
2369 match = strstr(buf,"=");
2372 /*format of alias.ini entry is 'tizen_app_id=alias_id'*/
2373 /*get the tizen appid id*/
2374 len = strlen(buf)-strlen(match);
2375 tizen_id = malloc(len + 1);
2376 tryvm_if(tizen_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2377 memset(tizen_id,'\0',len +1);
2378 strncpy(tizen_id,buf,len);
2380 __str_trim(tizen_id);
2382 /*get the corresponding alias id*/
2383 len = strlen(match)-1;
2384 app_id = malloc(len + 1);
2385 tryvm_if(app_id == NULL, ret = PM_PARSER_R_ERROR,"Malloc failed!!");
2386 memset(app_id,'\0',len + 1);
2387 strncpy(app_id, match + 1, len);
2391 /* Insert the data into DB*/
2392 query = sqlite3_mprintf("insert or replace into package_app_aliasid(app_id, alias_id) values(%Q ,%Q)",tizen_id,app_id);
2393 ret = __exec_db_query(pkgmgr_db, query, NULL, NULL);
2394 sqlite3_free(query);
2395 tryvm_if(ret != SQLITE_OK,ret = PM_PARSER_R_ERROR, "sqlite exec failed to insert entries into package_app_aliasid table!!");
2397 FREE_AND_NULL(tizen_id);
2398 FREE_AND_NULL(app_id);
2399 memset(buf,'\0',MAX_ALIAS_INI_ENTRY);
2402 /*Commit transaction*/
2403 ret = sqlite3_exec(pkgmgr_db, "COMMIT", NULL, NULL, NULL);
2404 if (ret != SQLITE_OK) {
2405 _LOGE("Failed to commit transaction, Rollback now\n");
2406 ret = sqlite3_exec(pkgmgr_db, "ROLLBACK", NULL, NULL, NULL);
2407 if (ret != SQLITE_OK)
2408 _LOGE("Failed to Rollback\n");
2410 ret = PM_PARSER_R_ERROR;
2413 _LOGE("Transaction Commit and End\n");
2414 ret = PM_PARSER_R_OK;
2416 perror(OPT_APPSVC_ALIAS_INI);
2424 FREE_AND_NULL(tizen_id);
2425 FREE_AND_NULL(app_id);
2426 sqlite3_close(pkgmgr_db);