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 #include <system_info.h>
37 /* For multi-user support */
38 #include <tzplatform_config.h>
40 #include "pkgmgr-info.h"
41 #include "pkgmgrinfo_basic.h"
42 #include "pkgmgrinfo_debug.h"
43 #include "pkgmgr_parser_internal.h"
44 #include "pkgmgr_parser_db.h"
49 #define LOG_TAG "PKGMGR_PARSER"
51 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
52 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
53 #define MAX_QUERY_LEN 4096
61 #define XXHDPI "xxhdpi"
71 #define XXHDPI_MIN 481
72 #define XXHDPI_MAX 600
74 #define DB_LABEL "User::Home"
75 #define SET_SMACK_LABEL(x) \
77 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
78 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
80 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
83 sqlite3 *pkgmgr_parser_db;
84 sqlite3 *pkgmgr_cert_db;
87 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
88 "(package text primary key not null, " \
89 "package_type text DEFAULT 'tpk', " \
90 "package_version text, " \
91 "package_api_version text, " \
92 "package_tep_name text, " \
93 "install_location text, " \
94 "package_size text, " \
95 "package_removable text DEFAULT 'true', " \
96 "package_preload text DEFAULT 'false', " \
97 "package_readonly text DEFAULT 'false', " \
98 "package_update text DEFAULT 'false', " \
99 "package_appsetting text DEFAULT 'false', " \
100 "package_nodisplay text DEFAULT 'false', " \
101 "package_system text DEFAULT 'false', " \
102 "author_name text, " \
103 "author_email text, " \
104 "author_href text," \
105 "installed_time text," \
106 "installed_storage text," \
107 "storeclient_id text," \
109 "package_url text," \
112 "package_support_disable text DEFAULT 'false', " \
113 "package_disable text DEFAULT 'false')"
115 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
116 "(package text not null, " \
117 "package_locale text DEFAULT 'No Locale', " \
118 "package_label text, " \
119 "package_icon text, " \
120 "package_description text, " \
121 "package_license text, " \
123 "PRIMARY KEY(package, package_locale), " \
124 "FOREIGN KEY(package) " \
125 "REFERENCES package_info(package) " \
128 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
129 "(package text not null, " \
130 "privilege text not null, " \
131 "PRIMARY KEY(package, privilege) " \
132 "FOREIGN KEY(package) " \
133 "REFERENCES package_info(package) " \
136 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
137 "(app_id text primary key not null, " \
138 "app_component text, " \
140 "app_nodisplay text DEFAULT 'false', " \
142 "app_onboot text DEFAULT 'false', " \
143 "app_multiple text DEFAULT 'false', " \
144 "app_autorestart text DEFAULT 'false', " \
145 "app_taskmanage text DEFAULT 'false', " \
146 "app_enabled text DEFAULT 'true', " \
147 "app_hwacceleration text DEFAULT 'use-system-setting', " \
148 "app_screenreader text DEFAULT 'use-system-setting', " \
149 "app_mainapp text, " \
150 "app_recentimage text, " \
151 "app_launchcondition text, " \
152 "app_indicatordisplay text DEFAULT 'true', " \
153 "app_portraitimg text, " \
154 "app_landscapeimg text, " \
155 "app_guestmodevisibility text DEFAULT 'true', " \
156 "app_permissiontype text DEFAULT 'normal', " \
157 "app_preload text DEFAULT 'false', " \
158 "app_submode text DEFAULT 'false', " \
159 "app_submode_mainid text, " \
160 "app_installed_storage text, " \
161 "app_process_pool text DEFAULT 'false', " \
162 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
163 "app_ui_gadget text DEFAULT 'false', " \
164 "app_support_disable text DEFAULT 'false', " \
165 "app_disable text DEFAULT 'false', " \
166 "app_package_type text DEFAULT 'tpk', " \
167 "component_type text, " \
168 "package text not null, " \
169 "app_tep_name text, " \
170 "app_background_category INTEGER DEFAULT 0, " \
171 "FOREIGN KEY(package) " \
172 "REFERENCES package_info(package) " \
175 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
176 "(app_id text not null, " \
177 "app_locale text DEFAULT 'No Locale', " \
180 "PRIMARY KEY(app_id,app_locale) " \
181 "FOREIGN KEY(app_id) " \
182 "REFERENCES package_app_info(app_id) " \
185 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
186 "(app_id text not null, " \
188 "app_icon_section text, " \
189 "app_icon_resolution text, " \
190 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
191 "FOREIGN KEY(app_id) " \
192 "REFERENCES package_app_info(app_id) " \
195 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
196 "(app_id text not null, " \
197 "app_locale text DEFAULT 'No Locale', " \
198 "app_image_section text, " \
200 "PRIMARY KEY(app_id,app_image_section) " \
201 "FOREIGN KEY(app_id) " \
202 "REFERENCES package_app_info(app_id) " \
205 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
206 "(app_id text not null, " \
207 "app_control text not null, " \
208 "PRIMARY KEY(app_id,app_control) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
214 "(app_id text not null, " \
215 "category text not null, " \
216 "PRIMARY KEY(app_id,category) " \
217 "FOREIGN KEY(app_id) " \
218 "REFERENCES package_app_info(app_id) " \
221 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
222 "(app_id text not null, " \
223 "md_key text not null, " \
224 "md_value text not null, " \
225 "PRIMARY KEY(app_id, md_key, md_value) " \
226 "FOREIGN KEY(app_id) " \
227 "REFERENCES package_app_info(app_id) " \
230 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
231 "(app_id text not null, " \
232 "pm_type text not null, " \
233 "pm_value text not null, " \
234 "PRIMARY KEY(app_id, pm_type, pm_value) " \
235 "FOREIGN KEY(app_id) " \
236 "REFERENCES package_app_info(app_id) " \
239 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
240 "(app_id text not null, " \
241 "data_share_path text not null, " \
242 "data_share_allowed text not null, " \
243 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
244 "FOREIGN KEY(app_id) " \
245 "REFERENCES package_app_info(app_id) " \
248 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
249 "(app_id text not null, " \
250 "data_share_request text not null, " \
251 "PRIMARY KEY(app_id,data_share_request) " \
252 "FOREIGN KEY(app_id) " \
253 "REFERENCES package_app_info(app_id) " \
256 /* FIXME: duplicated at pkgmgrinfo_db.c */
257 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
258 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
259 " cert_info TEXT UNIQUE, " \
260 " cert_id INTEGER PRIMARY KEY, " \
261 " cert_ref_count INTEGER NOT NULL)"
263 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
264 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
265 " package TEXT PRIMARY KEY, " \
266 " author_root_cert INTEGER, " \
267 " author_im_cert INTEGER, " \
268 " author_signer_cert INTEGER, " \
269 " dist_root_cert INTEGER, " \
270 " dist_im_cert INTEGER, " \
271 " dist_signer_cert INTEGER, " \
272 " dist2_root_cert INTEGER, " \
273 " dist2_im_cert INTEGER, " \
274 " dist2_signer_cert INTEGER)"
276 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
277 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
278 "AFTER DELETE ON package_cert_info " \
280 " UPDATE package_cert_index_info SET" \
281 " cert_ref_count = cert_ref_count - 1" \
282 " WHERE cert_id = OLD.author_root_cert" \
283 " OR cert_id = OLD.author_im_cert" \
284 " OR cert_id = OLD.author_signer_cert" \
285 " OR cert_id = OLD.dist_root_cert" \
286 " OR cert_id = OLD.dist_im_cert" \
287 " OR cert_id = OLD.dist_signer_cert" \
288 " OR cert_id = OLD.dist2_root_cert" \
289 " OR cert_id = OLD.dist2_im_cert" \
290 " OR cert_id = OLD.dist2_signer_cert;" \
293 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
294 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
295 "AFTER UPDATE ON package_cert_index_info " \
296 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
297 " WHERE cert_id = OLD.cert_id) = 0) "\
299 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
302 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
303 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
304 "AFTER UPDATE ON package_cert_info " \
305 "WHEN (OLD.%s IS NOT NULL) " \
307 " UPDATE package_cert_index_info SET" \
308 " cert_ref_count = cert_ref_count - 1" \
309 " WHERE cert_id = OLD.%s;" \
312 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
313 "(app_id text not null, " \
314 "providerid text not null, " \
315 "access text not null, " \
316 "type text not null, " \
317 "PRIMARY KEY(app_id, providerid, access, type) " \
318 "FOREIGN KEY(app_id) " \
319 "REFERENCES package_app_info(app_id) " \
322 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
323 "(app_id text not null, " \
324 "uid text not null, " \
325 "PRIMARY KEY(app_id, uid))"
327 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
328 "create table if not exists package_app_splash_screen " \
329 "(app_id text not null, " \
330 "src text not null, " \
331 "type text not null, " \
332 "orientation text not null, " \
333 "indicatordisplay text, " \
335 "PRIMARY KEY(app_id, orientation, operation) " \
336 "FOREIGN KEY(app_id) " \
337 "REFERENCES package_app_info(app_id) " \
340 static int __insert_application_info(manifest_x *mfx);
341 static int __insert_application_appcategory_info(manifest_x *mfx);
342 static int __insert_application_appcontrol_info(manifest_x *mfx);
343 static int __insert_application_appmetadata_info(manifest_x *mfx);
344 static int __insert_application_share_allowed_info(manifest_x *mfx);
345 static int __insert_application_share_request_info(manifest_x *mfx);
346 static int __insert_application_datacontrol_info(manifest_x *mfx);
347 static void __insert_application_locale_info(gpointer data, gpointer userdata);
348 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
349 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
350 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
351 static int __delete_subpkg_info_from_db(char *appid);
352 static int __delete_appinfo_from_db(char *db_table, const char *appid);
353 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
354 static int __exec_query(char *query);
355 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
356 char **label, char **license, char **icon, char **description, char **author);
357 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
358 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
359 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
360 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
361 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
362 static int __parserdb_change_perm(const char *db_file, uid_t uid);
364 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
367 __delete_subpkg_info_from_db(coltxt[0]);
372 static const char *__get_str(const char *str)
376 return PKGMGR_PARSER_EMPTY_STR;
382 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
387 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
388 if (ret != SQLITE_OK) {
389 _LOGD("connect db [%s] failed!\n", db_path);
397 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
399 manifest_x *mfx = (manifest_x *)data;
405 if (mfx->application == NULL)
407 app = (application_x *)mfx->application->data;
408 for(i = 0; i < ncols; i++)
410 if (strcmp(colname[i], "app_id") == 0) {
412 appid = strdup(coltxt[i]);
413 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
415 status = strdup(coltxt[i]);
421 _LOGD("app id is NULL\n");
424 /*update guest mode visibility*/
425 for (tmp = mfx->application; tmp; tmp = tmp->next) {
426 app = (application_x *)tmp->data;
429 if (strcmp(app->appid, appid) == 0) {
430 free((void *)app->guestmode_visibility);
431 app->guestmode_visibility = strdup(status);
447 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
449 char *error_message = NULL;
450 char query[MAX_QUERY_LEN] = {'\0'};
451 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
453 sqlite3_exec(pkgmgr_parser_db, query,
454 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
455 _LOGD("Don't execute query = %s error message = %s\n",
456 query, error_message);
457 sqlite3_free(error_message);
462 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
464 char *error_message = NULL;
466 sqlite3_exec(db_handle, db_query,
467 NULL, NULL, &error_message)) {
468 _LOGD("Don't execute query = %s error message = %s\n",
469 db_query, error_message);
470 sqlite3_free(error_message);
473 sqlite3_free(error_message);
477 static int __exec_query(char *query)
479 char *error_message = NULL;
481 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
482 _LOGE("Don't execute query = %s error message = %s\n", query,
484 sqlite3_free(error_message);
487 sqlite3_free(error_message);
491 static int __exec_query_no_msg(char *query)
493 char *error_message = NULL;
495 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
496 sqlite3_free(error_message);
499 sqlite3_free(error_message);
503 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
511 for (tmp = lbls; tmp; tmp = tmp->next) {
512 lbl = (label_x *)tmp->data;
516 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
518 for (tmp = lcns; tmp; tmp = tmp->next) {
519 lcn = (license_x *)tmp->data;
523 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
525 for (tmp = icns; tmp; tmp = tmp->next) {
526 icn = (icon_x *)tmp->data;
530 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
532 for (tmp = dcns; tmp; tmp = tmp->next) {
533 dcn = (description_x *)tmp->data;
537 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
539 for (tmp = aths; tmp; tmp = tmp->next) {
540 ath = (author_x *)tmp->data;
544 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
550 static GList *__create_icon_list(GList *appicon, GList *icns)
555 for (tmp = icns; tmp; tmp = tmp->next) {
556 icn = (icon_x *)tmp->data;
560 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
565 static GList *__create_image_list(GList *appimage, GList *imgs)
570 for (tmp = imgs; tmp; tmp = tmp->next) {
571 img = (image_x *)tmp->data;
575 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
580 static void __trimfunc(GList* trim_list)
582 char *trim_data = NULL;
586 list = g_list_first(trim_list);
589 trim_data = (char *)list->data;
592 if (strcmp(trim_data, prev) == 0) {
593 trim_list = g_list_remove(trim_list, trim_data);
594 list = g_list_first(trim_list);
603 list = g_list_next(list);
607 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
609 if (a == NULL || b == NULL)
611 if (strcmp((char*)a, (char*)b) == 0)
613 if (strcmp((char*)a, (char*)b) < 0)
615 if (strcmp((char*)a, (char*)b) > 0)
620 static int __check_dpi(const char *dpi_char, int dpi_int)
622 if (dpi_char == NULL)
625 if (strcasecmp(dpi_char, LDPI) == 0) {
626 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
630 } else if (strcasecmp(dpi_char, MDPI) == 0) {
631 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
635 } else if (strcasecmp(dpi_char, HDPI) == 0) {
636 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
640 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
641 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
645 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
646 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
654 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
657 char *icon_filename = NULL;
658 char modified_iconpath[BUFSIZE] = { '\0' };
659 char icon_path[BUFSIZE] = { '\0' };
663 if (orig_icon_path == NULL)
666 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
670 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
671 dpi_path[0] = "LDPI";
672 dpi_path[1] = "ldpi";
673 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
674 dpi_path[0] = "MDPI";
675 dpi_path[1] = "mdpi";
676 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
677 dpi_path[0] = "HDPI";
678 dpi_path[1] = "hdpi";
679 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
680 dpi_path[0] = "XHDPI";
681 dpi_path[1] = "xhdpi";
682 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
683 dpi_path[0] = "XXHDPI";
684 dpi_path[1] = "xxhdpi";
686 _LOGE("Unidentified dpi[%d]", dpi);
690 icon_filename = strrchr(orig_icon_path, '/');
691 if (icon_filename == NULL)
694 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), orig_icon_path);
695 for (i = 0; i < 2; i++) {
696 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
697 if (access(modified_iconpath, F_OK) != -1) {
698 // if exists, return modified icon path
699 *new_icon_path = strdup(modified_iconpath);
707 static gint __compare_icon(gconstpointer a, gconstpointer b)
709 icon_x *icon = (icon_x *)a;
711 char *icon_folder_path = NULL;
713 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
716 if (icon->dpi != NULL)
719 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
721 icon->text = icon_folder_path;
727 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
729 icon_x *icon = (icon_x *)a;
730 int dpi = GPOINTER_TO_INT(b);
732 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
735 if (icon->dpi == NULL)
738 if (__check_dpi(icon->dpi, dpi) == 0)
744 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
746 icon_x *icon = (icon_x *)a;
747 char *lang = (char *)b;
748 char *icon_folder_path = NULL;
750 if (icon->dpi != NULL)
753 if (strcasecmp(icon->lang, lang) == 0) {
754 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
755 //icon for no locale. check existance of folder-hierachied default icons
756 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
758 icon->text = icon_folder_path;
767 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
769 icon_x *icon = (icon_x *)a;
770 char *lang = (char *)b;
773 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
777 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
783 static char *__find_icon(GList *icons, const char *lang)
789 // first, find icon whose locale and dpi with given lang and system's dpi has matched
790 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
792 icon = (icon_x *)tmp->data;
793 return (char *)icon->text;
796 // if first has failed, find icon whose locale has matched
797 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
799 icon = (icon_x *)tmp->data;
800 return (char *)icon->text;
803 // if second has failed, find icon whose dpi has matched with system's dpi
804 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
807 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
809 icon = (icon_x *)tmp->data;
810 return (char *)icon->text;
813 // last, find default icon marked as "No Locale"
814 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
816 icon = (icon_x *)tmp->data;
817 return (char *)icon->text;
823 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
824 char **label, char **license, char **icon, char **description, char **author)
831 for (tmp = lbls; tmp; tmp = tmp->next) {
832 lbl = (label_x *)tmp->data;
836 if (strcmp(lbl->lang, (char *)data) == 0) {
837 *label = (char*)lbl->text;
842 for (tmp = lcns; tmp; tmp = tmp->next) {
843 lcn = (license_x *)tmp->data;
847 if (strcmp(lcn->lang, (char *)data) == 0) {
848 *license = (char*)lcn->text;
854 *icon = __find_icon(icns, (char *)data);
856 for (tmp = dcns; tmp; tmp = tmp->next) {
857 dcn = (description_x *)tmp->data;
861 if (strcmp(dcn->lang, (char *)data) == 0) {
862 *description = (char*)dcn->text;
867 for (tmp = aths; tmp; tmp = tmp->next) {
868 ath = (author_x *)tmp->data;
872 if (strcmp(ath->lang, (char *)data) == 0) {
873 *author = (char*)ath->text;
881 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
885 for (tmp = icns; tmp; tmp = tmp->next) {
886 icn = (icon_x *)tmp->data;
890 if (strcmp(icn->section, (char *)data) == 0) {
891 *icon = (char*)icn->text;
892 *resolution = (char*)icn->resolution;
899 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
903 for (tmp = imgs; tmp; tmp = tmp->next) {
904 img = (image_x *)tmp->data;
908 if (strcmp(img->section, (char *)data) == 0) {
909 *lang = (char*)img->lang;
910 *image = (char*)img->text;
917 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
922 char *description = NULL;
923 char *license = NULL;
927 manifest_x *mfx = (manifest_x *)userdata;
928 GList *lbl = mfx->label;
929 GList *lcn = mfx->license;
930 GList *icn = mfx->icon;
931 GList *dcn = mfx->description;
932 GList *ath = mfx->author;
934 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
935 if (!label && !description && !icon && !license && !author)
938 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
939 "package_label, package_icon, package_description, package_license, package_author) values " \
940 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
945 __get_str(description),
949 ret = __exec_query(query);
951 _LOGD("Package Localized Info DB Insert failed\n");
956 static void __insert_application_locale_info(gpointer data, gpointer userdata)
963 application_x *app = (application_x*)userdata;
964 GList *lbl = app->label;
965 GList *icn = app->icon;
967 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
971 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
972 "app_label, app_icon) values " \
973 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
974 __get_str(label), __get_str(icon));
975 ret = __exec_query(query);
977 _LOGD("Package UiApp Localized Info DB Insert failed\n");
981 /*insert ui app locale info to pkg locale to get mainapp data */
982 if (strcasecmp(app->mainapp, "true")==0) {
983 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
984 "package_label, package_icon, package_description, package_license, package_author) values " \
985 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
990 PKGMGR_PARSER_EMPTY_STR,
991 PKGMGR_PARSER_EMPTY_STR,
992 PKGMGR_PARSER_EMPTY_STR);
994 ret = __exec_query_no_msg(query);
998 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
999 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1000 ret = __exec_query_no_msg(query);
1001 sqlite3_free(query);
1006 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1010 char *resolution = NULL;
1011 char query[MAX_QUERY_LEN] = {'\0'};
1013 application_x *app = (application_x*)userdata;
1014 GList *icn = app->icon;
1016 __extract_icon_data(data, icn, &icon, &resolution);
1017 if (!icon && !resolution)
1019 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1020 "app_icon, app_icon_section, app_icon_resolution) values " \
1021 "('%q', '%q', '%q', '%q')", app->appid,
1022 icon, (char*)data, resolution);
1024 ret = __exec_query(query);
1026 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1030 static void __insert_application_image_info(gpointer data, gpointer userdata)
1035 char query[MAX_QUERY_LEN] = {'\0'};
1037 application_x *app = (application_x*)userdata;
1038 GList *image = app->image;
1040 __extract_image_data(data, image, &lang, &img);
1043 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1044 "app_image_section, app_image) values " \
1045 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1047 ret = __exec_query(query);
1049 _LOGD("Package UiApp image Info DB Insert failed\n");
1054 static int __insert_mainapp_info(manifest_x *mfx)
1059 char query[MAX_QUERY_LEN] = {'\0'};
1060 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1061 app = (application_x *)tmp->data;
1064 snprintf(query, MAX_QUERY_LEN,
1065 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1067 ret = __exec_query(query);
1069 _LOGD("Package App Info DB Insert Failed\n");
1072 if (strcasecmp(app->mainapp, "True")==0)
1073 mfx->mainapp_id = strdup(app->appid);
1076 if (mfx->mainapp_id == NULL) {
1077 if (mfx->application == NULL)
1079 app = (application_x *)mfx->application->data;
1083 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1085 _LOGD("Not valid appid\n");
1089 ret = __exec_query(query);
1091 _LOGD("Package UiApp Info DB Insert Failed\n");
1095 free((void *)app->mainapp);
1096 app->mainapp= strdup("true");
1097 mfx->mainapp_id = strdup(app->appid);
1100 memset(query, '\0', MAX_QUERY_LEN);
1101 snprintf(query, MAX_QUERY_LEN,
1102 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1103 ret = __exec_query(query);
1105 _LOGD("Package Info DB update Failed\n");
1112 static int __convert_background_category(GList *category_list)
1115 GList *tmp_list = category_list;
1116 char *category_data = NULL;
1118 if (category_list == NULL)
1121 while (tmp_list != NULL) {
1122 category_data = (char *)tmp_list->data;
1123 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1124 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1125 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1126 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1127 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1128 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1129 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1130 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1131 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1132 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1133 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1134 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1135 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1136 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1138 _LOGE("Unidentified category [%s]", category_data);
1140 tmp_list = g_list_next(tmp_list);
1146 /* _PRODUCT_LAUNCHING_ENHANCED_
1147 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1149 static int __insert_application_info(manifest_x *mfx)
1154 int background_value = 0;
1155 char query[MAX_QUERY_LEN] = {'\0'};
1159 type = strdup(mfx->type);
1161 type = strdup("tpk");
1163 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1164 app = (application_x *)tmp->data;
1168 background_value = __convert_background_category(app->background_category);
1169 if (background_value < 0) {
1170 _LOGE("Failed to retrieve background value[%d]", background_value);
1171 background_value = 0;
1174 snprintf(query, MAX_QUERY_LEN,
1175 "insert into package_app_info(" \
1176 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1177 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1178 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1179 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1180 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1181 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1182 "app_tep_name, app_background_category, app_package_type) " \
1184 "'%s', '%s', '%s', '%s', '%s', " \
1185 "'%s', '%s', '%s', '%s', '%s', " \
1186 "'%s', '%s', '%s', '%s', '%s', " \
1187 "'%s', '%s', '%s', '%s', '%s', " \
1188 "'%s', '%s', '%s', '%s', '%s', " \
1189 "'%s', '%s', '%s', '%s', '%s', " \
1190 "'%s', '%d', '%s')", \
1191 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1192 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1193 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1194 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1195 app->guestmode_visibility, app->permission_type,
1196 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1197 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1198 __get_str(mfx->tep_name), background_value, type);
1200 ret = __exec_query(query);
1202 _LOGD("Package UiApp Info DB Insert Failed\n");
1207 memset(query, '\0', MAX_QUERY_LEN);
1216 static int __insert_application_appcategory_info(manifest_x *mfx)
1223 char query[MAX_QUERY_LEN] = {'\0'};
1224 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1225 app = (application_x *)app_tmp->data;
1228 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1229 ct = (const char *)ct_tmp->data;
1232 snprintf(query, MAX_QUERY_LEN,
1233 "insert into package_app_app_category(app_id, category) " \
1234 "values('%s','%s')",\
1236 ret = __exec_query(query);
1238 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1241 memset(query, '\0', MAX_QUERY_LEN);
1247 static int __insert_application_appmetadata_info(manifest_x *mfx)
1254 char query[MAX_QUERY_LEN] = {'\0'};
1255 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1256 app = (application_x *)app_tmp->data;
1259 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1260 md = (metadata_x *)md_tmp->data;
1264 snprintf(query, MAX_QUERY_LEN,
1265 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1266 "values('%s','%s', '%s')",\
1267 app->appid, md->key, md->value ? md->value : "");
1268 ret = __exec_query(query);
1270 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1274 memset(query, '\0', MAX_QUERY_LEN);
1280 static int __insert_application_apppermission_info(manifest_x *mfx)
1287 char query[MAX_QUERY_LEN] = {'\0'};
1288 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1289 app = (application_x *)app_tmp->data;
1292 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1293 pm = (permission_x *)pm_tmp->data;
1296 snprintf(query, MAX_QUERY_LEN,
1297 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1298 "values('%s','%s', '%s')",\
1299 app->appid, pm->type, pm->value);
1300 ret = __exec_query(query);
1302 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1305 memset(query, '\0', MAX_QUERY_LEN);
1311 static int __insert_application_appcontrol_info(manifest_x *mfx)
1315 GList *acontrol_tmp;
1316 appcontrol_x *acontrol;
1318 char query[MAX_QUERY_LEN] = {'\0'};
1319 char buf[BUFSIZE] = {'\0'};
1320 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1321 app = (application_x *)app_tmp->data;
1324 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1325 acontrol = (appcontrol_x *)acontrol_tmp->data;
1326 if (acontrol == NULL)
1328 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1329 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1330 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1331 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1332 snprintf(query, MAX_QUERY_LEN,
1333 "insert into package_app_app_control(app_id, app_control) " \
1334 "values('%s', '%s')",\
1336 ret = __exec_query(query);
1338 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1341 memset(query, '\0', MAX_QUERY_LEN);
1347 static int __insert_application_datacontrol_info(manifest_x *mfx)
1354 char query[MAX_QUERY_LEN] = {'\0'};
1356 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1357 app = (application_x *)app_tmp->data;
1360 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1361 dc = (datacontrol_x *)dc_tmp->data;
1364 snprintf(query, MAX_QUERY_LEN,
1365 "insert into package_app_data_control(app_id, providerid, access, type) " \
1366 "values('%s', '%s', '%s', '%s')",\
1372 ret = __exec_query(query);
1374 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1377 memset(query, '\0', MAX_QUERY_LEN);
1383 static int __insert_application_share_request_info(manifest_x *mfx)
1392 char query[MAX_QUERY_LEN] = {'\0'};
1393 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1394 app = (application_x *)app_tmp->data;
1397 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1398 ds = (datashare_x *)ds_tmp->data;
1401 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1402 rq = (const char *)rq_tmp->data;
1405 snprintf(query, MAX_QUERY_LEN,
1406 "insert into package_app_share_request(app_id, data_share_request) " \
1407 "values('%s', '%s')",\
1409 ret = __exec_query(query);
1411 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1414 memset(query, '\0', MAX_QUERY_LEN);
1421 static int __insert_application_share_allowed_info(manifest_x *mfx)
1432 char query[MAX_QUERY_LEN] = {'\0'};
1433 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1434 app = (application_x *)app_tmp->data;
1437 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1438 ds = (datashare_x *)ds_tmp->data;
1441 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1442 df = (define_x *)df_tmp->data;
1445 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1446 al = (const char *)al_tmp->data;
1449 snprintf(query, MAX_QUERY_LEN,
1450 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1451 "values('%s', '%s', '%s')",\
1452 app->appid, df->path, al);
1453 ret = __exec_query(query);
1455 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1458 memset(query, '\0', MAX_QUERY_LEN);
1466 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1468 splashscreen_x *ss = (splashscreen_x *)a;
1469 const char *orientation = (const char *)b;
1472 if (ss->operation || ss->dpi == NULL)
1475 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1479 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1485 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1487 splashscreen_x *ss = (splashscreen_x *)a;
1488 const char *orientation = (const char *)b;
1490 if (ss->operation || ss->dpi)
1493 if (strcasecmp(ss->orientation, orientation) == 0)
1499 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1500 const char *orientation)
1504 tmp = g_list_find_custom(splashscreens, orientation,
1505 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1507 return (splashscreen_x *)tmp->data;
1509 tmp = g_list_find_custom(splashscreens, orientation,
1510 (GCompareFunc)__compare_splashscreen_with_orientation);
1512 return (splashscreen_x *)tmp->data;
1517 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1519 splashscreen_x *ss = (splashscreen_x *)data;
1520 GList **list = (GList **)user_data;
1523 if (ss->operation == NULL || ss->dpi == NULL)
1526 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1530 if (__check_dpi(ss->dpi, dpi) != 0)
1533 *list = g_list_append(*list, ss);
1536 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1538 splashscreen_x *ss = (splashscreen_x *)data;
1539 GList **list = (GList **)user_data;
1540 splashscreen_x *ss_tmp;
1543 if (ss->operation == NULL || ss->dpi)
1546 for (tmp = *list; tmp; tmp = tmp->next) {
1547 ss_tmp = (splashscreen_x *)tmp->data;
1548 if (ss_tmp->operation
1549 && strcmp(ss_tmp->operation, ss->operation) == 0
1550 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1554 *list = g_list_append(*list, ss);
1557 static GList *__find_splashscreens(GList *splashscreens)
1562 g_list_foreach(splashscreens,
1563 __find_appcontrol_splashscreen_with_dpi, &list);
1564 g_list_foreach(splashscreens,
1565 __find_appcontrol_splashscreen, &list);
1567 ss = __find_default_splashscreen(splashscreens, "portrait");
1569 list = g_list_append(list, ss);
1570 ss = __find_default_splashscreen(splashscreens, "landscape");
1572 list = g_list_append(list, ss);
1577 static int __insert_application_splashscreen_info(manifest_x *mfx)
1585 char query[MAX_QUERY_LEN];
1587 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1588 app = (application_x *)app_tmp->data;
1589 if (app == NULL || app->splashscreens == NULL)
1592 ss_tmp = __find_splashscreens(app->splashscreens);
1596 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1597 ss = (splashscreen_x *)tmp->data;
1598 snprintf(query, sizeof(query),
1599 "insert into package_app_splash_screen" \
1600 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1601 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1602 app->appid, ss->src, ss->type, ss->orientation,
1603 ss->indicatordisplay, __get_str(ss->operation));
1604 ret = __exec_query(query);
1606 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1609 memset(query, '\0', MAX_QUERY_LEN);
1611 g_list_free(ss_tmp);
1616 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1621 char query[MAX_QUERY_LEN];
1623 const char *image_type;
1624 const char *indicatordisplay;
1625 const char *orientation;
1626 const char *operation = NULL;
1628 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1629 app = (application_x *)app_tmp->data;
1631 (app->portraitimg == NULL && app->landscapeimg == NULL))
1633 image_type = "img"; /* default */
1634 if (app->effectimage_type) {
1635 tmp = strstr(app->effectimage_type, "edj");
1639 indicatordisplay = "true"; /* default */
1640 if (app->indicatordisplay)
1641 indicatordisplay = app->indicatordisplay;
1642 if (app->portraitimg) {
1643 orientation = "portrait";
1644 snprintf(query, sizeof(query),
1645 "insert into package_app_splash_screen" \
1646 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1647 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1648 app->appid, app->portraitimg, image_type,
1649 orientation, indicatordisplay, __get_str(operation));
1650 ret = __exec_query(query);
1652 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1655 memset(query, '\0', MAX_QUERY_LEN);
1656 } else if (app->landscapeimg) {
1657 orientation = "landscape";
1658 snprintf(query, sizeof(query),
1659 "insert into package_app_splash_screen" \
1660 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1661 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1662 app->appid, app->landscapeimg, image_type,
1663 orientation, indicatordisplay, __get_str(operation));
1664 ret = __exec_query(query);
1666 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1669 memset(query, '\0', MAX_QUERY_LEN);
1675 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1679 const char *pv = NULL;
1680 char query[MAX_QUERY_LEN] = { '\0' };
1683 const char *auth_name = NULL;
1684 const char *auth_email = NULL;
1685 const char *auth_href = NULL;
1687 GList *pkglocale = NULL;
1688 GList *applocale = NULL;
1689 GList *appicon = NULL;
1690 GList *appimage = NULL;
1692 if (mfx->author && mfx->author->data) {
1693 author = (author_x *)mfx->author->data;
1695 auth_name = author->text;
1697 auth_email = author->email;
1699 auth_href = author->href;
1701 /*Insert in the package_cert_info CERT_DB*/
1702 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1703 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1704 if (ret != PMINFO_R_OK) {
1705 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1706 _LOGE("Cert Info DB create handle failed\n");
1709 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1710 if (ret != PMINFO_R_OK) {
1711 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1712 _LOGE("Cert Info DB Insert Failed\n");
1716 /*Insert in the package_info DB*/
1717 snprintf(query, MAX_QUERY_LEN,
1718 "insert into package_info(" \
1719 "package, package_type, package_version, package_api_version, package_tep_name, " \
1720 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1721 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1722 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1723 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1725 "'%s', '%s', '%s', '%s', '%s', " \
1726 "'%s', '%s', '%s', '%s', '%s', " \
1727 "'%s', '%s', '%s', '%s', '%s', " \
1728 "'%s', '%s', '%s', '%s', '%s', " \
1729 "'%s', '%s', '%s', '%s', '%s')", \
1730 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1731 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1732 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1733 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1734 __get_str(mfx->storeclient_id),
1735 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1737 ret = __exec_query(query);
1739 _LOGD("Package Info DB Insert Failed\n");
1743 /*Insert in the package_privilege_info DB*/
1744 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1745 pv = (const char *)tmp->data;
1748 memset(query, '\0', MAX_QUERY_LEN);
1749 snprintf(query, MAX_QUERY_LEN,
1750 "insert into package_privilege_info(package, privilege) " \
1751 "values('%s','%s')",\
1753 ret = __exec_query(query);
1755 _LOGD("Package Privilege Info DB Insert Failed\n");
1760 if (mfx->application != NULL) {
1761 ret = __insert_mainapp_info(mfx);
1766 /*Insert the package locale*/
1767 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1768 /*remove duplicated data in pkglocale*/
1769 __trimfunc(pkglocale);
1771 /*Insert the app locale, icon, image info */
1772 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1773 app = (application_x *)tmp->data;
1776 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1777 appicon = __create_icon_list(appicon, app->icon);
1778 appimage = __create_image_list(appimage, app->image);
1780 /*remove duplicated data in applocale*/
1781 __trimfunc(applocale);
1782 __trimfunc(appicon);
1783 __trimfunc(appimage);
1785 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1787 /*native app locale info*/
1788 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1789 app = (application_x *)tmp->data;
1792 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1793 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1794 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1797 g_list_free(pkglocale);
1799 g_list_free(applocale);
1801 g_list_free(appicon);
1803 g_list_free(appimage);
1806 /*Insert in the package_app_info DB*/
1807 ret = __insert_application_info(mfx);
1810 /*Insert in the package_app_app_control DB*/
1811 ret = __insert_application_appcontrol_info(mfx);
1815 /*Insert in the package_app_app_category DB*/
1816 ret = __insert_application_appcategory_info(mfx);
1820 /*Insert in the package_app_app_metadata DB*/
1821 ret = __insert_application_appmetadata_info(mfx);
1825 /*Insert in the package_app_app_permission DB*/
1826 ret = __insert_application_apppermission_info(mfx);
1830 /*Insert in the package_app_share_allowed DB*/
1831 ret = __insert_application_share_allowed_info(mfx);
1835 /*Insert in the package_app_share_request DB*/
1836 ret = __insert_application_share_request_info(mfx);
1840 /*Insert in the package_app_data_control DB*/
1841 ret = __insert_application_datacontrol_info(mfx);
1845 /*Insert in the package_app_splash_screen DB*/
1846 ret = __insert_application_legacy_splashscreen_info(mfx);
1850 /*Insert in the package_app_splash_screen DB*/
1851 ret = __insert_application_splashscreen_info(mfx);
1859 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1861 char query[MAX_QUERY_LEN] = { '\0' };
1863 memset(query, '\0', MAX_QUERY_LEN);
1864 snprintf(query, MAX_QUERY_LEN,
1865 "delete from %s where app_id='%s'", db_table, appid);
1866 ret = __exec_query(query);
1868 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1874 static int __delete_subpkg_info_from_db(char *appid)
1878 ret = __delete_appinfo_from_db("package_app_info", appid);
1881 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1884 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1887 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1890 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1893 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1896 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1899 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1902 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1905 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1908 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1911 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1918 static int __delete_subpkg_from_db(manifest_x *mfx)
1920 char query[MAX_QUERY_LEN] = { '\0' };
1921 char *error_message = NULL;
1923 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1925 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1926 _LOGE("Don't execute query = %s error message = %s\n", query,
1928 sqlite3_free(error_message);
1931 sqlite3_free(error_message);
1936 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1938 char query[MAX_QUERY_LEN] = { '\0' };
1942 /*Delete from cert table*/
1943 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1945 _LOGD("Cert Info DB Delete Failed\n");
1949 /*Delete from Package Info DB*/
1950 snprintf(query, MAX_QUERY_LEN,
1951 "delete from package_info where package='%s'", mfx->package);
1952 ret = __exec_query(query);
1954 _LOGD("Package Info DB Delete Failed\n");
1957 memset(query, '\0', MAX_QUERY_LEN);
1959 /*Delete from Package Localized Info*/
1960 snprintf(query, MAX_QUERY_LEN,
1961 "delete from package_localized_info where package='%s'", mfx->package);
1962 ret = __exec_query(query);
1964 _LOGD("Package Localized Info DB Delete Failed\n");
1968 /*Delete from Package Privilege Info*/
1969 snprintf(query, MAX_QUERY_LEN,
1970 "delete from package_privilege_info where package='%s'", mfx->package);
1971 ret = __exec_query(query);
1973 _LOGD("Package Privilege Info DB Delete Failed\n");
1977 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1978 app = (application_x *)tmp->data;
1981 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1984 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1987 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1990 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1993 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1996 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
1999 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2002 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2005 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2008 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2011 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2014 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2019 /* if main package has sub pkg, delete sub pkg data*/
2020 __delete_subpkg_from_db(mfx);
2025 static int __disable_app(const char *appid)
2028 char query[MAX_QUERY_LEN] = {'\0'};
2029 sqlite3_snprintf(MAX_QUERY_LEN, query,
2030 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2032 ret = __exec_query(query);
2034 _LOGD("Insert global app disable failed\n");
2039 static int __enable_app(const char *appid)
2042 char query[MAX_QUERY_LEN] = {'\0'};
2043 sqlite3_snprintf(MAX_QUERY_LEN, query,
2044 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2046 ret = __exec_query(query);
2048 _LOGD("Insert global app disable failed\n");
2053 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2056 char query[MAX_QUERY_LEN] = {'\0'};
2058 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2059 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2061 ret = __exec_query(query);
2063 _LOGD("Insert global app disable failed\n");
2068 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2071 char query[MAX_QUERY_LEN] = {'\0'};
2073 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2074 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2076 ret = __exec_query(query);
2078 _LOGD("Delete global app disable failed\n");
2083 static int __update_preload_condition_in_db()
2086 char query[MAX_QUERY_LEN] = {'\0'};
2088 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2090 ret = __exec_query(query);
2092 _LOGD("Package preload_condition update failed\n");
2097 API int pkgmgr_parser_initialize_db(uid_t uid)
2101 char query[MAX_QUERY_LEN];
2102 static const char *columns[] = {
2103 "author_root_cert", "author_im_cert", "author_signer_cert",
2104 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2105 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2109 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2111 _LOGD("package info DB initialization failed\n");
2114 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2116 _LOGD("package localized info DB initialization failed\n");
2119 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2121 _LOGD("package app app privilege DB initialization failed\n");
2124 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2126 _LOGD("package app info DB initialization failed\n");
2129 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2131 _LOGD("package app localized info DB initialization failed\n");
2134 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2136 _LOGD("package app icon localized info DB initialization failed\n");
2139 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2141 _LOGD("package app image info DB initialization failed\n");
2144 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2146 _LOGD("package app app control DB initialization failed\n");
2149 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2151 _LOGD("package app app category DB initialization failed\n");
2154 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2156 _LOGD("package app app category DB initialization failed\n");
2159 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2161 _LOGD("package app app permission DB initialization failed\n");
2164 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2166 _LOGD("package app share allowed DB initialization failed\n");
2169 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2171 _LOGD("package app share request DB initialization failed\n");
2174 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2176 _LOGD("package app data control DB initialization failed\n");
2180 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2182 _LOGD("package app disable for user DB initialization failed\n");
2186 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2188 _LOGD("package app splash screen DB initialization failed\n");
2193 /* TODO: refactor this code */
2194 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2196 _LOGD("package cert info DB initialization failed\n");
2199 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2201 _LOGD("package cert index info DB initialization failed\n");
2204 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2206 _LOGD("package cert info DB initialization failed\n");
2209 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2211 _LOGD("package cert index info DB initialization failed\n");
2214 for (i = 0; columns[i] != NULL; i++) {
2215 snprintf(query, sizeof(query),
2216 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2217 columns[i], columns[i], columns[i]);
2218 ret = __initialize_db(pkgmgr_cert_db, query);
2220 _LOGD("package cert index info DB initialization failed\n");
2225 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2226 _LOGD("Failed to change cert db permission\n");
2228 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2229 _LOGD("Failed to change parser db permission\n");
2235 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2238 char journal_file[BUFSIZE];
2241 struct passwd *userinfo = NULL;
2242 files[0] = (char *)db_file;
2243 files[1] = journal_file;
2247 if (db_file == NULL)
2250 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2252 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2253 if (uid == OWNER_ROOT)
2255 userinfo = getpwuid(uid);
2257 _LOGE("FAIL: user %d doesn't exist", uid);
2260 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2262 for (i = 0; files[i]; i++) {
2263 ret = chown(files[i], uid, userinfo->pw_gid);
2265 if (strerror_r(errno, buf, sizeof(buf)))
2267 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2268 userinfo->pw_gid, buf);
2272 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2273 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2275 ret = chmod(files[i], mode);
2277 if (strerror_r(errno, buf, sizeof(buf)))
2279 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2282 SET_SMACK_LABEL(files[i]);
2287 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2291 if (getuid() != OWNER_ROOT) {
2292 _LOGE("Only root user is allowed");
2296 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2297 _LOGE("Manifest db for user %d is already exists", uid);
2301 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2302 _LOGE("Cert db for user %d is already exists", uid);
2306 ret = pkgmgr_parser_check_and_create_db(uid);
2309 ret = pkgmgr_parser_initialize_db(uid);
2311 pkgmgr_parser_close_db();
2314 pkgmgr_parser_close_db();
2319 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2323 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2325 _LOGD("Manifest DB creation Failed\n");
2330 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2332 _LOGD("Cert DB creation Failed\n");
2338 void pkgmgr_parser_close_db(void)
2340 sqlite3_close(pkgmgr_parser_db);
2341 sqlite3_close(pkgmgr_cert_db);
2345 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2347 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2349 _LOGD("manifest pointer is NULL\n");
2353 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2355 _LOGD("Failed to open DB\n");
2358 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2361 /*Begin transaction*/
2362 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2363 if (ret != SQLITE_OK) {
2364 _LOGD("Failed to begin transaction\n");
2368 _LOGD("Transaction Begin\n");
2369 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2371 _LOGD("Insert into DB failed. Rollback now\n");
2372 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2375 /*Commit transaction*/
2376 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2377 if (ret != SQLITE_OK) {
2378 _LOGD("Failed to commit transaction. Rollback now\n");
2379 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2383 _LOGD("Transaction Commit and End\n");
2385 pkgmgr_parser_close_db();
2389 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2391 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2393 _LOGD("manifest pointer is NULL\n");
2397 ret = pkgmgr_parser_check_and_create_db(uid);
2399 _LOGD("Failed to open DB\n");
2402 ret = pkgmgr_parser_initialize_db(uid);
2405 /*Begin transaction*/
2406 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2407 if (ret != SQLITE_OK) {
2408 _LOGD("Failed to begin transaction\n");
2412 _LOGD("Transaction Begin\n");
2413 ret = __insert_manifest_info_in_db(mfx, uid);
2415 _LOGD("Insert into DB failed. Rollback now\n");
2416 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2419 /*Commit transaction*/
2420 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2421 if (ret != SQLITE_OK) {
2422 _LOGD("Failed to commit transaction. Rollback now\n");
2423 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2427 _LOGD("Transaction Commit and End\n");
2429 pkgmgr_parser_close_db();
2433 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2435 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2438 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2440 if (pkgid == NULL || tep_path == NULL) {
2441 _LOGE("invalid parameter");
2448 ret = pkgmgr_parser_check_and_create_db(uid);
2450 _LOGD("Failed to open DB\n");
2453 ret = pkgmgr_parser_initialize_db(uid);
2457 /*Begin transaction*/
2458 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2459 if (ret != SQLITE_OK) {
2460 _LOGD("Failed to begin transaction\n");
2464 _LOGD("Transaction Begin\n");
2467 /* Updating TEP info in "package_info" table */
2468 query = sqlite3_mprintf("UPDATE package_info "\
2469 "SET package_tep_name = %Q "\
2470 "WHERE package = %Q", tep_path, pkgid);
2472 ret = __exec_query(query);
2473 sqlite3_free(query);
2474 if (ret != SQLITE_OK) {
2475 ret = PM_PARSER_R_ERROR;
2476 _LOGE("sqlite exec failed to insert entries into package_info!!");
2480 /* Updating TEP info in "package_app_info" table */
2481 query = sqlite3_mprintf("UPDATE package_app_info "\
2482 "SET app_tep_name = %Q "\
2483 "WHERE package = %Q", tep_path, pkgid);
2485 ret = __exec_query(query);
2486 sqlite3_free(query);
2487 if (ret != SQLITE_OK) {
2488 ret = PM_PARSER_R_ERROR;
2489 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2493 /*Commit transaction*/
2494 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2495 if (ret != SQLITE_OK) {
2496 _LOGE("Failed to commit transaction, Rollback now\n");
2497 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2498 if (ret != SQLITE_OK)
2499 _LOGE("Failed to Rollback\n");
2501 ret = PM_PARSER_R_ERROR;
2504 _LOGD("Transaction Commit and End\n");
2505 ret = PM_PARSER_R_OK;
2508 pkgmgr_parser_close_db();
2513 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2516 _LOGD("manifest pointer is NULL\n");
2520 ret = pkgmgr_parser_check_and_create_db(uid);
2522 _LOGD("Failed to open DB\n");
2525 ret = pkgmgr_parser_initialize_db(uid);
2528 /*Preserve guest mode visibility*/
2529 __preserve_guestmode_visibility_value( mfx);
2530 /*Begin transaction*/
2531 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2532 if (ret != SQLITE_OK) {
2533 _LOGD("Failed to begin transaction\n");
2537 _LOGD("Transaction Begin\n");
2538 ret = __delete_manifest_info_from_db(mfx, uid);
2540 _LOGD("Delete from DB failed. Rollback now\n");
2541 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2544 ret = __insert_manifest_info_in_db(mfx, uid);
2546 _LOGD("Insert into DB failed. Rollback now\n");
2547 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2551 /*Commit transaction*/
2552 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2553 if (ret != SQLITE_OK) {
2554 _LOGD("Failed to commit transaction. Rollback now\n");
2555 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2559 _LOGD("Transaction Commit and End\n");
2561 pkgmgr_parser_close_db();
2565 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2567 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2570 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2573 _LOGD("manifest pointer is NULL\n");
2577 ret = pkgmgr_parser_check_and_create_db(uid);
2579 _LOGD("Failed to open DB\n");
2582 /*Begin transaction*/
2583 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2584 if (ret != SQLITE_OK) {
2585 _LOGD("Failed to begin transaction\n");
2589 _LOGD("Transaction Begin\n");
2590 ret = __delete_manifest_info_from_db(mfx, uid);
2592 _LOGD("Delete from DB failed. Rollback now\n");
2593 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2596 /*Commit transaction*/
2597 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2598 if (ret != SQLITE_OK) {
2599 _LOGD("Failed to commit transaction, Rollback now\n");
2600 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2604 _LOGD("Transaction Commit and End\n");
2606 pkgmgr_parser_close_db();
2610 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2612 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2615 API int pkgmgr_parser_update_preload_info_in_db()
2618 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2620 _LOGD("Failed to open DB\n");
2623 /*Begin transaction*/
2624 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2625 if (ret != SQLITE_OK) {
2626 _LOGD("Failed to begin transaction\n");
2630 _LOGD("Transaction Begin\n");
2631 ret = __update_preload_condition_in_db();
2633 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2634 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2637 /*Commit transaction*/
2638 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2639 if (ret != SQLITE_OK) {
2640 _LOGD("Failed to commit transaction, Rollback now\n");
2641 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2645 _LOGD("Transaction Commit and End\n");
2647 pkgmgr_parser_close_db();
2651 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2654 ret = pkgmgr_parser_check_and_create_db(uid);
2656 _LOGD("Failed to open DB\n");
2659 /*Begin transaction*/
2660 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2661 if (ret != SQLITE_OK) {
2662 _LOGD("Failed to begin transaction\n");
2666 _LOGD("Transaction Begin\n");
2667 ret = __update_preload_condition_in_db();
2669 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2670 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2673 /*Commit transaction*/
2674 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2675 if (ret != SQLITE_OK) {
2676 _LOGD("Failed to commit transaction, Rollback now\n");
2677 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2681 _LOGD("Transaction Commit and End\n");
2683 pkgmgr_parser_close_db();
2687 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2691 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2693 _LOGD("Failed to open DB\n");
2697 /*Begin transaction*/
2698 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2699 if (ret != SQLITE_OK) {
2700 _LOGD("Failed to begin transaction\n");
2704 _LOGD("Transaction Begin\n");
2706 ret = __disable_global_app_for_user(appid, uid);
2708 ret = __enable_global_app_for_user(appid, uid);
2710 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2711 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2714 /*Commit transaction*/
2715 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2716 if (ret != SQLITE_OK) {
2717 _LOGD("Failed to commit transaction, Rollback now\n");
2718 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2722 _LOGD("Transaction Commit and End\n");
2724 pkgmgr_parser_close_db();
2729 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2731 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2734 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2738 ret = pkgmgr_parser_check_and_create_db(uid);
2740 _LOGD("Failed to open DB\n");
2744 /*Begin transaction*/
2745 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2746 if (ret != SQLITE_OK) {
2747 _LOGD("Failed to begin transaction\n");
2751 _LOGD("Transaction Begin\n");
2753 ret = __disable_app(appid);
2755 ret = __enable_app(appid);
2757 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2758 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2761 /*Commit transaction*/
2762 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2763 if (ret != SQLITE_OK) {
2764 _LOGD("Failed to commit transaction, Rollback now\n");
2765 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2769 _LOGD("Transaction Commit and End\n");
2771 pkgmgr_parser_close_db();