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 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
133 "component_type text, " \
134 "package text not null, " \
135 "FOREIGN KEY(package) " \
136 "REFERENCES package_info(package) " \
139 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
140 "(app_id text not null, " \
141 "app_locale text DEFAULT 'No Locale', " \
144 "PRIMARY KEY(app_id,app_locale) " \
145 "FOREIGN KEY(app_id) " \
146 "REFERENCES package_app_info(app_id) " \
149 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
150 "(app_id text not null, " \
152 "app_icon_section text, " \
153 "app_icon_resolution text, " \
154 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
155 "FOREIGN KEY(app_id) " \
156 "REFERENCES package_app_info(app_id) " \
159 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
160 "(app_id text not null, " \
161 "app_locale text DEFAULT 'No Locale', " \
162 "app_image_section text, " \
164 "PRIMARY KEY(app_id,app_image_section) " \
165 "FOREIGN KEY(app_id) " \
166 "REFERENCES package_app_info(app_id) " \
169 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
170 "(app_id text not null, " \
171 "app_control text not null, " \
172 "PRIMARY KEY(app_id,app_control) " \
173 "FOREIGN KEY(app_id) " \
174 "REFERENCES package_app_info(app_id) " \
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
178 "(app_id text not null, " \
179 "operation text not null, " \
180 "uri_scheme text, " \
182 "subapp_name text, " \
183 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
184 "FOREIGN KEY(app_id) " \
185 "REFERENCES package_app_info(app_id) " \
188 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
189 "(app_id text not null, " \
190 "category text not null, " \
191 "PRIMARY KEY(app_id,category) " \
192 "FOREIGN KEY(app_id) " \
193 "REFERENCES package_app_info(app_id) " \
196 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
197 "(app_id text not null, " \
198 "md_key text not null, " \
199 "md_value text not null, " \
200 "PRIMARY KEY(app_id, md_key, md_value) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
206 "(app_id text not null, " \
207 "pm_type text not null, " \
208 "pm_value text not null, " \
209 "PRIMARY KEY(app_id, pm_type, pm_value) " \
210 "FOREIGN KEY(app_id) " \
211 "REFERENCES package_app_info(app_id) " \
214 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
215 "(app_id text not null, " \
216 "data_share_path text not null, " \
217 "data_share_allowed text not null, " \
218 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
219 "FOREIGN KEY(app_id) " \
220 "REFERENCES package_app_info(app_id) " \
223 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
224 "(app_id text not null, " \
225 "data_share_request text not null, " \
226 "PRIMARY KEY(app_id,data_share_request) " \
227 "FOREIGN KEY(app_id) " \
228 "REFERENCES package_app_info(app_id) " \
231 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
232 "(cert_info text not null, " \
233 "cert_id integer, " \
234 "cert_ref_count integer, " \
235 "PRIMARY KEY(cert_id)) "
237 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
238 "(package text not null, " \
239 "author_root_cert integer, " \
240 "author_im_cert integer, " \
241 "author_signer_cert integer, " \
242 "dist_root_cert integer, " \
243 "dist_im_cert integer, " \
244 "dist_signer_cert integer, " \
245 "dist2_root_cert integer, " \
246 "dist2_im_cert integer, " \
247 "dist2_signer_cert integer, " \
248 "PRIMARY KEY(package)) "
250 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
251 "(app_id text not null, " \
252 "providerid text not null, " \
253 "access text not null, " \
254 "type text not null, " \
255 "PRIMARY KEY(app_id, providerid, access, type) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
259 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO "CREATE TABLE IF NOT EXISTS package_resource_info" \
260 "(pkg_id text NOT NULL," \
261 "group_folder text NOT NULL," \
262 "group_type text NOT NULL," \
263 "PRIMARY KEY(pkg_id, group_type))"
265 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA "CREATE TABLE IF NOT EXISTS package_resource_data" \
266 "(id integer REFERENCES package_resource_info(rowid)," \
267 "node_folder text NOT NULL," \
268 "attr_name text NOT NULL," \
269 "attr_value test NOT NULL," \
270 "PRIMARY KEY(id, node_folder, attr_name))"
272 static int __insert_uiapplication_info(manifest_x *mfx);
273 static int __insert_serviceapplication_info(manifest_x *mfx);
274 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
275 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
276 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
277 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
278 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
279 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
280 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
281 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
282 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
283 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
284 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
285 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
286 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
287 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
288 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
289 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
290 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
291 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
292 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
293 static int __delete_subpkg_info_from_db(char *appid);
294 static int __delete_appinfo_from_db(char *db_table, const char *appid);
295 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
296 static int __exec_query(char *query);
297 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
298 char **label, char **license, char **icon, char **description, char **author);
299 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
300 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
301 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
302 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
303 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
305 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
308 __delete_subpkg_info_from_db(coltxt[0]);
313 static char *__get_str(const char *str)
317 return PKGMGR_PARSER_EMPTY_STR;
323 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
328 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
329 if (ret != SQLITE_OK) {
330 _LOGD("connect db [%s] failed!\n", db_path);
338 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
340 manifest_x *mfx = (manifest_x *)data;
344 uiapplication_x *uiapp = NULL;
345 for(i = 0; i < ncols; i++)
347 uiapp = mfx->uiapplication;
348 if (strcmp(colname[i], "app_id") == 0) {
350 appid = strdup(coltxt[i]);
351 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
353 status = strdup(coltxt[i]);
357 _LOGD("app id is NULL\n");
360 /*update guest mode visibility*/
361 for (; uiapp != NULL; uiapp = uiapp->next) {
362 if (strcmp(uiapp->appid, appid) == 0) {
363 free((void *)uiapp->guestmode_visibility);
364 uiapp->guestmode_visibility = strdup(status);
380 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
382 char *error_message = NULL;
383 char query[MAX_QUERY_LEN] = {'\0'};
384 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
386 sqlite3_exec(pkgmgr_parser_db, query,
387 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
388 _LOGD("Don't execute query = %s error message = %s\n",
389 query, error_message);
390 sqlite3_free(error_message);
395 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
397 char *error_message = NULL;
399 sqlite3_exec(db_handle, db_query,
400 NULL, NULL, &error_message)) {
401 _LOGD("Don't execute query = %s error message = %s\n",
402 db_query, error_message);
403 sqlite3_free(error_message);
406 sqlite3_free(error_message);
410 static int __exec_query(char *query)
412 char *error_message = NULL;
414 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
415 _LOGD("Don't execute query = %s error message = %s\n", query,
417 sqlite3_free(error_message);
420 sqlite3_free(error_message);
424 static int __exec_query_no_msg(char *query)
426 char *error_message = NULL;
428 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
429 sqlite3_free(error_message);
432 sqlite3_free(error_message);
436 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
442 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
448 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
454 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
460 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
466 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
473 static GList *__create_icon_list(GList *locale, icon_x *icn)
478 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
484 static GList *__create_image_list(GList *locale, image_x *image)
489 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
495 static void __printfunc(gpointer data, gpointer userdata)
497 _LOGD("%s ", (char*)data);
500 static void __trimfunc(GList* trim_list)
502 char *trim_data = NULL;
506 list = g_list_first(trim_list);
509 trim_data = (char *)list->data;
512 if (strcmp(trim_data, prev) == 0) {
513 trim_list = g_list_remove(trim_list, trim_data);
514 list = g_list_first(trim_list);
523 list = g_list_next(list);
527 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
529 if (a == NULL || b == NULL)
531 if (strcmp((char*)a, (char*)b) == 0)
533 if (strcmp((char*)a, (char*)b) < 0)
535 if (strcmp((char*)a, (char*)b) > 0)
540 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
541 char **label, char **license, char **icon, char **description, char **author)
546 if (strcmp(lbl->lang, (char *)data) == 0) {
547 *label = (char*)lbl->text;
556 if (strcmp(lcn->lang, (char *)data) == 0) {
557 *license = (char*)lcn->text;
566 if (strcmp(icn->lang, (char *)data) == 0) {
567 *icon = (char*)icn->text;
576 if (strcmp(dcn->lang, (char *)data) == 0) {
577 *description = (char*)dcn->text;
586 if (strcmp(ath->lang, (char *)data) == 0) {
587 *author = (char*)ath->text;
596 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
601 if (strcmp(icn->section, (char *)data) == 0) {
602 *icon = (char*)icn->text;
603 *resolution = (char*)icn->resolution;
611 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
615 if (image->section) {
616 if (strcmp(image->section, (char *)data) == 0) {
617 *lang = (char*)image->lang;
618 *img = (char*)image->text;
626 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
631 char *description = NULL;
632 char *license = NULL;
634 char query[MAX_QUERY_LEN] = {'\0'};
636 manifest_x *mfx = (manifest_x *)userdata;
637 label_x *lbl = mfx->label;
638 license_x *lcn = mfx->license;
639 icon_x *icn = mfx->icon;
640 description_x *dcn = mfx->description;
641 author_x *ath = mfx->author;
643 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
644 if (!label && !description && !icon && !license && !author)
647 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
648 "package_label, package_icon, package_description, package_license, package_author) values " \
649 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
654 __get_str(description),
658 ret = __exec_query(query);
660 _LOGD("Package Localized Info DB Insert failed\n");
663 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
668 char query[MAX_QUERY_LEN] = {'\0'};
670 uiapplication_x *up = (uiapplication_x*)userdata;
671 label_x *lbl = up->label;
672 icon_x *icn = up->icon;
674 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
677 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
678 "app_label, app_icon) values " \
679 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
681 ret = __exec_query(query);
683 _LOGD("Package UiApp Localized Info DB Insert failed\n");
685 /*insert ui app locale info to pkg locale to get mainapp data */
686 if (strcasecmp(up->mainapp, "true")==0) {
687 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
688 "package_label, package_icon, package_description, package_license, package_author) values " \
689 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
694 PKGMGR_PARSER_EMPTY_STR,
695 PKGMGR_PARSER_EMPTY_STR,
696 PKGMGR_PARSER_EMPTY_STR);
698 ret = __exec_query_no_msg(query);
701 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
702 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
703 ret = __exec_query_no_msg(query);
708 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
712 char *resolution = NULL;
713 char query[MAX_QUERY_LEN] = {'\0'};
715 uiapplication_x *up = (uiapplication_x*)userdata;
716 icon_x *icn = up->icon;
718 __extract_icon_data(data, icn, &icon, &resolution);
719 if (!icon && !resolution)
721 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
722 "app_icon, app_icon_section, app_icon_resolution) values " \
723 "('%q', '%q', '%q', '%q')", up->appid,
724 icon, (char*)data, resolution);
726 ret = __exec_query(query);
728 _LOGD("Package UiApp Localized Info DB Insert failed\n");
732 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
737 char query[MAX_QUERY_LEN] = {'\0'};
739 uiapplication_x *up = (uiapplication_x*)userdata;
740 image_x *image = up->image;
742 __extract_image_data(data, image, &lang, &img);
745 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
746 "app_image_section, app_image) values " \
747 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
749 ret = __exec_query(query);
751 _LOGD("Package UiApp image Info DB Insert failed\n");
756 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
761 char query[MAX_QUERY_LEN] = {'\0'};
763 serviceapplication_x *sp = (serviceapplication_x*)userdata;
764 label_x *lbl = sp->label;
765 icon_x *icn = sp->icon;
767 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
770 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
771 "app_label, app_icon) values " \
772 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
774 ret = __exec_query(query);
776 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
779 static int __insert_ui_mainapp_info(manifest_x *mfx)
781 uiapplication_x *up = mfx->uiapplication;
783 char query[MAX_QUERY_LEN] = {'\0'};
786 snprintf(query, MAX_QUERY_LEN,
787 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
789 ret = __exec_query(query);
791 _LOGD("Package UiApp Info DB Insert Failed\n");
794 if (strcasecmp(up->mainapp, "True")==0)
795 mfx->mainapp_id = strdup(up->appid);
798 memset(query, '\0', MAX_QUERY_LEN);
801 if (mfx->mainapp_id == NULL){
802 if (mfx->uiapplication && mfx->uiapplication->appid) {
803 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
805 _LOGD("Not valid appid\n");
809 ret = __exec_query(query);
811 _LOGD("Package UiApp Info DB Insert Failed\n");
815 free((void *)mfx->uiapplication->mainapp);
816 mfx->uiapplication->mainapp= strdup("true");
817 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
820 memset(query, '\0', MAX_QUERY_LEN);
821 snprintf(query, MAX_QUERY_LEN,
822 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
823 ret = __exec_query(query);
825 _LOGD("Package Info DB update Failed\n");
831 /* _PRODUCT_LAUNCHING_ENHANCED_
832 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
834 static int __insert_uiapplication_info(manifest_x *mfx)
836 uiapplication_x *up = mfx->uiapplication;
838 char query[MAX_QUERY_LEN] = {'\0'};
841 snprintf(query, MAX_QUERY_LEN,
842 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
843 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
844 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
845 "app_preload, app_submode, app_submode_mainid, component_type, package, app_launch_mode) " \
846 "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', '%s')",\
852 PKGMGR_PARSER_EMPTY_STR,
854 PKGMGR_PARSER_EMPTY_STR,
860 __get_str(up->recentimage),
862 up->indicatordisplay,
863 __get_str(up->portraitimg),
864 __get_str(up->landscapeimg),
865 up->guestmode_visibility,
869 __get_str(up->submode_mainid),
874 ret = __exec_query(query);
876 _LOGD("Package UiApp Info DB Insert Failed\n");
880 memset(query, '\0', MAX_QUERY_LEN);
885 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
887 uiapplication_x *up = mfx->uiapplication;
888 category_x *ct = NULL;
890 char query[MAX_QUERY_LEN] = {'\0'};
896 snprintf(query, MAX_QUERY_LEN,
897 "insert into package_app_app_category(app_id, category) " \
898 "values('%s','%s')",\
899 up->appid, ct->name);
900 ret = __exec_query(query);
902 _LOGD("Package UiApp Category Info DB Insert Failed\n");
906 memset(query, '\0', MAX_QUERY_LEN);
913 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
915 uiapplication_x *up = mfx->uiapplication;
916 metadata_x *md = NULL;
918 char query[MAX_QUERY_LEN] = {'\0'};
925 snprintf(query, MAX_QUERY_LEN,
926 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
927 "values('%s','%s', '%s')",\
928 up->appid, md->key, md->value);
929 ret = __exec_query(query);
931 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
936 memset(query, '\0', MAX_QUERY_LEN);
943 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
945 uiapplication_x *up = mfx->uiapplication;
946 permission_x *pm = NULL;
948 char query[MAX_QUERY_LEN] = {'\0'};
954 snprintf(query, MAX_QUERY_LEN,
955 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
956 "values('%s','%s', '%s')",\
957 up->appid, pm->type, pm->value);
958 ret = __exec_query(query);
960 _LOGD("Package UiApp permission Info DB Insert Failed\n");
964 memset(query, '\0', MAX_QUERY_LEN);
971 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
973 uiapplication_x *up = mfx->uiapplication;
974 appcontrol_x *acontrol = NULL;
976 char query[MAX_QUERY_LEN] = {'\0'};
977 char buf[BUFSIZE] = {'\0'};
979 acontrol = up->appcontrol;
980 while (acontrol != NULL) {
981 snprintf(buf, BUFSIZE, "%s|%s|%s",\
982 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
983 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
984 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
985 snprintf(query, MAX_QUERY_LEN,
986 "insert into package_app_app_control(app_id, app_control) " \
987 "values('%s', '%s')",\
989 ret = __exec_query(query);
991 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
994 memset(query, '\0', MAX_QUERY_LEN);
995 acontrol = acontrol->next;
1002 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1004 uiapplication_x *up = mfx->uiapplication;
1005 appsvc_x *asvc = NULL;
1006 operation_x *op = NULL;
1009 subapp_x *sub = NULL;
1011 char query[MAX_QUERY_LEN] = {'\0'};
1012 const char *operation = NULL;
1013 const char *mime = NULL;
1014 const char *uri = NULL;
1015 const char *subapp = NULL;
1021 op = asvc->operation;
1025 operation = op->name;
1042 snprintf(query, MAX_QUERY_LEN,
1043 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1044 "values('%s', '%s', '%s', '%s', '%s')",\
1051 ret = __exec_query(query);
1053 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1056 memset(query, '\0', MAX_QUERY_LEN);
1060 } while(ui != NULL);
1064 }while(sub != NULL);
1080 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1082 uiapplication_x *up = mfx->uiapplication;
1083 datacontrol_x *dc = NULL;
1085 char query[MAX_QUERY_LEN] = {'\0'};
1089 dc = up->datacontrol;
1092 snprintf(query, MAX_QUERY_LEN,
1093 "insert into package_app_data_control(app_id, providerid, access, type) " \
1094 "values('%s', '%s', '%s', '%s')",\
1095 mfx->uiapplication->appid,
1100 ret = __exec_query(query);
1102 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1105 memset(query, '\0', MAX_QUERY_LEN);
1113 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1115 uiapplication_x *up = mfx->uiapplication;
1116 datashare_x *ds = NULL;
1117 request_x *rq = NULL;
1119 char query[MAX_QUERY_LEN] = {'\0'};
1128 snprintf(query, MAX_QUERY_LEN,
1129 "insert into package_app_share_request(app_id, data_share_request) " \
1130 "values('%s', '%s')",\
1131 up->appid, rq->text);
1132 ret = __exec_query(query);
1134 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1137 memset(query, '\0', MAX_QUERY_LEN);
1147 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1149 uiapplication_x *up = mfx->uiapplication;
1150 datashare_x *ds = NULL;
1151 define_x *df = NULL;
1152 allowed_x *al = NULL;
1154 char query[MAX_QUERY_LEN] = {'\0'};
1166 snprintf(query, MAX_QUERY_LEN,
1167 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1168 "values('%s', '%s', '%s')",\
1169 up->appid, df->path, al->text);
1170 ret = __exec_query(query);
1172 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1175 memset(query, '\0', MAX_QUERY_LEN);
1187 static int __insert_serviceapplication_info(manifest_x *mfx)
1189 serviceapplication_x *sp = mfx->serviceapplication;
1191 char query[MAX_QUERY_LEN] = {'\0'};
1194 snprintf(query, MAX_QUERY_LEN,
1195 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1196 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1197 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1198 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1199 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1200 ret = __exec_query(query);
1202 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1206 memset(query, '\0', MAX_QUERY_LEN);
1211 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1213 serviceapplication_x *sp = mfx->serviceapplication;
1214 category_x *ct = NULL;
1216 char query[MAX_QUERY_LEN] = {'\0'};
1222 snprintf(query, MAX_QUERY_LEN,
1223 "insert into package_app_app_category(app_id, category) " \
1224 "values('%s','%s')",\
1225 sp->appid, ct->name);
1226 ret = __exec_query(query);
1228 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1232 memset(query, '\0', MAX_QUERY_LEN);
1239 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1241 serviceapplication_x *sp = mfx->serviceapplication;
1242 metadata_x *md = NULL;
1244 char query[MAX_QUERY_LEN] = {'\0'};
1251 snprintf(query, MAX_QUERY_LEN,
1252 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1253 "values('%s','%s', '%s')",\
1254 sp->appid, md->key, md->value);
1255 ret = __exec_query(query);
1257 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1262 memset(query, '\0', MAX_QUERY_LEN);
1269 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1271 serviceapplication_x *sp = mfx->serviceapplication;
1272 permission_x *pm = NULL;
1274 char query[MAX_QUERY_LEN] = {'\0'};
1277 pm = sp->permission;
1280 snprintf(query, MAX_QUERY_LEN,
1281 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1282 "values('%s','%s', '%s')",\
1283 sp->appid, pm->type, pm->value);
1284 ret = __exec_query(query);
1286 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1290 memset(query, '\0', MAX_QUERY_LEN);
1297 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1299 serviceapplication_x *sp = mfx->serviceapplication;
1300 appcontrol_x *acontrol = NULL;
1302 char query[MAX_QUERY_LEN] = {'\0'};
1303 char buf[BUFSIZE] = {'\0'};
1304 while (sp != NULL) {
1305 acontrol = sp->appcontrol;
1306 while (acontrol != NULL) {
1307 snprintf(buf, BUFSIZE, "%s|%s|%s",
1308 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1309 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1310 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1311 snprintf(query, MAX_QUERY_LEN,
1312 "insert into package_app_app_control(app_id, app_control) " \
1313 "values('%s', '%s')",\
1315 ret = __exec_query(query);
1317 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1320 memset(query, '\0', MAX_QUERY_LEN);
1321 acontrol = acontrol->next;
1328 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1330 serviceapplication_x *sp = mfx->serviceapplication;
1331 appsvc_x *asvc = NULL;
1333 char query[MAX_QUERY_LEN] = {'\0'};
1334 operation_x *op = NULL;
1337 subapp_x *sub = NULL;
1338 const char *operation = NULL;
1339 const char *mime = NULL;
1340 const char *uri = NULL;
1341 const char *subapp = NULL;
1347 op = asvc->operation;
1351 operation = op->name;
1367 snprintf(query, MAX_QUERY_LEN,
1368 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1369 "values('%s', '%s', '%s', '%s', '%s')",\
1375 ret = __exec_query(query);
1377 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1380 memset(query, '\0', MAX_QUERY_LEN);
1384 } while(ui != NULL);
1388 }while(sub != NULL);
1404 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1406 serviceapplication_x *sp = mfx->serviceapplication;
1407 datacontrol_x *dc = NULL;
1409 char query[MAX_QUERY_LEN] = {'\0'};
1413 dc = sp->datacontrol;
1416 snprintf(query, MAX_QUERY_LEN,
1417 "insert into package_app_data_control(app_id, providerid, access, type) " \
1418 "values('%s', '%s', '%s', '%s')",\
1419 mfx->serviceapplication->appid,
1424 ret = __exec_query(query);
1426 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1429 memset(query, '\0', MAX_QUERY_LEN);
1437 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1439 serviceapplication_x *sp = mfx->serviceapplication;
1440 datashare_x *ds = NULL;
1441 request_x *rq = NULL;
1443 char query[MAX_QUERY_LEN] = {'\0'};
1452 snprintf(query, MAX_QUERY_LEN,
1453 "insert into package_app_share_request(app_id, data_share_request) " \
1454 "values('%s', '%s')",\
1455 sp->appid, rq->text);
1456 ret = __exec_query(query);
1458 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1461 memset(query, '\0', MAX_QUERY_LEN);
1473 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1475 serviceapplication_x *sp = mfx->serviceapplication;
1476 datashare_x *ds = NULL;
1477 define_x *df = NULL;
1478 allowed_x *al = NULL;
1480 char query[MAX_QUERY_LEN] = {'\0'};
1492 snprintf(query, MAX_QUERY_LEN,
1493 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1494 "values('%s', '%s', '%s')",\
1495 sp->appid, df->path, al->text);
1496 ret = __exec_query(query);
1498 _LOGD("Package App Share Allowed DB Insert Failed\n");
1501 memset(query, '\0', MAX_QUERY_LEN);
1513 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1515 label_x *lbl = mfx->label;
1516 license_x *lcn = mfx->license;
1517 icon_x *icn = mfx->icon;
1518 description_x *dcn = mfx->description;
1519 author_x *ath = mfx->author;
1520 uiapplication_x *up = mfx->uiapplication;
1521 uiapplication_x *up_icn = mfx->uiapplication;
1522 uiapplication_x *up_image = mfx->uiapplication;
1523 serviceapplication_x *sp = mfx->serviceapplication;
1524 privileges_x *pvs = NULL;
1525 privilege_x *pv = NULL;
1526 char query[MAX_QUERY_LEN] = { '\0' };
1527 char root[MAX_QUERY_LEN] = { '\0' };
1531 const char *auth_name = NULL;
1532 const char *auth_email = NULL;
1533 const char *auth_href = NULL;
1534 const char *apps_path = NULL;
1536 GList *pkglocale = NULL;
1537 GList *applocale = NULL;
1538 GList *appicon = NULL;
1539 GList *appimage = NULL;
1543 auth_name = ath->text;
1545 auth_email = ath->email;
1547 auth_href = ath->href;
1549 /*Insert in the package_cert_info CERT_DB*/
1550 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1551 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1552 if (ret != PMINFO_R_OK) {
1553 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1554 _LOGE("Cert Info DB create handle failed\n");
1557 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1558 if (ret != PMINFO_R_OK) {
1559 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1560 _LOGE("Cert Info DB Insert Failed\n");
1564 /*Insert in the package_info DB*/
1566 type = strdup(mfx->type);
1568 type = strdup("rpm");
1569 /*Insert in the package_info DB*/
1571 path = strdup(mfx->root_path);
1573 if (strcmp(type,"rpm")==0) {
1574 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1575 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1577 apps_path = tzplatform_getenv(TZ_USER_APP);
1578 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1580 path = strdup(root);
1582 snprintf(query, MAX_QUERY_LEN,
1583 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1584 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1585 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1586 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1590 __get_str(mfx->installlocation),
1591 __get_str(mfx->package_size),
1597 mfx->nodisplay_setting,
1599 __get_str(auth_name),
1600 __get_str(auth_email),
1601 __get_str(auth_href),
1602 mfx->installed_time,
1603 mfx->installed_storage,
1604 __get_str(mfx->storeclient_id),
1606 __get_str(mfx->package_url),
1608 __get_str(mfx->csc_path));
1609 /*If package dont have main_package tag, this package is main package.*/
1610 if (mfx->main_package == NULL) {
1611 ret = __exec_query(query);
1613 _LOGD("Package Info DB Insert Failed\n");
1625 /*If package has main_package tag, this package is sub package(ug, efl).
1626 skip __exec_query for package_info and change pkgid with main_package*/
1627 memset(root, '\0', MAX_QUERY_LEN);
1628 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1629 if (access(root, F_OK) == 0) {
1630 free((void *)mfx->package);
1631 mfx->package = strdup(mfx->main_package);
1633 _LOGE("main package[%s] is not installed\n", root);
1646 /*Insert in the package_privilege_info DB*/
1647 pvs = mfx->privileges;
1648 while (pvs != NULL) {
1649 pv = pvs->privilege;
1650 while (pv != NULL) {
1651 memset(query, '\0', MAX_QUERY_LEN);
1652 snprintf(query, MAX_QUERY_LEN,
1653 "insert into package_privilege_info(package, privilege) " \
1654 "values('%s','%s')",\
1655 mfx->package, pv->text);
1656 ret = __exec_query(query);
1658 _LOGD("Package Privilege Info DB Insert Failed\n");
1667 ret = __insert_ui_mainapp_info(mfx);
1672 /*Insert the package locale*/
1673 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1674 /*remove duplicated data in pkglocale*/
1675 __trimfunc(pkglocale);
1677 /*Insert the app locale info */
1680 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1685 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1688 /*remove duplicated data in applocale*/
1689 __trimfunc(applocale);
1691 /*Insert the app icon info */
1692 while(up_icn != NULL)
1694 appicon = __create_icon_list(appicon, up_icn->icon);
1695 up_icn = up_icn->next;
1697 /*remove duplicated data in appicon*/
1698 __trimfunc(appicon);
1700 /*Insert the image info */
1701 while(up_image != NULL)
1703 appimage = __create_image_list(appimage, up_image->image);
1704 up_image = up_image->next;
1706 /*remove duplicated data in appimage*/
1707 __trimfunc(appimage);
1709 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1711 /*g_list_foreach(applocale, __printfunc, NULL);*/
1713 /*package locale info, it is only for main package.*/
1714 if (mfx->main_package == NULL)
1715 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1717 /*native app locale info*/
1718 up = mfx->uiapplication;
1721 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1724 /*agent app locale info*/
1725 sp = mfx->serviceapplication;
1728 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1732 /*app icon locale info*/
1733 up_icn = mfx->uiapplication;
1734 while(up_icn != NULL)
1736 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1737 up_icn = up_icn->next;
1741 up_image = mfx->uiapplication;
1742 while(up_image != NULL)
1744 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1745 up_image = up_image->next;
1748 g_list_free(pkglocale);
1750 g_list_free(applocale);
1752 g_list_free(appicon);
1754 g_list_free(appimage);
1757 /*Insert in the package_app_info DB*/
1758 ret = __insert_uiapplication_info(mfx);
1761 ret = __insert_serviceapplication_info(mfx);
1764 /*Insert in the package_app_app_control DB*/
1765 ret = __insert_uiapplication_appcontrol_info(mfx);
1768 ret = __insert_serviceapplication_appcontrol_info(mfx);
1772 /*Insert in the package_app_app_category DB*/
1773 ret = __insert_uiapplication_appcategory_info(mfx);
1776 ret = __insert_serviceapplication_appcategory_info(mfx);
1780 /*Insert in the package_app_app_metadata DB*/
1781 ret = __insert_uiapplication_appmetadata_info(mfx);
1784 ret = __insert_serviceapplication_appmetadata_info(mfx);
1788 /*Insert in the package_app_app_permission DB*/
1789 ret = __insert_uiapplication_apppermission_info(mfx);
1792 ret = __insert_serviceapplication_apppermission_info(mfx);
1796 /*Insert in the package_app_app_svc DB*/
1797 ret = __insert_uiapplication_appsvc_info(mfx);
1800 ret = __insert_serviceapplication_appsvc_info(mfx);
1804 /*Insert in the package_app_share_allowed DB*/
1805 ret = __insert_uiapplication_share_allowed_info(mfx);
1808 ret = __insert_serviceapplication_share_allowed_info(mfx);
1812 /*Insert in the package_app_share_request DB*/
1813 ret = __insert_uiapplication_share_request_info(mfx);
1816 ret = __insert_serviceapplication_share_request_info(mfx);
1820 /*Insert in the package_app_data_control DB*/
1821 ret = __insert_uiapplication_datacontrol_info(mfx);
1824 ret = __insert_serviceapplication_datacontrol_info(mfx);
1832 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1834 char query[MAX_QUERY_LEN] = { '\0' };
1836 memset(query, '\0', MAX_QUERY_LEN);
1837 snprintf(query, MAX_QUERY_LEN,
1838 "delete from %s where app_id='%s'", db_table, appid);
1839 ret = __exec_query(query);
1841 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1847 static int __delete_subpkg_info_from_db(char *appid)
1851 ret = __delete_appinfo_from_db("package_app_info", appid);
1854 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1857 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1860 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1863 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1866 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1869 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1872 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1875 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1878 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1881 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1884 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1891 static int __delete_subpkg_from_db(manifest_x *mfx)
1893 char query[MAX_QUERY_LEN] = { '\0' };
1894 char *error_message = NULL;
1896 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1898 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1899 _LOGE("Don't execute query = %s error message = %s\n", query,
1901 sqlite3_free(error_message);
1904 sqlite3_free(error_message);
1909 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1911 char query[MAX_QUERY_LEN] = { '\0' };
1913 uiapplication_x *up = mfx->uiapplication;
1914 serviceapplication_x *sp = mfx->serviceapplication;
1915 /*Delete from cert table*/
1916 if (uid != GLOBAL_USER)
1917 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1919 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1921 _LOGD("Cert Info DB Delete Failed\n");
1925 /*Delete from Package Info DB*/
1926 snprintf(query, MAX_QUERY_LEN,
1927 "delete from package_info where package='%s'", mfx->package);
1928 ret = __exec_query(query);
1930 _LOGD("Package Info DB Delete Failed\n");
1933 memset(query, '\0', MAX_QUERY_LEN);
1935 /*Delete from Package Localized Info*/
1936 snprintf(query, MAX_QUERY_LEN,
1937 "delete from package_localized_info where package='%s'", mfx->package);
1938 ret = __exec_query(query);
1940 _LOGD("Package Localized Info DB Delete Failed\n");
1944 /*Delete from Package Privilege Info*/
1945 snprintf(query, MAX_QUERY_LEN,
1946 "delete from package_privilege_info where package='%s'", mfx->package);
1947 ret = __exec_query(query);
1949 _LOGD("Package Privilege Info DB Delete Failed\n");
1953 while (up != NULL) {
1954 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1957 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1960 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1963 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1966 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1969 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1972 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1975 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1978 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1981 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1984 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1987 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1993 while (sp != NULL) {
1994 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
1997 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2000 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2003 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2006 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2009 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2012 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2015 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2018 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2021 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2024 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2027 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
2033 /* if main package has sub pkg, delete sub pkg data*/
2034 __delete_subpkg_from_db(mfx);
2039 static int __update_preload_condition_in_db()
2042 char query[MAX_QUERY_LEN] = {'\0'};
2044 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2046 ret = __exec_query(query);
2048 _LOGD("Package preload_condition update failed\n");
2053 API int pkgmgr_parser_initialize_db(void)
2057 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2059 _LOGD("package info DB initialization failed\n");
2062 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2064 _LOGD("package localized info DB initialization failed\n");
2067 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2069 _LOGD("package app app privilege DB initialization failed\n");
2072 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2074 _LOGD("package app info DB initialization failed\n");
2077 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2079 _LOGD("package app localized info DB initialization failed\n");
2082 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2084 _LOGD("package app icon localized info DB initialization failed\n");
2087 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2089 _LOGD("package app image info DB initialization failed\n");
2092 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2094 _LOGD("package app app control DB initialization failed\n");
2097 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2099 _LOGD("package app app category DB initialization failed\n");
2102 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2104 _LOGD("package app app category DB initialization failed\n");
2107 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2109 _LOGD("package app app permission DB initialization failed\n");
2112 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2114 _LOGD("package app app svc DB initialization failed\n");
2117 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2119 _LOGD("package app share allowed DB initialization failed\n");
2122 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2124 _LOGD("package app share request DB initialization failed\n");
2127 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2129 _LOGD("package app data control DB initialization failed\n");
2133 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2135 _LOGD("package cert info DB initialization failed\n");
2138 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2140 _LOGD("package cert index info DB initialization failed\n");
2144 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO);
2146 _LOGD("package resource info DB initialization failed\n");
2149 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA);
2151 _LOGD("package resource data DB initialization failed\n");
2158 static int parserdb_change_perm(const char *db_file, uid_t uid)
2161 char journal_file[BUFSIZE];
2164 struct passwd *userinfo = NULL;
2165 files[0] = (char *)db_file;
2166 files[1] = journal_file;
2172 if(getuid() != OWNER_ROOT) //At this time we should be root to apply this
2174 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2175 userinfo = getpwuid(uid);
2177 _LOGE("FAIL: user %d doesn't exist", uid);
2180 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2182 for (i = 0; files[i]; i++) {
2183 ret = chown(files[i], uid, userinfo->pw_gid);
2184 SET_SMACK_LABEL(files[i],uid)
2186 strerror_r(errno, buf, sizeof(buf));
2187 _LOGD("FAIL : chown %s %d.%d, because %s", db_file, uid, userinfo->pw_gid, buf);
2191 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2193 strerror_r(errno, buf, sizeof(buf));
2194 _LOGD("FAIL : chmod %s 0664, because %s", db_file, buf);
2201 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2205 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2207 _LOGD("Manifest DB creation Failed\n");
2212 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2214 _LOGD("Cert DB creation Failed\n");
2217 if( 0 != parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2218 _LOGD("Failed to change cert db permission\n");
2220 if( 0 != parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2221 _LOGD("Failed to change parser db permission\n");
2226 void pkgmgr_parser_close_db()
2228 sqlite3_close(pkgmgr_parser_db);
2229 sqlite3_close(pkgmgr_cert_db);
2233 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2235 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2237 _LOGD("manifest pointer is NULL\n");
2241 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2243 _LOGD("Failed to open DB\n");
2246 ret = pkgmgr_parser_initialize_db();
2249 /*Begin transaction*/
2250 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2251 if (ret != SQLITE_OK) {
2252 _LOGD("Failed to begin transaction\n");
2256 _LOGD("Transaction Begin\n");
2257 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2259 _LOGD("Insert into DB failed. Rollback now\n");
2260 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2263 /*Commit transaction*/
2264 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2265 if (ret != SQLITE_OK) {
2266 _LOGD("Failed to commit transaction. Rollback now\n");
2267 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2271 _LOGD("Transaction Commit and End\n");
2273 pkgmgr_parser_close_db();
2277 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2279 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2281 _LOGD("manifest pointer is NULL\n");
2285 ret = pkgmgr_parser_check_and_create_db(uid);
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, uid);
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_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2324 _LOGD("manifest pointer is NULL\n");
2328 ret = pkgmgr_parser_check_and_create_db(uid);
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, uid);
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, uid);
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_db(manifest_x *mfx)
2375 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2378 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2381 _LOGD("manifest pointer is NULL\n");
2385 ret = pkgmgr_parser_check_and_create_db(uid);
2387 _LOGD("Failed to open DB\n");
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, uid);
2400 _LOGD("Delete from DB failed. Rollback now\n");
2401 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2404 /*Commit transaction*/
2405 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2406 if (ret != SQLITE_OK) {
2407 _LOGD("Failed to commit transaction, Rollback now\n");
2408 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2412 _LOGD("Transaction Commit and End\n");
2414 pkgmgr_parser_close_db();
2418 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2420 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2423 API int pkgmgr_parser_update_preload_info_in_db()
2426 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2428 _LOGD("Failed to open DB\n");
2431 /*Begin transaction*/
2432 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2433 if (ret != SQLITE_OK) {
2434 _LOGD("Failed to begin transaction\n");
2438 _LOGD("Transaction Begin\n");
2439 ret = __update_preload_condition_in_db();
2441 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2442 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2445 /*Commit transaction*/
2446 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2447 if (ret != SQLITE_OK) {
2448 _LOGD("Failed to commit transaction, Rollback now\n");
2449 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2453 _LOGD("Transaction Commit and End\n");
2455 pkgmgr_parser_close_db();
2459 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2462 ret = pkgmgr_parser_check_and_create_db(uid);
2464 _LOGD("Failed to open DB\n");
2467 /*Begin transaction*/
2468 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2469 if (ret != SQLITE_OK) {
2470 _LOGD("Failed to begin transaction\n");
2474 _LOGD("Transaction Begin\n");
2475 ret = __update_preload_condition_in_db();
2477 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2478 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2481 /*Commit transaction*/
2482 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2483 if (ret != SQLITE_OK) {
2484 _LOGD("Failed to commit transaction, Rollback now\n");
2485 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2489 _LOGD("Transaction Commit and End\n");
2491 pkgmgr_parser_close_db();