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)) "
253 static int __insert_uiapplication_info(manifest_x *mfx);
254 static int __insert_serviceapplication_info(manifest_x *mfx);
255 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
256 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
257 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
258 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
259 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
260 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
261 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
262 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
263 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
264 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
265 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
266 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
267 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
268 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
269 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
270 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
271 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
272 static int __delete_subpkg_info_from_db(char *appid);
273 static int __delete_appinfo_from_db(char *db_table, const char *appid);
274 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
275 static int __exec_query(char *query);
276 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
277 char **label, char **license, char **icon, char **description, char **author);
278 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
279 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
280 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
281 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
282 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
283 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
285 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
288 __delete_subpkg_info_from_db(coltxt[0]);
293 static char *__get_str(const char *str)
297 return PKGMGR_PARSER_EMPTY_STR;
303 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
307 char *pk, key1, key2, key3, key4, key5;
309 if (access(db_path, F_OK) == 0) {
311 db_util_open(db_path, &handle,
312 DB_UTIL_REGISTER_HOOK_METHOD);
313 if (ret != SQLITE_OK) {
314 _LOGD("connect db [%s] failed!\n",
321 _LOGD("%s DB does not exists. Create one!!\n", db_path);
324 db_util_open(db_path, &handle,
325 DB_UTIL_REGISTER_HOOK_METHOD);
327 if (ret != SQLITE_OK) {
328 _LOGD("connect db [%s] failed!\n", db_path);
336 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
341 if (access(db_path, F_OK) == 0) {
343 db_util_open(db_path, &handle,
344 DB_UTIL_REGISTER_HOOK_METHOD);
345 if (ret != SQLITE_OK) {
346 _LOGD("connect db [%s] failed!\n",
353 _LOGD("%s DB does not exists. Create one!!\n", db_path);
356 db_util_open(db_path, &handle,
357 DB_UTIL_REGISTER_HOOK_METHOD);
359 if (ret != SQLITE_OK) {
360 _LOGD("connect db [%s] failed!\n", db_path);
368 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
370 manifest_x *mfx = (manifest_x *)data;
374 uiapplication_x *uiapp = NULL;
375 for(i = 0; i < ncols; i++)
377 uiapp = mfx->uiapplication;
378 if (strcmp(colname[i], "app_id") == 0) {
380 appid = strdup(coltxt[i]);
381 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
383 status = strdup(coltxt[i]);
387 _LOGD("app id is NULL\n");
390 /*update guest mode visibility*/
391 for (; uiapp != NULL; uiapp = uiapp->next) {
392 if (strcmp(uiapp->appid, appid) == 0) {
393 free((void *)uiapp->guestmode_visibility);
394 uiapp->guestmode_visibility = strdup(status);
410 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
412 char *error_message = NULL;
413 char query[MAX_QUERY_LEN] = {'\0'};
414 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
416 sqlite3_exec(pkgmgr_parser_db, query,
417 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
418 _LOGD("Don't execute query = %s error message = %s\n",
419 query, error_message);
420 sqlite3_free(error_message);
425 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
427 char *error_message = NULL;
429 sqlite3_exec(db_handle, db_query,
430 NULL, NULL, &error_message)) {
431 _LOGD("Don't execute query = %s error message = %s\n",
432 db_query, error_message);
433 sqlite3_free(error_message);
436 sqlite3_free(error_message);
440 static int __exec_query(char *query)
442 char *error_message = NULL;
444 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
445 _LOGD("Don't execute query = %s error message = %s\n", query,
447 sqlite3_free(error_message);
450 sqlite3_free(error_message);
454 static int __exec_query_no_msg(char *query)
456 char *error_message = NULL;
458 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
459 sqlite3_free(error_message);
462 sqlite3_free(error_message);
466 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
472 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
478 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
484 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
490 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
496 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
503 static GList *__create_icon_list(GList *locale, icon_x *icn)
508 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
514 static GList *__create_image_list(GList *locale, image_x *image)
519 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
525 static void __printfunc(gpointer data, gpointer userdata)
527 _LOGD("%s ", (char*)data);
530 static void __trimfunc(GList* trim_list)
532 char *trim_data = NULL;
536 list = g_list_first(trim_list);
539 trim_data = (char *)list->data;
542 if (strcmp(trim_data, prev) == 0) {
543 trim_list = g_list_remove(trim_list, trim_data);
544 list = g_list_first(trim_list);
553 list = g_list_next(list);
557 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
559 if (a == NULL || b == NULL)
561 if (strcmp((char*)a, (char*)b) == 0)
563 if (strcmp((char*)a, (char*)b) < 0)
565 if (strcmp((char*)a, (char*)b) > 0)
570 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
571 char **label, char **license, char **icon, char **description, char **author)
576 if (strcmp(lbl->lang, (char *)data) == 0) {
577 *label = (char*)lbl->text;
586 if (strcmp(lcn->lang, (char *)data) == 0) {
587 *license = (char*)lcn->text;
596 if (strcmp(icn->lang, (char *)data) == 0) {
597 *icon = (char*)icn->text;
606 if (strcmp(dcn->lang, (char *)data) == 0) {
607 *description = (char*)dcn->text;
616 if (strcmp(ath->lang, (char *)data) == 0) {
617 *author = (char*)ath->text;
626 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
631 if (strcmp(icn->section, (char *)data) == 0) {
632 *icon = (char*)icn->text;
633 *resolution = (char*)icn->resolution;
641 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
645 if (image->section) {
646 if (strcmp(image->section, (char *)data) == 0) {
647 *lang = (char*)image->lang;
648 *img = (char*)image->text;
656 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
661 char *description = NULL;
662 char *license = NULL;
664 char query[MAX_QUERY_LEN] = {'\0'};
666 manifest_x *mfx = (manifest_x *)userdata;
667 label_x *lbl = mfx->label;
668 license_x *lcn = mfx->license;
669 icon_x *icn = mfx->icon;
670 description_x *dcn = mfx->description;
671 author_x *ath = mfx->author;
673 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
674 if (!label && !description && !icon && !license && !author)
677 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
678 "package_label, package_icon, package_description, package_license, package_author) values " \
679 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
684 __get_str(description),
688 ret = __exec_query(query);
690 _LOGD("Package Localized Info DB Insert failed\n");
693 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
698 char query[MAX_QUERY_LEN] = {'\0'};
700 uiapplication_x *up = (uiapplication_x*)userdata;
701 label_x *lbl = up->label;
702 icon_x *icn = up->icon;
704 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
707 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
708 "app_label, app_icon) values " \
709 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
711 ret = __exec_query(query);
713 _LOGD("Package UiApp Localized Info DB Insert failed\n");
715 /*insert ui app locale info to pkg locale to get mainapp data */
716 if (strcasecmp(up->mainapp, "true")==0) {
717 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
718 "package_label, package_icon, package_description, package_license, package_author) values " \
719 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
724 PKGMGR_PARSER_EMPTY_STR,
725 PKGMGR_PARSER_EMPTY_STR,
726 PKGMGR_PARSER_EMPTY_STR);
728 ret = __exec_query_no_msg(query);
731 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
732 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
733 ret = __exec_query_no_msg(query);
738 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
742 char *resolution = NULL;
743 char query[MAX_QUERY_LEN] = {'\0'};
745 uiapplication_x *up = (uiapplication_x*)userdata;
746 icon_x *icn = up->icon;
748 __extract_icon_data(data, icn, &icon, &resolution);
749 if (!icon && !resolution)
751 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
752 "app_icon, app_icon_section, app_icon_resolution) values " \
753 "('%q', '%q', '%q', '%q')", up->appid,
754 icon, (char*)data, resolution);
756 ret = __exec_query(query);
758 _LOGD("Package UiApp Localized Info DB Insert failed\n");
762 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
767 char query[MAX_QUERY_LEN] = {'\0'};
769 uiapplication_x *up = (uiapplication_x*)userdata;
770 image_x *image = up->image;
772 __extract_image_data(data, image, &lang, &img);
775 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
776 "app_image_section, app_image) values " \
777 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
779 ret = __exec_query(query);
781 _LOGD("Package UiApp image Info DB Insert failed\n");
786 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
791 char query[MAX_QUERY_LEN] = {'\0'};
793 serviceapplication_x *sp = (serviceapplication_x*)userdata;
794 label_x *lbl = sp->label;
795 icon_x *icn = sp->icon;
797 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
800 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
801 "app_label, app_icon) values " \
802 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
804 ret = __exec_query(query);
806 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
809 static int __insert_ui_mainapp_info(manifest_x *mfx)
811 uiapplication_x *up = mfx->uiapplication;
813 char query[MAX_QUERY_LEN] = {'\0'};
816 snprintf(query, MAX_QUERY_LEN,
817 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
819 ret = __exec_query(query);
821 _LOGD("Package UiApp Info DB Insert Failed\n");
824 if (strcasecmp(up->mainapp, "True")==0)
825 mfx->mainapp_id = strdup(up->appid);
828 memset(query, '\0', MAX_QUERY_LEN);
831 if (mfx->mainapp_id == NULL){
832 if (mfx->uiapplication && mfx->uiapplication->appid) {
833 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
835 _LOGD("Not valid appid\n");
839 ret = __exec_query(query);
841 _LOGD("Package UiApp Info DB Insert Failed\n");
845 free((void *)mfx->uiapplication->mainapp);
846 mfx->uiapplication->mainapp= strdup("true");
847 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
850 memset(query, '\0', MAX_QUERY_LEN);
851 snprintf(query, MAX_QUERY_LEN,
852 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
853 ret = __exec_query(query);
855 _LOGD("Package Info DB update Failed\n");
861 /* _PRODUCT_LAUNCHING_ENHANCED_
862 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
864 static int __insert_uiapplication_info(manifest_x *mfx)
866 uiapplication_x *up = mfx->uiapplication;
868 char query[MAX_QUERY_LEN] = {'\0'};
871 snprintf(query, MAX_QUERY_LEN,
872 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
873 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
874 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
875 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
876 "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')",\
882 PKGMGR_PARSER_EMPTY_STR,
884 PKGMGR_PARSER_EMPTY_STR,
890 __get_str(up->recentimage),
892 up->indicatordisplay,
893 __get_str(up->portraitimg),
894 __get_str(up->landscapeimg),
895 up->guestmode_visibility,
899 __get_str(up->submode_mainid),
903 ret = __exec_query(query);
905 _LOGD("Package UiApp Info DB Insert Failed\n");
909 memset(query, '\0', MAX_QUERY_LEN);
914 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
916 uiapplication_x *up = mfx->uiapplication;
917 category_x *ct = NULL;
919 char query[MAX_QUERY_LEN] = {'\0'};
925 snprintf(query, MAX_QUERY_LEN,
926 "insert into package_app_app_category(app_id, category) " \
927 "values('%s','%s')",\
928 up->appid, ct->name);
929 ret = __exec_query(query);
931 _LOGD("Package UiApp Category Info DB Insert Failed\n");
935 memset(query, '\0', MAX_QUERY_LEN);
942 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
944 uiapplication_x *up = mfx->uiapplication;
945 metadata_x *md = NULL;
947 char query[MAX_QUERY_LEN] = {'\0'};
954 snprintf(query, MAX_QUERY_LEN,
955 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
956 "values('%s','%s', '%s')",\
957 up->appid, md->key, md->value);
958 ret = __exec_query(query);
960 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
965 memset(query, '\0', MAX_QUERY_LEN);
972 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
974 uiapplication_x *up = mfx->uiapplication;
975 permission_x *pm = NULL;
977 char query[MAX_QUERY_LEN] = {'\0'};
983 snprintf(query, MAX_QUERY_LEN,
984 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
985 "values('%s','%s', '%s')",\
986 up->appid, pm->type, pm->value);
987 ret = __exec_query(query);
989 _LOGD("Package UiApp permission Info DB Insert Failed\n");
993 memset(query, '\0', MAX_QUERY_LEN);
1000 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
1002 uiapplication_x *up = mfx->uiapplication;
1003 appcontrol_x *acontrol = NULL;
1004 operation_x *op = NULL;
1007 subapp_x *sub = NULL;
1009 char query[MAX_QUERY_LEN] = {'\0'};
1010 const char *operation = NULL;
1011 const char *mime = NULL;
1012 const char *uri = NULL;
1013 const char *subapp = NULL;
1016 acontrol = up->appcontrol;
1017 while(acontrol != NULL)
1019 op = acontrol->operation;
1023 operation = op->name;
1024 mi = acontrol->mime;
1030 sub = acontrol->subapp;
1040 snprintf(query, MAX_QUERY_LEN,
1041 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1042 "values('%s', '%s', '%s', '%s', '%s')",\
1043 up->appid, operation, uri, mime, subapp);
1045 ret = __exec_query(query);
1047 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1050 memset(query, '\0', MAX_QUERY_LEN);
1054 } while(ui != NULL);
1058 }while(sub != NULL);
1067 acontrol = acontrol->next;
1074 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1076 uiapplication_x *up = mfx->uiapplication;
1077 appsvc_x *asvc = NULL;
1078 operation_x *op = NULL;
1081 subapp_x *sub = NULL;
1083 char query[MAX_QUERY_LEN] = {'\0'};
1084 const char *operation = NULL;
1085 const char *mime = NULL;
1086 const char *uri = NULL;
1087 const char *subapp = NULL;
1093 op = asvc->operation;
1097 operation = op->name;
1114 snprintf(query, MAX_QUERY_LEN,
1115 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1116 "values('%s', '%s', '%s', '%s', '%s')",\
1123 ret = __exec_query(query);
1125 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1128 memset(query, '\0', MAX_QUERY_LEN);
1132 } while(ui != NULL);
1136 }while(sub != NULL);
1152 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1154 uiapplication_x *up = mfx->uiapplication;
1155 datashare_x *ds = NULL;
1156 request_x *rq = NULL;
1158 char query[MAX_QUERY_LEN] = {'\0'};
1167 snprintf(query, MAX_QUERY_LEN,
1168 "insert into package_app_share_request(app_id, data_share_request) " \
1169 "values('%s', '%s')",\
1170 up->appid, rq->text);
1171 ret = __exec_query(query);
1173 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1176 memset(query, '\0', MAX_QUERY_LEN);
1186 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1188 uiapplication_x *up = mfx->uiapplication;
1189 datashare_x *ds = NULL;
1190 define_x *df = NULL;
1191 allowed_x *al = NULL;
1193 char query[MAX_QUERY_LEN] = {'\0'};
1205 snprintf(query, MAX_QUERY_LEN,
1206 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1207 "values('%s', '%s', '%s')",\
1208 up->appid, df->path, al->text);
1209 ret = __exec_query(query);
1211 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1214 memset(query, '\0', MAX_QUERY_LEN);
1226 static int __insert_serviceapplication_info(manifest_x *mfx)
1228 serviceapplication_x *sp = mfx->serviceapplication;
1230 char query[MAX_QUERY_LEN] = {'\0'};
1233 snprintf(query, MAX_QUERY_LEN,
1234 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1235 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1236 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1237 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1238 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1239 ret = __exec_query(query);
1241 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1245 memset(query, '\0', MAX_QUERY_LEN);
1250 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1252 serviceapplication_x *sp = mfx->serviceapplication;
1253 category_x *ct = NULL;
1255 char query[MAX_QUERY_LEN] = {'\0'};
1261 snprintf(query, MAX_QUERY_LEN,
1262 "insert into package_app_app_category(app_id, category) " \
1263 "values('%s','%s')",\
1264 sp->appid, ct->name);
1265 ret = __exec_query(query);
1267 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1271 memset(query, '\0', MAX_QUERY_LEN);
1278 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1280 serviceapplication_x *sp = mfx->serviceapplication;
1281 metadata_x *md = NULL;
1283 char query[MAX_QUERY_LEN] = {'\0'};
1290 snprintf(query, MAX_QUERY_LEN,
1291 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1292 "values('%s','%s', '%s')",\
1293 sp->appid, md->key, md->value);
1294 ret = __exec_query(query);
1296 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1301 memset(query, '\0', MAX_QUERY_LEN);
1308 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1310 serviceapplication_x *sp = mfx->serviceapplication;
1311 permission_x *pm = NULL;
1313 char query[MAX_QUERY_LEN] = {'\0'};
1316 pm = sp->permission;
1319 snprintf(query, MAX_QUERY_LEN,
1320 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1321 "values('%s','%s', '%s')",\
1322 sp->appid, pm->type, pm->value);
1323 ret = __exec_query(query);
1325 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1329 memset(query, '\0', MAX_QUERY_LEN);
1336 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1338 serviceapplication_x *sp = mfx->serviceapplication;
1339 appcontrol_x *acontrol = NULL;
1341 char query[MAX_QUERY_LEN] = {'\0'};
1342 operation_x *op = NULL;
1345 subapp_x *sub = NULL;
1346 const char *operation = NULL;
1347 const char *mime = NULL;
1348 const char *uri = NULL;
1349 const char *subapp = NULL;
1352 acontrol = sp->appcontrol;
1353 while(acontrol != NULL)
1355 op = acontrol->operation;
1359 operation = op->name;
1360 mi = acontrol->mime;
1365 sub = acontrol->subapp;
1375 snprintf(query, MAX_QUERY_LEN,
1376 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1377 "values('%s', '%s', '%s', '%s', '%s')",\
1378 sp->appid, operation, uri, mime, subapp);
1379 ret = __exec_query(query);
1381 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1384 memset(query, '\0', MAX_QUERY_LEN);
1388 } while(ui != NULL);
1392 }while(sub != NULL);
1401 acontrol = acontrol->next;
1408 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1410 serviceapplication_x *sp = mfx->serviceapplication;
1411 appsvc_x *asvc = NULL;
1413 char query[MAX_QUERY_LEN] = {'\0'};
1414 operation_x *op = NULL;
1417 subapp_x *sub = NULL;
1418 const char *operation = NULL;
1419 const char *mime = NULL;
1420 const char *uri = NULL;
1421 const char *subapp = NULL;
1427 op = asvc->operation;
1431 operation = op->name;
1447 snprintf(query, MAX_QUERY_LEN,
1448 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1449 "values('%s', '%s', '%s', '%s', '%s')",\
1455 ret = __exec_query(query);
1457 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1460 memset(query, '\0', MAX_QUERY_LEN);
1464 } while(ui != NULL);
1468 }while(sub != NULL);
1486 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1488 serviceapplication_x *sp = mfx->serviceapplication;
1489 datashare_x *ds = NULL;
1490 request_x *rq = NULL;
1492 char query[MAX_QUERY_LEN] = {'\0'};
1501 snprintf(query, MAX_QUERY_LEN,
1502 "insert into package_app_share_request(app_id, data_share_request) " \
1503 "values('%s', '%s')",\
1504 sp->appid, rq->text);
1505 ret = __exec_query(query);
1507 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1510 memset(query, '\0', MAX_QUERY_LEN);
1522 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1524 serviceapplication_x *sp = mfx->serviceapplication;
1525 datashare_x *ds = NULL;
1526 define_x *df = NULL;
1527 allowed_x *al = NULL;
1529 char query[MAX_QUERY_LEN] = {'\0'};
1541 snprintf(query, MAX_QUERY_LEN,
1542 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1543 "values('%s', '%s', '%s')",\
1544 sp->appid, df->path, al->text);
1545 ret = __exec_query(query);
1547 _LOGD("Package App Share Allowed DB Insert Failed\n");
1550 memset(query, '\0', MAX_QUERY_LEN);
1562 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1564 label_x *lbl = mfx->label;
1565 license_x *lcn = mfx->license;
1566 icon_x *icn = mfx->icon;
1567 description_x *dcn = mfx->description;
1568 author_x *ath = mfx->author;
1569 uiapplication_x *up = mfx->uiapplication;
1570 uiapplication_x *up_icn = mfx->uiapplication;
1571 uiapplication_x *up_image = mfx->uiapplication;
1572 serviceapplication_x *sp = mfx->serviceapplication;
1573 privileges_x *pvs = NULL;
1574 privilege_x *pv = NULL;
1575 char query[MAX_QUERY_LEN] = { '\0' };
1576 char root[MAX_QUERY_LEN] = { '\0' };
1580 const char *auth_name = NULL;
1581 const char *auth_email = NULL;
1582 const char *auth_href = NULL;
1583 const char *apps_path = NULL;
1585 GList *pkglocale = NULL;
1586 GList *applocale = NULL;
1587 GList *appicon = NULL;
1588 GList *appimage = NULL;
1592 auth_name = ath->text;
1594 auth_email = ath->email;
1596 auth_href = ath->href;
1598 /*Insert in the package_cert_info CERT_DB*/
1599 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1600 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1601 if (ret != PMINFO_R_OK) {
1602 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1603 _LOGE("Cert Info DB create handle failed\n");
1606 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1607 if (ret != PMINFO_R_OK) {
1608 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1609 _LOGE("Cert Info DB Insert Failed\n");
1613 /*Insert in the package_info DB*/
1615 type = strdup(mfx->type);
1617 type = strdup("rpm");
1618 /*Insert in the package_info DB*/
1620 path = strdup(mfx->root_path);
1622 if (strcmp(type,"rpm")==0) {
1623 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1624 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1626 apps_path = tzplatform_getenv(TZ_USER_APP);
1627 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1629 path = strdup(root);
1631 snprintf(query, MAX_QUERY_LEN,
1632 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1633 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1634 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1635 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1639 __get_str(mfx->installlocation),
1640 __get_str(mfx->package_size),
1646 mfx->nodisplay_setting,
1648 __get_str(auth_name),
1649 __get_str(auth_email),
1650 __get_str(auth_href),
1651 mfx->installed_time,
1652 mfx->installed_storage,
1653 __get_str(mfx->storeclient_id),
1655 __get_str(mfx->package_url),
1657 __get_str(mfx->csc_path));
1658 /*If package dont have main_package tag, this package is main package.*/
1659 if (mfx->main_package == NULL) {
1660 ret = __exec_query(query);
1662 _LOGD("Package Info DB Insert Failed\n");
1674 /*If package has main_package tag, this package is sub package(ug, efl).
1675 skip __exec_query for package_info and change pkgid with main_package*/
1676 memset(root, '\0', MAX_QUERY_LEN);
1677 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1678 if (access(root, F_OK) == 0) {
1679 free((void *)mfx->package);
1680 mfx->package = strdup(mfx->main_package);
1682 _LOGE("main package[%s] is not installed\n", root);
1695 /*Insert in the package_privilege_info DB*/
1696 pvs = mfx->privileges;
1697 while (pvs != NULL) {
1698 pv = pvs->privilege;
1699 while (pv != NULL) {
1700 memset(query, '\0', MAX_QUERY_LEN);
1701 snprintf(query, MAX_QUERY_LEN,
1702 "insert into package_privilege_info(package, privilege) " \
1703 "values('%s','%s')",\
1704 mfx->package, pv->text);
1705 ret = __exec_query(query);
1707 _LOGD("Package Privilege Info DB Insert Failed\n");
1715 ret = __insert_ui_mainapp_info(mfx);
1719 /*Insert the package locale*/
1720 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1721 /*remove duplicated data in pkglocale*/
1722 __trimfunc(pkglocale);
1724 /*Insert the app locale info */
1727 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1732 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1735 /*remove duplicated data in applocale*/
1736 __trimfunc(applocale);
1738 /*Insert the app icon info */
1739 while(up_icn != NULL)
1741 appicon = __create_icon_list(appicon, up_icn->icon);
1742 up_icn = up_icn->next;
1744 /*remove duplicated data in appicon*/
1745 __trimfunc(appicon);
1747 /*Insert the image info */
1748 while(up_image != NULL)
1750 appimage = __create_image_list(appimage, up_image->image);
1751 up_image = up_image->next;
1753 /*remove duplicated data in appimage*/
1754 __trimfunc(appimage);
1756 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1758 /*g_list_foreach(applocale, __printfunc, NULL);*/
1760 /*package locale info, it is only for main package.*/
1761 if (mfx->main_package == NULL)
1762 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1764 /*native app locale info*/
1765 up = mfx->uiapplication;
1768 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1771 /*agent app locale info*/
1772 sp = mfx->serviceapplication;
1775 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1779 /*app icon locale info*/
1780 up_icn = mfx->uiapplication;
1781 while(up_icn != NULL)
1783 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1784 up_icn = up_icn->next;
1788 up_image = mfx->uiapplication;
1789 while(up_image != NULL)
1791 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1792 up_image = up_image->next;
1795 g_list_free(pkglocale);
1797 g_list_free(applocale);
1799 g_list_free(appicon);
1801 g_list_free(appimage);
1804 /*Insert in the package_app_info DB*/
1805 ret = __insert_uiapplication_info(mfx);
1808 ret = __insert_serviceapplication_info(mfx);
1811 /*Insert in the package_app_app_control DB*/
1812 ret = __insert_uiapplication_appcontrol_info(mfx);
1815 ret = __insert_serviceapplication_appcontrol_info(mfx);
1819 /*Insert in the package_app_app_category DB*/
1820 ret = __insert_uiapplication_appcategory_info(mfx);
1823 ret = __insert_serviceapplication_appcategory_info(mfx);
1827 /*Insert in the package_app_app_metadata DB*/
1828 ret = __insert_uiapplication_appmetadata_info(mfx);
1831 ret = __insert_serviceapplication_appmetadata_info(mfx);
1835 /*Insert in the package_app_app_permission DB*/
1836 ret = __insert_uiapplication_apppermission_info(mfx);
1839 ret = __insert_serviceapplication_apppermission_info(mfx);
1843 /*Insert in the package_app_app_svc DB*/
1844 ret = __insert_uiapplication_appsvc_info(mfx);
1847 ret = __insert_serviceapplication_appsvc_info(mfx);
1851 /*Insert in the package_app_share_allowed DB*/
1852 ret = __insert_uiapplication_share_allowed_info(mfx);
1855 ret = __insert_serviceapplication_share_allowed_info(mfx);
1859 /*Insert in the package_app_share_request DB*/
1860 ret = __insert_uiapplication_share_request_info(mfx);
1863 ret = __insert_serviceapplication_share_request_info(mfx);
1871 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1873 char query[MAX_QUERY_LEN] = { '\0' };
1875 memset(query, '\0', MAX_QUERY_LEN);
1876 snprintf(query, MAX_QUERY_LEN,
1877 "delete from %s where app_id='%s'", db_table, appid);
1878 ret = __exec_query(query);
1880 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1886 static int __delete_subpkg_info_from_db(char *appid)
1890 ret = __delete_appinfo_from_db("package_app_info", appid);
1893 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1896 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1899 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1902 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1905 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1908 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1911 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1914 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1917 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1920 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1927 static int __delete_subpkg_from_db(manifest_x *mfx)
1929 char query[MAX_QUERY_LEN] = { '\0' };
1931 char *error_message = NULL;
1933 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1935 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1936 _LOGE("Don't execute query = %s error message = %s\n", query,
1938 sqlite3_free(error_message);
1941 sqlite3_free(error_message);
1946 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1948 char query[MAX_QUERY_LEN] = { '\0' };
1950 uiapplication_x *up = mfx->uiapplication;
1951 serviceapplication_x *sp = mfx->serviceapplication;
1952 /*Delete from cert table*/
1953 if (uid != GLOBAL_USER)
1954 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1956 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1958 _LOGD("Cert Info DB Delete Failed\n");
1962 /*Delete from Package Info DB*/
1963 snprintf(query, MAX_QUERY_LEN,
1964 "delete from package_info where package='%s'", mfx->package);
1965 ret = __exec_query(query);
1967 _LOGD("Package Info DB Delete Failed\n");
1970 memset(query, '\0', MAX_QUERY_LEN);
1972 /*Delete from Package Localized Info*/
1973 snprintf(query, MAX_QUERY_LEN,
1974 "delete from package_localized_info where package='%s'", mfx->package);
1975 ret = __exec_query(query);
1977 _LOGD("Package Localized Info DB Delete Failed\n");
1981 /*Delete from Package Privilege Info*/
1982 snprintf(query, MAX_QUERY_LEN,
1983 "delete from package_privilege_info where package='%s'", mfx->package);
1984 ret = __exec_query(query);
1986 _LOGD("Package Privilege Info DB Delete Failed\n");
1990 while (up != NULL) {
1991 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1994 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1997 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
2000 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
2003 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
2006 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
2009 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
2012 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
2015 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
2018 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
2021 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2027 while (sp != NULL) {
2028 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2031 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2034 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2037 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2040 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2043 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2046 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2049 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2052 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2055 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2058 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2064 /* if main package has sub pkg, delete sub pkg data*/
2065 __delete_subpkg_from_db(mfx);
2070 static int __update_preload_condition_in_db()
2073 char query[MAX_QUERY_LEN] = {'\0'};
2075 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2077 ret = __exec_query(query);
2079 _LOGD("Package preload_condition update failed\n");
2084 int pkgmgr_parser_initialize_db()
2088 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2090 _LOGD("package info DB initialization failed\n");
2093 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2095 _LOGD("package localized info DB initialization failed\n");
2098 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2100 _LOGD("package app app privilege DB initialization failed\n");
2103 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2105 _LOGD("package app info DB initialization failed\n");
2108 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2110 _LOGD("package app localized info DB initialization failed\n");
2113 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2115 _LOGD("package app icon localized info DB initialization failed\n");
2118 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2120 _LOGD("package app image info DB initialization failed\n");
2123 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2125 _LOGD("package app app control DB initialization failed\n");
2128 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2130 _LOGD("package app app category DB initialization failed\n");
2133 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2135 _LOGD("package app app category DB initialization failed\n");
2138 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2140 _LOGD("package app app permission DB initialization failed\n");
2143 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2145 _LOGD("package app app svc DB initialization failed\n");
2148 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2150 _LOGD("package app share allowed DB initialization failed\n");
2153 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2155 _LOGD("package app share request DB initialization failed\n");
2159 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2161 _LOGD("package cert info DB initialization failed\n");
2164 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2166 _LOGD("package cert index info DB initialization failed\n");
2173 static int parserdb_change_perm(const char *db_file, uid_t uid)
2176 char journal_file[BUFSIZE];
2179 struct passwd *userinfo = NULL;
2180 files[0] = (char *)db_file;
2181 files[1] = journal_file;
2187 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2189 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2190 userinfo = getpwuid(uid);
2192 _LOGE("FAIL: user %d doesn't exist", uid);
2195 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2197 for (i = 0; files[i]; i++) {
2198 ret = chown(files[i], uid, userinfo->pw_gid);
2199 SET_SMACK_LABEL(files[i],uid)
2201 strerror_r(errno, buf, sizeof(buf));
2202 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2206 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2208 strerror_r(errno, buf, sizeof(buf));
2209 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2216 int pkgmgr_parser_check_and_create_db(uid_t uid)
2220 ret = __pkgmgr_parser_create_parser_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid), uid);
2221 _LOGD("create db %s", getUserPkgParserDBPathUID(uid));
2223 _LOGD("Manifest DB creation Failed\n");
2228 ret = __pkgmgr_parser_create_cert_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid), uid);
2230 _LOGD("Cert DB creation Failed\n");
2233 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2234 _LOGD("Failed to change cert db permission\n");
2236 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2237 _LOGD("Failed to change parser db permission\n");
2242 void pkgmgr_parser_close_db()
2244 sqlite3_close(pkgmgr_parser_db);
2245 sqlite3_close(pkgmgr_cert_db);
2249 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2251 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2253 _LOGD("manifest pointer is NULL\n");
2257 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2259 _LOGD("Failed to open DB\n");
2262 ret = pkgmgr_parser_initialize_db();
2265 /*Begin transaction*/
2266 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2267 if (ret != SQLITE_OK) {
2268 _LOGD("Failed to begin transaction\n");
2272 _LOGD("Transaction Begin\n");
2273 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2275 _LOGD("Insert into DB failed. Rollback now\n");
2276 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2279 /*Commit transaction*/
2280 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2281 if (ret != SQLITE_OK) {
2282 _LOGD("Failed to commit transaction. Rollback now\n");
2283 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2287 _LOGD("Transaction Commit and End\n");
2289 pkgmgr_parser_close_db();
2293 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2295 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2297 _LOGD("manifest pointer is NULL\n");
2301 ret = pkgmgr_parser_check_and_create_db(uid);
2303 _LOGD("Failed to open DB\n");
2306 ret = pkgmgr_parser_initialize_db();
2309 /*Begin transaction*/
2310 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2311 if (ret != SQLITE_OK) {
2312 _LOGD("Failed to begin transaction\n");
2316 _LOGD("Transaction Begin\n");
2317 ret = __insert_manifest_info_in_db(mfx, uid);
2319 _LOGD("Insert into DB failed. Rollback now\n");
2320 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2323 /*Commit transaction*/
2324 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2325 if (ret != SQLITE_OK) {
2326 _LOGD("Failed to commit transaction. Rollback now\n");
2327 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2331 _LOGD("Transaction Commit and End\n");
2333 pkgmgr_parser_close_db();
2337 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2340 _LOGD("manifest pointer is NULL\n");
2344 ret = pkgmgr_parser_check_and_create_db(uid);
2346 _LOGD("Failed to open DB\n");
2349 ret = pkgmgr_parser_initialize_db();
2352 /*Preserve guest mode visibility*/
2353 __preserve_guestmode_visibility_value( mfx);
2354 /*Begin transaction*/
2355 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2356 if (ret != SQLITE_OK) {
2357 _LOGD("Failed to begin transaction\n");
2361 _LOGD("Transaction Begin\n");
2362 ret = __delete_manifest_info_from_db(mfx, uid);
2364 _LOGD("Delete from DB failed. Rollback now\n");
2365 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2368 ret = __insert_manifest_info_in_db(mfx, uid);
2370 _LOGD("Insert into DB failed. Rollback now\n");
2371 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2375 /*Commit transaction*/
2376 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2377 if (ret != SQLITE_OK) {
2378 _LOGD("Failed to commit transaction. Rollback now\n");
2379 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2383 _LOGD("Transaction Commit and End\n");
2385 pkgmgr_parser_close_db();
2389 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2391 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2394 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2397 _LOGD("manifest pointer is NULL\n");
2401 ret = pkgmgr_parser_check_and_create_db(uid);
2403 _LOGD("Failed to open DB\n");
2406 /*Begin transaction*/
2407 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2408 if (ret != SQLITE_OK) {
2409 _LOGD("Failed to begin transaction\n");
2413 _LOGD("Transaction Begin\n");
2414 ret = __delete_manifest_info_from_db(mfx, uid);
2416 _LOGD("Delete from DB failed. Rollback now\n");
2417 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2420 /*Commit transaction*/
2421 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2422 if (ret != SQLITE_OK) {
2423 _LOGD("Failed to commit transaction, Rollback now\n");
2424 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2428 _LOGD("Transaction Commit and End\n");
2430 pkgmgr_parser_close_db();
2434 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2436 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2439 API int pkgmgr_parser_update_preload_info_in_db()
2442 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2444 _LOGD("Failed to open DB\n");
2447 /*Begin transaction*/
2448 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2449 if (ret != SQLITE_OK) {
2450 _LOGD("Failed to begin transaction\n");
2454 _LOGD("Transaction Begin\n");
2455 ret = __update_preload_condition_in_db();
2457 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2458 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2461 /*Commit transaction*/
2462 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2463 if (ret != SQLITE_OK) {
2464 _LOGD("Failed to commit transaction, Rollback now\n");
2465 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2469 _LOGD("Transaction Commit and End\n");
2471 pkgmgr_parser_close_db();
2475 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2478 ret = pkgmgr_parser_check_and_create_db(uid);
2480 _LOGD("Failed to open DB\n");
2483 /*Begin transaction*/
2484 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2485 if (ret != SQLITE_OK) {
2486 _LOGD("Failed to begin transaction\n");
2490 _LOGD("Transaction Begin\n");
2491 ret = __update_preload_condition_in_db();
2493 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2494 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2497 /*Commit transaction*/
2498 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2499 if (ret != SQLITE_OK) {
2500 _LOGD("Failed to commit transaction, Rollback now\n");
2501 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2505 _LOGD("Transaction Commit and End\n");
2507 pkgmgr_parser_close_db();