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) \
57 if (smack_setlabel((x), "System::Shared", SMACK_LABEL_ACCESS)) \
58 _LOGE("failed chsmack -a \"System::Shared\" %s", x); \
60 _LOGD("chsmack -a \"System::Shared\" %s", x); \
63 sqlite3 *pkgmgr_parser_db;
64 sqlite3 *pkgmgr_cert_db;
67 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
68 "(package text primary key not null, " \
69 "package_type text DEFAULT 'rpm', " \
70 "package_version text, " \
71 "install_location text, " \
72 "package_size text, " \
73 "package_removable text DEFAULT 'true', " \
74 "package_preload text DEFAULT 'false', " \
75 "package_readonly text DEFAULT 'false', " \
76 "package_update text DEFAULT 'false', " \
77 "package_appsetting text DEFAULT 'false', " \
78 "package_nodisplay text DEFAULT 'false', " \
79 "package_system text DEFAULT 'false', " \
80 "author_name text, " \
81 "author_email text, " \
83 "installed_time text," \
84 "installed_storage text," \
85 "storeclient_id text," \
91 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
92 "(package text not null, " \
93 "package_locale text DEFAULT 'No Locale', " \
94 "package_label text, " \
95 "package_icon text, " \
96 "package_description text, " \
97 "package_license text, " \
99 "PRIMARY KEY(package, package_locale), " \
100 "FOREIGN KEY(package) " \
101 "REFERENCES package_info(package) " \
104 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
105 "(package text not null, " \
106 "privilege text not null, " \
107 "PRIMARY KEY(package, privilege) " \
108 "FOREIGN KEY(package) " \
109 "REFERENCES package_info(package) " \
112 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
113 "(app_id text primary key not null, " \
114 "app_component text, " \
116 "app_nodisplay text DEFAULT 'false', " \
118 "app_onboot text DEFAULT 'false', " \
119 "app_multiple text DEFAULT 'false', " \
120 "app_autorestart text DEFAULT 'false', " \
121 "app_taskmanage text DEFAULT 'false', " \
122 "app_enabled text DEFAULT 'true', " \
123 "app_hwacceleration text DEFAULT 'use-system-setting', " \
124 "app_screenreader text DEFAULT 'use-system-setting', " \
125 "app_mainapp text, " \
126 "app_recentimage text, " \
127 "app_launchcondition text, " \
128 "app_indicatordisplay text DEFAULT 'true', " \
129 "app_portraitimg text, " \
130 "app_landscapeimg text, " \
131 "app_guestmodevisibility text DEFAULT 'true', " \
132 "app_permissiontype text DEFAULT 'normal', " \
133 "app_preload text DEFAULT 'false', " \
134 "app_submode text DEFAULT 'false', " \
135 "app_submode_mainid text, " \
136 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
137 "component_type text, " \
138 "package text not null, " \
139 "FOREIGN KEY(package) " \
140 "REFERENCES package_info(package) " \
143 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
144 "(app_id text not null, " \
145 "app_locale text DEFAULT 'No Locale', " \
148 "PRIMARY KEY(app_id,app_locale) " \
149 "FOREIGN KEY(app_id) " \
150 "REFERENCES package_app_info(app_id) " \
153 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
154 "(app_id text not null, " \
156 "app_icon_section text, " \
157 "app_icon_resolution text, " \
158 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
159 "FOREIGN KEY(app_id) " \
160 "REFERENCES package_app_info(app_id) " \
163 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
164 "(app_id text not null, " \
165 "app_locale text DEFAULT 'No Locale', " \
166 "app_image_section text, " \
168 "PRIMARY KEY(app_id,app_image_section) " \
169 "FOREIGN KEY(app_id) " \
170 "REFERENCES package_app_info(app_id) " \
173 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
174 "(app_id text not null, " \
175 "app_control text not null, " \
176 "PRIMARY KEY(app_id,app_control) " \
177 "FOREIGN KEY(app_id) " \
178 "REFERENCES package_app_info(app_id) " \
181 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC "create table if not exists package_app_app_svc " \
182 "(app_id text not null, " \
183 "operation text not null, " \
184 "uri_scheme text, " \
186 "subapp_name text, " \
187 "PRIMARY KEY(app_id,operation,uri_scheme,mime_type,subapp_name) " \
188 "FOREIGN KEY(app_id) " \
189 "REFERENCES package_app_info(app_id) " \
192 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
193 "(app_id text not null, " \
194 "category text not null, " \
195 "PRIMARY KEY(app_id,category) " \
196 "FOREIGN KEY(app_id) " \
197 "REFERENCES package_app_info(app_id) " \
200 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
201 "(app_id text not null, " \
202 "md_key text not null, " \
203 "md_value text not null, " \
204 "PRIMARY KEY(app_id, md_key, md_value) " \
205 "FOREIGN KEY(app_id) " \
206 "REFERENCES package_app_info(app_id) " \
209 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
210 "(app_id text not null, " \
211 "pm_type text not null, " \
212 "pm_value text not null, " \
213 "PRIMARY KEY(app_id, pm_type, pm_value) " \
214 "FOREIGN KEY(app_id) " \
215 "REFERENCES package_app_info(app_id) " \
218 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
219 "(app_id text not null, " \
220 "data_share_path text not null, " \
221 "data_share_allowed text not null, " \
222 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
223 "FOREIGN KEY(app_id) " \
224 "REFERENCES package_app_info(app_id) " \
227 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
228 "(app_id text not null, " \
229 "data_share_request text not null, " \
230 "PRIMARY KEY(app_id,data_share_request) " \
231 "FOREIGN KEY(app_id) " \
232 "REFERENCES package_app_info(app_id) " \
235 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO "create table if not exists package_cert_index_info " \
236 "(cert_info text not null, " \
237 "cert_id integer, " \
238 "cert_ref_count integer, " \
239 "PRIMARY KEY(cert_id)) "
241 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO "create table if not exists package_cert_info " \
242 "(package text not null, " \
243 "author_root_cert integer, " \
244 "author_im_cert integer, " \
245 "author_signer_cert integer, " \
246 "dist_root_cert integer, " \
247 "dist_im_cert integer, " \
248 "dist_signer_cert integer, " \
249 "dist2_root_cert integer, " \
250 "dist2_im_cert integer, " \
251 "dist2_signer_cert integer, " \
252 "PRIMARY KEY(package)) "
254 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
255 "(app_id text not null, " \
256 "providerid text not null, " \
257 "access text not null, " \
258 "type text not null, " \
259 "PRIMARY KEY(app_id, providerid, access, type) " \
260 "FOREIGN KEY(app_id) " \
261 "REFERENCES package_app_info(app_id) " \
263 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO "CREATE TABLE IF NOT EXISTS package_resource_info" \
264 "(pkg_id text NOT NULL," \
265 "group_folder text NOT NULL," \
266 "group_type text NOT NULL," \
267 "PRIMARY KEY(pkg_id, group_type))"
269 #define QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA "CREATE TABLE IF NOT EXISTS package_resource_data" \
270 "(id integer REFERENCES package_resource_info(rowid)," \
271 "node_folder text NOT NULL," \
272 "attr_name text NOT NULL," \
273 "attr_value test NOT NULL," \
274 "PRIMARY KEY(id, node_folder, attr_name))"
276 static int __insert_uiapplication_info(manifest_x *mfx);
277 static int __insert_serviceapplication_info(manifest_x *mfx);
278 static int __insert_uiapplication_appsvc_info(manifest_x *mfx);
279 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx);
280 static int __insert_uiapplication_appcategory_info(manifest_x *mfx);
281 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx);
282 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx);
283 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx);
284 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx);
285 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx);
286 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx);
287 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx);
288 static int __insert_uiapplication_share_request_info(manifest_x *mfx);
289 static int __insert_serviceapplication_share_request_info(manifest_x *mfx);
290 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx);
291 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx);
292 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata);
293 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata);
294 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
295 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
296 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
297 static int __delete_subpkg_info_from_db(char *appid);
298 static int __delete_appinfo_from_db(char *db_table, const char *appid);
299 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
300 static int __exec_query(char *query);
301 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
302 char **label, char **license, char **icon, char **description, char **author);
303 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
304 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath);
305 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
306 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
307 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
308 static int __parserdb_change_perm(const char *db_file, uid_t uid);
310 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
313 __delete_subpkg_info_from_db(coltxt[0]);
318 static char *__get_str(const char *str)
322 return PKGMGR_PARSER_EMPTY_STR;
328 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
333 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
334 if (ret != SQLITE_OK) {
335 _LOGD("connect db [%s] failed!\n", db_path);
343 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
345 manifest_x *mfx = (manifest_x *)data;
349 uiapplication_x *uiapp = NULL;
350 for(i = 0; i < ncols; i++)
352 uiapp = mfx->uiapplication;
353 if (strcmp(colname[i], "app_id") == 0) {
355 appid = strdup(coltxt[i]);
356 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
358 status = strdup(coltxt[i]);
362 _LOGD("app id is NULL\n");
365 /*update guest mode visibility*/
366 for (; uiapp != NULL; uiapp = uiapp->next) {
367 if (strcmp(uiapp->appid, appid) == 0) {
368 free((void *)uiapp->guestmode_visibility);
369 uiapp->guestmode_visibility = strdup(status);
385 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
387 char *error_message = NULL;
388 char query[MAX_QUERY_LEN] = {'\0'};
389 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
391 sqlite3_exec(pkgmgr_parser_db, query,
392 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
393 _LOGD("Don't execute query = %s error message = %s\n",
394 query, error_message);
395 sqlite3_free(error_message);
400 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
402 char *error_message = NULL;
404 sqlite3_exec(db_handle, db_query,
405 NULL, NULL, &error_message)) {
406 _LOGD("Don't execute query = %s error message = %s\n",
407 db_query, error_message);
408 sqlite3_free(error_message);
411 sqlite3_free(error_message);
415 static int __exec_query(char *query)
417 char *error_message = NULL;
419 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
420 _LOGD("Don't execute query = %s error message = %s\n", query,
422 sqlite3_free(error_message);
425 sqlite3_free(error_message);
429 static int __exec_query_no_msg(char *query)
431 char *error_message = NULL;
433 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
434 sqlite3_free(error_message);
437 sqlite3_free(error_message);
441 static GList *__create_locale_list(GList *locale, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath)
447 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
453 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
459 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
465 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
471 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
478 static GList *__create_icon_list(GList *locale, icon_x *icn)
483 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->section, __comparefunc, NULL);
489 static GList *__create_image_list(GList *locale, image_x *image)
494 locale = g_list_insert_sorted_with_data(locale, (gpointer)image->section, __comparefunc, NULL);
500 static void __printfunc(gpointer data, gpointer userdata)
502 _LOGD("%s ", (char*)data);
505 static void __trimfunc(GList* trim_list)
507 char *trim_data = NULL;
511 list = g_list_first(trim_list);
514 trim_data = (char *)list->data;
517 if (strcmp(trim_data, prev) == 0) {
518 trim_list = g_list_remove(trim_list, trim_data);
519 list = g_list_first(trim_list);
528 list = g_list_next(list);
532 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
534 if (a == NULL || b == NULL)
536 if (strcmp((char*)a, (char*)b) == 0)
538 if (strcmp((char*)a, (char*)b) < 0)
540 if (strcmp((char*)a, (char*)b) > 0)
545 static void __extract_data(gpointer data, label_x *lbl, license_x *lcn, icon_x *icn, description_x *dcn, author_x *ath,
546 char **label, char **license, char **icon, char **description, char **author)
551 if (strcmp(lbl->lang, (char *)data) == 0) {
552 *label = (char*)lbl->text;
561 if (strcmp(lcn->lang, (char *)data) == 0) {
562 *license = (char*)lcn->text;
571 if (strcmp(icn->lang, (char *)data) == 0) {
572 *icon = (char*)icn->text;
581 if (strcmp(dcn->lang, (char *)data) == 0) {
582 *description = (char*)dcn->text;
591 if (strcmp(ath->lang, (char *)data) == 0) {
592 *author = (char*)ath->text;
601 static void __extract_icon_data(gpointer data, icon_x *icn, char **icon, char **resolution)
606 if (strcmp(icn->section, (char *)data) == 0) {
607 *icon = (char*)icn->text;
608 *resolution = (char*)icn->resolution;
616 static void __extract_image_data(gpointer data, image_x*image, char **lang, char **img)
620 if (image->section) {
621 if (strcmp(image->section, (char *)data) == 0) {
622 *lang = (char*)image->lang;
623 *img = (char*)image->text;
631 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
636 char *description = NULL;
637 char *license = NULL;
639 char query[MAX_QUERY_LEN] = {'\0'};
641 manifest_x *mfx = (manifest_x *)userdata;
642 label_x *lbl = mfx->label;
643 license_x *lcn = mfx->license;
644 icon_x *icn = mfx->icon;
645 description_x *dcn = mfx->description;
646 author_x *ath = mfx->author;
648 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
649 if (!label && !description && !icon && !license && !author)
652 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
653 "package_label, package_icon, package_description, package_license, package_author) values " \
654 "('%q', '%q', '%q', '%q', '%s', '%s', '%s')",
659 __get_str(description),
663 ret = __exec_query(query);
665 _LOGD("Package Localized Info DB Insert failed\n");
668 static void __insert_uiapplication_locale_info(gpointer data, gpointer userdata)
673 char query[MAX_QUERY_LEN] = {'\0'};
675 uiapplication_x *up = (uiapplication_x*)userdata;
676 label_x *lbl = up->label;
677 icon_x *icn = up->icon;
679 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
682 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
683 "app_label, app_icon) values " \
684 "('%q', '%q', '%q', '%q')", up->appid, (char*)data,
686 ret = __exec_query(query);
688 _LOGD("Package UiApp Localized Info DB Insert failed\n");
690 /*insert ui app locale info to pkg locale to get mainapp data */
691 if (strcasecmp(up->mainapp, "true")==0) {
692 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_localized_info(package, package_locale, " \
693 "package_label, package_icon, package_description, package_license, package_author) values " \
694 "('%q', '%q', '%q', '%q', '%q', '%q', '%q')",
699 PKGMGR_PARSER_EMPTY_STR,
700 PKGMGR_PARSER_EMPTY_STR,
701 PKGMGR_PARSER_EMPTY_STR);
703 ret = __exec_query_no_msg(query);
706 sqlite3_snprintf(MAX_QUERY_LEN, query, "update package_localized_info set package_icon='%s' "\
707 "where package='%s' and package_locale='%s'", icon, up->package, (char*)data);
708 ret = __exec_query_no_msg(query);
713 static void __insert_uiapplication_icon_section_info(gpointer data, gpointer userdata)
717 char *resolution = NULL;
718 char query[MAX_QUERY_LEN] = {'\0'};
720 uiapplication_x *up = (uiapplication_x*)userdata;
721 icon_x *icn = up->icon;
723 __extract_icon_data(data, icn, &icon, &resolution);
724 if (!icon && !resolution)
726 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
727 "app_icon, app_icon_section, app_icon_resolution) values " \
728 "('%q', '%q', '%q', '%q')", up->appid,
729 icon, (char*)data, resolution);
731 ret = __exec_query(query);
733 _LOGD("Package UiApp Localized Info DB Insert failed\n");
737 static void __insert_uiapplication_image_info(gpointer data, gpointer userdata)
742 char query[MAX_QUERY_LEN] = {'\0'};
744 uiapplication_x *up = (uiapplication_x*)userdata;
745 image_x *image = up->image;
747 __extract_image_data(data, image, &lang, &img);
750 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
751 "app_image_section, app_image) values " \
752 "('%q', '%q', '%q', '%q')", up->appid, lang, (char*)data, img);
754 ret = __exec_query(query);
756 _LOGD("Package UiApp image Info DB Insert failed\n");
761 static void __insert_serviceapplication_locale_info(gpointer data, gpointer userdata)
766 char query[MAX_QUERY_LEN] = {'\0'};
768 serviceapplication_x *sp = (serviceapplication_x*)userdata;
769 label_x *lbl = sp->label;
770 icon_x *icn = sp->icon;
772 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
775 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_localized_info(app_id, app_locale, " \
776 "app_label, app_icon) values " \
777 "('%q', '%q', '%q', '%q')", sp->appid, (char*)data,
779 ret = __exec_query(query);
781 _LOGD("Package ServiceApp Localized Info DB Insert failed\n");
784 static int __insert_ui_mainapp_info(manifest_x *mfx)
786 uiapplication_x *up = mfx->uiapplication;
788 char query[MAX_QUERY_LEN] = {'\0'};
791 snprintf(query, MAX_QUERY_LEN,
792 "update package_app_info set app_mainapp='%s' where app_id='%s'", up->mainapp, up->appid);
794 ret = __exec_query(query);
796 _LOGD("Package UiApp Info DB Insert Failed\n");
799 if (strcasecmp(up->mainapp, "True")==0)
800 mfx->mainapp_id = strdup(up->appid);
803 memset(query, '\0', MAX_QUERY_LEN);
806 if (mfx->mainapp_id == NULL){
807 if (mfx->uiapplication && mfx->uiapplication->appid) {
808 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", mfx->uiapplication->appid);
810 _LOGD("Not valid appid\n");
814 ret = __exec_query(query);
816 _LOGD("Package UiApp Info DB Insert Failed\n");
820 free((void *)mfx->uiapplication->mainapp);
821 mfx->uiapplication->mainapp= strdup("true");
822 mfx->mainapp_id = strdup(mfx->uiapplication->appid);
825 memset(query, '\0', MAX_QUERY_LEN);
826 snprintf(query, MAX_QUERY_LEN,
827 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
828 ret = __exec_query(query);
830 _LOGD("Package Info DB update Failed\n");
836 /* _PRODUCT_LAUNCHING_ENHANCED_
837 * up->indicatordisplay, up->portraitimg, up->landscapeimg, up->guestmode_appstatus
839 static int __insert_uiapplication_info(manifest_x *mfx)
841 uiapplication_x *up = mfx->uiapplication;
843 char query[MAX_QUERY_LEN] = {'\0'};
846 snprintf(query, MAX_QUERY_LEN,
847 "insert into package_app_info(app_id, app_component, app_exec, app_nodisplay, app_type, app_onboot, " \
848 "app_multiple, app_autorestart, app_taskmanage, app_enabled, app_hwacceleration, app_screenreader, app_mainapp , app_recentimage, " \
849 "app_launchcondition, app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, "\
850 "app_preload, app_submode, app_submode_mainid, component_type, package, app_launch_mode) " \
851 "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')",\
857 PKGMGR_PARSER_EMPTY_STR,
859 PKGMGR_PARSER_EMPTY_STR,
865 __get_str(up->recentimage),
867 up->indicatordisplay,
868 __get_str(up->portraitimg),
869 __get_str(up->landscapeimg),
870 up->guestmode_visibility,
874 __get_str(up->submode_mainid),
879 ret = __exec_query(query);
881 _LOGD("Package UiApp Info DB Insert Failed\n");
885 memset(query, '\0', MAX_QUERY_LEN);
890 static int __insert_uiapplication_appcategory_info(manifest_x *mfx)
892 uiapplication_x *up = mfx->uiapplication;
893 category_x *ct = NULL;
895 char query[MAX_QUERY_LEN] = {'\0'};
901 snprintf(query, MAX_QUERY_LEN,
902 "insert into package_app_app_category(app_id, category) " \
903 "values('%s','%s')",\
904 up->appid, ct->name);
905 ret = __exec_query(query);
907 _LOGD("Package UiApp Category Info DB Insert Failed\n");
911 memset(query, '\0', MAX_QUERY_LEN);
918 static int __insert_uiapplication_appmetadata_info(manifest_x *mfx)
920 uiapplication_x *up = mfx->uiapplication;
921 metadata_x *md = NULL;
923 char query[MAX_QUERY_LEN] = {'\0'};
930 snprintf(query, MAX_QUERY_LEN,
931 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
932 "values('%s','%s', '%s')",\
933 up->appid, md->key, md->value);
934 ret = __exec_query(query);
936 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
941 memset(query, '\0', MAX_QUERY_LEN);
948 static int __insert_uiapplication_apppermission_info(manifest_x *mfx)
950 uiapplication_x *up = mfx->uiapplication;
951 permission_x *pm = NULL;
953 char query[MAX_QUERY_LEN] = {'\0'};
959 snprintf(query, MAX_QUERY_LEN,
960 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
961 "values('%s','%s', '%s')",\
962 up->appid, pm->type, pm->value);
963 ret = __exec_query(query);
965 _LOGD("Package UiApp permission Info DB Insert Failed\n");
969 memset(query, '\0', MAX_QUERY_LEN);
976 static int __insert_uiapplication_appcontrol_info(manifest_x *mfx)
978 uiapplication_x *up = mfx->uiapplication;
979 appcontrol_x *acontrol = NULL;
981 char query[MAX_QUERY_LEN] = {'\0'};
982 char buf[BUFSIZE] = {'\0'};
984 acontrol = up->appcontrol;
985 while (acontrol != NULL) {
986 snprintf(buf, BUFSIZE, "%s|%s|%s",\
987 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
988 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
989 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
990 snprintf(query, MAX_QUERY_LEN,
991 "insert into package_app_app_control(app_id, app_control) " \
992 "values('%s', '%s')",\
994 ret = __exec_query(query);
996 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
999 memset(query, '\0', MAX_QUERY_LEN);
1000 acontrol = acontrol->next;
1007 static int __insert_uiapplication_appsvc_info(manifest_x *mfx)
1009 uiapplication_x *up = mfx->uiapplication;
1010 appsvc_x *asvc = NULL;
1011 operation_x *op = NULL;
1014 subapp_x *sub = NULL;
1016 char query[MAX_QUERY_LEN] = {'\0'};
1017 const char *operation = NULL;
1018 const char *mime = NULL;
1019 const char *uri = NULL;
1020 const char *subapp = NULL;
1026 op = asvc->operation;
1030 operation = op->name;
1047 snprintf(query, MAX_QUERY_LEN,
1048 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1049 "values('%s', '%s', '%s', '%s', '%s')",\
1056 ret = __exec_query(query);
1058 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1061 memset(query, '\0', MAX_QUERY_LEN);
1065 } while(ui != NULL);
1069 }while(sub != NULL);
1085 static int __insert_uiapplication_datacontrol_info(manifest_x *mfx)
1087 uiapplication_x *up = mfx->uiapplication;
1088 datacontrol_x *dc = NULL;
1090 char query[MAX_QUERY_LEN] = {'\0'};
1094 dc = up->datacontrol;
1097 snprintf(query, MAX_QUERY_LEN,
1098 "insert into package_app_data_control(app_id, providerid, access, type) " \
1099 "values('%s', '%s', '%s', '%s')",\
1100 mfx->uiapplication->appid,
1105 ret = __exec_query(query);
1107 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1110 memset(query, '\0', MAX_QUERY_LEN);
1118 static int __insert_uiapplication_share_request_info(manifest_x *mfx)
1120 uiapplication_x *up = mfx->uiapplication;
1121 datashare_x *ds = NULL;
1122 request_x *rq = NULL;
1124 char query[MAX_QUERY_LEN] = {'\0'};
1133 snprintf(query, MAX_QUERY_LEN,
1134 "insert into package_app_share_request(app_id, data_share_request) " \
1135 "values('%s', '%s')",\
1136 up->appid, rq->text);
1137 ret = __exec_query(query);
1139 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1142 memset(query, '\0', MAX_QUERY_LEN);
1152 static int __insert_uiapplication_share_allowed_info(manifest_x *mfx)
1154 uiapplication_x *up = mfx->uiapplication;
1155 datashare_x *ds = NULL;
1156 define_x *df = NULL;
1157 allowed_x *al = NULL;
1159 char query[MAX_QUERY_LEN] = {'\0'};
1171 snprintf(query, MAX_QUERY_LEN,
1172 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1173 "values('%s', '%s', '%s')",\
1174 up->appid, df->path, al->text);
1175 ret = __exec_query(query);
1177 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1180 memset(query, '\0', MAX_QUERY_LEN);
1192 static int __insert_serviceapplication_info(manifest_x *mfx)
1194 serviceapplication_x *sp = mfx->serviceapplication;
1196 char query[MAX_QUERY_LEN] = {'\0'};
1199 snprintf(query, MAX_QUERY_LEN,
1200 "insert into package_app_info(app_id, app_component, app_exec, app_type, app_onboot, " \
1201 "app_multiple, app_autorestart, app_enabled, app_permissiontype, package) " \
1202 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1203 sp->appid, "svcapp", sp->exec, sp->type, sp->onboot, "\0",
1204 sp->autorestart, sp->enabled, sp->permission_type, mfx->package);
1205 ret = __exec_query(query);
1207 _LOGD("Package ServiceApp Info DB Insert Failed\n");
1211 memset(query, '\0', MAX_QUERY_LEN);
1216 static int __insert_serviceapplication_appcategory_info(manifest_x *mfx)
1218 serviceapplication_x *sp = mfx->serviceapplication;
1219 category_x *ct = NULL;
1221 char query[MAX_QUERY_LEN] = {'\0'};
1227 snprintf(query, MAX_QUERY_LEN,
1228 "insert into package_app_app_category(app_id, category) " \
1229 "values('%s','%s')",\
1230 sp->appid, ct->name);
1231 ret = __exec_query(query);
1233 _LOGD("Package ServiceApp Category Info DB Insert Failed\n");
1237 memset(query, '\0', MAX_QUERY_LEN);
1244 static int __insert_serviceapplication_appmetadata_info(manifest_x *mfx)
1246 serviceapplication_x *sp = mfx->serviceapplication;
1247 metadata_x *md = NULL;
1249 char query[MAX_QUERY_LEN] = {'\0'};
1256 snprintf(query, MAX_QUERY_LEN,
1257 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1258 "values('%s','%s', '%s')",\
1259 sp->appid, md->key, md->value);
1260 ret = __exec_query(query);
1262 _LOGD("Package ServiceApp Metadata Info DB Insert Failed\n");
1267 memset(query, '\0', MAX_QUERY_LEN);
1274 static int __insert_serviceapplication_apppermission_info(manifest_x *mfx)
1276 serviceapplication_x *sp = mfx->serviceapplication;
1277 permission_x *pm = NULL;
1279 char query[MAX_QUERY_LEN] = {'\0'};
1282 pm = sp->permission;
1285 snprintf(query, MAX_QUERY_LEN,
1286 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1287 "values('%s','%s', '%s')",\
1288 sp->appid, pm->type, pm->value);
1289 ret = __exec_query(query);
1291 _LOGD("Package ServiceApp permission Info DB Insert Failed\n");
1295 memset(query, '\0', MAX_QUERY_LEN);
1302 static int __insert_serviceapplication_appcontrol_info(manifest_x *mfx)
1304 serviceapplication_x *sp = mfx->serviceapplication;
1305 appcontrol_x *acontrol = NULL;
1307 char query[MAX_QUERY_LEN] = {'\0'};
1308 char buf[BUFSIZE] = {'\0'};
1309 while (sp != NULL) {
1310 acontrol = sp->appcontrol;
1311 while (acontrol != NULL) {
1312 snprintf(buf, BUFSIZE, "%s|%s|%s",
1313 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1314 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1315 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1316 snprintf(query, MAX_QUERY_LEN,
1317 "insert into package_app_app_control(app_id, app_control) " \
1318 "values('%s', '%s')",\
1320 ret = __exec_query(query);
1322 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1325 memset(query, '\0', MAX_QUERY_LEN);
1326 acontrol = acontrol->next;
1333 static int __insert_serviceapplication_appsvc_info(manifest_x *mfx)
1335 serviceapplication_x *sp = mfx->serviceapplication;
1336 appsvc_x *asvc = NULL;
1338 char query[MAX_QUERY_LEN] = {'\0'};
1339 operation_x *op = NULL;
1342 subapp_x *sub = NULL;
1343 const char *operation = NULL;
1344 const char *mime = NULL;
1345 const char *uri = NULL;
1346 const char *subapp = NULL;
1352 op = asvc->operation;
1356 operation = op->name;
1372 snprintf(query, MAX_QUERY_LEN,
1373 "insert into package_app_app_svc(app_id, operation, uri_scheme, mime_type, subapp_name) " \
1374 "values('%s', '%s', '%s', '%s', '%s')",\
1380 ret = __exec_query(query);
1382 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1385 memset(query, '\0', MAX_QUERY_LEN);
1389 } while(ui != NULL);
1393 }while(sub != NULL);
1409 static int __insert_serviceapplication_datacontrol_info(manifest_x *mfx)
1411 serviceapplication_x *sp = mfx->serviceapplication;
1412 datacontrol_x *dc = NULL;
1414 char query[MAX_QUERY_LEN] = {'\0'};
1418 dc = sp->datacontrol;
1421 snprintf(query, MAX_QUERY_LEN,
1422 "insert into package_app_data_control(app_id, providerid, access, type) " \
1423 "values('%s', '%s', '%s', '%s')",\
1424 mfx->serviceapplication->appid,
1429 ret = __exec_query(query);
1431 _LOGD("Package ServiceApp Data Control DB Insert Failed\n");
1434 memset(query, '\0', MAX_QUERY_LEN);
1442 static int __insert_serviceapplication_share_request_info(manifest_x *mfx)
1444 serviceapplication_x *sp = mfx->serviceapplication;
1445 datashare_x *ds = NULL;
1446 request_x *rq = NULL;
1448 char query[MAX_QUERY_LEN] = {'\0'};
1457 snprintf(query, MAX_QUERY_LEN,
1458 "insert into package_app_share_request(app_id, data_share_request) " \
1459 "values('%s', '%s')",\
1460 sp->appid, rq->text);
1461 ret = __exec_query(query);
1463 _LOGD("Package ServiceApp Share Request DB Insert Failed\n");
1466 memset(query, '\0', MAX_QUERY_LEN);
1478 static int __insert_serviceapplication_share_allowed_info(manifest_x *mfx)
1480 serviceapplication_x *sp = mfx->serviceapplication;
1481 datashare_x *ds = NULL;
1482 define_x *df = NULL;
1483 allowed_x *al = NULL;
1485 char query[MAX_QUERY_LEN] = {'\0'};
1497 snprintf(query, MAX_QUERY_LEN,
1498 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1499 "values('%s', '%s', '%s')",\
1500 sp->appid, df->path, al->text);
1501 ret = __exec_query(query);
1503 _LOGD("Package App Share Allowed DB Insert Failed\n");
1506 memset(query, '\0', MAX_QUERY_LEN);
1518 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1520 label_x *lbl = mfx->label;
1521 license_x *lcn = mfx->license;
1522 icon_x *icn = mfx->icon;
1523 description_x *dcn = mfx->description;
1524 author_x *ath = mfx->author;
1525 uiapplication_x *up = mfx->uiapplication;
1526 uiapplication_x *up_icn = mfx->uiapplication;
1527 uiapplication_x *up_image = mfx->uiapplication;
1528 serviceapplication_x *sp = mfx->serviceapplication;
1529 privileges_x *pvs = NULL;
1530 privilege_x *pv = NULL;
1531 char query[MAX_QUERY_LEN] = { '\0' };
1532 char root[MAX_QUERY_LEN] = { '\0' };
1536 const char *auth_name = NULL;
1537 const char *auth_email = NULL;
1538 const char *auth_href = NULL;
1539 const char *apps_path = NULL;
1541 GList *pkglocale = NULL;
1542 GList *applocale = NULL;
1543 GList *appicon = NULL;
1544 GList *appimage = NULL;
1548 auth_name = ath->text;
1550 auth_email = ath->email;
1552 auth_href = ath->href;
1554 /*Insert in the package_cert_info CERT_DB*/
1555 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1556 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1557 if (ret != PMINFO_R_OK) {
1558 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1559 _LOGE("Cert Info DB create handle failed\n");
1562 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1563 if (ret != PMINFO_R_OK) {
1564 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1565 _LOGE("Cert Info DB Insert Failed\n");
1569 /*Insert in the package_info DB*/
1571 type = strdup(mfx->type);
1573 type = strdup("rpm");
1574 /*Insert in the package_info DB*/
1576 path = strdup(mfx->root_path);
1578 if (strcmp(type,"rpm")==0) {
1579 apps_path = tzplatform_getenv(TZ_SYS_RO_APP);
1580 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1582 apps_path = tzplatform_getenv(TZ_USER_APP);
1583 snprintf(root, MAX_QUERY_LEN - 1, "%s/%s", apps_path, mfx->package);
1585 path = strdup(root);
1587 snprintf(query, MAX_QUERY_LEN,
1588 "insert into package_info(package, package_type, package_version, install_location, package_size, " \
1589 "package_removable, package_preload, package_readonly, package_update, package_appsetting, package_nodisplay, package_system," \
1590 "author_name, author_email, author_href, installed_time, installed_storage, storeclient_id, mainapp_id, package_url, root_path, csc_path) " \
1591 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",\
1595 __get_str(mfx->installlocation),
1596 __get_str(mfx->package_size),
1602 mfx->nodisplay_setting,
1604 __get_str(auth_name),
1605 __get_str(auth_email),
1606 __get_str(auth_href),
1607 mfx->installed_time,
1608 mfx->installed_storage,
1609 __get_str(mfx->storeclient_id),
1611 __get_str(mfx->package_url),
1613 __get_str(mfx->csc_path));
1614 /*If package dont have main_package tag, this package is main package.*/
1615 if (mfx->main_package == NULL) {
1616 ret = __exec_query(query);
1618 _LOGD("Package Info DB Insert Failed\n");
1630 /*If package has main_package tag, this package is sub package(ug, efl).
1631 skip __exec_query for package_info and change pkgid with main_package*/
1632 memset(root, '\0', MAX_QUERY_LEN);
1633 snprintf(root, MAX_QUERY_LEN - 1, "/usr/apps/%s", mfx->main_package);
1634 if (access(root, F_OK) == 0) {
1635 free((void *)mfx->package);
1636 mfx->package = strdup(mfx->main_package);
1638 _LOGE("main package[%s] is not installed\n", root);
1651 /*Insert in the package_privilege_info DB*/
1652 pvs = mfx->privileges;
1653 while (pvs != NULL) {
1654 pv = pvs->privilege;
1655 while (pv != NULL) {
1656 memset(query, '\0', MAX_QUERY_LEN);
1657 snprintf(query, MAX_QUERY_LEN,
1658 "insert into package_privilege_info(package, privilege) " \
1659 "values('%s','%s')",\
1660 mfx->package, pv->text);
1661 ret = __exec_query(query);
1663 _LOGD("Package Privilege Info DB Insert Failed\n");
1672 ret = __insert_ui_mainapp_info(mfx);
1677 /*Insert the package locale*/
1678 pkglocale = __create_locale_list(pkglocale, lbl, lcn, icn, dcn, ath);
1679 /*remove duplicated data in pkglocale*/
1680 __trimfunc(pkglocale);
1682 /*Insert the app locale info */
1685 applocale = __create_locale_list(applocale, up->label, NULL, up->icon, NULL, NULL);
1690 applocale = __create_locale_list(applocale, sp->label, NULL, sp->icon, NULL, NULL);
1693 /*remove duplicated data in applocale*/
1694 __trimfunc(applocale);
1696 /*Insert the app icon info */
1697 while(up_icn != NULL)
1699 appicon = __create_icon_list(appicon, up_icn->icon);
1700 up_icn = up_icn->next;
1702 /*remove duplicated data in appicon*/
1703 __trimfunc(appicon);
1705 /*Insert the image info */
1706 while(up_image != NULL)
1708 appimage = __create_image_list(appimage, up_image->image);
1709 up_image = up_image->next;
1711 /*remove duplicated data in appimage*/
1712 __trimfunc(appimage);
1714 /*g_list_foreach(pkglocale, __printfunc, NULL);*/
1716 /*g_list_foreach(applocale, __printfunc, NULL);*/
1718 /*package locale info, it is only for main package.*/
1719 if (mfx->main_package == NULL)
1720 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1722 /*native app locale info*/
1723 up = mfx->uiapplication;
1726 g_list_foreach(applocale, __insert_uiapplication_locale_info, (gpointer)up);
1729 /*agent app locale info*/
1730 sp = mfx->serviceapplication;
1733 g_list_foreach(applocale, __insert_serviceapplication_locale_info, (gpointer)sp);
1737 /*app icon locale info*/
1738 up_icn = mfx->uiapplication;
1739 while(up_icn != NULL)
1741 g_list_foreach(appicon, __insert_uiapplication_icon_section_info, (gpointer)up_icn);
1742 up_icn = up_icn->next;
1746 up_image = mfx->uiapplication;
1747 while(up_image != NULL)
1749 g_list_foreach(appimage, __insert_uiapplication_image_info, (gpointer)up_image);
1750 up_image = up_image->next;
1753 g_list_free(pkglocale);
1755 g_list_free(applocale);
1757 g_list_free(appicon);
1759 g_list_free(appimage);
1762 /*Insert in the package_app_info DB*/
1763 ret = __insert_uiapplication_info(mfx);
1766 ret = __insert_serviceapplication_info(mfx);
1769 /*Insert in the package_app_app_control DB*/
1770 ret = __insert_uiapplication_appcontrol_info(mfx);
1773 ret = __insert_serviceapplication_appcontrol_info(mfx);
1777 /*Insert in the package_app_app_category DB*/
1778 ret = __insert_uiapplication_appcategory_info(mfx);
1781 ret = __insert_serviceapplication_appcategory_info(mfx);
1785 /*Insert in the package_app_app_metadata DB*/
1786 ret = __insert_uiapplication_appmetadata_info(mfx);
1789 ret = __insert_serviceapplication_appmetadata_info(mfx);
1793 /*Insert in the package_app_app_permission DB*/
1794 ret = __insert_uiapplication_apppermission_info(mfx);
1797 ret = __insert_serviceapplication_apppermission_info(mfx);
1801 /*Insert in the package_app_app_svc DB*/
1802 ret = __insert_uiapplication_appsvc_info(mfx);
1805 ret = __insert_serviceapplication_appsvc_info(mfx);
1809 /*Insert in the package_app_share_allowed DB*/
1810 ret = __insert_uiapplication_share_allowed_info(mfx);
1813 ret = __insert_serviceapplication_share_allowed_info(mfx);
1817 /*Insert in the package_app_share_request DB*/
1818 ret = __insert_uiapplication_share_request_info(mfx);
1821 ret = __insert_serviceapplication_share_request_info(mfx);
1825 /*Insert in the package_app_data_control DB*/
1826 ret = __insert_uiapplication_datacontrol_info(mfx);
1829 ret = __insert_serviceapplication_datacontrol_info(mfx);
1837 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1839 char query[MAX_QUERY_LEN] = { '\0' };
1841 memset(query, '\0', MAX_QUERY_LEN);
1842 snprintf(query, MAX_QUERY_LEN,
1843 "delete from %s where app_id='%s'", db_table, appid);
1844 ret = __exec_query(query);
1846 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1852 static int __delete_subpkg_info_from_db(char *appid)
1856 ret = __delete_appinfo_from_db("package_app_info", appid);
1859 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1862 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1865 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1868 ret = __delete_appinfo_from_db("package_app_app_svc", appid);
1871 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1874 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1877 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1880 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1883 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1886 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1889 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1896 static int __delete_subpkg_from_db(manifest_x *mfx)
1898 char query[MAX_QUERY_LEN] = { '\0' };
1899 char *error_message = NULL;
1901 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1903 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1904 _LOGE("Don't execute query = %s error message = %s\n", query,
1906 sqlite3_free(error_message);
1909 sqlite3_free(error_message);
1914 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1916 char query[MAX_QUERY_LEN] = { '\0' };
1918 uiapplication_x *up = mfx->uiapplication;
1919 serviceapplication_x *sp = mfx->serviceapplication;
1920 /*Delete from cert table*/
1921 if (uid != GLOBAL_USER)
1922 ret = pkgmgrinfo_delete_usr_certinfo(mfx->package, uid);
1924 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1926 _LOGD("Cert Info DB Delete Failed\n");
1930 /*Delete from Package Info DB*/
1931 snprintf(query, MAX_QUERY_LEN,
1932 "delete from package_info where package='%s'", mfx->package);
1933 ret = __exec_query(query);
1935 _LOGD("Package Info DB Delete Failed\n");
1938 memset(query, '\0', MAX_QUERY_LEN);
1940 /*Delete from Package Localized Info*/
1941 snprintf(query, MAX_QUERY_LEN,
1942 "delete from package_localized_info where package='%s'", mfx->package);
1943 ret = __exec_query(query);
1945 _LOGD("Package Localized Info DB Delete Failed\n");
1949 /*Delete from Package Privilege Info*/
1950 snprintf(query, MAX_QUERY_LEN,
1951 "delete from package_privilege_info where package='%s'", mfx->package);
1952 ret = __exec_query(query);
1954 _LOGD("Package Privilege Info DB Delete Failed\n");
1958 while (up != NULL) {
1959 ret = __delete_appinfo_from_db("package_app_info", up->appid);
1962 ret = __delete_appinfo_from_db("package_app_localized_info", up->appid);
1965 ret = __delete_appinfo_from_db("package_app_icon_section_info", up->appid);
1968 ret = __delete_appinfo_from_db("package_app_image_info", up->appid);
1971 ret = __delete_appinfo_from_db("package_app_app_svc", up->appid);
1974 ret = __delete_appinfo_from_db("package_app_app_control", up->appid);
1977 ret = __delete_appinfo_from_db("package_app_app_category", up->appid);
1980 ret = __delete_appinfo_from_db("package_app_app_metadata", up->appid);
1983 ret = __delete_appinfo_from_db("package_app_app_permission", up->appid);
1986 ret = __delete_appinfo_from_db("package_app_share_allowed", up->appid);
1989 ret = __delete_appinfo_from_db("package_app_share_request", up->appid);
1992 ret = __delete_appinfo_from_db("package_app_data_control", up->appid);
1998 while (sp != NULL) {
1999 ret = __delete_appinfo_from_db("package_app_info", sp->appid);
2002 ret = __delete_appinfo_from_db("package_app_localized_info", sp->appid);
2005 ret = __delete_appinfo_from_db("package_app_icon_section_info", sp->appid);
2008 ret = __delete_appinfo_from_db("package_app_image_info", sp->appid);
2011 ret = __delete_appinfo_from_db("package_app_app_svc", sp->appid);
2014 ret = __delete_appinfo_from_db("package_app_app_control", sp->appid);
2017 ret = __delete_appinfo_from_db("package_app_app_category", sp->appid);
2020 ret = __delete_appinfo_from_db("package_app_app_metadata", sp->appid);
2023 ret = __delete_appinfo_from_db("package_app_app_permission", sp->appid);
2026 ret = __delete_appinfo_from_db("package_app_share_allowed", sp->appid);
2029 ret = __delete_appinfo_from_db("package_app_share_request", sp->appid);
2032 ret = __delete_appinfo_from_db("package_app_data_control", sp->appid);
2038 /* if main package has sub pkg, delete sub pkg data*/
2039 __delete_subpkg_from_db(mfx);
2044 static int __update_preload_condition_in_db()
2047 char query[MAX_QUERY_LEN] = {'\0'};
2049 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2051 ret = __exec_query(query);
2053 _LOGD("Package preload_condition update failed\n");
2058 API int pkgmgr_parser_initialize_db(uid_t uid)
2062 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2064 _LOGD("package info DB initialization failed\n");
2067 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2069 _LOGD("package localized info DB initialization failed\n");
2072 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2074 _LOGD("package app app privilege DB initialization failed\n");
2077 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2079 _LOGD("package app info DB initialization failed\n");
2082 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2084 _LOGD("package app localized info DB initialization failed\n");
2087 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2089 _LOGD("package app icon localized info DB initialization failed\n");
2092 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2094 _LOGD("package app image info DB initialization failed\n");
2097 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2099 _LOGD("package app app control DB initialization failed\n");
2102 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2104 _LOGD("package app app category DB initialization failed\n");
2107 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2109 _LOGD("package app app category DB initialization failed\n");
2112 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2114 _LOGD("package app app permission DB initialization failed\n");
2117 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_SVC);
2119 _LOGD("package app app svc DB initialization failed\n");
2122 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2124 _LOGD("package app share allowed DB initialization failed\n");
2127 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2129 _LOGD("package app share request DB initialization failed\n");
2132 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2134 _LOGD("package app data control DB initialization failed\n");
2138 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2140 _LOGD("package cert info DB initialization failed\n");
2143 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2145 _LOGD("package cert index info DB initialization failed\n");
2149 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_INFO);
2151 _LOGD("package resource info DB initialization failed\n");
2154 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_RESOURCE_DATA);
2156 _LOGD("package resource data DB initialization failed\n");
2160 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(uid), uid)) {
2161 _LOGD("Failed to change cert db permission\n");
2163 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2164 _LOGD("Failed to change parser db permission\n");
2170 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2173 char journal_file[BUFSIZE];
2176 struct passwd *userinfo = NULL;
2177 files[0] = (char *)db_file;
2178 files[1] = journal_file;
2181 if (db_file == NULL)
2184 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2186 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2187 if (uid == OWNER_ROOT)
2189 userinfo = getpwuid(uid);
2191 _LOGE("FAIL: user %d doesn't exist", uid);
2194 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2196 for (i = 0; files[i]; i++) {
2197 ret = chown(files[i], uid, userinfo->pw_gid);
2199 if (strerror_r(errno, buf, sizeof(buf)))
2201 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2202 userinfo->pw_gid, buf);
2206 ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
2208 if (strerror_r(errno, buf, sizeof(buf)))
2210 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2213 SET_SMACK_LABEL(files[i]);
2218 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2222 if (getuid() != OWNER_ROOT) {
2223 _LOGE("Only root user is allowed");
2227 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2228 _LOGE("Manifest db for user %d is already exists", uid);
2232 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2233 _LOGE("Cert db for user %d is already exists", uid);
2237 ret = pkgmgr_parser_check_and_create_db(uid);
2240 ret = pkgmgr_parser_initialize_db(uid);
2242 pkgmgr_parser_close_db();
2245 pkgmgr_parser_close_db();
2250 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2254 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2256 _LOGD("Manifest DB creation Failed\n");
2261 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(uid));
2263 _LOGD("Cert DB creation Failed\n");
2269 void pkgmgr_parser_close_db()
2271 sqlite3_close(pkgmgr_parser_db);
2272 sqlite3_close(pkgmgr_cert_db);
2276 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2278 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2280 _LOGD("manifest pointer is NULL\n");
2284 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2286 _LOGD("Failed to open DB\n");
2289 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2292 /*Begin transaction*/
2293 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2294 if (ret != SQLITE_OK) {
2295 _LOGD("Failed to begin transaction\n");
2299 _LOGD("Transaction Begin\n");
2300 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2302 _LOGD("Insert into DB failed. Rollback now\n");
2303 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2306 /*Commit transaction*/
2307 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2308 if (ret != SQLITE_OK) {
2309 _LOGD("Failed to commit transaction. Rollback now\n");
2310 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2314 _LOGD("Transaction Commit and End\n");
2316 pkgmgr_parser_close_db();
2320 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2322 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
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(uid);
2336 /*Begin transaction*/
2337 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2338 if (ret != SQLITE_OK) {
2339 _LOGD("Failed to begin transaction\n");
2343 _LOGD("Transaction Begin\n");
2344 ret = __insert_manifest_info_in_db(mfx, uid);
2346 _LOGD("Insert into DB failed. Rollback now\n");
2347 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2350 /*Commit transaction*/
2351 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2352 if (ret != SQLITE_OK) {
2353 _LOGD("Failed to commit transaction. Rollback now\n");
2354 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2358 _LOGD("Transaction Commit and End\n");
2360 pkgmgr_parser_close_db();
2364 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2367 _LOGD("manifest pointer is NULL\n");
2371 ret = pkgmgr_parser_check_and_create_db(uid);
2373 _LOGD("Failed to open DB\n");
2376 ret = pkgmgr_parser_initialize_db(uid);
2379 /*Preserve guest mode visibility*/
2380 __preserve_guestmode_visibility_value( mfx);
2381 /*Begin transaction*/
2382 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2383 if (ret != SQLITE_OK) {
2384 _LOGD("Failed to begin transaction\n");
2388 _LOGD("Transaction Begin\n");
2389 ret = __delete_manifest_info_from_db(mfx, uid);
2391 _LOGD("Delete from DB failed. Rollback now\n");
2392 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2395 ret = __insert_manifest_info_in_db(mfx, uid);
2397 _LOGD("Insert into DB failed. Rollback now\n");
2398 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2402 /*Commit transaction*/
2403 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2404 if (ret != SQLITE_OK) {
2405 _LOGD("Failed to commit transaction. Rollback now\n");
2406 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2410 _LOGD("Transaction Commit and End\n");
2412 pkgmgr_parser_close_db();
2416 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2418 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2421 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2424 _LOGD("manifest pointer is NULL\n");
2428 ret = pkgmgr_parser_check_and_create_db(uid);
2430 _LOGD("Failed to open DB\n");
2433 /*Begin transaction*/
2434 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2435 if (ret != SQLITE_OK) {
2436 _LOGD("Failed to begin transaction\n");
2440 _LOGD("Transaction Begin\n");
2441 ret = __delete_manifest_info_from_db(mfx, uid);
2443 _LOGD("Delete from DB failed. Rollback now\n");
2444 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2447 /*Commit transaction*/
2448 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2449 if (ret != SQLITE_OK) {
2450 _LOGD("Failed to commit transaction, Rollback now\n");
2451 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2455 _LOGD("Transaction Commit and End\n");
2457 pkgmgr_parser_close_db();
2461 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2463 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2466 API int pkgmgr_parser_update_preload_info_in_db()
2469 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2471 _LOGD("Failed to open DB\n");
2474 /*Begin transaction*/
2475 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2476 if (ret != SQLITE_OK) {
2477 _LOGD("Failed to begin transaction\n");
2481 _LOGD("Transaction Begin\n");
2482 ret = __update_preload_condition_in_db();
2484 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2485 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2488 /*Commit transaction*/
2489 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2490 if (ret != SQLITE_OK) {
2491 _LOGD("Failed to commit transaction, Rollback now\n");
2492 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2496 _LOGD("Transaction Commit and End\n");
2498 pkgmgr_parser_close_db();
2502 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2505 ret = pkgmgr_parser_check_and_create_db(uid);
2507 _LOGD("Failed to open DB\n");
2510 /*Begin transaction*/
2511 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2512 if (ret != SQLITE_OK) {
2513 _LOGD("Failed to begin transaction\n");
2517 _LOGD("Transaction Begin\n");
2518 ret = __update_preload_condition_in_db();
2520 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2521 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2524 /*Commit transaction*/
2525 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2526 if (ret != SQLITE_OK) {
2527 _LOGD("Failed to commit transaction, Rollback now\n");
2528 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2532 _LOGD("Transaction Commit and End\n");
2534 pkgmgr_parser_close_db();