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>
27 #include <sys/smack.h>
35 /* For multi-user support */
36 #include <tzplatform_config.h>
38 #include "pkgmgr-info.h"
39 #include "pkgmgr_parser_internal.h"
40 #include "pkgmgr_parser_db.h"
42 #include "pkgmgr-info-debug.h"
47 #define LOG_TAG "PKGMGR_PARSER"
49 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
50 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
51 #define MAX_QUERY_LEN 4096
55 #define SET_SMACK_LABEL(x,uid) \
56 if(smack_setlabel((x), (((uid) == GLOBAL_USER)?"*":"User"), SMACK_LABEL_ACCESS)) _LOGE("failed chsmack -a \"User/*\" %s", x); \
57 else _LOGD("chsmack -a \"User/*\" %s", x);
59 sqlite3 *pkgmgr_parser_db;
60 sqlite3 *pkgmgr_cert_db;
63 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
64 "(package text primary key not null, " \
65 "package_type text DEFAULT 'rpm', " \
66 "package_version text, " \
67 "install_location text, " \
68 "package_size text, " \
69 "package_removable text DEFAULT 'true', " \
70 "package_preload text DEFAULT 'false', " \
71 "package_readonly text DEFAULT 'false', " \
72 "package_update text DEFAULT 'false', " \
73 "package_appsetting text DEFAULT 'false', " \
74 "package_nodisplay text DEFAULT 'false', " \
75 "package_system text DEFAULT 'false', " \
76 "author_name text, " \
77 "author_email text, " \
79 "installed_time text," \
80 "installed_storage text," \
81 "storeclient_id text," \
87 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
88 "(package text not null, " \
89 "package_locale text DEFAULT 'No Locale', " \
90 "package_label text, " \
91 "package_icon text, " \
92 "package_description text, " \
93 "package_license text, " \
95 "PRIMARY KEY(package, package_locale), " \
96 "FOREIGN KEY(package) " \
97 "REFERENCES package_info(package) " \
100 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
101 "(package text not null, " \
102 "privilege text not null, " \
103 "PRIMARY KEY(package, privilege) " \
104 "FOREIGN KEY(package) " \
105 "REFERENCES package_info(package) " \
108 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
109 "(app_id text primary key not null, " \
110 "app_component text, " \
112 "app_nodisplay text DEFAULT 'false', " \
114 "app_onboot text DEFAULT 'false', " \
115 "app_multiple text DEFAULT 'false', " \
116 "app_autorestart text DEFAULT 'false', " \
117 "app_taskmanage text DEFAULT 'false', " \
118 "app_enabled text DEFAULT 'true', " \
119 "app_hwacceleration text DEFAULT 'use-system-setting', " \
120 "app_screenreader text DEFAULT 'use-system-setting', " \
121 "app_mainapp text, " \
122 "app_recentimage text, " \
123 "app_launchcondition text, " \
124 "app_indicatordisplay text DEFAULT 'true', " \
125 "app_portraitimg text, " \
126 "app_landscapeimg text, " \
127 "app_guestmodevisibility text DEFAULT 'true', " \
128 "app_permissiontype text DEFAULT 'normal', " \
129 "app_preload text DEFAULT 'false', " \
130 "app_submode text DEFAULT 'false', " \
131 "app_submode_mainid text, " \
132 "component_type text, " \
133 "package text not null, " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
139 "(app_id text not null, " \
140 "app_locale text DEFAULT 'No Locale', " \
143 "PRIMARY KEY(app_id,app_locale) " \
144 "FOREIGN KEY(app_id) " \
145 "REFERENCES package_app_info(app_id) " \
148 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
149 "(app_id text not null, " \
151 "app_icon_section text, " \
152 "app_icon_resolution text, " \
153 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
154 "FOREIGN KEY(app_id) " \
155 "REFERENCES package_app_info(app_id) " \
158 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
159 "(app_id text not null, " \
160 "app_locale text DEFAULT 'No Locale', " \
161 "app_image_section text, " \
163 "PRIMARY KEY(app_id,app_image_section) " \
164 "FOREIGN KEY(app_id) " \
165 "REFERENCES package_app_info(app_id) " \
168 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
169 "(app_id text not null, " \
170 "operation text not null, " \
171 "uri_scheme text, " \
173 "subapp_name text, " \
174 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
175 "FOREIGN KEY(app_id) " \
176 "REFERENCES package_app_info(app_id) " \
179 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
180 "(app_id text not null, " \
181 "operation text not null, " \
182 "uri_scheme text, " \
184 "subapp_name text, " \
185 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
186 "FOREIGN KEY(app_id) " \
187 "REFERENCES package_app_info(app_id) " \
190 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
191 "(app_id text not null, " \
192 "category text not null, " \
193 "PRIMARY KEY(app_id,category) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
199 "(app_id text not null, " \
200 "md_key text not null, " \
201 "md_value text not null, " \
202 "PRIMARY KEY(app_id, md_key, md_value) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
208 "(app_id text not null, " \
209 "pm_type text not null, " \
210 "pm_value text not null, " \
211 "PRIMARY KEY(app_id, pm_type, pm_value) " \
212 "FOREIGN KEY(app_id) " \
213 "REFERENCES package_app_info(app_id) " \
216 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
217 "(app_id text not null, " \
218 "data_share_path text not null, " \
219 "data_share_allowed text not null, " \
220 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
226 "(app_id text not null, " \
227 "data_share_request text not null, " \
228 "PRIMARY KEY(app_id,data_share_request) " \
229 "FOREIGN KEY(app_id) " \
230 "REFERENCES package_app_info(app_id) " \
233 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
234 "(cert_info text not null, " \
235 "cert_id integer, " \
236 "cert_ref_count integer, " \
237 "PRIMARY KEY(cert_id)) "
239 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
240 "(package text not null, " \
241 "author_root_cert integer, " \
242 "author_im_cert integer, " \
243 "author_signer_cert integer, " \
244 "dist_root_cert integer, " \
245 "dist_im_cert integer, " \
246 "dist_signer_cert integer, " \
247 "dist2_root_cert integer, " \
248 "dist2_im_cert integer, " \
249 "dist2_signer_cert integer, " \
250 "PRIMARY KEY(package)) "
252 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
253 "(app_id text not null, " \
254 "provider_id text not null, " \
255 "access text not null, " \
256 "type text not null, " \
257 "PRIMARY KEY(app_id, provider_id, access, type) " \
258 "FOREIGN KEY(app_id) " \
259 "REFERENCES package_app_info(app_id) " \
262 static int __insert_uiapplication_info(manifest_x *mfx);
263 static int __insert_serviceapplication_info(manifest_x *mfx);
264 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
265 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
266 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
267 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
268 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
269 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
270 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
271 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
272 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
273 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
274 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
275 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
276 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
277 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
278 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
279 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
280 static int __insert_manifest_info_in_db(manifest_x *mfx);
281 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
282 static int __delete_subpkg_info_from_db(char *appid);
283 static int __delete_appinfo_from_db(char *db_table, const char *appid);
284 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
285 static int __exec_query(char *query);
286 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
287 char **label, char **license, char **icon, char **description, char **author);
288 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
289 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
290 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
291 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
292 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
293 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
295 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
298 __delete_subpkg_info_from_db(coltxt[0]);
303 static char *__get_str(const char *str)
307 return PKGMGR_PARSER_EMPTY_STR;
313 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
317 char *pk, key1, key2, key3, key4, key5;
319 if (access(db_path, F_OK) == 0) {
321 db_util_open(db_path, &handle,
322 DB_UTIL_REGISTER_HOOK_METHOD);
323 if (ret != SQLITE_OK) {
324 _LOGD("connect db [%s] failed!\n",
331 _LOGD("%s DB does not exists. Create one!!\n", db_path);
334 db_util_open(db_path, &handle,
335 DB_UTIL_REGISTER_HOOK_METHOD);
337 if (ret != SQLITE_OK) {
338 _LOGD("connect db [%s] failed!\n", db_path);
346 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
351 if (access(db_path, F_OK) == 0) {
353 db_util_open(db_path, &handle,
354 DB_UTIL_REGISTER_HOOK_METHOD);
355 if (ret != SQLITE_OK) {
356 _LOGD("connect db [%s] failed!\n",
363 _LOGD("%s DB does not exists. Create one!!\n", db_path);
366 db_util_open(db_path, &handle,
367 DB_UTIL_REGISTER_HOOK_METHOD);
369 if (ret != SQLITE_OK) {
370 _LOGD("connect db [%s] failed!\n", db_path);
378 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
380 manifest_x *mfx = (manifest_x *)data;
384 uiapplication_x *uiapp = NULL;
385 for(i = 0; i < ncols; i++)
387 uiapp = mfx->uiapplication;
388 if (strcmp(colname[i], "app_id") == 0) {
390 appid = strdup(coltxt[i]);
391 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
393 status = strdup(coltxt[i]);
397 _LOGD("app id is NULL\n");
400 /*update guest mode visibility*/
401 for (; uiapp != NULL; uiapp = uiapp->next) {
402 if (strcmp(uiapp->appid, appid) == 0) {
403 free((void *)uiapp->guestmode_visibility);
404 uiapp->guestmode_visibility = strdup(status);
420 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
422 char *error_message = NULL;
423 char query[MAX_QUERY_LEN] = {'\0'};
424 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
426 sqlite3_exec(pkgmgr_parser_db, query,
427 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
428 _LOGD("Don't execute query = %s error message = %s\n",
429 query, error_message);
430 sqlite3_free(error_message);
435 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
437 char *error_message = NULL;
439 sqlite3_exec(db_handle, db_query,
440 NULL, NULL, &error_message)) {
441 _LOGD("Don't execute query = %s error message = %s\n",
442 db_query, error_message);
443 sqlite3_free(error_message);
446 sqlite3_free(error_message);
450 static int __exec_query(char *query)
452 char *error_message = NULL;
454 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
455 _LOGD("Don't execute query = %s error message = %s\n", query,
457 sqlite3_free(error_message);
460 sqlite3_free(error_message);
464 static int __exec_query_no_msg(char *query)
466 char *error_message = NULL;
468 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
469 sqlite3_free(error_message);
472 sqlite3_free(error_message);
476 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
482 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
488 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
494 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
500 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
506 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
513 static GList *__create_icon_list(GList *locale, icon_x *icn)
518 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
524 static GList *__create_image_list(GList *locale, image_x *image)
529 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
535 static void __printfunc(gpointer data, gpointer userdata)
537 _LOGD("%s ", (char*)data);
540 static void __trimfunc(GList* trim_list)
542 char *trim_data = NULL;
546 list = g_list_first(trim_list);
549 trim_data = (char *)list->data;
552 if (strcmp(trim_data, prev) == 0) {
553 trim_list = g_list_remove(trim_list, trim_data);
554 list = g_list_first(trim_list);
563 list = g_list_next(list);
567 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
569 if (a == NULL || b == NULL)
571 if (strcmp((char*)a, (char*)b) == 0)
573 if (strcmp((char*)a, (char*)b) < 0)
575 if (strcmp((char*)a, (char*)b) > 0)
580 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
581 char **label, char **license, char **icon, char **description, char **author)
586 if (strcmp(lbl->lang, (char *)data) == 0) {
587 *label = (char*)lbl->text;
596 if (strcmp(lcn->lang, (char *)data) == 0) {
597 *license = (char*)lcn->text;
606 if (strcmp(icn->lang, (char *)data) == 0) {
607 *icon = (char*)icn->text;
616 if (strcmp(dcn->lang, (char *)data) == 0) {
617 *description = (char*)dcn->text;
626 if (strcmp(ath->lang, (char *)data) == 0) {
627 *author = (char*)ath->text;
636 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
641 if (strcmp(icn->section, (char *)data) == 0) {
642 *icon = (char*)icn->text;
643 *resolution = (char*)icn->resolution;
651 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
655 if (image->section) {
656 if (strcmp(image->section, (char *)data) == 0) {
657 *lang = (char*)image->lang;
658 *img = (char*)image->text;
666 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
671 char *description = NULL;
672 char *license = NULL;
674 char query[MAX_QUERY_LEN] = {'\0'};
676 manifest_x *mfx = (manifest_x *)userdata;
677 label_x *lbl = mfx->label;
678 license_x *lcn = mfx->license;
679 icon_x *icn = mfx->icon;
680 description_x *dcn = mfx->description;
681 author_x *ath = mfx->author;
683 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
684 if (!label && !description && !icon && !license && !author)
687 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
688 "package_label, package_icon, package_description, package_license, package_author) values " \
689 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
694 __get_str(description),
698 ret = __exec_query(query);
700 _LOGD("Package Localized Info DB Insert failed\n");
703 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
708 char query[MAX_QUERY_LEN] = {'\0'};
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);
717 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
718 "app_label, app_icon) values " \
719 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
721 ret = __exec_query(query);
723 _LOGD("Package UiApp Localized Info DB Insert failed\n");
725 /*insert ui app locale info to pkg locale to get mainapp data */
726 if (strcasecmp(up->mainapp, "true")==0) {
727 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
728 "package_label, package_icon, package_description, package_license, package_author) values " \
729 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
734 PKGMGR_PARSER_EMPTY_STR,
735 PKGMGR_PARSER_EMPTY_STR,
736 PKGMGR_PARSER_EMPTY_STR);
738 ret = __exec_query_no_msg(query);
741 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
742 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
743 ret = __exec_query_no_msg(query);
748 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
752 char *resolution = NULL;
753 char query[MAX_QUERY_LEN] = {'\0'};
755 uiapplication_x *up = (uiapplication_x*)userdata;
756 icon_x *icn = up->icon;
758 __extract_icon_data(data, icn, &icon, &resolution);
759 if (!icon && !resolution)
761 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
762 "app_icon, app_icon_section, app_icon_resolution) values " \
763 "('%q', '%q', '%q', '%q')", up->appid,
764 icon, (char*)data, resolution);
766 ret = __exec_query(query);
768 _LOGD("Package UiApp Localized Info DB Insert failed\n");
772 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
777 char query[MAX_QUERY_LEN] = {'\0'};
779 uiapplication_x *up = (uiapplication_x*)userdata;
780 image_x *image = up->image;
782 __extract_image_data(data, image, &lang, &img);
785 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
786 "app_image_section, app_image) values " \
787 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
789 ret = __exec_query(query);
791 _LOGD("Package UiApp image Info DB Insert failed\n");
796 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
801 char query[MAX_QUERY_LEN] = {'\0'};
803 serviceapplication_x *sp = (serviceapplication_x*)userdata;
804 label_x *lbl = sp->label;
805 icon_x *icn = sp->icon;
807 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
810 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
811 "app_label, app_icon) values " \
812 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
814 ret = __exec_query(query);
816 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
819 static int __insert_ui_mainapp_info(manifest_x *mfx)
821 uiapplication_x *up = mfx->uiapplication;
823 char query[MAX_QUERY_LEN] = {'\0'};
826 snprintf(query, MAX_QUERY_LEN,
827 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
829 ret = __exec_query(query);
831 _LOGD("Package UiApp Info DB Insert Failed\n");
834 if (strcasecmp(up->mainapp, "True")==0)
835 mfx->mainapp_id = strdup(up->appid);
838 memset(query, '\0', MAX_QUERY_LEN);
841 if (mfx->mainapp_id == NULL){
842 if (mfx->uiapplication && mfx->uiapplication->appid) {
843 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
845 _LOGD("Not valid appid\n");
849 ret = __exec_query(query);
851 _LOGD("Package UiApp Info DB Insert Failed\n");
855 free((void *)mfx->uiapplication->mainapp);
856 mfx->uiapplication->mainapp= strdup("true");
857 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
860 memset(query, '\0', MAX_QUERY_LEN);
861 snprintf(query, MAX_QUERY_LEN,
862 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
863 ret = __exec_query(query);
865 _LOGD("Package Info DB update Failed\n");
871 /* _PRODUCT_LAUNCHING_ENHANCED_
872 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
874 static int __insert_uiapplication_info(manifest_x *mfx)
876 uiapplication_x *up = mfx->uiapplication;
878 char query[MAX_QUERY_LEN] = {'\0'};
881 snprintf(query, MAX_QUERY_LEN,
882 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
883 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
884 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
885 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
886 "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')",\
892 PKGMGR_PARSER_EMPTY_STR,
894 PKGMGR_PARSER_EMPTY_STR,
900 __get_str(up->recentimage),
902 up->indicatordisplay,
903 __get_str(up->portraitimg),
904 __get_str(up->landscapeimg),
905 up->guestmode_visibility,
909 __get_str(up->submode_mainid),
913 ret = __exec_query(query);
915 _LOGD("Package UiApp Info DB Insert Failed\n");
919 memset(query, '\0', MAX_QUERY_LEN);
924 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
926 uiapplication_x *up = mfx->uiapplication;
927 category_x *ct = NULL;
929 char query[MAX_QUERY_LEN] = {'\0'};
935 snprintf(query, MAX_QUERY_LEN,
936 "insert into package_app_app_category(app_id, category) " \
937 "values('%s','%s')",\
938 up->appid, ct->name);
939 ret = __exec_query(query);
941 _LOGD("Package UiApp Category Info DB Insert Failed\n");
945 memset(query, '\0', MAX_QUERY_LEN);
952 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
954 uiapplication_x *up = mfx->uiapplication;
955 metadata_x *md = NULL;
957 char query[MAX_QUERY_LEN] = {'\0'};
964 snprintf(query, MAX_QUERY_LEN,
965 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
966 "values('%s','%s', '%s')",\
967 up->appid, md->key, md->value);
968 ret = __exec_query(query);
970 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
975 memset(query, '\0', MAX_QUERY_LEN);
982 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
984 uiapplication_x *up = mfx->uiapplication;
985 permission_x *pm = NULL;
987 char query[MAX_QUERY_LEN] = {'\0'};
993 snprintf(query, MAX_QUERY_LEN,
994 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
995 "values('%s','%s', '%s')",\
996 up->appid, pm->type, pm->value);
997 ret = __exec_query(query);
999 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1003 memset(query, '\0', MAX_QUERY_LEN);
1010 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1012 uiapplication_x *up = mfx->uiapplication;
1013 appcontrol_x *acontrol = NULL;
1014 operation_x *op = NULL;
1017 subapp_x *sub = NULL;
1019 char query[MAX_QUERY_LEN] = {'\0'};
1020 const char *operation = NULL;
1021 const char *mime = NULL;
1022 const char *uri = NULL;
1023 const char *subapp = NULL;
1026 acontrol = up->appcontrol;
1027 while(acontrol != NULL)
1029 op = acontrol->operation;
1033 operation = op->name;
1034 mi = acontrol->mime;
1040 sub = acontrol->subapp;
1050 snprintf(query, MAX_QUERY_LEN,
1051 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1052 "values('%s', '%s', '%s', '%s', '%s')",\
1053 up->appid, operation, uri, mime, subapp);
1055 ret = __exec_query(query);
1057 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1060 memset(query, '\0', MAX_QUERY_LEN);
1064 } while(ui != NULL);
1068 }while(sub != NULL);
1077 acontrol = acontrol->next;
1084 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1086 uiapplication_x *up = mfx->uiapplication;
1087 appsvc_x *asvc = NULL;
1088 operation_x *op = NULL;
1091 subapp_x *sub = NULL;
1093 char query[MAX_QUERY_LEN] = {'\0'};
1094 const char *operation = NULL;
1095 const char *mime = NULL;
1096 const char *uri = NULL;
1097 const char *subapp = NULL;
1103 op = asvc->operation;
1107 operation = op->name;
1124 snprintf(query, MAX_QUERY_LEN,
1125 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1126 "values('%s', '%s', '%s', '%s', '%s')",\
1133 ret = __exec_query(query);
1135 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1138 memset(query, '\0', MAX_QUERY_LEN);
1142 } while(ui != NULL);
1146 }while(sub != NULL);
1162 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1164 uiapplication_x *up = mfx->uiapplication;
1165 datashare_x *ds = NULL;
1166 request_x *rq = NULL;
1168 char query[MAX_QUERY_LEN] = {'\0'};
1177 snprintf(query, MAX_QUERY_LEN,
1178 "insert into package_app_share_request(app_id, data_share_request) " \
1179 "values('%s', '%s')",\
1180 up->appid, rq->text);
1181 ret = __exec_query(query);
1183 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1186 memset(query, '\0', MAX_QUERY_LEN);
1196 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1198 uiapplication_x *up = mfx->uiapplication;
1199 datashare_x *ds = NULL;
1200 define_x *df = NULL;
1201 allowed_x *al = NULL;
1203 char query[MAX_QUERY_LEN] = {'\0'};
1215 snprintf(query, MAX_QUERY_LEN,
1216 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1217 "values('%s', '%s', '%s')",\
1218 up->appid, df->path, al->text);
1219 ret = __exec_query(query);
1221 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1224 memset(query, '\0', MAX_QUERY_LEN);
1236 static int __insert_serviceapplication_info(manifest_x *mfx)
1238 serviceapplication_x *sp = mfx->serviceapplication;
1240 char query[MAX_QUERY_LEN] = {'\0'};
1243 snprintf(query, MAX_QUERY_LEN,
1244 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1245 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1246 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1247 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1248 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1249 ret = __exec_query(query);
1251 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1255 memset(query, '\0', MAX_QUERY_LEN);
1260 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1262 serviceapplication_x *sp = mfx->serviceapplication;
1263 category_x *ct = NULL;
1265 char query[MAX_QUERY_LEN] = {'\0'};
1271 snprintf(query, MAX_QUERY_LEN,
1272 "insert into package_app_app_category(app_id, category) " \
1273 "values('%s','%s')",\
1274 sp->appid, ct->name);
1275 ret = __exec_query(query);
1277 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1281 memset(query, '\0', MAX_QUERY_LEN);
1288 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1290 serviceapplication_x *sp = mfx->serviceapplication;
1291 metadata_x *md = NULL;
1293 char query[MAX_QUERY_LEN] = {'\0'};
1300 snprintf(query, MAX_QUERY_LEN,
1301 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1302 "values('%s','%s', '%s')",\
1303 sp->appid, md->key, md->value);
1304 ret = __exec_query(query);
1306 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1311 memset(query, '\0', MAX_QUERY_LEN);
1318 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1320 serviceapplication_x *sp = mfx->serviceapplication;
1321 permission_x *pm = NULL;
1323 char query[MAX_QUERY_LEN] = {'\0'};
1326 pm = sp->permission;
1329 snprintf(query, MAX_QUERY_LEN,
1330 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1331 "values('%s','%s', '%s')",\
1332 sp->appid, pm->type, pm->value);
1333 ret = __exec_query(query);
1335 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1339 memset(query, '\0', MAX_QUERY_LEN);
1346 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1348 serviceapplication_x *sp = mfx->serviceapplication;
1349 appcontrol_x *acontrol = NULL;
1351 char query[MAX_QUERY_LEN] = {'\0'};
1352 operation_x *op = NULL;
1355 subapp_x *sub = NULL;
1356 const char *operation = NULL;
1357 const char *mime = NULL;
1358 const char *uri = NULL;
1359 const char *subapp = NULL;
1362 acontrol = sp->appcontrol;
1363 while(acontrol != NULL)
1365 op = acontrol->operation;
1369 operation = op->name;
1370 mi = acontrol->mime;
1375 sub = acontrol->subapp;
1385 snprintf(query, MAX_QUERY_LEN,
1386 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1387 "values('%s', '%s', '%s', '%s', '%s')",\
1388 sp->appid, operation, uri, mime, subapp);
1389 ret = __exec_query(query);
1391 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1394 memset(query, '\0', MAX_QUERY_LEN);
1398 } while(ui != NULL);
1402 }while(sub != NULL);
1411 acontrol = acontrol->next;
1418 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1420 serviceapplication_x *sp = mfx->serviceapplication;
1421 appsvc_x *asvc = NULL;
1423 char query[MAX_QUERY_LEN] = {'\0'};
1424 operation_x *op = NULL;
1427 subapp_x *sub = NULL;
1428 const char *operation = NULL;
1429 const char *mime = NULL;
1430 const char *uri = NULL;
1431 const char *subapp = NULL;
1437 op = asvc->operation;
1441 operation = op->name;
1457 snprintf(query, MAX_QUERY_LEN,
1458 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1459 "values('%s', '%s', '%s', '%s', '%s')",\
1465 ret = __exec_query(query);
1467 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1470 memset(query, '\0', MAX_QUERY_LEN);
1474 } while(ui != NULL);
1478 }while(sub != NULL);
1494 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1496 serviceapplication_x *sp = mfx->serviceapplication;
1497 datacontrol_x *dc = NULL;
1499 char query[MAX_QUERY_LEN] = {'\0'};
1503 dc = sp->datacontrol;
1506 snprintf(query, MAX_QUERY_LEN,
1507 "insert into package_app_data_control(app_id, provider_id, access, type) " \
1508 "values('%s', '%s', '%s', '%s')",\
1509 mfx->serviceapplication->appid,
1514 ret = __exec_query(query);
1516 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1519 memset(query, '\0', MAX_QUERY_LEN);
1527 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1529 serviceapplication_x *sp = mfx->serviceapplication;
1530 datashare_x *ds = NULL;
1531 request_x *rq = NULL;
1533 char query[MAX_QUERY_LEN] = {'\0'};
1542 snprintf(query, MAX_QUERY_LEN,
1543 "insert into package_app_share_request(app_id, data_share_request) " \
1544 "values('%s', '%s')",\
1545 sp->appid, rq->text);
1546 ret = __exec_query(query);
1548 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1551 memset(query, '\0', MAX_QUERY_LEN);
1563 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1565 serviceapplication_x *sp = mfx->serviceapplication;
1566 datashare_x *ds = NULL;
1567 define_x *df = NULL;
1568 allowed_x *al = NULL;
1570 char query[MAX_QUERY_LEN] = {'\0'};
1582 snprintf(query, MAX_QUERY_LEN,
1583 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1584 "values('%s', '%s', '%s')",\
1585 sp->appid, df->path, al->text);
1586 ret = __exec_query(query);
1588 _LOGD("Package App Share Allowed DB Insert Failed\n");
1591 memset(query, '\0', MAX_QUERY_LEN);
1603 static int __insert_manifest_info_in_db(manifest_x *mfx)
1605 label_x *lbl = mfx->label;
1606 license_x *lcn = mfx->license;
1607 icon_x *icn = mfx->icon;
1608 description_x *dcn = mfx->description;
1609 author_x *ath = mfx->author;
1610 uiapplication_x *up = mfx->uiapplication;
1611 uiapplication_x *up_icn = mfx->uiapplication;
1612 uiapplication_x *up_image = mfx->uiapplication;
1613 serviceapplication_x *sp = mfx->serviceapplication;
1614 privileges_x *pvs = NULL;
1615 privilege_x *pv = NULL;
1616 char query[MAX_QUERY_LEN] = { '\0' };
1617 char root[MAX_QUERY_LEN] = { '\0' };
1621 const char *auth_name = NULL;
1622 const char *auth_email = NULL;
1623 const char *auth_href = NULL;
1624 const char *apps_path = NULL;
1626 GList *pkglocale = NULL;
1627 GList *applocale = NULL;
1628 GList *appicon = NULL;
1629 GList *appimage = NULL;
1633 auth_name = ath->text;
1635 auth_email = ath->email;
1637 auth_href = ath->href;
1639 /*Insert in the package_info DB*/
1641 type = strdup(mfx->type);
1643 type = strdup("rpm");
1644 /*Insert in the package_info DB*/
1646 path = strdup(mfx->root_path);
1648 if (strcmp(type,"rpm")==0) {
1649 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1650 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1652 apps_path = tzplatform_getenv(TZ_USER_APP);
1653 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1655 path = strdup(root);
1657 snprintf(query, MAX_QUERY_LEN,
1658 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1659 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1660 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1661 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1665 __get_str(mfx->installlocation),
1666 __get_str(mfx->package_size),
1672 mfx->nodisplay_setting,
1674 __get_str(auth_name),
1675 __get_str(auth_email),
1676 __get_str(auth_href),
1677 mfx->installed_time,
1678 mfx->installed_storage,
1679 __get_str(mfx->storeclient_id),
1681 __get_str(mfx->package_url),
1683 __get_str(mfx->csc_path));
1684 /*If package dont have main_package tag, this package is main package.*/
1685 if (mfx->main_package == NULL) {
1686 ret = __exec_query(query);
1688 _LOGD("Package Info DB Insert Failed\n");
1700 /*If package has main_package tag, this package is sub package(ug, efl).
1701 skip __exec_query for package_info and change pkgid with main_package*/
1702 memset(root, '\0', MAX_QUERY_LEN);
1703 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1704 if (access(root, F_OK) == 0) {
1705 free((void *)mfx->package);
1706 mfx->package = strdup(mfx->main_package);
1708 _LOGE("main package[%s] is not installed\n", root);
1721 /*Insert in the package_privilege_info DB*/
1722 pvs = mfx->privileges;
1723 while (pvs != NULL) {
1724 pv = pvs->privilege;
1725 while (pv != NULL) {
1726 memset(query, '\0', MAX_QUERY_LEN);
1727 snprintf(query, MAX_QUERY_LEN,
1728 "insert into package_privilege_info(package, privilege) " \
1729 "values('%s','%s')",\
1730 mfx->package, pv->text);
1731 ret = __exec_query(query);
1733 _LOGD("Package Privilege Info DB Insert Failed\n");
1742 ret = __insert_ui_mainapp_info(mfx);
1747 /*Insert the package locale*/
1748 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1749 /*remove duplicated data in pkglocale*/
1750 __trimfunc(pkglocale);
1752 /*Insert the app locale info */
1755 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1760 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1763 /*remove duplicated data in applocale*/
1764 __trimfunc(applocale);
1766 /*Insert the app icon info */
1767 while(up_icn != NULL)
1769 appicon = __create_icon_list(appicon, up_icn->icon);
1770 up_icn = up_icn->next;
1772 /*remove duplicated data in appicon*/
1773 __trimfunc(appicon);
1775 /*Insert the image info */
1776 while(up_image != NULL)
1778 appimage = __create_image_list(appimage, up_image->image);
1779 up_image = up_image->next;
1781 /*remove duplicated data in appimage*/
1782 __trimfunc(appimage);
1784 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1786 /*g_list_foreach(applocale, __printfunc, NULL);*/
1788 /*package locale info, it is only for main package.*/
1789 if (mfx->main_package == NULL)
1790 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1792 /*native app locale info*/
1793 up = mfx->uiapplication;
1796 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1799 /*agent app locale info*/
1800 sp = mfx->serviceapplication;
1803 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1807 /*app icon locale info*/
1808 up_icn = mfx->uiapplication;
1809 while(up_icn != NULL)
1811 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1812 up_icn = up_icn->next;
1816 up_image = mfx->uiapplication;
1817 while(up_image != NULL)
1819 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1820 up_image = up_image->next;
1823 g_list_free(pkglocale);
1825 g_list_free(applocale);
1827 g_list_free(appicon);
1829 g_list_free(appimage);
1832 /*Insert in the package_app_info DB*/
1833 ret = __insert_uiapplication_info(mfx);
1836 ret = __insert_serviceapplication_info(mfx);
1839 /*Insert in the package_app_app_control DB*/
1840 ret = __insert_uiapplication_appcontrol_info(mfx);
1843 ret = __insert_serviceapplication_appcontrol_info(mfx);
1847 /*Insert in the package_app_app_category DB*/
1848 ret = __insert_uiapplication_appcategory_info(mfx);
1851 ret = __insert_serviceapplication_appcategory_info(mfx);
1855 /*Insert in the package_app_app_metadata DB*/
1856 ret = __insert_uiapplication_appmetadata_info(mfx);
1859 ret = __insert_serviceapplication_appmetadata_info(mfx);
1863 /*Insert in the package_app_app_permission DB*/
1864 ret = __insert_uiapplication_apppermission_info(mfx);
1867 ret = __insert_serviceapplication_apppermission_info(mfx);
1871 /*Insert in the package_app_app_svc DB*/
1872 ret = __insert_uiapplication_appsvc_info(mfx);
1875 ret = __insert_serviceapplication_appsvc_info(mfx);
1879 /*Insert in the package_app_share_allowed DB*/
1880 ret = __insert_uiapplication_share_allowed_info(mfx);
1883 ret = __insert_serviceapplication_share_allowed_info(mfx);
1887 /*Insert in the package_app_share_request DB*/
1888 ret = __insert_uiapplication_share_request_info(mfx);
1891 ret = __insert_serviceapplication_share_request_info(mfx);
1895 /*Insert in the package_app_data_control DB*/
1896 ret = __insert_serviceapplication_datacontrol_info(mfx);
1904 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1906 char query[MAX_QUERY_LEN] = { '\0' };
1908 memset(query, '\0', MAX_QUERY_LEN);
1909 snprintf(query, MAX_QUERY_LEN,
1910 "delete from %s where app_id='%s'", db_table, appid);
1911 ret = __exec_query(query);
1913 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1919 static int __delete_subpkg_info_from_db(char *appid)
1923 ret = __delete_appinfo_from_db("package_app_info", appid);
1926 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1929 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1932 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1935 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1938 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1941 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1944 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1947 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1950 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1953 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1956 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1963 static int __delete_subpkg_from_db(manifest_x *mfx)
1965 char query[MAX_QUERY_LEN] = { '\0' };
1967 char *error_message = NULL;
1969 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1971 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1972 _LOGE("Don't execute query = %s error message = %s\n", query,
1974 sqlite3_free(error_message);
1977 sqlite3_free(error_message);
1982 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1984 char query[MAX_QUERY_LEN] = { '\0' };
1986 uiapplication_x *up = mfx->uiapplication;
1987 serviceapplication_x *sp = mfx->serviceapplication;
1988 /*Delete from cert table*/
1989 if (uid != GLOBAL_USER)
1990 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1992 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1994 _LOGD("Cert Info DB Delete Failed\n");
1998 /*Delete from Package Info DB*/
1999 snprintf(query, MAX_QUERY_LEN,
2000 "delete from package_info where package='%s'", mfx->package);
2001 ret = __exec_query(query);
2003 _LOGD("Package Info DB Delete Failed\n");
2006 memset(query, '\0', MAX_QUERY_LEN);
2008 /*Delete from Package Localized Info*/
2009 snprintf(query, MAX_QUERY_LEN,
2010 "delete from package_localized_info where package='%s'", mfx->package);
2011 ret = __exec_query(query);
2013 _LOGD("Package Localized Info DB Delete Failed\n");
2017 /*Delete from Package Privilege Info*/
2018 snprintf(query, MAX_QUERY_LEN,
2019 "delete from package_privilege_info where package='%s'", mfx->package);
2020 ret = __exec_query(query);
2022 _LOGD("Package Privilege Info DB Delete Failed\n");
2026 while (up != NULL) {
2027 ret = __delete_appinfo_from_db("package_app_info", up->appid);
2030 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
2033 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
2036 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
2039 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
2042 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
2045 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
2048 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
2051 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
2054 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
2057 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2060 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
2066 while (sp != NULL) {
2067 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2070 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2073 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2076 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2079 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2082 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2085 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2088 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2091 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2094 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2097 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2100 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
2106 /* if main package has sub pkg, delete sub pkg data*/
2107 __delete_subpkg_from_db(mfx);
2112 static int __update_preload_condition_in_db()
2115 char query[MAX_QUERY_LEN] = {'\0'};
2117 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2119 ret = __exec_query(query);
2121 _LOGD("Package preload_condition update failed\n");
2126 int pkgmgr_parser_initialize_db()
2130 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2132 _LOGD("package info DB initialization failed\n");
2135 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2137 _LOGD("package localized info DB initialization failed\n");
2140 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2142 _LOGD("package app app privilege DB initialization failed\n");
2145 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2147 _LOGD("package app info DB initialization failed\n");
2150 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2152 _LOGD("package app localized info DB initialization failed\n");
2155 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2157 _LOGD("package app icon localized info DB initialization failed\n");
2160 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2162 _LOGD("package app image info DB initialization failed\n");
2165 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2167 _LOGD("package app app control DB initialization failed\n");
2170 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2172 _LOGD("package app app category DB initialization failed\n");
2175 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2177 _LOGD("package app app category DB initialization failed\n");
2180 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2182 _LOGD("package app app permission DB initialization failed\n");
2185 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2187 _LOGD("package app app svc DB initialization failed\n");
2190 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2192 _LOGD("package app share allowed DB initialization failed\n");
2195 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2197 _LOGD("package app share request DB initialization failed\n");
2200 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2202 _LOGD("package app data control DB initialization failed\n");
2206 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2208 _LOGD("package cert info DB initialization failed\n");
2211 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2213 _LOGD("package cert index info DB initialization failed\n");
2220 static int parserdb_change_perm(const char *db_file, uid_t uid)
2223 char journal_file[BUFSIZE];
2226 struct passwd *userinfo = NULL;
2227 files[0] = (char *)db_file;
2228 files[1] = journal_file;
2234 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2236 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2237 userinfo = getpwuid(uid);
2239 _LOGE("FAIL: user %d doesn't exist", uid);
2242 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2244 for (i = 0; files[i]; i++) {
2245 ret = chown(files[i], uid, userinfo->pw_gid);
2246 SET_SMACK_LABEL(files[i],uid)
2248 strerror_r(errno, buf, sizeof(buf));
2249 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2253 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2255 strerror_r(errno, buf, sizeof(buf));
2256 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2263 int pkgmgr_parser_check_and_create_db(uid_t uid)
2267 ret = __pkgmgr_parser_create_parser_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid), uid);
2268 _LOGD("create db %s", getUserPkgParserDBPathUID(uid));
2270 _LOGD("Manifest DB creation Failed\n");
2275 ret = __pkgmgr_parser_create_cert_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid), uid);
2277 _LOGD("Cert DB creation Failed\n");
2280 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2281 _LOGD("Failed to change cert db permission\n");
2283 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2284 _LOGD("Failed to change parser db permission\n");
2289 void pkgmgr_parser_close_db()
2291 sqlite3_close(pkgmgr_parser_db);
2292 sqlite3_close(pkgmgr_cert_db);
2296 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2298 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2300 _LOGD("manifest pointer is NULL\n");
2304 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2306 _LOGD("Failed to open DB\n");
2309 ret = pkgmgr_parser_initialize_db();
2312 /*Begin transaction*/
2313 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2314 if (ret != SQLITE_OK) {
2315 _LOGD("Failed to begin transaction\n");
2319 _LOGD("Transaction Begin\n");
2320 ret = __insert_manifest_info_in_db(mfx);
2322 _LOGD("Insert into DB failed. Rollback now\n");
2323 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2326 /*Commit transaction*/
2327 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2328 if (ret != SQLITE_OK) {
2329 _LOGD("Failed to commit transaction. Rollback now\n");
2330 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2334 _LOGD("Transaction Commit and End\n");
2336 pkgmgr_parser_close_db();
2340 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2342 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2344 _LOGD("manifest pointer is NULL\n");
2348 ret = pkgmgr_parser_check_and_create_db(uid);
2350 _LOGD("Failed to open DB\n");
2353 ret = pkgmgr_parser_initialize_db();
2356 /*Begin transaction*/
2357 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2358 if (ret != SQLITE_OK) {
2359 _LOGD("Failed to begin transaction\n");
2363 _LOGD("Transaction Begin\n");
2364 ret = __insert_manifest_info_in_db(mfx);
2366 _LOGD("Insert into DB failed. Rollback now\n");
2367 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2370 /*Commit transaction*/
2371 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2372 if (ret != SQLITE_OK) {
2373 _LOGD("Failed to commit transaction. Rollback now\n");
2374 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2378 _LOGD("Transaction Commit and End\n");
2380 pkgmgr_parser_close_db();
2384 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2387 _LOGD("manifest pointer is NULL\n");
2391 ret = pkgmgr_parser_check_and_create_db(uid);
2393 _LOGD("Failed to open DB\n");
2396 ret = pkgmgr_parser_initialize_db();
2399 /*Preserve guest mode visibility*/
2400 __preserve_guestmode_visibility_value( mfx);
2401 /*Begin transaction*/
2402 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2403 if (ret != SQLITE_OK) {
2404 _LOGD("Failed to begin transaction\n");
2408 _LOGD("Transaction Begin\n");
2409 ret = __delete_manifest_info_from_db(mfx, uid);
2411 _LOGD("Delete from DB failed. Rollback now\n");
2412 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2415 ret = __insert_manifest_info_in_db(mfx);
2417 _LOGD("Insert into DB failed. Rollback now\n");
2418 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2422 /*Commit transaction*/
2423 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2424 if (ret != SQLITE_OK) {
2425 _LOGD("Failed to commit transaction. Rollback now\n");
2426 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2430 _LOGD("Transaction Commit and End\n");
2432 pkgmgr_parser_close_db();
2436 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2438 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2441 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2444 _LOGD("manifest pointer is NULL\n");
2448 ret = pkgmgr_parser_check_and_create_db(uid);
2450 _LOGD("Failed to open DB\n");
2453 /*Begin transaction*/
2454 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2455 if (ret != SQLITE_OK) {
2456 _LOGD("Failed to begin transaction\n");
2460 _LOGD("Transaction Begin\n");
2461 ret = __delete_manifest_info_from_db(mfx, uid);
2463 _LOGD("Delete from DB failed. Rollback now\n");
2464 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2467 /*Commit transaction*/
2468 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2469 if (ret != SQLITE_OK) {
2470 _LOGD("Failed to commit transaction, Rollback now\n");
2471 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2475 _LOGD("Transaction Commit and End\n");
2477 pkgmgr_parser_close_db();
2481 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2483 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2486 API int pkgmgr_parser_update_preload_info_in_db()
2489 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2491 _LOGD("Failed to open DB\n");
2494 /*Begin transaction*/
2495 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2496 if (ret != SQLITE_OK) {
2497 _LOGD("Failed to begin transaction\n");
2501 _LOGD("Transaction Begin\n");
2502 ret = __update_preload_condition_in_db();
2504 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2505 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2508 /*Commit transaction*/
2509 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2510 if (ret != SQLITE_OK) {
2511 _LOGD("Failed to commit transaction, Rollback now\n");
2512 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2516 _LOGD("Transaction Commit and End\n");
2518 pkgmgr_parser_close_db();
2522 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2525 ret = pkgmgr_parser_check_and_create_db(uid);
2527 _LOGD("Failed to open DB\n");
2530 /*Begin transaction*/
2531 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2532 if (ret != SQLITE_OK) {
2533 _LOGD("Failed to begin transaction\n");
2537 _LOGD("Transaction Begin\n");
2538 ret = __update_preload_condition_in_db();
2540 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2541 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2544 /*Commit transaction*/
2545 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2546 if (ret != SQLITE_OK) {
2547 _LOGD("Failed to commit transaction, Rollback now\n");
2548 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2552 _LOGD("Transaction Commit and End\n");
2554 pkgmgr_parser_close_db();