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>
34 /* For multi-user support */
35 #include <tzplatform_config.h>
37 #include "pkgmgr-info.h"
38 #include "pkgmgr_parser_internal.h"
39 #include "pkgmgr_parser_db.h"
41 #include "pkgmgr-info-debug.h"
46 #define LOG_TAG "PKGMGR_PARSER"
48 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
49 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
50 #define MAX_QUERY_LEN 4096
54 sqlite3 *pkgmgr_parser_db;
55 sqlite3 *pkgmgr_cert_db;
58 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
59 "(package text primary key not null, " \
60 "package_type text DEFAULT 'rpm', " \
61 "package_version text, " \
62 "install_location text, " \
63 "package_size text, " \
64 "package_removable text DEFAULT 'true', " \
65 "package_preload text DEFAULT 'false', " \
66 "package_readonly text DEFAULT 'false', " \
67 "package_update text DEFAULT 'false', " \
68 "package_appsetting text DEFAULT 'false', " \
69 "package_nodisplay text DEFAULT 'false', " \
70 "package_system text DEFAULT 'false', " \
71 "author_name text, " \
72 "author_email text, " \
74 "installed_time text," \
75 "installed_storage text," \
76 "storeclient_id text," \
82 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
83 "(package text not null, " \
84 "package_locale text DEFAULT 'No Locale', " \
85 "package_label text, " \
86 "package_icon text, " \
87 "package_description text, " \
88 "package_license text, " \
90 "PRIMARY KEY(package, package_locale), " \
91 "FOREIGN KEY(package) " \
92 "REFERENCES package_info(package) " \
95 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
96 "(package text not null, " \
97 "privilege text not null, " \
98 "PRIMARY KEY(package, privilege) " \
99 "FOREIGN KEY(package) " \
100 "REFERENCES package_info(package) " \
103 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
104 "(app_id text primary key not null, " \
105 "app_component text, " \
107 "app_nodisplay text DEFAULT 'false', " \
109 "app_onboot text DEFAULT 'false', " \
110 "app_multiple text DEFAULT 'false', " \
111 "app_autorestart text DEFAULT 'false', " \
112 "app_taskmanage text DEFAULT 'false', " \
113 "app_enabled text DEFAULT 'true', " \
114 "app_hwacceleration text DEFAULT 'use-system-setting', " \
115 "app_screenreader text DEFAULT 'use-system-setting', " \
116 "app_mainapp text, " \
117 "app_recentimage text, " \
118 "app_launchcondition text, " \
119 "app_indicatordisplay text DEFAULT 'true', " \
120 "app_portraitimg text, " \
121 "app_landscapeimg text, " \
122 "app_guestmodevisibility text DEFAULT 'true', " \
123 "app_permissiontype text DEFAULT 'normal', " \
124 "app_preload text DEFAULT 'false', " \
125 "app_submode text DEFAULT 'false', " \
126 "app_submode_mainid text, " \
127 "component_type text, " \
128 "package text not null, " \
129 "FOREIGN KEY(package) " \
130 "REFERENCES package_info(package) " \
133 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
134 "(app_id text not null, " \
135 "app_locale text DEFAULT 'No Locale', " \
138 "PRIMARY KEY(app_id,app_locale) " \
139 "FOREIGN KEY(app_id) " \
140 "REFERENCES package_app_info(app_id) " \
143 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
144 "(app_id text not null, " \
146 "app_icon_section text, " \
147 "app_icon_resolution text, " \
148 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
149 "FOREIGN KEY(app_id) " \
150 "REFERENCES package_app_info(app_id) " \
153 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
154 "(app_id text not null, " \
155 "app_locale text DEFAULT 'No Locale', " \
156 "app_image_section text, " \
158 "PRIMARY KEY(app_id,app_image_section) " \
159 "FOREIGN KEY(app_id) " \
160 "REFERENCES package_app_info(app_id) " \
163 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
164 "(app_id text not null, " \
165 "operation text not null, " \
166 "uri_scheme text, " \
168 "subapp_name text, " \
169 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
170 "FOREIGN KEY(app_id) " \
171 "REFERENCES package_app_info(app_id) " \
174 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
175 "(app_id text not null, " \
176 "operation text not null, " \
177 "uri_scheme text, " \
179 "subapp_name text, " \
180 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
181 "FOREIGN KEY(app_id) " \
182 "REFERENCES package_app_info(app_id) " \
185 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
186 "(app_id text not null, " \
187 "category text not null, " \
188 "PRIMARY KEY(app_id,category) " \
189 "FOREIGN KEY(app_id) " \
190 "REFERENCES package_app_info(app_id) " \
193 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
194 "(app_id text not null, " \
195 "md_key text not null, " \
196 "md_value text not null, " \
197 "PRIMARY KEY(app_id, md_key, md_value) " \
198 "FOREIGN KEY(app_id) " \
199 "REFERENCES package_app_info(app_id) " \
202 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
203 "(app_id text not null, " \
204 "pm_type text not null, " \
205 "pm_value text not null, " \
206 "PRIMARY KEY(app_id, pm_type, pm_value) " \
207 "FOREIGN KEY(app_id) " \
208 "REFERENCES package_app_info(app_id) " \
211 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
212 "(app_id text not null, " \
213 "data_share_path text not null, " \
214 "data_share_allowed text not null, " \
215 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
216 "FOREIGN KEY(app_id) " \
217 "REFERENCES package_app_info(app_id) " \
220 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
221 "(app_id text not null, " \
222 "data_share_request text not null, " \
223 "PRIMARY KEY(app_id,data_share_request) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
229 "(cert_info text not null, " \
230 "cert_id integer, " \
231 "cert_ref_count integer, " \
232 "PRIMARY KEY(cert_id)) "
234 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
235 "(package text not null, " \
236 "author_root_cert integer, " \
237 "author_im_cert integer, " \
238 "author_signer_cert integer, " \
239 "dist_root_cert integer, " \
240 "dist_im_cert integer, " \
241 "dist_signer_cert integer, " \
242 "dist2_root_cert integer, " \
243 "dist2_im_cert integer, " \
244 "dist2_signer_cert integer, " \
245 "PRIMARY KEY(package)) "
248 static int __insert_uiapplication_info(manifest_x *mfx);
249 static int __insert_serviceapplication_info(manifest_x *mfx);
250 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
251 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
252 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
253 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
254 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
255 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
256 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
257 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
258 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
259 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
260 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
261 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
262 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
263 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
264 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
265 static int __insert_manifest_info_in_db(manifest_x *mfx);
266 static int __delete_manifest_info_from_db(manifest_x *mfx);
267 static int __delete_subpkg_info_from_db(char *appid);
268 static int __delete_appinfo_from_db(char *db_table, const char *appid);
269 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
270 static int __exec_query(char *query);
271 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
272 char **label, char **license, char **icon, char **description, char **author);
273 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
274 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
275 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
276 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
277 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
278 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid);
280 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
283 __delete_subpkg_info_from_db(coltxt[0]);
288 static char *__get_str(const char *str)
292 return PKGMGR_PARSER_EMPTY_STR;
298 static int __pkgmgr_parser_create_parser_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
302 char *pk, key1, key2, key3, key4, key5;
304 if (access(db_path, F_OK) == 0) {
306 db_util_open(db_path, &handle,
307 DB_UTIL_REGISTER_HOOK_METHOD);
308 if (ret != SQLITE_OK) {
309 _LOGD("connect db [%s] failed!\n",
316 _LOGD("%s DB does not exists. Create one!!\n", db_path);
319 db_util_open(db_path, &handle,
320 DB_UTIL_REGISTER_HOOK_METHOD);
322 if (ret != SQLITE_OK) {
323 _LOGD("connect db [%s] failed!\n", db_path);
331 static int __pkgmgr_parser_create_cert_db(sqlite3 **db_handle, const char *db_path, uid_t uid)
336 if (access(db_path, F_OK) == 0) {
338 db_util_open(db_path, &handle,
339 DB_UTIL_REGISTER_HOOK_METHOD);
340 if (ret != SQLITE_OK) {
341 _LOGD("connect db [%s] failed!\n",
348 _LOGD("%s DB does not exists. Create one!!\n", db_path);
351 db_util_open(db_path, &handle,
352 DB_UTIL_REGISTER_HOOK_METHOD);
354 if (ret != SQLITE_OK) {
355 _LOGD("connect db [%s] failed!\n", db_path);
363 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
365 manifest_x *mfx = (manifest_x *)data;
369 uiapplication_x *uiapp = NULL;
370 for(i = 0; i < ncols; i++)
372 uiapp = mfx->uiapplication;
373 if (strcmp(colname[i], "app_id") == 0) {
375 appid = strdup(coltxt[i]);
376 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
378 status = strdup(coltxt[i]);
382 _LOGD("app id is NULL\n");
385 /*update guest mode visibility*/
386 for (; uiapp != NULL; uiapp = uiapp->next) {
387 if (strcmp(uiapp->appid, appid) == 0) {
388 free((void *)uiapp->guestmode_visibility);
389 uiapp->guestmode_visibility = strdup(status);
405 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
407 char *error_message = NULL;
408 char query[MAX_QUERY_LEN] = {'\0'};
409 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
411 sqlite3_exec(pkgmgr_parser_db, query,
412 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
413 _LOGD("Don't execute query = %s error message = %s\n",
414 query, error_message);
415 sqlite3_free(error_message);
420 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
422 char *error_message = NULL;
424 sqlite3_exec(db_handle, db_query,
425 NULL, NULL, &error_message)) {
426 _LOGD("Don't execute query = %s error message = %s\n",
427 db_query, error_message);
428 sqlite3_free(error_message);
431 sqlite3_free(error_message);
435 static int __exec_query(char *query)
437 char *error_message = NULL;
439 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
440 _LOGD("Don't execute query = %s error message = %s\n", query,
442 sqlite3_free(error_message);
445 sqlite3_free(error_message);
449 static int __exec_query_no_msg(char *query)
451 char *error_message = NULL;
453 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
454 sqlite3_free(error_message);
457 sqlite3_free(error_message);
461 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
467 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
473 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
479 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
485 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
491 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
498 static GList *__create_icon_list(GList *locale, icon_x *icn)
503 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
509 static GList *__create_image_list(GList *locale, image_x *image)
514 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
520 static void __printfunc(gpointer data, gpointer userdata)
522 _LOGD("%s ", (char*)data);
525 static void __trimfunc(GList* trim_list)
527 char *trim_data = NULL;
531 list = g_list_first(trim_list);
534 trim_data = (char *)list->data;
537 if (strcmp(trim_data, prev) == 0) {
538 trim_list = g_list_remove(trim_list, trim_data);
539 list = g_list_first(trim_list);
548 list = g_list_next(list);
552 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
554 if (a == NULL || b == NULL)
556 if (strcmp((char*)a, (char*)b) == 0)
558 if (strcmp((char*)a, (char*)b) < 0)
560 if (strcmp((char*)a, (char*)b) > 0)
565 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
566 char **label, char **license, char **icon, char **description, char **author)
571 if (strcmp(lbl->lang, (char *)data) == 0) {
572 *label = (char*)lbl->text;
581 if (strcmp(lcn->lang, (char *)data) == 0) {
582 *license = (char*)lcn->text;
591 if (strcmp(icn->lang, (char *)data) == 0) {
592 *icon = (char*)icn->text;
601 if (strcmp(dcn->lang, (char *)data) == 0) {
602 *description = (char*)dcn->text;
611 if (strcmp(ath->lang, (char *)data) == 0) {
612 *author = (char*)ath->text;
621 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
626 if (strcmp(icn->section, (char *)data) == 0) {
627 *icon = (char*)icn->text;
628 *resolution = (char*)icn->resolution;
636 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
640 if (image->section) {
641 if (strcmp(image->section, (char *)data) == 0) {
642 *lang = (char*)image->lang;
643 *img = (char*)image->text;
651 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
656 char *description = NULL;
657 char *license = NULL;
659 char query[MAX_QUERY_LEN] = {'\0'};
661 manifest_x *mfx = (manifest_x *)userdata;
662 label_x *lbl = mfx->label;
663 license_x *lcn = mfx->license;
664 icon_x *icn = mfx->icon;
665 description_x *dcn = mfx->description;
666 author_x *ath = mfx->author;
668 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
669 if (!label && !description && !icon && !license && !author)
672 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
673 "package_label, package_icon, package_description, package_license, package_author) values " \
674 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
679 __get_str(description),
683 ret = __exec_query(query);
685 _LOGD("Package Localized Info DB Insert failed\n");
688 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
693 char query[MAX_QUERY_LEN] = {'\0'};
695 uiapplication_x *up = (uiapplication_x*)userdata;
696 label_x *lbl = up->label;
697 icon_x *icn = up->icon;
699 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
702 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
703 "app_label, app_icon) values " \
704 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
706 ret = __exec_query(query);
708 _LOGD("Package UiApp Localized Info DB Insert failed\n");
710 /*insert ui app locale info to pkg locale to get mainapp data */
711 if (strcasecmp(up->mainapp, "true")==0) {
712 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
713 "package_label, package_icon, package_description, package_license, package_author) values " \
714 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
719 PKGMGR_PARSER_EMPTY_STR,
720 PKGMGR_PARSER_EMPTY_STR,
721 PKGMGR_PARSER_EMPTY_STR);
723 ret = __exec_query_no_msg(query);
726 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
727 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
728 ret = __exec_query_no_msg(query);
733 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
737 char *resolution = NULL;
738 char query[MAX_QUERY_LEN] = {'\0'};
740 uiapplication_x *up = (uiapplication_x*)userdata;
741 icon_x *icn = up->icon;
743 __extract_icon_data(data, icn, &icon, &resolution);
744 if (!icon && !resolution)
746 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
747 "app_icon, app_icon_section, app_icon_resolution) values " \
748 "('%q', '%q', '%q', '%q')", up->appid,
749 icon, (char*)data, resolution);
751 ret = __exec_query(query);
753 _LOGD("Package UiApp Localized Info DB Insert failed\n");
757 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
762 char query[MAX_QUERY_LEN] = {'\0'};
764 uiapplication_x *up = (uiapplication_x*)userdata;
765 image_x *image = up->image;
767 __extract_image_data(data, image, &lang, &img);
770 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
771 "app_image_section, app_image) values " \
772 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
774 ret = __exec_query(query);
776 _LOGD("Package UiApp image Info DB Insert failed\n");
781 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
786 char query[MAX_QUERY_LEN] = {'\0'};
788 serviceapplication_x *sp = (serviceapplication_x*)userdata;
789 label_x *lbl = sp->label;
790 icon_x *icn = sp->icon;
792 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
795 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
796 "app_label, app_icon) values " \
797 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
799 ret = __exec_query(query);
801 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
804 static int __insert_ui_mainapp_info(manifest_x *mfx)
806 uiapplication_x *up = mfx->uiapplication;
808 char query[MAX_QUERY_LEN] = {'\0'};
811 snprintf(query, MAX_QUERY_LEN,
812 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
814 ret = __exec_query(query);
816 _LOGD("Package UiApp Info DB Insert Failed\n");
819 if (strcasecmp(up->mainapp, "True")==0)
820 mfx->mainapp_id = strdup(up->appid);
823 memset(query, '\0', MAX_QUERY_LEN);
826 if (mfx->mainapp_id == NULL){
827 if (mfx->uiapplication && mfx->uiapplication->appid) {
828 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
830 _LOGD("Not valid appid\n");
834 ret = __exec_query(query);
836 _LOGD("Package UiApp Info DB Insert Failed\n");
840 free((void *)mfx->uiapplication->mainapp);
841 mfx->uiapplication->mainapp= strdup("true");
842 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
845 memset(query, '\0', MAX_QUERY_LEN);
846 snprintf(query, MAX_QUERY_LEN,
847 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
848 ret = __exec_query(query);
850 _LOGD("Package Info DB update Failed\n");
856 /* _PRODUCT_LAUNCHING_ENHANCED_
857 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
859 static int __insert_uiapplication_info(manifest_x *mfx)
861 uiapplication_x *up = mfx->uiapplication;
863 char query[MAX_QUERY_LEN] = {'\0'};
866 snprintf(query, MAX_QUERY_LEN,
867 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
868 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
869 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
870 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
871 "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')",\
877 PKGMGR_PARSER_EMPTY_STR,
879 PKGMGR_PARSER_EMPTY_STR,
885 __get_str(up->recentimage),
887 up->indicatordisplay,
888 __get_str(up->portraitimg),
889 __get_str(up->landscapeimg),
890 up->guestmode_visibility,
894 __get_str(up->submode_mainid),
898 ret = __exec_query(query);
900 _LOGD("Package UiApp Info DB Insert Failed\n");
904 memset(query, '\0', MAX_QUERY_LEN);
909 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
911 uiapplication_x *up = mfx->uiapplication;
912 category_x *ct = NULL;
914 char query[MAX_QUERY_LEN] = {'\0'};
920 snprintf(query, MAX_QUERY_LEN,
921 "insert into package_app_app_category(app_id, category) " \
922 "values('%s','%s')",\
923 up->appid, ct->name);
924 ret = __exec_query(query);
926 _LOGD("Package UiApp Category Info DB Insert Failed\n");
930 memset(query, '\0', MAX_QUERY_LEN);
937 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
939 uiapplication_x *up = mfx->uiapplication;
940 metadata_x *md = NULL;
942 char query[MAX_QUERY_LEN] = {'\0'};
949 snprintf(query, MAX_QUERY_LEN,
950 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
951 "values('%s','%s', '%s')",\
952 up->appid, md->key, md->value);
953 ret = __exec_query(query);
955 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
960 memset(query, '\0', MAX_QUERY_LEN);
967 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
969 uiapplication_x *up = mfx->uiapplication;
970 permission_x *pm = NULL;
972 char query[MAX_QUERY_LEN] = {'\0'};
978 snprintf(query, MAX_QUERY_LEN,
979 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
980 "values('%s','%s', '%s')",\
981 up->appid, pm->type, pm->value);
982 ret = __exec_query(query);
984 _LOGD("Package UiApp permission Info DB Insert Failed\n");
988 memset(query, '\0', MAX_QUERY_LEN);
995 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
997 uiapplication_x *up = mfx->uiapplication;
998 appcontrol_x *acontrol = NULL;
999 operation_x *op = NULL;
1002 subapp_x *sub = NULL;
1004 char query[MAX_QUERY_LEN] = {'\0'};
1005 const char *operation = NULL;
1006 const char *mime = NULL;
1007 const char *uri = NULL;
1008 const char *subapp = NULL;
1011 acontrol = up->appcontrol;
1012 while(acontrol != NULL)
1014 op = acontrol->operation;
1018 operation = op->name;
1019 mi = acontrol->mime;
1025 sub = acontrol->subapp;
1035 snprintf(query, MAX_QUERY_LEN,
1036 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1037 "values('%s', '%s', '%s', '%s', '%s')",\
1038 up->appid, operation, uri, mime, subapp);
1040 ret = __exec_query(query);
1042 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1045 memset(query, '\0', MAX_QUERY_LEN);
1049 } while(ui != NULL);
1053 }while(sub != NULL);
1062 acontrol = acontrol->next;
1069 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1071 uiapplication_x *up = mfx->uiapplication;
1072 appsvc_x *asvc = NULL;
1073 operation_x *op = NULL;
1076 subapp_x *sub = NULL;
1078 char query[MAX_QUERY_LEN] = {'\0'};
1079 const char *operation = NULL;
1080 const char *mime = NULL;
1081 const char *uri = NULL;
1082 const char *subapp = NULL;
1088 op = asvc->operation;
1092 operation = op->name;
1109 snprintf(query, MAX_QUERY_LEN,
1110 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1111 "values('%s', '%s', '%s', '%s', '%s')",\
1118 ret = __exec_query(query);
1120 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1123 memset(query, '\0', MAX_QUERY_LEN);
1127 } while(ui != NULL);
1131 }while(sub != NULL);
1147 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1149 uiapplication_x *up = mfx->uiapplication;
1150 datashare_x *ds = NULL;
1151 request_x *rq = NULL;
1153 char query[MAX_QUERY_LEN] = {'\0'};
1162 snprintf(query, MAX_QUERY_LEN,
1163 "insert into package_app_share_request(app_id, data_share_request) " \
1164 "values('%s', '%s')",\
1165 up->appid, rq->text);
1166 ret = __exec_query(query);
1168 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1171 memset(query, '\0', MAX_QUERY_LEN);
1181 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1183 uiapplication_x *up = mfx->uiapplication;
1184 datashare_x *ds = NULL;
1185 define_x *df = NULL;
1186 allowed_x *al = NULL;
1188 char query[MAX_QUERY_LEN] = {'\0'};
1200 snprintf(query, MAX_QUERY_LEN,
1201 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1202 "values('%s', '%s', '%s')",\
1203 up->appid, df->path, al->text);
1204 ret = __exec_query(query);
1206 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1209 memset(query, '\0', MAX_QUERY_LEN);
1221 static int __insert_serviceapplication_info(manifest_x *mfx)
1223 serviceapplication_x *sp = mfx->serviceapplication;
1225 char query[MAX_QUERY_LEN] = {'\0'};
1228 snprintf(query, MAX_QUERY_LEN,
1229 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1230 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1231 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1232 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1233 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1234 ret = __exec_query(query);
1236 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1240 memset(query, '\0', MAX_QUERY_LEN);
1245 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1247 serviceapplication_x *sp = mfx->serviceapplication;
1248 category_x *ct = NULL;
1250 char query[MAX_QUERY_LEN] = {'\0'};
1256 snprintf(query, MAX_QUERY_LEN,
1257 "insert into package_app_app_category(app_id, category) " \
1258 "values('%s','%s')",\
1259 sp->appid, ct->name);
1260 ret = __exec_query(query);
1262 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1266 memset(query, '\0', MAX_QUERY_LEN);
1273 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1275 serviceapplication_x *sp = mfx->serviceapplication;
1276 metadata_x *md = NULL;
1278 char query[MAX_QUERY_LEN] = {'\0'};
1285 snprintf(query, MAX_QUERY_LEN,
1286 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1287 "values('%s','%s', '%s')",\
1288 sp->appid, md->key, md->value);
1289 ret = __exec_query(query);
1291 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1296 memset(query, '\0', MAX_QUERY_LEN);
1303 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1305 serviceapplication_x *sp = mfx->serviceapplication;
1306 permission_x *pm = NULL;
1308 char query[MAX_QUERY_LEN] = {'\0'};
1311 pm = sp->permission;
1314 snprintf(query, MAX_QUERY_LEN,
1315 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1316 "values('%s','%s', '%s')",\
1317 sp->appid, pm->type, pm->value);
1318 ret = __exec_query(query);
1320 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1324 memset(query, '\0', MAX_QUERY_LEN);
1331 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1333 serviceapplication_x *sp = mfx->serviceapplication;
1334 appcontrol_x *acontrol = NULL;
1336 char query[MAX_QUERY_LEN] = {'\0'};
1337 operation_x *op = NULL;
1340 subapp_x *sub = NULL;
1341 const char *operation = NULL;
1342 const char *mime = NULL;
1343 const char *uri = NULL;
1344 const char *subapp = NULL;
1347 acontrol = sp->appcontrol;
1348 while(acontrol != NULL)
1350 op = acontrol->operation;
1354 operation = op->name;
1355 mi = acontrol->mime;
1360 sub = acontrol->subapp;
1370 snprintf(query, MAX_QUERY_LEN,
1371 "insert into package_app_app_control(app_id, operation, uri_scheme, mime_type,subapp_name) " \
1372 "values('%s', '%s', '%s', '%s', '%s')",\
1373 sp->appid, operation, uri, mime, subapp);
1374 ret = __exec_query(query);
1376 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1379 memset(query, '\0', MAX_QUERY_LEN);
1383 } while(ui != NULL);
1387 }while(sub != NULL);
1396 acontrol = acontrol->next;
1403 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1405 serviceapplication_x *sp = mfx->serviceapplication;
1406 appsvc_x *asvc = NULL;
1408 char query[MAX_QUERY_LEN] = {'\0'};
1409 operation_x *op = NULL;
1412 subapp_x *sub = NULL;
1413 const char *operation = NULL;
1414 const char *mime = NULL;
1415 const char *uri = NULL;
1416 const char *subapp = NULL;
1422 op = asvc->operation;
1426 operation = op->name;
1442 snprintf(query, MAX_QUERY_LEN,
1443 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1444 "values('%s', '%s', '%s', '%s', '%s')",\
1450 ret = __exec_query(query);
1452 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1455 memset(query, '\0', MAX_QUERY_LEN);
1459 } while(ui != NULL);
1463 }while(sub != NULL);
1481 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1483 serviceapplication_x *sp = mfx->serviceapplication;
1484 datashare_x *ds = NULL;
1485 request_x *rq = NULL;
1487 char query[MAX_QUERY_LEN] = {'\0'};
1496 snprintf(query, MAX_QUERY_LEN,
1497 "insert into package_app_share_request(app_id, data_share_request) " \
1498 "values('%s', '%s')",\
1499 sp->appid, rq->text);
1500 ret = __exec_query(query);
1502 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1505 memset(query, '\0', MAX_QUERY_LEN);
1517 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1519 serviceapplication_x *sp = mfx->serviceapplication;
1520 datashare_x *ds = NULL;
1521 define_x *df = NULL;
1522 allowed_x *al = NULL;
1524 char query[MAX_QUERY_LEN] = {'\0'};
1536 snprintf(query, MAX_QUERY_LEN,
1537 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1538 "values('%s', '%s', '%s')",\
1539 sp->appid, df->path, al->text);
1540 ret = __exec_query(query);
1542 _LOGD("Package App Share Allowed DB Insert Failed\n");
1545 memset(query, '\0', MAX_QUERY_LEN);
1557 static int __insert_manifest_info_in_db(manifest_x *mfx)
1559 label_x *lbl = mfx->label;
1560 license_x *lcn = mfx->license;
1561 icon_x *icn = mfx->icon;
1562 description_x *dcn = mfx->description;
1563 author_x *ath = mfx->author;
1564 uiapplication_x *up = mfx->uiapplication;
1565 uiapplication_x *up_icn = mfx->uiapplication;
1566 uiapplication_x *up_image = mfx->uiapplication;
1567 serviceapplication_x *sp = mfx->serviceapplication;
1568 privileges_x *pvs = NULL;
1569 privilege_x *pv = NULL;
1570 char query[MAX_QUERY_LEN] = { '\0' };
1571 char root[MAX_QUERY_LEN] = { '\0' };
1575 const char *auth_name = NULL;
1576 const char *auth_email = NULL;
1577 const char *auth_href = NULL;
1578 const char *apps_path = NULL;
1580 GList *pkglocale = NULL;
1581 GList *applocale = NULL;
1582 GList *appicon = NULL;
1583 GList *appimage = NULL;
1587 auth_name = ath->text;
1589 auth_email = ath->email;
1591 auth_href = ath->href;
1593 /*Insert in the package_info DB*/
1595 type = strdup(mfx->type);
1597 type = strdup("rpm");
1598 /*Insert in the package_info DB*/
1600 path = strdup(mfx->root_path);
1602 if (strcmp(type,"rpm")==0) {
1603 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1604 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1606 apps_path = tzplatform_getenv(TZ_USER_APP);
1607 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1609 path = strdup(root);
1611 snprintf(query, MAX_QUERY_LEN,
1612 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1613 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1614 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1615 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1619 __get_str(mfx->installlocation),
1620 __get_str(mfx->package_size),
1626 mfx->nodisplay_setting,
1628 __get_str(auth_name),
1629 __get_str(auth_email),
1630 __get_str(auth_href),
1631 mfx->installed_time,
1632 mfx->installed_storage,
1633 __get_str(mfx->storeclient_id),
1635 __get_str(mfx->package_url),
1637 __get_str(mfx->csc_path));
1638 /*If package dont have main_package tag, this package is main package.*/
1639 if (mfx->main_package == NULL) {
1640 ret = __exec_query(query);
1642 _LOGD("Package Info DB Insert Failed\n");
1654 /*If package has main_package tag, this package is sub package(ug, efl).
1655 skip __exec_query for package_info and change pkgid with main_package*/
1656 memset(root, '\0', MAX_QUERY_LEN);
1657 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1658 if (access(root, F_OK) == 0) {
1659 free((void *)mfx->package);
1660 mfx->package = strdup(mfx->main_package);
1662 _LOGE("main package[%s] is not installed\n", root);
1675 /*Insert in the package_privilege_info DB*/
1676 pvs = mfx->privileges;
1677 while (pvs != NULL) {
1678 pv = pvs->privilege;
1679 while (pv != NULL) {
1680 memset(query, '\0', MAX_QUERY_LEN);
1681 snprintf(query, MAX_QUERY_LEN,
1682 "insert into package_privilege_info(package, privilege) " \
1683 "values('%s','%s')",\
1684 mfx->package, pv->text);
1685 ret = __exec_query(query);
1687 _LOGD("Package Privilege Info DB Insert Failed\n");
1695 ret = __insert_ui_mainapp_info(mfx);
1699 /*Insert the package locale*/
1700 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1701 /*remove duplicated data in pkglocale*/
1702 __trimfunc(pkglocale);
1704 /*Insert the app locale info */
1707 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1712 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1715 /*remove duplicated data in applocale*/
1716 __trimfunc(applocale);
1718 /*Insert the app icon info */
1719 while(up_icn != NULL)
1721 appicon = __create_icon_list(appicon, up_icn->icon);
1722 up_icn = up_icn->next;
1724 /*remove duplicated data in appicon*/
1725 __trimfunc(appicon);
1727 /*Insert the image info */
1728 while(up_image != NULL)
1730 appimage = __create_image_list(appimage, up_image->image);
1731 up_image = up_image->next;
1733 /*remove duplicated data in appimage*/
1734 __trimfunc(appimage);
1736 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1738 /*g_list_foreach(applocale, __printfunc, NULL);*/
1740 /*package locale info, it is only for main package.*/
1741 if (mfx->main_package == NULL)
1742 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1744 /*native app locale info*/
1745 up = mfx->uiapplication;
1748 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1751 /*agent app locale info*/
1752 sp = mfx->serviceapplication;
1755 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1759 /*app icon locale info*/
1760 up_icn = mfx->uiapplication;
1761 while(up_icn != NULL)
1763 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1764 up_icn = up_icn->next;
1768 up_image = mfx->uiapplication;
1769 while(up_image != NULL)
1771 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1772 up_image = up_image->next;
1775 g_list_free(pkglocale);
1777 g_list_free(applocale);
1779 g_list_free(appicon);
1781 g_list_free(appimage);
1784 /*Insert in the package_app_info DB*/
1785 ret = __insert_uiapplication_info(mfx);
1788 ret = __insert_serviceapplication_info(mfx);
1791 /*Insert in the package_app_app_control DB*/
1792 ret = __insert_uiapplication_appcontrol_info(mfx);
1795 ret = __insert_serviceapplication_appcontrol_info(mfx);
1799 /*Insert in the package_app_app_category DB*/
1800 ret = __insert_uiapplication_appcategory_info(mfx);
1803 ret = __insert_serviceapplication_appcategory_info(mfx);
1807 /*Insert in the package_app_app_metadata DB*/
1808 ret = __insert_uiapplication_appmetadata_info(mfx);
1811 ret = __insert_uiapplication_appmetadata_info(mfx);
1815 /*Insert in the package_app_app_permission DB*/
1816 ret = __insert_uiapplication_apppermission_info(mfx);
1819 ret = __insert_serviceapplication_apppermission_info(mfx);
1823 /*Insert in the package_app_app_svc DB*/
1824 ret = __insert_uiapplication_appsvc_info(mfx);
1827 ret = __insert_serviceapplication_appsvc_info(mfx);
1831 /*Insert in the package_app_share_allowed DB*/
1832 ret = __insert_uiapplication_share_allowed_info(mfx);
1835 ret = __insert_serviceapplication_share_allowed_info(mfx);
1839 /*Insert in the package_app_share_request DB*/
1840 ret = __insert_uiapplication_share_request_info(mfx);
1843 ret = __insert_serviceapplication_share_request_info(mfx);
1851 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1853 char query[MAX_QUERY_LEN] = { '\0' };
1855 memset(query, '\0', MAX_QUERY_LEN);
1856 snprintf(query, MAX_QUERY_LEN,
1857 "delete from %s where app_id='%s'", db_table, appid);
1858 ret = __exec_query(query);
1860 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1866 static int __delete_subpkg_info_from_db(char *appid)
1870 ret = __delete_appinfo_from_db("package_app_info", appid);
1873 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1876 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1879 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1882 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1885 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1888 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1891 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1894 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1897 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1900 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1907 static int __delete_subpkg_from_db(manifest_x *mfx)
1909 char query[MAX_QUERY_LEN] = { '\0' };
1911 char *error_message = NULL;
1913 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1915 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1916 _LOGE("Don't execute query = %s error message = %s\n", query,
1918 sqlite3_free(error_message);
1921 sqlite3_free(error_message);
1926 static int __delete_manifest_info_from_db(manifest_x *mfx)
1928 char query[MAX_QUERY_LEN] = { '\0' };
1930 uiapplication_x *up = mfx->uiapplication;
1931 serviceapplication_x *sp = mfx->serviceapplication;
1932 /*Delete from cert table*/
1933 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1935 _LOGD("Cert Info DB Delete Failed\n");
1939 /*Delete from Package Info DB*/
1940 snprintf(query, MAX_QUERY_LEN,
1941 "delete from package_info where package='%s'", mfx->package);
1942 ret = __exec_query(query);
1944 _LOGD("Package Info DB Delete Failed\n");
1947 memset(query, '\0', MAX_QUERY_LEN);
1949 /*Delete from Package Localized Info*/
1950 snprintf(query, MAX_QUERY_LEN,
1951 "delete from package_localized_info where package='%s'", mfx->package);
1952 ret = __exec_query(query);
1954 _LOGD("Package Localized Info DB Delete Failed\n");
1958 /*Delete from Package Privilege Info*/
1959 snprintf(query, MAX_QUERY_LEN,
1960 "delete from package_privilege_info where package='%s'", mfx->package);
1961 ret = __exec_query(query);
1963 _LOGD("Package Privilege Info DB Delete Failed\n");
1967 while (up != NULL) {
1968 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1971 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1974 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1977 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1980 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1983 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1986 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1989 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1992 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1995 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1998 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2004 while (sp != NULL) {
2005 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2008 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2011 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2014 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2017 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2020 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2023 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2026 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2029 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2032 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2035 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2041 /* if main package has sub pkg, delete sub pkg data*/
2042 __delete_subpkg_from_db(mfx);
2047 static int __update_preload_condition_in_db()
2050 char query[MAX_QUERY_LEN] = {'\0'};
2052 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2054 ret = __exec_query(query);
2056 _LOGD("Package preload_condition update failed\n");
2061 int pkgmgr_parser_initialize_db()
2065 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2067 _LOGD("package info DB initialization failed\n");
2070 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2072 _LOGD("package localized info DB initialization failed\n");
2075 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2077 _LOGD("package app app privilege DB initialization failed\n");
2080 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2082 _LOGD("package app info DB initialization failed\n");
2085 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2087 _LOGD("package app localized info DB initialization failed\n");
2090 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2092 _LOGD("package app icon localized info DB initialization failed\n");
2095 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2097 _LOGD("package app image info DB initialization failed\n");
2100 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2102 _LOGD("package app app control DB initialization failed\n");
2105 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2107 _LOGD("package app app category DB initialization failed\n");
2110 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2112 _LOGD("package app app category DB initialization failed\n");
2115 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2117 _LOGD("package app app permission DB initialization failed\n");
2120 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2122 _LOGD("package app app svc DB initialization failed\n");
2125 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2127 _LOGD("package app share allowed DB initialization failed\n");
2130 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2132 _LOGD("package app share request DB initialization failed\n");
2136 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2138 _LOGD("package cert info DB initialization failed\n");
2141 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2143 _LOGD("package cert index info DB initialization failed\n");
2149 static int parserdb_change_perm(const char *db_file, uid_t uid)
2152 char journal_file[BUFSIZE];
2155 struct group *grpinfo = NULL;
2156 files[0] = (char *)db_file;
2157 files[1] = journal_file;
2160 const char *name = "users";
2167 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2168 grpinfo = getgrnam(name);
2169 if(grpinfo == NULL){
2170 _LOGD("getgrnam(users) returns NULL !");
2172 for (i = 0; files[i]; i++) {
2173 ret = chown(files[i], uid, (gid_t)grpinfo->gr_gid);
2175 strerror_r(errno, buf, sizeof(buf));
2176 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, grpinfo->gr_gid, buf);
2180 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2182 strerror_r(errno, buf, sizeof(buf));
2183 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2187 if(smack_setlabel(db_file, "_", SMACK_LABEL_ACCESS))
2189 _LOGE("failed chsmack -a \"_\" %s", db_file);
2191 _LOGD("chsmack -a \"_\" %s", db_file);
2198 int pkgmgr_parser_check_and_create_db(uid_t uid)
2202 ret = __pkgmgr_parser_create_parser_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid), uid);
2203 _LOGD("create db %s", getUserPkgParserDBPathUID(uid));
2205 _LOGD("Manifest DB creation Failed\n");
2208 if(uid != GLOBAL_USER) {
2209 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2210 _LOGD("Failed to change permission\n");
2214 ret = __pkgmgr_parser_create_cert_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid), uid);
2216 _LOGD("Cert DB creation Failed\n");
2219 if(uid != GLOBAL_USER) {
2220 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2221 _LOGD("Failed to change permission\n");
2227 void pkgmgr_parser_close_db()
2229 sqlite3_close(pkgmgr_parser_db);
2230 sqlite3_close(pkgmgr_cert_db);
2234 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2236 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2238 _LOGD("manifest pointer is NULL\n");
2242 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2244 _LOGD("Failed to open DB\n");
2247 ret = pkgmgr_parser_initialize_db();
2250 /*Begin transaction*/
2251 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2252 if (ret != SQLITE_OK) {
2253 _LOGD("Failed to begin transaction\n");
2257 _LOGD("Transaction Begin\n");
2258 ret = __insert_manifest_info_in_db(mfx);
2260 _LOGD("Insert into DB failed. Rollback now\n");
2261 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2264 /*Commit transaction*/
2265 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2266 if (ret != SQLITE_OK) {
2267 _LOGD("Failed to commit transaction. Rollback now\n");
2268 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2272 _LOGD("Transaction Commit and End\n");
2274 pkgmgr_parser_close_db();
2278 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2280 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2282 _LOGD("manifest pointer is NULL\n");
2286 ret = pkgmgr_parser_check_and_create_db(uid);
2288 _LOGD("Failed to open DB\n");
2291 ret = pkgmgr_parser_initialize_db();
2294 /*Begin transaction*/
2295 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2296 if (ret != SQLITE_OK) {
2297 _LOGD("Failed to begin transaction\n");
2301 _LOGD("Transaction Begin\n");
2302 ret = __insert_manifest_info_in_db(mfx);
2304 _LOGD("Insert into DB failed. Rollback now\n");
2305 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2308 /*Commit transaction*/
2309 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2310 if (ret != SQLITE_OK) {
2311 _LOGD("Failed to commit transaction. Rollback now\n");
2312 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2316 _LOGD("Transaction Commit and End\n");
2318 pkgmgr_parser_close_db();
2321 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2324 _LOGD("manifest pointer is NULL\n");
2328 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2330 _LOGD("Failed to open DB\n");
2333 ret = pkgmgr_parser_initialize_db();
2336 /*Preserve guest mode visibility*/
2337 __preserve_guestmode_visibility_value( mfx);
2338 /*Begin transaction*/
2339 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2340 if (ret != SQLITE_OK) {
2341 _LOGD("Failed to begin transaction\n");
2345 _LOGD("Transaction Begin\n");
2346 ret = __delete_manifest_info_from_db(mfx);
2348 _LOGD("Delete from DB failed. Rollback now\n");
2349 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2352 ret = __insert_manifest_info_in_db(mfx);
2354 _LOGD("Insert into DB failed. Rollback now\n");
2355 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2359 /*Commit transaction*/
2360 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2361 if (ret != SQLITE_OK) {
2362 _LOGD("Failed to commit transaction. Rollback now\n");
2363 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2367 _LOGD("Transaction Commit and End\n");
2369 pkgmgr_parser_close_db();
2373 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2376 _LOGD("manifest pointer is NULL\n");
2380 ret = pkgmgr_parser_check_and_create_db(uid);
2382 _LOGD("Failed to open DB\n");
2385 ret = pkgmgr_parser_initialize_db();
2388 /*Preserve guest mode visibility*/
2389 __preserve_guestmode_visibility_value( mfx);
2390 /*Begin transaction*/
2391 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2392 if (ret != SQLITE_OK) {
2393 _LOGD("Failed to begin transaction\n");
2397 _LOGD("Transaction Begin\n");
2398 ret = __delete_manifest_info_from_db(mfx);
2400 _LOGD("Delete from DB failed. Rollback now\n");
2401 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2404 ret = __insert_manifest_info_in_db(mfx);
2406 _LOGD("Insert into DB failed. Rollback now\n");
2407 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2411 /*Commit transaction*/
2412 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2413 if (ret != SQLITE_OK) {
2414 _LOGD("Failed to commit transaction. Rollback now\n");
2415 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2419 _LOGD("Transaction Commit and End\n");
2421 pkgmgr_parser_close_db();
2426 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2429 _LOGD("manifest pointer is NULL\n");
2433 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2435 _LOGD("Failed to open DB\n");
2438 /*Begin transaction*/
2439 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2440 if (ret != SQLITE_OK) {
2441 _LOGD("Failed to begin transaction\n");
2445 _LOGD("Transaction Begin\n");
2446 ret = __delete_manifest_info_from_db(mfx);
2448 _LOGD("Delete from DB failed. Rollback now\n");
2449 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2452 /*Commit transaction*/
2453 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2454 if (ret != SQLITE_OK) {
2455 _LOGD("Failed to commit transaction, Rollback now\n");
2456 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2460 _LOGD("Transaction Commit and End\n");
2462 pkgmgr_parser_close_db();
2466 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2469 _LOGD("manifest pointer is NULL\n");
2473 ret = pkgmgr_parser_check_and_create_db(uid);
2475 _LOGD("Failed to open DB\n");
2478 /*Begin transaction*/
2479 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2480 if (ret != SQLITE_OK) {
2481 _LOGD("Failed to begin transaction\n");
2485 _LOGD("Transaction Begin\n");
2486 ret = __delete_manifest_info_from_db(mfx);
2488 _LOGD("Delete from DB failed. Rollback now\n");
2489 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2492 /*Commit transaction*/
2493 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2494 if (ret != SQLITE_OK) {
2495 _LOGD("Failed to commit transaction, Rollback now\n");
2496 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2500 _LOGD("Transaction Commit and End\n");
2502 pkgmgr_parser_close_db();
2506 API int pkgmgr_parser_update_preload_info_in_db()
2509 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2511 _LOGD("Failed to open DB\n");
2514 /*Begin transaction*/
2515 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2516 if (ret != SQLITE_OK) {
2517 _LOGD("Failed to begin transaction\n");
2521 _LOGD("Transaction Begin\n");
2522 ret = __update_preload_condition_in_db();
2524 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2525 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2528 /*Commit transaction*/
2529 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2530 if (ret != SQLITE_OK) {
2531 _LOGD("Failed to commit transaction, Rollback now\n");
2532 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2536 _LOGD("Transaction Commit and End\n");
2538 pkgmgr_parser_close_db();
2542 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2545 ret = pkgmgr_parser_check_and_create_db(uid);
2547 _LOGD("Failed to open DB\n");
2550 /*Begin transaction*/
2551 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2552 if (ret != SQLITE_OK) {
2553 _LOGD("Failed to begin transaction\n");
2557 _LOGD("Transaction Begin\n");
2558 ret = __update_preload_condition_in_db();
2560 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2561 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2564 /*Commit transaction*/
2565 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2566 if (ret != SQLITE_OK) {
2567 _LOGD("Failed to commit transaction, Rollback now\n");
2568 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2572 _LOGD("Transaction Commit and End\n");
2574 pkgmgr_parser_close_db();