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 /* For multi-user support */
34 #include <tzplatform_config.h>
36 #include "pkgmgr-info.h"
37 #include "pkgmgr_parser_internal.h"
38 #include "pkgmgr_parser_db.h"
40 #include "pkgmgr-info-debug.h"
45 #define LOG_TAG "PKGMGR_PARSER"
47 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
48 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
49 #define MAX_QUERY_LEN 4096
53 sqlite3 *pkgmgr_parser_db;
54 sqlite3 *pkgmgr_cert_db;
57 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
58 "(package text primary key not null, " \
59 "package_type text DEFAULT 'rpm', " \
60 "package_version text, " \
61 "install_location text, " \
62 "package_size text, " \
63 "package_removable text DEFAULT 'true', " \
64 "package_preload text DEFAULT 'false', " \
65 "package_readonly text DEFAULT 'false', " \
66 "package_update text DEFAULT 'false', " \
67 "package_appsetting text DEFAULT 'false', " \
68 "package_nodisplay text DEFAULT 'false', " \
69 "package_system text DEFAULT 'false', " \
70 "author_name text, " \
71 "author_email text, " \
73 "installed_time text," \
74 "installed_storage text," \
75 "storeclient_id text," \
81 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
82 "(package text not null, " \
83 "package_locale text DEFAULT 'No Locale', " \
84 "package_label text, " \
85 "package_icon text, " \
86 "package_description text, " \
87 "package_license text, " \
89 "PRIMARY KEY(package, package_locale), " \
90 "FOREIGN KEY(package) " \
91 "REFERENCES package_info(package) " \
94 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
95 "(package text not null, " \
96 "privilege text not null, " \
97 "PRIMARY KEY(package, privilege) " \
98 "FOREIGN KEY(package) " \
99 "REFERENCES package_info(package) " \
102 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
103 "(app_id text primary key not null, " \
104 "app_component text, " \
106 "app_nodisplay text DEFAULT 'false', " \
108 "app_onboot text DEFAULT 'false', " \
109 "app_multiple text DEFAULT 'false', " \
110 "app_autorestart text DEFAULT 'false', " \
111 "app_taskmanage text DEFAULT 'false', " \
112 "app_enabled text DEFAULT 'true', " \
113 "app_hwacceleration text DEFAULT 'use-system-setting', " \
114 "app_screenreader text DEFAULT 'use-system-setting', " \
115 "app_mainapp text, " \
116 "app_recentimage text, " \
117 "app_launchcondition text, " \
118 "app_indicatordisplay text DEFAULT 'true', " \
119 "app_portraitimg text, " \
120 "app_landscapeimg text, " \
121 "app_guestmodevisibility text DEFAULT 'true', " \
122 "app_permissiontype text DEFAULT 'normal', " \
123 "app_preload text DEFAULT 'false', " \
124 "app_submode text DEFAULT 'false', " \
125 "app_submode_mainid text, " \
126 "component_type text, " \
127 "package text not null, " \
128 "FOREIGN KEY(package) " \
129 "REFERENCES package_info(package) " \
132 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
133 "(app_id text not null, " \
134 "app_locale text DEFAULT 'No Locale', " \
137 "PRIMARY KEY(app_id,app_locale) " \
138 "FOREIGN KEY(app_id) " \
139 "REFERENCES package_app_info(app_id) " \
142 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
143 "(app_id text not null, " \
145 "app_icon_section text, " \
146 "app_icon_resolution text, " \
147 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
148 "FOREIGN KEY(app_id) " \
149 "REFERENCES package_app_info(app_id) " \
152 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
153 "(app_id text not null, " \
154 "app_locale text DEFAULT 'No Locale', " \
155 "app_image_section text, " \
157 "PRIMARY KEY(app_id,app_image_section) " \
158 "FOREIGN KEY(app_id) " \
159 "REFERENCES package_app_info(app_id) " \
162 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
163 "(app_id text not null, " \
164 "operation text not null, " \
165 "uri_scheme text, " \
167 "subapp_name text, " \
168 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
169 "FOREIGN KEY(app_id) " \
170 "REFERENCES package_app_info(app_id) " \
173 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
174 "(app_id text not null, " \
175 "operation text not null, " \
176 "uri_scheme text, " \
178 "subapp_name text, " \
179 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
180 "FOREIGN KEY(app_id) " \
181 "REFERENCES package_app_info(app_id) " \
184 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
185 "(app_id text not null, " \
186 "category text not null, " \
187 "PRIMARY KEY(app_id,category) " \
188 "FOREIGN KEY(app_id) " \
189 "REFERENCES package_app_info(app_id) " \
192 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
193 "(app_id text not null, " \
194 "md_key text not null, " \
195 "md_value text not null, " \
196 "PRIMARY KEY(app_id, md_key, md_value) " \
197 "FOREIGN KEY(app_id) " \
198 "REFERENCES package_app_info(app_id) " \
201 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
202 "(app_id text not null, " \
203 "pm_type text not null, " \
204 "pm_value text not null, " \
205 "PRIMARY KEY(app_id, pm_type, pm_value) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
211 "(app_id text not null, " \
212 "data_share_path text not null, " \
213 "data_share_allowed text not null, " \
214 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
220 "(app_id text not null, " \
221 "data_share_request text not null, " \
222 "PRIMARY KEY(app_id,data_share_request) " \
223 "FOREIGN KEY(app_id) " \
224 "REFERENCES package_app_info(app_id) " \
227 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
228 "(cert_info text not null, " \
229 "cert_id integer, " \
230 "cert_ref_count integer, " \
231 "PRIMARY KEY(cert_id)) "
233 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
234 "(package text not null, " \
235 "author_root_cert integer, " \
236 "author_im_cert integer, " \
237 "author_signer_cert integer, " \
238 "dist_root_cert integer, " \
239 "dist_im_cert integer, " \
240 "dist_signer_cert integer, " \
241 "dist2_root_cert integer, " \
242 "dist2_im_cert integer, " \
243 "dist2_signer_cert integer, " \
244 "PRIMARY KEY(package)) "
247 static int __insert_uiapplication_info(manifest_x *mfx);
248 static int __insert_serviceapplication_info(manifest_x *mfx);
249 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
250 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
251 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
252 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
253 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
254 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
255 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
256 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
257 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
258 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
259 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
260 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
261 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
262 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
263 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
264 static int __insert_manifest_info_in_db(manifest_x *mfx);
265 static int __delete_manifest_info_from_db(manifest_x *mfx);
266 static int __delete_subpkg_info_from_db(char *appid);
267 static int __delete_appinfo_from_db(char *db_table, const char *appid);
268 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
269 static int __exec_query(char *query);
270 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
271 char **label, char **license, char **icon, char **description, char **author);
272 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
273 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
274 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
275 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
276 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
277 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
279 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
282 __delete_subpkg_info_from_db(coltxt[0]);
287 static char *__get_str(const char *str)
291 return PKGMGR_PARSER_EMPTY_STR;
297 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
301 char *pk, key1, key2, key3, key4, key5;
303 if (access(db_path, F_OK) == 0) {
305 db_util_open(db_path, &handle,
306 DB_UTIL_REGISTER_HOOK_METHOD);
307 if (ret != SQLITE_OK) {
308 _LOGD("connect db [%s] failed!\n",
315 _LOGD("%s DB does not exists. Create one!!\n", db_path);
318 db_util_open(db_path, &handle,
319 DB_UTIL_REGISTER_HOOK_METHOD);
321 if (ret != SQLITE_OK) {
322 _LOGD("connect db [%s] failed!\n", db_path);
330 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
335 if (access(db_path, F_OK) == 0) {
337 db_util_open(db_path, &handle,
338 DB_UTIL_REGISTER_HOOK_METHOD);
339 if (ret != SQLITE_OK) {
340 _LOGD("connect db [%s] failed!\n",
347 _LOGD("%s DB does not exists. Create one!!\n", db_path);
350 db_util_open(db_path, &handle,
351 DB_UTIL_REGISTER_HOOK_METHOD);
353 if (ret != SQLITE_OK) {
354 _LOGD("connect db [%s] failed!\n", db_path);
362 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
364 manifest_x *mfx = (manifest_x *)data;
368 uiapplication_x *uiapp = NULL;
369 for(i = 0; i < ncols; i++)
371 uiapp = mfx->uiapplication;
372 if (strcmp(colname[i], "app_id") == 0) {
374 appid = strdup(coltxt[i]);
375 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
377 status = strdup(coltxt[i]);
381 _LOGD("app id is NULL\n");
384 /*update guest mode visibility*/
385 for (; uiapp != NULL; uiapp = uiapp->next) {
386 if (strcmp(uiapp->appid, appid) == 0) {
387 free((void *)uiapp->guestmode_visibility);
388 uiapp->guestmode_visibility = strdup(status);
404 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
406 char *error_message = NULL;
407 char query[MAX_QUERY_LEN] = {'\0'};
408 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
410 sqlite3_exec(pkgmgr_parser_db, query,
411 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
412 _LOGD("Don't execute query = %s error message = %s\n",
413 query, error_message);
414 sqlite3_free(error_message);
419 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
421 char *error_message = NULL;
423 sqlite3_exec(db_handle, db_query,
424 NULL, NULL, &error_message)) {
425 _LOGD("Don't execute query = %s error message = %s\n",
426 db_query, error_message);
427 sqlite3_free(error_message);
430 sqlite3_free(error_message);
434 static int __exec_query(char *query)
436 char *error_message = NULL;
438 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
439 _LOGD("Don't execute query = %s error message = %s\n", query,
441 sqlite3_free(error_message);
444 sqlite3_free(error_message);
448 static int __exec_query_no_msg(char *query)
450 char *error_message = NULL;
452 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
453 sqlite3_free(error_message);
456 sqlite3_free(error_message);
460 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
466 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
472 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
478 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
484 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
490 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
497 static GList *__create_icon_list(GList *locale, icon_x *icn)
502 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
508 static GList *__create_image_list(GList *locale, image_x *image)
513 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
519 static void __printfunc(gpointer data, gpointer userdata)
521 _LOGD("%s ", (char*)data);
524 static void __trimfunc(GList* trim_list)
526 char *trim_data = NULL;
530 list = g_list_first(trim_list);
533 trim_data = (char *)list->data;
536 if (strcmp(trim_data, prev) == 0) {
537 trim_list = g_list_remove(trim_list, trim_data);
538 list = g_list_first(trim_list);
547 list = g_list_next(list);
551 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
553 if (a == NULL || b == NULL)
555 if (strcmp((char*)a, (char*)b) == 0)
557 if (strcmp((char*)a, (char*)b) < 0)
559 if (strcmp((char*)a, (char*)b) > 0)
564 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
565 char **label, char **license, char **icon, char **description, char **author)
570 if (strcmp(lbl->lang, (char *)data) == 0) {
571 *label = (char*)lbl->text;
580 if (strcmp(lcn->lang, (char *)data) == 0) {
581 *license = (char*)lcn->text;
590 if (strcmp(icn->lang, (char *)data) == 0) {
591 *icon = (char*)icn->text;
600 if (strcmp(dcn->lang, (char *)data) == 0) {
601 *description = (char*)dcn->text;
610 if (strcmp(ath->lang, (char *)data) == 0) {
611 *author = (char*)ath->text;
620 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
625 if (strcmp(icn->section, (char *)data) == 0) {
626 *icon = (char*)icn->text;
627 *resolution = (char*)icn->resolution;
635 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
639 if (image->section) {
640 if (strcmp(image->section, (char *)data) == 0) {
641 *lang = (char*)image->lang;
642 *img = (char*)image->text;
650 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
655 char *description = NULL;
656 char *license = NULL;
658 char query[MAX_QUERY_LEN] = {'\0'};
660 manifest_x *mfx = (manifest_x *)userdata;
661 label_x *lbl = mfx->label;
662 license_x *lcn = mfx->license;
663 icon_x *icn = mfx->icon;
664 description_x *dcn = mfx->description;
665 author_x *ath = mfx->author;
667 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
668 if (!label && !description && !icon && !license && !author)
671 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
672 "package_label, package_icon, package_description, package_license, package_author) values " \
673 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
678 __get_str(description),
682 ret = __exec_query(query);
684 _LOGD("Package Localized Info DB Insert failed\n");
687 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
692 char query[MAX_QUERY_LEN] = {'\0'};
694 uiapplication_x *up = (uiapplication_x*)userdata;
695 label_x *lbl = up->label;
696 icon_x *icn = up->icon;
698 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
701 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
702 "app_label, app_icon) values " \
703 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
705 ret = __exec_query(query);
707 _LOGD("Package UiApp Localized Info DB Insert failed\n");
709 /*insert ui app locale info to pkg locale to get mainapp data */
710 if (strcasecmp(up->mainapp, "true")==0) {
711 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
712 "package_label, package_icon, package_description, package_license, package_author) values " \
713 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
718 PKGMGR_PARSER_EMPTY_STR,
719 PKGMGR_PARSER_EMPTY_STR,
720 PKGMGR_PARSER_EMPTY_STR);
722 ret = __exec_query_no_msg(query);
725 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
726 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
727 ret = __exec_query_no_msg(query);
732 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
736 char *resolution = NULL;
737 char query[MAX_QUERY_LEN] = {'\0'};
739 uiapplication_x *up = (uiapplication_x*)userdata;
740 icon_x *icn = up->icon;
742 __extract_icon_data(data, icn, &icon, &resolution);
743 if (!icon && !resolution)
745 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
746 "app_icon, app_icon_section, app_icon_resolution) values " \
747 "('%q', '%q', '%q', '%q')", up->appid,
748 icon, (char*)data, resolution);
750 ret = __exec_query(query);
752 _LOGD("Package UiApp Localized Info DB Insert failed\n");
756 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
761 char query[MAX_QUERY_LEN] = {'\0'};
763 uiapplication_x *up = (uiapplication_x*)userdata;
764 image_x *image = up->image;
766 __extract_image_data(data, image, &lang, &img);
769 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
770 "app_image_section, app_image) values " \
771 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
773 ret = __exec_query(query);
775 _LOGD("Package UiApp image Info DB Insert failed\n");
780 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
785 char query[MAX_QUERY_LEN] = {'\0'};
787 serviceapplication_x *sp = (serviceapplication_x*)userdata;
788 label_x *lbl = sp->label;
789 icon_x *icn = sp->icon;
791 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
794 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
795 "app_label, app_icon) values " \
796 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
798 ret = __exec_query(query);
800 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
803 static int __insert_ui_mainapp_info(manifest_x *mfx)
805 uiapplication_x *up = mfx->uiapplication;
807 char query[MAX_QUERY_LEN] = {'\0'};
810 snprintf(query, MAX_QUERY_LEN,
811 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
813 ret = __exec_query(query);
815 _LOGD("Package UiApp Info DB Insert Failed\n");
818 if (strcasecmp(up->mainapp, "True")==0)
819 mfx->mainapp_id = strdup(up->appid);
822 memset(query, '\0', MAX_QUERY_LEN);
825 if (mfx->mainapp_id == NULL){
826 if (mfx->uiapplication && mfx->uiapplication->appid) {
827 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
829 _LOGD("Not valid appid\n");
833 ret = __exec_query(query);
835 _LOGD("Package UiApp Info DB Insert Failed\n");
839 free((void *)mfx->uiapplication->mainapp);
840 mfx->uiapplication->mainapp= strdup("true");
841 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
844 memset(query, '\0', MAX_QUERY_LEN);
845 snprintf(query, MAX_QUERY_LEN,
846 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
847 ret = __exec_query(query);
849 _LOGD("Package Info DB update Failed\n");
855 /* _PRODUCT_LAUNCHING_ENHANCED_
856 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
858 static int __insert_uiapplication_info(manifest_x *mfx)
860 uiapplication_x *up = mfx->uiapplication;
862 char query[MAX_QUERY_LEN] = {'\0'};
865 snprintf(query, MAX_QUERY_LEN,
866 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
867 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
868 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
869 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
870 "values('%s', '%s', '%s', '%s', '%s', '%s','%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
876 PKGMGR_PARSER_EMPTY_STR,
878 PKGMGR_PARSER_EMPTY_STR,
884 __get_str(up->recentimage),
886 up->indicatordisplay,
887 __get_str(up->portraitimg),
888 __get_str(up->landscapeimg),
889 up->guestmode_visibility,
893 __get_str(up->submode_mainid),
897 ret = __exec_query(query);
899 _LOGD("Package UiApp Info DB Insert Failed\n");
903 memset(query, '\0', MAX_QUERY_LEN);
908 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
910 uiapplication_x *up = mfx->uiapplication;
911 category_x *ct = NULL;
913 char query[MAX_QUERY_LEN] = {'\0'};
919 snprintf(query, MAX_QUERY_LEN,
920 "insert into package_app_app_category(app_id, category) " \
921 "values('%s','%s')",\
922 up->appid, ct->name);
923 ret = __exec_query(query);
925 _LOGD("Package UiApp Category Info DB Insert Failed\n");
929 memset(query, '\0', MAX_QUERY_LEN);
936 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
938 uiapplication_x *up = mfx->uiapplication;
939 metadata_x *md = NULL;
941 char query[MAX_QUERY_LEN] = {'\0'};
948 snprintf(query, MAX_QUERY_LEN,
949 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
950 "values('%s','%s', '%s')",\
951 up->appid, md->key, md->value);
952 ret = __exec_query(query);
954 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
959 memset(query, '\0', MAX_QUERY_LEN);
966 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
968 uiapplication_x *up = mfx->uiapplication;
969 permission_x *pm = NULL;
971 char query[MAX_QUERY_LEN] = {'\0'};
977 snprintf(query, MAX_QUERY_LEN,
978 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
979 "values('%s','%s', '%s')",\
980 up->appid, pm->type, pm->value);
981 ret = __exec_query(query);
983 _LOGD("Package UiApp permission Info DB Insert Failed\n");
987 memset(query, '\0', MAX_QUERY_LEN);
994 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
996 uiapplication_x *up = mfx->uiapplication;
997 appcontrol_x *acontrol = NULL;
998 operation_x *op = NULL;
1001 subapp_x *sub = NULL;
1003 char query[MAX_QUERY_LEN] = {'\0'};
1004 const char *operation = NULL;
1005 const char *mime = NULL;
1006 const char *uri = NULL;
1007 const char *subapp = NULL;
1010 acontrol = up->appcontrol;
1011 while(acontrol != NULL)
1013 op = acontrol->operation;
1017 operation = op->name;
1018 mi = acontrol->mime;
1024 sub = acontrol->subapp;
1034 snprintf(query, MAX_QUERY_LEN,
1035 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1036 "values('%s', '%s', '%s', '%s', '%s')",\
1037 up->appid, operation, uri, mime, subapp);
1039 ret = __exec_query(query);
1041 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1044 memset(query, '\0', MAX_QUERY_LEN);
1048 } while(ui != NULL);
1052 }while(sub != NULL);
1061 acontrol = acontrol->next;
1068 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1070 uiapplication_x *up = mfx->uiapplication;
1071 appsvc_x *asvc = NULL;
1072 operation_x *op = NULL;
1075 subapp_x *sub = NULL;
1077 char query[MAX_QUERY_LEN] = {'\0'};
1078 const char *operation = NULL;
1079 const char *mime = NULL;
1080 const char *uri = NULL;
1081 const char *subapp = NULL;
1087 op = asvc->operation;
1091 operation = op->name;
1108 snprintf(query, MAX_QUERY_LEN,
1109 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1110 "values('%s', '%s', '%s', '%s', '%s')",\
1117 ret = __exec_query(query);
1119 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1122 memset(query, '\0', MAX_QUERY_LEN);
1126 } while(ui != NULL);
1130 }while(sub != NULL);
1146 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1148 uiapplication_x *up = mfx->uiapplication;
1149 datashare_x *ds = NULL;
1150 request_x *rq = NULL;
1152 char query[MAX_QUERY_LEN] = {'\0'};
1161 snprintf(query, MAX_QUERY_LEN,
1162 "insert into package_app_share_request(app_id, data_share_request) " \
1163 "values('%s', '%s')",\
1164 up->appid, rq->text);
1165 ret = __exec_query(query);
1167 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1170 memset(query, '\0', MAX_QUERY_LEN);
1180 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1182 uiapplication_x *up = mfx->uiapplication;
1183 datashare_x *ds = NULL;
1184 define_x *df = NULL;
1185 allowed_x *al = NULL;
1187 char query[MAX_QUERY_LEN] = {'\0'};
1199 snprintf(query, MAX_QUERY_LEN,
1200 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1201 "values('%s', '%s', '%s')",\
1202 up->appid, df->path, al->text);
1203 ret = __exec_query(query);
1205 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1208 memset(query, '\0', MAX_QUERY_LEN);
1220 static int __insert_serviceapplication_info(manifest_x *mfx)
1222 serviceapplication_x *sp = mfx->serviceapplication;
1224 char query[MAX_QUERY_LEN] = {'\0'};
1227 snprintf(query, MAX_QUERY_LEN,
1228 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1229 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1230 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1231 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1232 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1233 ret = __exec_query(query);
1235 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1239 memset(query, '\0', MAX_QUERY_LEN);
1244 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1246 serviceapplication_x *sp = mfx->serviceapplication;
1247 category_x *ct = NULL;
1249 char query[MAX_QUERY_LEN] = {'\0'};
1255 snprintf(query, MAX_QUERY_LEN,
1256 "insert into package_app_app_category(app_id, category) " \
1257 "values('%s','%s')",\
1258 sp->appid, ct->name);
1259 ret = __exec_query(query);
1261 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1265 memset(query, '\0', MAX_QUERY_LEN);
1272 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1274 serviceapplication_x *sp = mfx->serviceapplication;
1275 metadata_x *md = NULL;
1277 char query[MAX_QUERY_LEN] = {'\0'};
1284 snprintf(query, MAX_QUERY_LEN,
1285 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1286 "values('%s','%s', '%s')",\
1287 sp->appid, md->key, md->value);
1288 ret = __exec_query(query);
1290 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1295 memset(query, '\0', MAX_QUERY_LEN);
1302 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1304 serviceapplication_x *sp = mfx->serviceapplication;
1305 permission_x *pm = NULL;
1307 char query[MAX_QUERY_LEN] = {'\0'};
1310 pm = sp->permission;
1313 snprintf(query, MAX_QUERY_LEN,
1314 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1315 "values('%s','%s', '%s')",\
1316 sp->appid, pm->type, pm->value);
1317 ret = __exec_query(query);
1319 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1323 memset(query, '\0', MAX_QUERY_LEN);
1330 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1332 serviceapplication_x *sp = mfx->serviceapplication;
1333 appcontrol_x *acontrol = NULL;
1335 char query[MAX_QUERY_LEN] = {'\0'};
1336 operation_x *op = NULL;
1339 subapp_x *sub = NULL;
1340 const char *operation = NULL;
1341 const char *mime = NULL;
1342 const char *uri = NULL;
1343 const char *subapp = NULL;
1346 acontrol = sp->appcontrol;
1347 while(acontrol != NULL)
1349 op = acontrol->operation;
1353 operation = op->name;
1354 mi = acontrol->mime;
1359 sub = acontrol->subapp;
1369 snprintf(query, MAX_QUERY_LEN,
1370 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1371 "values('%s', '%s', '%s', '%s', '%s')",\
1372 sp->appid, operation, uri, mime, subapp);
1373 ret = __exec_query(query);
1375 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1378 memset(query, '\0', MAX_QUERY_LEN);
1382 } while(ui != NULL);
1386 }while(sub != NULL);
1395 acontrol = acontrol->next;
1402 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1404 serviceapplication_x *sp = mfx->serviceapplication;
1405 appsvc_x *asvc = NULL;
1407 char query[MAX_QUERY_LEN] = {'\0'};
1408 operation_x *op = NULL;
1411 subapp_x *sub = NULL;
1412 const char *operation = NULL;
1413 const char *mime = NULL;
1414 const char *uri = NULL;
1415 const char *subapp = NULL;
1421 op = asvc->operation;
1425 operation = op->name;
1441 snprintf(query, MAX_QUERY_LEN,
1442 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1443 "values('%s', '%s', '%s', '%s', '%s')",\
1449 ret = __exec_query(query);
1451 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1454 memset(query, '\0', MAX_QUERY_LEN);
1458 } while(ui != NULL);
1462 }while(sub != NULL);
1480 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1482 serviceapplication_x *sp = mfx->serviceapplication;
1483 datashare_x *ds = NULL;
1484 request_x *rq = NULL;
1486 char query[MAX_QUERY_LEN] = {'\0'};
1495 snprintf(query, MAX_QUERY_LEN,
1496 "insert into package_app_share_request(app_id, data_share_request) " \
1497 "values('%s', '%s')",\
1498 sp->appid, rq->text);
1499 ret = __exec_query(query);
1501 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1504 memset(query, '\0', MAX_QUERY_LEN);
1516 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1518 serviceapplication_x *sp = mfx->serviceapplication;
1519 datashare_x *ds = NULL;
1520 define_x *df = NULL;
1521 allowed_x *al = NULL;
1523 char query[MAX_QUERY_LEN] = {'\0'};
1535 snprintf(query, MAX_QUERY_LEN,
1536 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1537 "values('%s', '%s', '%s')",\
1538 sp->appid, df->path, al->text);
1539 ret = __exec_query(query);
1541 _LOGD("Package App Share Allowed DB Insert Failed\n");
1544 memset(query, '\0', MAX_QUERY_LEN);
1556 static int __insert_manifest_info_in_db(manifest_x *mfx)
1558 label_x *lbl = mfx->label;
1559 license_x *lcn = mfx->license;
1560 icon_x *icn = mfx->icon;
1561 description_x *dcn = mfx->description;
1562 author_x *ath = mfx->author;
1563 uiapplication_x *up = mfx->uiapplication;
1564 uiapplication_x *up_icn = mfx->uiapplication;
1565 uiapplication_x *up_image = mfx->uiapplication;
1566 serviceapplication_x *sp = mfx->serviceapplication;
1567 privileges_x *pvs = NULL;
1568 privilege_x *pv = NULL;
1569 char query[MAX_QUERY_LEN] = { '\0' };
1570 char root[MAX_QUERY_LEN] = { '\0' };
1574 const char *auth_name = NULL;
1575 const char *auth_email = NULL;
1576 const char *auth_href = NULL;
1577 const char *apps_path = NULL;
1579 GList *pkglocale = NULL;
1580 GList *applocale = NULL;
1581 GList *appicon = NULL;
1582 GList *appimage = NULL;
1586 auth_name = ath->text;
1588 auth_email = ath->email;
1590 auth_href = ath->href;
1592 /*Insert in the package_info DB*/
1594 type = strdup(mfx->type);
1596 type = strdup("rpm");
1597 /*Insert in the package_info DB*/
1599 path = strdup(mfx->root_path);
1601 if (strcmp(type,"rpm")==0) {
1602 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1603 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1605 apps_path = tzplatform_getenv(TZ_USER_APP);
1606 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1608 path = strdup(root);
1610 snprintf(query, MAX_QUERY_LEN,
1611 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1612 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1613 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1614 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1618 __get_str(mfx->installlocation),
1619 __get_str(mfx->package_size),
1625 mfx->nodisplay_setting,
1627 __get_str(auth_name),
1628 __get_str(auth_email),
1629 __get_str(auth_href),
1630 mfx->installed_time,
1631 mfx->installed_storage,
1632 __get_str(mfx->storeclient_id),
1634 __get_str(mfx->package_url),
1636 __get_str(mfx->csc_path));
1637 /*If package dont have main_package tag, this package is main package.*/
1638 if (mfx->main_package == NULL) {
1639 ret = __exec_query(query);
1641 _LOGD("Package Info DB Insert Failed\n");
1653 /*If package has main_package tag, this package is sub package(ug, efl).
1654 skip __exec_query for package_info and change pkgid with main_package*/
1655 memset(root, '\0', MAX_QUERY_LEN);
1656 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1657 if (access(root, F_OK) == 0) {
1658 free((void *)mfx->package);
1659 mfx->package = strdup(mfx->main_package);
1661 _LOGE("main package[%s] is not installed\n", root);
1674 /*Insert in the package_privilege_info DB*/
1675 pvs = mfx->privileges;
1676 while (pvs != NULL) {
1677 pv = pvs->privilege;
1678 while (pv != NULL) {
1679 memset(query, '\0', MAX_QUERY_LEN);
1680 snprintf(query, MAX_QUERY_LEN,
1681 "insert into package_privilege_info(package, privilege) " \
1682 "values('%s','%s')",\
1683 mfx->package, pv->text);
1684 ret = __exec_query(query);
1686 _LOGD("Package Privilege Info DB Insert Failed\n");
1694 ret = __insert_ui_mainapp_info(mfx);
1698 /*Insert the package locale*/
1699 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1700 /*remove duplicated data in pkglocale*/
1701 __trimfunc(pkglocale);
1703 /*Insert the app locale info */
1706 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1711 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1714 /*remove duplicated data in applocale*/
1715 __trimfunc(applocale);
1717 /*Insert the app icon info */
1718 while(up_icn != NULL)
1720 appicon = __create_icon_list(appicon, up_icn->icon);
1721 up_icn = up_icn->next;
1723 /*remove duplicated data in appicon*/
1724 __trimfunc(appicon);
1726 /*Insert the image info */
1727 while(up_image != NULL)
1729 appimage = __create_image_list(appimage, up_image->image);
1730 up_image = up_image->next;
1732 /*remove duplicated data in appimage*/
1733 __trimfunc(appimage);
1735 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1737 /*g_list_foreach(applocale, __printfunc, NULL);*/
1739 /*package locale info, it is only for main package.*/
1740 if (mfx->main_package == NULL)
1741 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1743 /*native app locale info*/
1744 up = mfx->uiapplication;
1747 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1750 /*agent app locale info*/
1751 sp = mfx->serviceapplication;
1754 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1758 /*app icon locale info*/
1759 up_icn = mfx->uiapplication;
1760 while(up_icn != NULL)
1762 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1763 up_icn = up_icn->next;
1767 up_image = mfx->uiapplication;
1768 while(up_image != NULL)
1770 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1771 up_image = up_image->next;
1774 g_list_free(pkglocale);
1776 g_list_free(applocale);
1778 g_list_free(appicon);
1780 g_list_free(appimage);
1783 /*Insert in the package_app_info DB*/
1784 ret = __insert_uiapplication_info(mfx);
1787 ret = __insert_serviceapplication_info(mfx);
1790 /*Insert in the package_app_app_control DB*/
1791 ret = __insert_uiapplication_appcontrol_info(mfx);
1794 ret = __insert_serviceapplication_appcontrol_info(mfx);
1798 /*Insert in the package_app_app_category DB*/
1799 ret = __insert_uiapplication_appcategory_info(mfx);
1802 ret = __insert_serviceapplication_appcategory_info(mfx);
1806 /*Insert in the package_app_app_metadata DB*/
1807 ret = __insert_uiapplication_appmetadata_info(mfx);
1810 ret = __insert_uiapplication_appmetadata_info(mfx);
1814 /*Insert in the package_app_app_permission DB*/
1815 ret = __insert_uiapplication_apppermission_info(mfx);
1818 ret = __insert_serviceapplication_apppermission_info(mfx);
1822 /*Insert in the package_app_app_svc DB*/
1823 ret = __insert_uiapplication_appsvc_info(mfx);
1826 ret = __insert_serviceapplication_appsvc_info(mfx);
1830 /*Insert in the package_app_share_allowed DB*/
1831 ret = __insert_uiapplication_share_allowed_info(mfx);
1834 ret = __insert_serviceapplication_share_allowed_info(mfx);
1838 /*Insert in the package_app_share_request DB*/
1839 ret = __insert_uiapplication_share_request_info(mfx);
1842 ret = __insert_serviceapplication_share_request_info(mfx);
1850 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1852 char query[MAX_QUERY_LEN] = { '\0' };
1854 memset(query, '\0', MAX_QUERY_LEN);
1855 snprintf(query, MAX_QUERY_LEN,
1856 "delete from %s where app_id='%s'", db_table, appid);
1857 ret = __exec_query(query);
1859 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1865 static int __delete_subpkg_info_from_db(char *appid)
1869 ret = __delete_appinfo_from_db("package_app_info", appid);
1872 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1875 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1878 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1881 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1884 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1887 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1890 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1893 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1896 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1899 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1906 static int __delete_subpkg_from_db(manifest_x *mfx)
1908 char query[MAX_QUERY_LEN] = { '\0' };
1910 char *error_message = NULL;
1912 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1914 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1915 _LOGE("Don't execute query = %s error message = %s\n", query,
1917 sqlite3_free(error_message);
1920 sqlite3_free(error_message);
1925 static int __delete_manifest_info_from_db(manifest_x *mfx)
1927 char query[MAX_QUERY_LEN] = { '\0' };
1929 uiapplication_x *up = mfx->uiapplication;
1930 serviceapplication_x *sp = mfx->serviceapplication;
1931 /*Delete from cert table*/
1932 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1934 _LOGD("Cert Info DB Delete Failed\n");
1938 /*Delete from Package Info DB*/
1939 snprintf(query, MAX_QUERY_LEN,
1940 "delete from package_info where package='%s'", mfx->package);
1941 ret = __exec_query(query);
1943 _LOGD("Package Info DB Delete Failed\n");
1946 memset(query, '\0', MAX_QUERY_LEN);
1948 /*Delete from Package Localized Info*/
1949 snprintf(query, MAX_QUERY_LEN,
1950 "delete from package_localized_info where package='%s'", mfx->package);
1951 ret = __exec_query(query);
1953 _LOGD("Package Localized Info DB Delete Failed\n");
1957 /*Delete from Package Privilege Info*/
1958 snprintf(query, MAX_QUERY_LEN,
1959 "delete from package_privilege_info where package='%s'", mfx->package);
1960 ret = __exec_query(query);
1962 _LOGD("Package Privilege Info DB Delete Failed\n");
1966 while (up != NULL) {
1967 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1970 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1973 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1976 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1979 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1982 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1985 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1988 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1991 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1994 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1997 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2003 while (sp != NULL) {
2004 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2007 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2010 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2013 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2016 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2019 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2022 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2025 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2028 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2031 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2034 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2040 /* if main package has sub pkg, delete sub pkg data*/
2041 __delete_subpkg_from_db(mfx);
2046 static int __update_preload_condition_in_db()
2049 char query[MAX_QUERY_LEN] = {'\0'};
2051 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2053 ret = __exec_query(query);
2055 _LOGD("Package preload_condition update failed\n");
2060 int pkgmgr_parser_initialize_db()
2064 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2066 _LOGD("package info DB initialization failed\n");
2069 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2071 _LOGD("package localized info DB initialization failed\n");
2074 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2076 _LOGD("package app app privilege DB initialization failed\n");
2079 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2081 _LOGD("package app info DB initialization failed\n");
2084 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2086 _LOGD("package app localized info DB initialization failed\n");
2089 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2091 _LOGD("package app icon localized info DB initialization failed\n");
2094 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2096 _LOGD("package app image info DB initialization failed\n");
2099 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2101 _LOGD("package app app control DB initialization failed\n");
2104 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2106 _LOGD("package app app category DB initialization failed\n");
2109 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2111 _LOGD("package app app category DB initialization failed\n");
2114 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2116 _LOGD("package app app permission DB initialization failed\n");
2119 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2121 _LOGD("package app app svc DB initialization failed\n");
2124 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2126 _LOGD("package app share allowed DB initialization failed\n");
2129 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2131 _LOGD("package app share request DB initialization failed\n");
2135 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2137 _LOGD("package cert info DB initialization failed\n");
2140 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2142 _LOGD("package cert index info DB initialization failed\n");
2148 static int parserdb_change_perm(const char *db_file)
2151 char journal_file[BUFSIZE];
2154 struct group *grpinfo = NULL;
2155 files[0] = (char *)db_file;
2156 files[1] = journal_file;
2159 const char *name = "users";
2166 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2167 grpinfo = getgrnam(name);
2168 if(grpinfo == NULL){
2169 _LOGD("getgrnam(users) returns NULL !");
2171 for (i = 0; files[i]; i++) {
2172 ret = chown(files[i], OWNER_ROOT, (gid_t)grpinfo->gr_gid);
2174 strerror_r(errno, buf, sizeof(buf));
2175 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, grpinfo->gr_gid, buf);
2179 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2181 strerror_r(errno, buf, sizeof(buf));
2182 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2190 int pkgmgr_parser_check_and_create_db(uid_t uid)
2194 ret = __pkgmgr_parser_create_parser_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid), uid);
2195 _LOGD("create db %s", getUserPkgParserDBPathUID(uid));
2197 _LOGD("Manifest DB creation Failed\n");
2200 if(uid != GLOBAL_USER) {
2201 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid))) {
2202 _LOGD("Failed to change permission\n");
2206 ret = __pkgmgr_parser_create_cert_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid), uid);
2208 _LOGD("Cert DB creation Failed\n");
2211 if(uid != GLOBAL_USER) {
2212 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid))) {
2213 _LOGD("Failed to change permission\n");
2219 void pkgmgr_parser_close_db()
2221 sqlite3_close(pkgmgr_parser_db);
2222 sqlite3_close(pkgmgr_cert_db);
2226 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2228 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2230 _LOGD("manifest pointer is NULL\n");
2234 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2236 _LOGD("Failed to open DB\n");
2239 ret = pkgmgr_parser_initialize_db();
2242 /*Begin transaction*/
2243 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2244 if (ret != SQLITE_OK) {
2245 _LOGD("Failed to begin transaction\n");
2249 _LOGD("Transaction Begin\n");
2250 ret = __insert_manifest_info_in_db(mfx);
2252 _LOGD("Insert into DB failed. Rollback now\n");
2253 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2256 /*Commit transaction*/
2257 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2258 if (ret != SQLITE_OK) {
2259 _LOGD("Failed to commit transaction. Rollback now\n");
2260 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2264 _LOGD("Transaction Commit and End\n");
2266 pkgmgr_parser_close_db();
2270 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2272 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2274 _LOGD("manifest pointer is NULL\n");
2278 ret = pkgmgr_parser_check_and_create_db(uid);
2280 _LOGD("Failed to open DB\n");
2283 ret = pkgmgr_parser_initialize_db();
2286 /*Begin transaction*/
2287 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2288 if (ret != SQLITE_OK) {
2289 _LOGD("Failed to begin transaction\n");
2293 _LOGD("Transaction Begin\n");
2294 ret = __insert_manifest_info_in_db(mfx);
2296 _LOGD("Insert into DB failed. Rollback now\n");
2297 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2300 /*Commit transaction*/
2301 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2302 if (ret != SQLITE_OK) {
2303 _LOGD("Failed to commit transaction. Rollback now\n");
2304 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2308 _LOGD("Transaction Commit and End\n");
2310 pkgmgr_parser_close_db();
2313 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2316 _LOGD("manifest pointer is NULL\n");
2320 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2322 _LOGD("Failed to open DB\n");
2325 ret = pkgmgr_parser_initialize_db();
2328 /*Preserve guest mode visibility*/
2329 __preserve_guestmode_visibility_value( mfx);
2330 /*Begin transaction*/
2331 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2332 if (ret != SQLITE_OK) {
2333 _LOGD("Failed to begin transaction\n");
2337 _LOGD("Transaction Begin\n");
2338 ret = __delete_manifest_info_from_db(mfx);
2340 _LOGD("Delete from DB failed. Rollback now\n");
2341 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2344 ret = __insert_manifest_info_in_db(mfx);
2346 _LOGD("Insert into DB failed. Rollback now\n");
2347 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2351 /*Commit transaction*/
2352 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2353 if (ret != SQLITE_OK) {
2354 _LOGD("Failed to commit transaction. Rollback now\n");
2355 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2359 _LOGD("Transaction Commit and End\n");
2361 pkgmgr_parser_close_db();
2365 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2368 _LOGD("manifest pointer is NULL\n");
2372 ret = pkgmgr_parser_check_and_create_db(uid);
2374 _LOGD("Failed to open DB\n");
2377 ret = pkgmgr_parser_initialize_db();
2380 /*Preserve guest mode visibility*/
2381 __preserve_guestmode_visibility_value( mfx);
2382 /*Begin transaction*/
2383 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2384 if (ret != SQLITE_OK) {
2385 _LOGD("Failed to begin transaction\n");
2389 _LOGD("Transaction Begin\n");
2390 ret = __delete_manifest_info_from_db(mfx);
2392 _LOGD("Delete from DB failed. Rollback now\n");
2393 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2396 ret = __insert_manifest_info_in_db(mfx);
2398 _LOGD("Insert into DB failed. Rollback now\n");
2399 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2403 /*Commit transaction*/
2404 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2405 if (ret != SQLITE_OK) {
2406 _LOGD("Failed to commit transaction. Rollback now\n");
2407 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2411 _LOGD("Transaction Commit and End\n");
2413 pkgmgr_parser_close_db();
2418 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2421 _LOGD("manifest pointer is NULL\n");
2425 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2427 _LOGD("Failed to open DB\n");
2430 /*Begin transaction*/
2431 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2432 if (ret != SQLITE_OK) {
2433 _LOGD("Failed to begin transaction\n");
2437 _LOGD("Transaction Begin\n");
2438 ret = __delete_manifest_info_from_db(mfx);
2440 _LOGD("Delete from DB failed. Rollback now\n");
2441 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2444 /*Commit transaction*/
2445 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2446 if (ret != SQLITE_OK) {
2447 _LOGD("Failed to commit transaction, Rollback now\n");
2448 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2452 _LOGD("Transaction Commit and End\n");
2454 pkgmgr_parser_close_db();
2458 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2461 _LOGD("manifest pointer is NULL\n");
2465 ret = pkgmgr_parser_check_and_create_db(uid);
2467 _LOGD("Failed to open DB\n");
2470 /*Begin transaction*/
2471 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2472 if (ret != SQLITE_OK) {
2473 _LOGD("Failed to begin transaction\n");
2477 _LOGD("Transaction Begin\n");
2478 ret = __delete_manifest_info_from_db(mfx);
2480 _LOGD("Delete from DB failed. Rollback now\n");
2481 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2484 /*Commit transaction*/
2485 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2486 if (ret != SQLITE_OK) {
2487 _LOGD("Failed to commit transaction, Rollback now\n");
2488 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2492 _LOGD("Transaction Commit and End\n");
2494 pkgmgr_parser_close_db();
2498 API int pkgmgr_parser_update_preload_info_in_db()
2501 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2503 _LOGD("Failed to open DB\n");
2506 /*Begin transaction*/
2507 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2508 if (ret != SQLITE_OK) {
2509 _LOGD("Failed to begin transaction\n");
2513 _LOGD("Transaction Begin\n");
2514 ret = __update_preload_condition_in_db();
2516 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2517 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2520 /*Commit transaction*/
2521 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2522 if (ret != SQLITE_OK) {
2523 _LOGD("Failed to commit transaction, Rollback now\n");
2524 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2528 _LOGD("Transaction Commit and End\n");
2530 pkgmgr_parser_close_db();
2534 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2537 ret = pkgmgr_parser_check_and_create_db(uid);
2539 _LOGD("Failed to open DB\n");
2542 /*Begin transaction*/
2543 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2544 if (ret != SQLITE_OK) {
2545 _LOGD("Failed to begin transaction\n");
2549 _LOGD("Transaction Begin\n");
2550 ret = __update_preload_condition_in_db();
2552 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2553 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2556 /*Commit transaction*/
2557 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2558 if (ret != SQLITE_OK) {
2559 _LOGD("Failed to commit transaction, Rollback now\n");
2560 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2564 _LOGD("Transaction Commit and End\n");
2566 pkgmgr_parser_close_db();