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 "app_control text not null, " \
171 "PRIMARY KEY(app_id,app_control) " \
172 "FOREIGN KEY(app_id) " \
173 "REFERENCES package_app_info(app_id) " \
176 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
177 "(app_id text not null, " \
178 "operation text not null, " \
179 "uri_scheme text, " \
181 "subapp_name text, " \
182 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
183 "FOREIGN KEY(app_id) " \
184 "REFERENCES package_app_info(app_id) " \
187 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
188 "(app_id text not null, " \
189 "category text not null, " \
190 "PRIMARY KEY(app_id,category) " \
191 "FOREIGN KEY(app_id) " \
192 "REFERENCES package_app_info(app_id) " \
195 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
196 "(app_id text not null, " \
197 "md_key text not null, " \
198 "md_value text not null, " \
199 "PRIMARY KEY(app_id, md_key, md_value) " \
200 "FOREIGN KEY(app_id) " \
201 "REFERENCES package_app_info(app_id) " \
204 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
205 "(app_id text not null, " \
206 "pm_type text not null, " \
207 "pm_value text not null, " \
208 "PRIMARY KEY(app_id, pm_type, pm_value) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
214 "(app_id text not null, " \
215 "data_share_path text not null, " \
216 "data_share_allowed text not null, " \
217 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
218 "FOREIGN KEY(app_id) " \
219 "REFERENCES package_app_info(app_id) " \
222 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
223 "(app_id text not null, " \
224 "data_share_request text not null, " \
225 "PRIMARY KEY(app_id,data_share_request) " \
226 "FOREIGN KEY(app_id) " \
227 "REFERENCES package_app_info(app_id) " \
230 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
231 "(cert_info text not null, " \
232 "cert_id integer, " \
233 "cert_ref_count integer, " \
234 "PRIMARY KEY(cert_id)) "
236 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
237 "(package text not null, " \
238 "author_root_cert integer, " \
239 "author_im_cert integer, " \
240 "author_signer_cert integer, " \
241 "dist_root_cert integer, " \
242 "dist_im_cert integer, " \
243 "dist_signer_cert integer, " \
244 "dist2_root_cert integer, " \
245 "dist2_im_cert integer, " \
246 "dist2_signer_cert integer, " \
247 "PRIMARY KEY(package)) "
249 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
250 "(app_id text not null, " \
251 "providerid text not null, " \
252 "access text not null, " \
253 "type text not null, " \
254 "PRIMARY KEY(app_id, providerid, access, type) " \
255 "FOREIGN KEY(app_id) " \
256 "REFERENCES package_app_info(app_id) " \
258 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO "CREATE TABLE IF NOT EXISTS package_resource_info" \
259 "(pkg_id text NOT NULL," \
260 "group_folder text NOT NULL," \
261 "group_type text NOT NULL," \
262 "PRIMARY KEY(pkg_id, group_type))"
264 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA "CREATE TABLE IF NOT EXISTS package_resource_data" \
265 "(id integer REFERENCES package_resource_info(rowid)," \
266 "node_folder text NOT NULL," \
267 "attr_name text NOT NULL," \
268 "attr_value test NOT NULL," \
269 "PRIMARY KEY(id, node_folder, attr_name))"
271 static int __insert_uiapplication_info(manifest_x *mfx);
272 static int __insert_serviceapplication_info(manifest_x *mfx);
273 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
274 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
275 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
276 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
277 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
278 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
279 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
280 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
281 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
282 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
283 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
284 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
285 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
286 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
287 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
288 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
289 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
290 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
291 static int __delete_subpkg_info_from_db(char *appid);
292 static int __delete_appinfo_from_db(char *db_table, const char *appid);
293 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
294 static int __exec_query(char *query);
295 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
296 char **label, char **license, char **icon, char **description, char **author);
297 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
298 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
299 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
300 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
301 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
303 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
306 __delete_subpkg_info_from_db(coltxt[0]);
311 static char *__get_str(const char *str)
315 return PKGMGR_PARSER_EMPTY_STR;
321 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
326 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
327 if (ret != SQLITE_OK) {
328 _LOGD("connect db [%s] failed!\n", db_path);
336 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
338 manifest_x *mfx = (manifest_x *)data;
342 uiapplication_x *uiapp = NULL;
343 for(i = 0; i < ncols; i++)
345 uiapp = mfx->uiapplication;
346 if (strcmp(colname[i], "app_id") == 0) {
348 appid = strdup(coltxt[i]);
349 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
351 status = strdup(coltxt[i]);
355 _LOGD("app id is NULL\n");
358 /*update guest mode visibility*/
359 for (; uiapp != NULL; uiapp = uiapp->next) {
360 if (strcmp(uiapp->appid, appid) == 0) {
361 free((void *)uiapp->guestmode_visibility);
362 uiapp->guestmode_visibility = strdup(status);
378 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
380 char *error_message = NULL;
381 char query[MAX_QUERY_LEN] = {'\0'};
382 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
384 sqlite3_exec(pkgmgr_parser_db, query,
385 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
386 _LOGD("Don't execute query = %s error message = %s\n",
387 query, error_message);
388 sqlite3_free(error_message);
393 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
395 char *error_message = NULL;
397 sqlite3_exec(db_handle, db_query,
398 NULL, NULL, &error_message)) {
399 _LOGD("Don't execute query = %s error message = %s\n",
400 db_query, error_message);
401 sqlite3_free(error_message);
404 sqlite3_free(error_message);
408 static int __exec_query(char *query)
410 char *error_message = NULL;
412 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
413 _LOGD("Don't execute query = %s error message = %s\n", query,
415 sqlite3_free(error_message);
418 sqlite3_free(error_message);
422 static int __exec_query_no_msg(char *query)
424 char *error_message = NULL;
426 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
427 sqlite3_free(error_message);
430 sqlite3_free(error_message);
434 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
440 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
446 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
452 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
458 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
464 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
471 static GList *__create_icon_list(GList *locale, icon_x *icn)
476 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
482 static GList *__create_image_list(GList *locale, image_x *image)
487 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
493 static void __printfunc(gpointer data, gpointer userdata)
495 _LOGD("%s ", (char*)data);
498 static void __trimfunc(GList* trim_list)
500 char *trim_data = NULL;
504 list = g_list_first(trim_list);
507 trim_data = (char *)list->data;
510 if (strcmp(trim_data, prev) == 0) {
511 trim_list = g_list_remove(trim_list, trim_data);
512 list = g_list_first(trim_list);
521 list = g_list_next(list);
525 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
527 if (a == NULL || b == NULL)
529 if (strcmp((char*)a, (char*)b) == 0)
531 if (strcmp((char*)a, (char*)b) < 0)
533 if (strcmp((char*)a, (char*)b) > 0)
538 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
539 char **label, char **license, char **icon, char **description, char **author)
544 if (strcmp(lbl->lang, (char *)data) == 0) {
545 *label = (char*)lbl->text;
554 if (strcmp(lcn->lang, (char *)data) == 0) {
555 *license = (char*)lcn->text;
564 if (strcmp(icn->lang, (char *)data) == 0) {
565 *icon = (char*)icn->text;
574 if (strcmp(dcn->lang, (char *)data) == 0) {
575 *description = (char*)dcn->text;
584 if (strcmp(ath->lang, (char *)data) == 0) {
585 *author = (char*)ath->text;
594 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
599 if (strcmp(icn->section, (char *)data) == 0) {
600 *icon = (char*)icn->text;
601 *resolution = (char*)icn->resolution;
609 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
613 if (image->section) {
614 if (strcmp(image->section, (char *)data) == 0) {
615 *lang = (char*)image->lang;
616 *img = (char*)image->text;
624 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
629 char *description = NULL;
630 char *license = NULL;
632 char query[MAX_QUERY_LEN] = {'\0'};
634 manifest_x *mfx = (manifest_x *)userdata;
635 label_x *lbl = mfx->label;
636 license_x *lcn = mfx->license;
637 icon_x *icn = mfx->icon;
638 description_x *dcn = mfx->description;
639 author_x *ath = mfx->author;
641 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
642 if (!label && !description && !icon && !license && !author)
645 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
646 "package_label, package_icon, package_description, package_license, package_author) values " \
647 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
652 __get_str(description),
656 ret = __exec_query(query);
658 _LOGD("Package Localized Info DB Insert failed\n");
661 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
666 char query[MAX_QUERY_LEN] = {'\0'};
668 uiapplication_x *up = (uiapplication_x*)userdata;
669 label_x *lbl = up->label;
670 icon_x *icn = up->icon;
672 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
675 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
676 "app_label, app_icon) values " \
677 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
679 ret = __exec_query(query);
681 _LOGD("Package UiApp Localized Info DB Insert failed\n");
683 /*insert ui app locale info to pkg locale to get mainapp data */
684 if (strcasecmp(up->mainapp, "true")==0) {
685 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
686 "package_label, package_icon, package_description, package_license, package_author) values " \
687 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
692 PKGMGR_PARSER_EMPTY_STR,
693 PKGMGR_PARSER_EMPTY_STR,
694 PKGMGR_PARSER_EMPTY_STR);
696 ret = __exec_query_no_msg(query);
699 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
700 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
701 ret = __exec_query_no_msg(query);
706 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
710 char *resolution = NULL;
711 char query[MAX_QUERY_LEN] = {'\0'};
713 uiapplication_x *up = (uiapplication_x*)userdata;
714 icon_x *icn = up->icon;
716 __extract_icon_data(data, icn, &icon, &resolution);
717 if (!icon && !resolution)
719 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
720 "app_icon, app_icon_section, app_icon_resolution) values " \
721 "('%q', '%q', '%q', '%q')", up->appid,
722 icon, (char*)data, resolution);
724 ret = __exec_query(query);
726 _LOGD("Package UiApp Localized Info DB Insert failed\n");
730 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
735 char query[MAX_QUERY_LEN] = {'\0'};
737 uiapplication_x *up = (uiapplication_x*)userdata;
738 image_x *image = up->image;
740 __extract_image_data(data, image, &lang, &img);
743 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
744 "app_image_section, app_image) values " \
745 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
747 ret = __exec_query(query);
749 _LOGD("Package UiApp image Info DB Insert failed\n");
754 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
759 char query[MAX_QUERY_LEN] = {'\0'};
761 serviceapplication_x *sp = (serviceapplication_x*)userdata;
762 label_x *lbl = sp->label;
763 icon_x *icn = sp->icon;
765 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
768 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
769 "app_label, app_icon) values " \
770 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
772 ret = __exec_query(query);
774 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
777 static int __insert_ui_mainapp_info(manifest_x *mfx)
779 uiapplication_x *up = mfx->uiapplication;
781 char query[MAX_QUERY_LEN] = {'\0'};
784 snprintf(query, MAX_QUERY_LEN,
785 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
787 ret = __exec_query(query);
789 _LOGD("Package UiApp Info DB Insert Failed\n");
792 if (strcasecmp(up->mainapp, "True")==0)
793 mfx->mainapp_id = strdup(up->appid);
796 memset(query, '\0', MAX_QUERY_LEN);
799 if (mfx->mainapp_id == NULL){
800 if (mfx->uiapplication && mfx->uiapplication->appid) {
801 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
803 _LOGD("Not valid appid\n");
807 ret = __exec_query(query);
809 _LOGD("Package UiApp Info DB Insert Failed\n");
813 free((void *)mfx->uiapplication->mainapp);
814 mfx->uiapplication->mainapp= strdup("true");
815 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
818 memset(query, '\0', MAX_QUERY_LEN);
819 snprintf(query, MAX_QUERY_LEN,
820 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
821 ret = __exec_query(query);
823 _LOGD("Package Info DB update Failed\n");
829 /* _PRODUCT_LAUNCHING_ENHANCED_
830 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
832 static int __insert_uiapplication_info(manifest_x *mfx)
834 uiapplication_x *up = mfx->uiapplication;
836 char query[MAX_QUERY_LEN] = {'\0'};
839 snprintf(query, MAX_QUERY_LEN,
840 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
841 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
842 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
843 "app_preload, app_submode, app_submode_mainid, component_type, package) " \
844 "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')",\
850 PKGMGR_PARSER_EMPTY_STR,
852 PKGMGR_PARSER_EMPTY_STR,
858 __get_str(up->recentimage),
860 up->indicatordisplay,
861 __get_str(up->portraitimg),
862 __get_str(up->landscapeimg),
863 up->guestmode_visibility,
867 __get_str(up->submode_mainid),
871 ret = __exec_query(query);
873 _LOGD("Package UiApp Info DB Insert Failed\n");
877 memset(query, '\0', MAX_QUERY_LEN);
882 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
884 uiapplication_x *up = mfx->uiapplication;
885 category_x *ct = NULL;
887 char query[MAX_QUERY_LEN] = {'\0'};
893 snprintf(query, MAX_QUERY_LEN,
894 "insert into package_app_app_category(app_id, category) " \
895 "values('%s','%s')",\
896 up->appid, ct->name);
897 ret = __exec_query(query);
899 _LOGD("Package UiApp Category Info DB Insert Failed\n");
903 memset(query, '\0', MAX_QUERY_LEN);
910 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
912 uiapplication_x *up = mfx->uiapplication;
913 metadata_x *md = NULL;
915 char query[MAX_QUERY_LEN] = {'\0'};
922 snprintf(query, MAX_QUERY_LEN,
923 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
924 "values('%s','%s', '%s')",\
925 up->appid, md->key, md->value);
926 ret = __exec_query(query);
928 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
933 memset(query, '\0', MAX_QUERY_LEN);
940 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
942 uiapplication_x *up = mfx->uiapplication;
943 permission_x *pm = NULL;
945 char query[MAX_QUERY_LEN] = {'\0'};
951 snprintf(query, MAX_QUERY_LEN,
952 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
953 "values('%s','%s', '%s')",\
954 up->appid, pm->type, pm->value);
955 ret = __exec_query(query);
957 _LOGD("Package UiApp permission Info DB Insert Failed\n");
961 memset(query, '\0', MAX_QUERY_LEN);
968 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
970 uiapplication_x *up = mfx->uiapplication;
971 appcontrol_x *acontrol = NULL;
972 operation_x *op = NULL;
975 subapp_x *sub = NULL;
977 char query[MAX_QUERY_LEN] = {'\0'};
978 char buf[BUFSIZE] = {'\0'};
979 const char *operation = NULL;
980 const char *mime = NULL;
981 const char *uri = NULL;
982 const char *subapp = NULL;
984 acontrol = up->appcontrol;
985 while (acontrol != NULL) {
986 op = acontrol->operation;
989 operation = op->name;
995 sub = acontrol->subapp;
1003 snprintf(buf, BUFSIZE, "%s|%s|%s|%s",
1004 operation ? operation : "NULL",
1006 mime ? mime : "NULL",
1007 subapp ? subapp : "NULL");
1008 snprintf(query, MAX_QUERY_LEN,
1009 "insert into package_app_app_control(app_id, app_control) " \
1010 "values('%s', '%s')",\
1012 ret = __exec_query(query);
1014 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1017 memset(query, '\0', MAX_QUERY_LEN);
1021 } while (ui != NULL);
1025 } while (sub != NULL);
1029 } while (mi != NULL);
1034 acontrol = acontrol->next;
1041 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1043 uiapplication_x *up = mfx->uiapplication;
1044 appsvc_x *asvc = NULL;
1045 operation_x *op = NULL;
1048 subapp_x *sub = NULL;
1050 char query[MAX_QUERY_LEN] = {'\0'};
1051 const char *operation = NULL;
1052 const char *mime = NULL;
1053 const char *uri = NULL;
1054 const char *subapp = NULL;
1060 op = asvc->operation;
1064 operation = op->name;
1081 snprintf(query, MAX_QUERY_LEN,
1082 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1083 "values('%s', '%s', '%s', '%s', '%s')",\
1090 ret = __exec_query(query);
1092 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1095 memset(query, '\0', MAX_QUERY_LEN);
1099 } while(ui != NULL);
1103 }while(sub != NULL);
1119 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1121 uiapplication_x *up = mfx->uiapplication;
1122 datashare_x *ds = NULL;
1123 request_x *rq = NULL;
1125 char query[MAX_QUERY_LEN] = {'\0'};
1134 snprintf(query, MAX_QUERY_LEN,
1135 "insert into package_app_share_request(app_id, data_share_request) " \
1136 "values('%s', '%s')",\
1137 up->appid, rq->text);
1138 ret = __exec_query(query);
1140 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1143 memset(query, '\0', MAX_QUERY_LEN);
1153 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1155 uiapplication_x *up = mfx->uiapplication;
1156 datashare_x *ds = NULL;
1157 define_x *df = NULL;
1158 allowed_x *al = NULL;
1160 char query[MAX_QUERY_LEN] = {'\0'};
1172 snprintf(query, MAX_QUERY_LEN,
1173 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1174 "values('%s', '%s', '%s')",\
1175 up->appid, df->path, al->text);
1176 ret = __exec_query(query);
1178 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1181 memset(query, '\0', MAX_QUERY_LEN);
1193 static int __insert_serviceapplication_info(manifest_x *mfx)
1195 serviceapplication_x *sp = mfx->serviceapplication;
1197 char query[MAX_QUERY_LEN] = {'\0'};
1200 snprintf(query, MAX_QUERY_LEN,
1201 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1202 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1203 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1204 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1205 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1206 ret = __exec_query(query);
1208 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1212 memset(query, '\0', MAX_QUERY_LEN);
1217 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1219 serviceapplication_x *sp = mfx->serviceapplication;
1220 category_x *ct = NULL;
1222 char query[MAX_QUERY_LEN] = {'\0'};
1228 snprintf(query, MAX_QUERY_LEN,
1229 "insert into package_app_app_category(app_id, category) " \
1230 "values('%s','%s')",\
1231 sp->appid, ct->name);
1232 ret = __exec_query(query);
1234 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1238 memset(query, '\0', MAX_QUERY_LEN);
1245 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1247 serviceapplication_x *sp = mfx->serviceapplication;
1248 metadata_x *md = NULL;
1250 char query[MAX_QUERY_LEN] = {'\0'};
1257 snprintf(query, MAX_QUERY_LEN,
1258 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1259 "values('%s','%s', '%s')",\
1260 sp->appid, md->key, md->value);
1261 ret = __exec_query(query);
1263 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1268 memset(query, '\0', MAX_QUERY_LEN);
1275 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1277 serviceapplication_x *sp = mfx->serviceapplication;
1278 permission_x *pm = NULL;
1280 char query[MAX_QUERY_LEN] = {'\0'};
1283 pm = sp->permission;
1286 snprintf(query, MAX_QUERY_LEN,
1287 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1288 "values('%s','%s', '%s')",\
1289 sp->appid, pm->type, pm->value);
1290 ret = __exec_query(query);
1292 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1296 memset(query, '\0', MAX_QUERY_LEN);
1303 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1305 serviceapplication_x *sp = mfx->serviceapplication;
1306 appcontrol_x *acontrol = NULL;
1308 char query[MAX_QUERY_LEN] = {'\0'};
1309 char buf[BUFSIZE] = {'\0'};
1310 operation_x *op = NULL;
1313 subapp_x *sub = NULL;
1314 const char *operation = NULL;
1315 const char *mime = NULL;
1316 const char *uri = NULL;
1317 const char *subapp = NULL;
1318 while (sp != NULL) {
1319 acontrol = sp->appcontrol;
1320 while (acontrol != NULL) {
1321 op = acontrol->operation;
1322 while (op != NULL) {
1324 operation = op->name;
1325 mi = acontrol->mime;
1329 sub = acontrol->subapp;
1337 snprintf(buf, BUFSIZE, "%s|%s|%s|%s",
1338 operation ? operation : "NULL",
1340 mime ? mime : "NULL",
1341 subapp ? subapp : "NULL");
1342 snprintf(query, MAX_QUERY_LEN,
1343 "insert into package_app_app_control(app_id, app_control) " \
1344 "values('%s', '%s')",\
1346 ret = __exec_query(query);
1348 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1351 memset(query, '\0', MAX_QUERY_LEN);
1355 } while (ui != NULL);
1359 } while (sub != NULL);
1363 } while (mi != NULL);
1368 acontrol = acontrol->next;
1375 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1377 serviceapplication_x *sp = mfx->serviceapplication;
1378 appsvc_x *asvc = NULL;
1380 char query[MAX_QUERY_LEN] = {'\0'};
1381 operation_x *op = NULL;
1384 subapp_x *sub = NULL;
1385 const char *operation = NULL;
1386 const char *mime = NULL;
1387 const char *uri = NULL;
1388 const char *subapp = NULL;
1394 op = asvc->operation;
1398 operation = op->name;
1414 snprintf(query, MAX_QUERY_LEN,
1415 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1416 "values('%s', '%s', '%s', '%s', '%s')",\
1422 ret = __exec_query(query);
1424 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1427 memset(query, '\0', MAX_QUERY_LEN);
1431 } while(ui != NULL);
1435 }while(sub != NULL);
1451 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1453 serviceapplication_x *sp = mfx->serviceapplication;
1454 datacontrol_x *dc = NULL;
1456 char query[MAX_QUERY_LEN] = {'\0'};
1460 dc = sp->datacontrol;
1463 snprintf(query, MAX_QUERY_LEN,
1464 "insert into package_app_data_control(app_id, providerid, access, type) " \
1465 "values('%s', '%s', '%s', '%s')",\
1466 mfx->serviceapplication->appid,
1471 ret = __exec_query(query);
1473 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1476 memset(query, '\0', MAX_QUERY_LEN);
1484 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1486 serviceapplication_x *sp = mfx->serviceapplication;
1487 datashare_x *ds = NULL;
1488 request_x *rq = NULL;
1490 char query[MAX_QUERY_LEN] = {'\0'};
1499 snprintf(query, MAX_QUERY_LEN,
1500 "insert into package_app_share_request(app_id, data_share_request) " \
1501 "values('%s', '%s')",\
1502 sp->appid, rq->text);
1503 ret = __exec_query(query);
1505 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1508 memset(query, '\0', MAX_QUERY_LEN);
1520 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1522 serviceapplication_x *sp = mfx->serviceapplication;
1523 datashare_x *ds = NULL;
1524 define_x *df = NULL;
1525 allowed_x *al = NULL;
1527 char query[MAX_QUERY_LEN] = {'\0'};
1539 snprintf(query, MAX_QUERY_LEN,
1540 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1541 "values('%s', '%s', '%s')",\
1542 sp->appid, df->path, al->text);
1543 ret = __exec_query(query);
1545 _LOGD("Package App Share Allowed DB Insert Failed\n");
1548 memset(query, '\0', MAX_QUERY_LEN);
1560 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1562 label_x *lbl = mfx->label;
1563 license_x *lcn = mfx->license;
1564 icon_x *icn = mfx->icon;
1565 description_x *dcn = mfx->description;
1566 author_x *ath = mfx->author;
1567 uiapplication_x *up = mfx->uiapplication;
1568 uiapplication_x *up_icn = mfx->uiapplication;
1569 uiapplication_x *up_image = mfx->uiapplication;
1570 serviceapplication_x *sp = mfx->serviceapplication;
1571 privileges_x *pvs = NULL;
1572 privilege_x *pv = NULL;
1573 char query[MAX_QUERY_LEN] = { '\0' };
1574 char root[MAX_QUERY_LEN] = { '\0' };
1578 const char *auth_name = NULL;
1579 const char *auth_email = NULL;
1580 const char *auth_href = NULL;
1581 const char *apps_path = NULL;
1583 GList *pkglocale = NULL;
1584 GList *applocale = NULL;
1585 GList *appicon = NULL;
1586 GList *appimage = NULL;
1590 auth_name = ath->text;
1592 auth_email = ath->email;
1594 auth_href = ath->href;
1596 /*Insert in the package_cert_info CERT_DB*/
1597 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1598 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1599 if (ret != PMINFO_R_OK) {
1600 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1601 _LOGE("Cert Info DB create handle failed\n");
1604 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1605 if (ret != PMINFO_R_OK) {
1606 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1607 _LOGE("Cert Info DB Insert Failed\n");
1611 /*Insert in the package_info DB*/
1613 type = strdup(mfx->type);
1615 type = strdup("rpm");
1616 /*Insert in the package_info DB*/
1618 path = strdup(mfx->root_path);
1620 if (strcmp(type,"rpm")==0) {
1621 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1622 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1624 apps_path = tzplatform_getenv(TZ_USER_APP);
1625 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1627 path = strdup(root);
1629 snprintf(query, MAX_QUERY_LEN,
1630 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1631 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1632 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1633 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1637 __get_str(mfx->installlocation),
1638 __get_str(mfx->package_size),
1644 mfx->nodisplay_setting,
1646 __get_str(auth_name),
1647 __get_str(auth_email),
1648 __get_str(auth_href),
1649 mfx->installed_time,
1650 mfx->installed_storage,
1651 __get_str(mfx->storeclient_id),
1653 __get_str(mfx->package_url),
1655 __get_str(mfx->csc_path));
1656 /*If package dont have main_package tag, this package is main package.*/
1657 if (mfx->main_package == NULL) {
1658 ret = __exec_query(query);
1660 _LOGD("Package Info DB Insert Failed\n");
1672 /*If package has main_package tag, this package is sub package(ug, efl).
1673 skip __exec_query for package_info and change pkgid with main_package*/
1674 memset(root, '\0', MAX_QUERY_LEN);
1675 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1676 if (access(root, F_OK) == 0) {
1677 free((void *)mfx->package);
1678 mfx->package = strdup(mfx->main_package);
1680 _LOGE("main package[%s] is not installed\n", root);
1693 /*Insert in the package_privilege_info DB*/
1694 pvs = mfx->privileges;
1695 while (pvs != NULL) {
1696 pv = pvs->privilege;
1697 while (pv != NULL) {
1698 memset(query, '\0', MAX_QUERY_LEN);
1699 snprintf(query, MAX_QUERY_LEN,
1700 "insert into package_privilege_info(package, privilege) " \
1701 "values('%s','%s')",\
1702 mfx->package, pv->text);
1703 ret = __exec_query(query);
1705 _LOGD("Package Privilege Info DB Insert Failed\n");
1714 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);
1867 /*Insert in the package_app_data_control DB*/
1868 ret = __insert_serviceapplication_datacontrol_info(mfx);
1876 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1878 char query[MAX_QUERY_LEN] = { '\0' };
1880 memset(query, '\0', MAX_QUERY_LEN);
1881 snprintf(query, MAX_QUERY_LEN,
1882 "delete from %s where app_id='%s'", db_table, appid);
1883 ret = __exec_query(query);
1885 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1891 static int __delete_subpkg_info_from_db(char *appid)
1895 ret = __delete_appinfo_from_db("package_app_info", appid);
1898 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1901 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1904 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1907 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1910 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1913 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1916 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1919 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1922 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1925 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1928 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1935 static int __delete_subpkg_from_db(manifest_x *mfx)
1937 char query[MAX_QUERY_LEN] = { '\0' };
1938 char *error_message = NULL;
1940 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1942 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1943 _LOGE("Don't execute query = %s error message = %s\n", query,
1945 sqlite3_free(error_message);
1948 sqlite3_free(error_message);
1953 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1955 char query[MAX_QUERY_LEN] = { '\0' };
1957 uiapplication_x *up = mfx->uiapplication;
1958 serviceapplication_x *sp = mfx->serviceapplication;
1959 /*Delete from cert table*/
1960 if (uid != GLOBAL_USER)
1961 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1963 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1965 _LOGD("Cert Info DB Delete Failed\n");
1969 /*Delete from Package Info DB*/
1970 snprintf(query, MAX_QUERY_LEN,
1971 "delete from package_info where package='%s'", mfx->package);
1972 ret = __exec_query(query);
1974 _LOGD("Package Info DB Delete Failed\n");
1977 memset(query, '\0', MAX_QUERY_LEN);
1979 /*Delete from Package Localized Info*/
1980 snprintf(query, MAX_QUERY_LEN,
1981 "delete from package_localized_info where package='%s'", mfx->package);
1982 ret = __exec_query(query);
1984 _LOGD("Package Localized Info DB Delete Failed\n");
1988 /*Delete from Package Privilege Info*/
1989 snprintf(query, MAX_QUERY_LEN,
1990 "delete from package_privilege_info where package='%s'", mfx->package);
1991 ret = __exec_query(query);
1993 _LOGD("Package Privilege Info DB Delete Failed\n");
1997 while (up != NULL) {
1998 ret = __delete_appinfo_from_db("package_app_info", up->appid);
2001 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
2004 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
2007 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
2010 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
2013 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
2016 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
2019 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
2022 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
2025 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
2028 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
2031 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
2037 while (sp != NULL) {
2038 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2041 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2044 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2047 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2050 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2053 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2056 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2059 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2062 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2065 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2068 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2071 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
2077 /* if main package has sub pkg, delete sub pkg data*/
2078 __delete_subpkg_from_db(mfx);
2083 static int __update_preload_condition_in_db()
2086 char query[MAX_QUERY_LEN] = {'\0'};
2088 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2090 ret = __exec_query(query);
2092 _LOGD("Package preload_condition update failed\n");
2097 API int pkgmgr_parser_initialize_db(void)
2101 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2103 _LOGD("package info DB initialization failed\n");
2106 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2108 _LOGD("package localized info DB initialization failed\n");
2111 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2113 _LOGD("package app app privilege DB initialization failed\n");
2116 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2118 _LOGD("package app info DB initialization failed\n");
2121 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2123 _LOGD("package app localized info DB initialization failed\n");
2126 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2128 _LOGD("package app icon localized info DB initialization failed\n");
2131 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2133 _LOGD("package app image info DB initialization failed\n");
2136 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2138 _LOGD("package app app control DB initialization failed\n");
2141 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2143 _LOGD("package app app category DB initialization failed\n");
2146 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2148 _LOGD("package app app category DB initialization failed\n");
2151 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2153 _LOGD("package app app permission DB initialization failed\n");
2156 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2158 _LOGD("package app app svc DB initialization failed\n");
2161 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2163 _LOGD("package app share allowed DB initialization failed\n");
2166 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2168 _LOGD("package app share request DB initialization failed\n");
2171 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2173 _LOGD("package app data control DB initialization failed\n");
2177 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2179 _LOGD("package cert info DB initialization failed\n");
2182 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2184 _LOGD("package cert index info DB initialization failed\n");
2188 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO);
2190 _LOGD("package resource info DB initialization failed\n");
2193 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA);
2195 _LOGD("package resource data DB initialization failed\n");
2202 static int parserdb_change_perm(const char *db_file, uid_t uid)
2205 char journal_file[BUFSIZE];
2208 struct passwd *userinfo = NULL;
2209 files[0] = (char *)db_file;
2210 files[1] = journal_file;
2216 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2218 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2219 userinfo = getpwuid(uid);
2221 _LOGE("FAIL: user %d doesn't exist", uid);
2224 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2226 for (i = 0; files[i]; i++) {
2227 ret = chown(files[i], uid, userinfo->pw_gid);
2228 SET_SMACK_LABEL(files[i],uid)
2230 strerror_r(errno, buf, sizeof(buf));
2231 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2235 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2237 strerror_r(errno, buf, sizeof(buf));
2238 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2245 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2249 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2251 _LOGD("Manifest DB creation Failed\n");
2256 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2258 _LOGD("Cert DB creation Failed\n");
2261 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2262 _LOGD("Failed to change cert db permission\n");
2264 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2265 _LOGD("Failed to change parser db permission\n");
2270 void pkgmgr_parser_close_db()
2272 sqlite3_close(pkgmgr_parser_db);
2273 sqlite3_close(pkgmgr_cert_db);
2277 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2279 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2281 _LOGD("manifest pointer is NULL\n");
2285 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2287 _LOGD("Failed to open DB\n");
2290 ret = pkgmgr_parser_initialize_db();
2293 /*Begin transaction*/
2294 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2295 if (ret != SQLITE_OK) {
2296 _LOGD("Failed to begin transaction\n");
2300 _LOGD("Transaction Begin\n");
2301 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2303 _LOGD("Insert into DB failed. Rollback now\n");
2304 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2307 /*Commit transaction*/
2308 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2309 if (ret != SQLITE_OK) {
2310 _LOGD("Failed to commit transaction. Rollback now\n");
2311 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2315 _LOGD("Transaction Commit and End\n");
2317 pkgmgr_parser_close_db();
2321 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2323 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2325 _LOGD("manifest pointer is NULL\n");
2329 ret = pkgmgr_parser_check_and_create_db(uid);
2331 _LOGD("Failed to open DB\n");
2334 ret = pkgmgr_parser_initialize_db();
2337 /*Begin transaction*/
2338 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2339 if (ret != SQLITE_OK) {
2340 _LOGD("Failed to begin transaction\n");
2344 _LOGD("Transaction Begin\n");
2345 ret = __insert_manifest_info_in_db(mfx, uid);
2347 _LOGD("Insert into DB failed. Rollback now\n");
2348 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2351 /*Commit transaction*/
2352 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2353 if (ret != SQLITE_OK) {
2354 _LOGD("Failed to commit transaction. Rollback now\n");
2355 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2359 _LOGD("Transaction Commit and End\n");
2361 pkgmgr_parser_close_db();
2365 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2368 _LOGD("manifest pointer is NULL\n");
2372 ret = pkgmgr_parser_check_and_create_db(uid);
2374 _LOGD("Failed to open DB\n");
2377 ret = pkgmgr_parser_initialize_db();
2380 /*Preserve guest mode visibility*/
2381 __preserve_guestmode_visibility_value( mfx);
2382 /*Begin transaction*/
2383 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2384 if (ret != SQLITE_OK) {
2385 _LOGD("Failed to begin transaction\n");
2389 _LOGD("Transaction Begin\n");
2390 ret = __delete_manifest_info_from_db(mfx, uid);
2392 _LOGD("Delete from DB failed. Rollback now\n");
2393 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2396 ret = __insert_manifest_info_in_db(mfx, uid);
2398 _LOGD("Insert into DB failed. Rollback now\n");
2399 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2403 /*Commit transaction*/
2404 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2405 if (ret != SQLITE_OK) {
2406 _LOGD("Failed to commit transaction. Rollback now\n");
2407 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2411 _LOGD("Transaction Commit and End\n");
2413 pkgmgr_parser_close_db();
2417 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2419 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2422 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2425 _LOGD("manifest pointer is NULL\n");
2429 ret = pkgmgr_parser_check_and_create_db(uid);
2431 _LOGD("Failed to open DB\n");
2434 /*Begin transaction*/
2435 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2436 if (ret != SQLITE_OK) {
2437 _LOGD("Failed to begin transaction\n");
2441 _LOGD("Transaction Begin\n");
2442 ret = __delete_manifest_info_from_db(mfx, uid);
2444 _LOGD("Delete from DB failed. Rollback now\n");
2445 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2448 /*Commit transaction*/
2449 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2450 if (ret != SQLITE_OK) {
2451 _LOGD("Failed to commit transaction, Rollback now\n");
2452 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2456 _LOGD("Transaction Commit and End\n");
2458 pkgmgr_parser_close_db();
2462 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2464 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2467 API int pkgmgr_parser_update_preload_info_in_db()
2470 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2472 _LOGD("Failed to open DB\n");
2475 /*Begin transaction*/
2476 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2477 if (ret != SQLITE_OK) {
2478 _LOGD("Failed to begin transaction\n");
2482 _LOGD("Transaction Begin\n");
2483 ret = __update_preload_condition_in_db();
2485 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2486 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2489 /*Commit transaction*/
2490 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2491 if (ret != SQLITE_OK) {
2492 _LOGD("Failed to commit transaction, Rollback now\n");
2493 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2497 _LOGD("Transaction Commit and End\n");
2499 pkgmgr_parser_close_db();
2503 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2506 ret = pkgmgr_parser_check_and_create_db(uid);
2508 _LOGD("Failed to open DB\n");
2511 /*Begin transaction*/
2512 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2513 if (ret != SQLITE_OK) {
2514 _LOGD("Failed to begin transaction\n");
2518 _LOGD("Transaction Begin\n");
2519 ret = __update_preload_condition_in_db();
2521 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2522 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2525 /*Commit transaction*/
2526 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2527 if (ret != SQLITE_OK) {
2528 _LOGD("Failed to commit transaction, Rollback now\n");
2529 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2533 _LOGD("Transaction Commit and End\n");
2535 pkgmgr_parser_close_db();