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.
27 #include <sys/types.h>
28 #include <sys/smack.h>
36 #include <system_info.h>
38 /* For multi-user support */
39 #include <tzplatform_config.h>
41 #include "pkgmgr-info.h"
42 #include "pkgmgrinfo_basic.h"
43 #include "pkgmgrinfo_debug.h"
44 #include "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
50 #define LOG_TAG "PKGMGR_PARSER"
52 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
53 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
54 #define MAX_QUERY_LEN 4096
62 #define XXHDPI "xxhdpi"
72 #define XXHDPI_MIN 481
73 #define XXHDPI_MAX 600
75 #define DB_LABEL "User::Home"
76 #define SET_SMACK_LABEL(x) \
78 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
79 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
81 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
84 sqlite3 *pkgmgr_parser_db;
85 sqlite3 *pkgmgr_cert_db;
88 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
89 "(package text primary key not null, " \
90 "package_type text DEFAULT 'tpk', " \
91 "package_version text, " \
92 "package_api_version text, " \
93 "package_tep_name text, " \
94 "install_location text, " \
95 "package_size text, " \
96 "package_removable text DEFAULT 'true', " \
97 "package_preload text DEFAULT 'false', " \
98 "package_readonly text DEFAULT 'false', " \
99 "package_update text DEFAULT 'false', " \
100 "package_appsetting text DEFAULT 'false', " \
101 "package_nodisplay text DEFAULT 'false', " \
102 "package_system text DEFAULT 'false', " \
103 "author_name text, " \
104 "author_email text, " \
105 "author_href text," \
106 "installed_time text," \
107 "installed_storage text," \
108 "storeclient_id text," \
110 "package_url text," \
113 "package_support_disable text DEFAULT 'false', " \
114 "package_disable text DEFAULT 'false')"
116 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
117 "(package text not null, " \
118 "package_locale text DEFAULT 'No Locale', " \
119 "package_label text, " \
120 "package_icon text, " \
121 "package_description text, " \
122 "package_license text, " \
124 "PRIMARY KEY(package, package_locale), " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
130 "(package text not null, " \
131 "privilege text not null, " \
132 "PRIMARY KEY(package, privilege) " \
133 "FOREIGN KEY(package) " \
134 "REFERENCES package_info(package) " \
137 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
138 "(app_id text primary key not null, " \
139 "app_component text, " \
141 "app_nodisplay text DEFAULT 'false', " \
143 "app_onboot text DEFAULT 'false', " \
144 "app_multiple text DEFAULT 'false', " \
145 "app_autorestart text DEFAULT 'false', " \
146 "app_taskmanage text DEFAULT 'false', " \
147 "app_enabled text DEFAULT 'true', " \
148 "app_hwacceleration text DEFAULT 'use-system-setting', " \
149 "app_screenreader text DEFAULT 'use-system-setting', " \
150 "app_mainapp text, " \
151 "app_recentimage text, " \
152 "app_launchcondition text, " \
153 "app_indicatordisplay text DEFAULT 'true', " \
154 "app_portraitimg text, " \
155 "app_landscapeimg text, " \
156 "app_guestmodevisibility text DEFAULT 'true', " \
157 "app_permissiontype text DEFAULT 'normal', " \
158 "app_preload text DEFAULT 'false', " \
159 "app_submode text DEFAULT 'false', " \
160 "app_submode_mainid text, " \
161 "app_installed_storage text, " \
162 "app_process_pool text DEFAULT 'false', " \
163 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
164 "app_ui_gadget text DEFAULT 'false', " \
165 "app_support_disable text DEFAULT 'false', " \
166 "app_disable text DEFAULT 'false', " \
167 "app_package_type text DEFAULT 'tpk', " \
168 "component_type text, " \
169 "package text not null, " \
170 "app_tep_name text, " \
171 "app_background_category INTEGER DEFAULT 0, " \
172 "app_root_path text, " \
173 "app_api_version text, " \
174 "app_effective_appid text, " \
175 "app_splash_screen_display text DEFAULT 'true', " \
176 "FOREIGN KEY(package) " \
177 "REFERENCES package_info(package) " \
180 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
181 "(app_id text not null, " \
182 "app_locale text DEFAULT 'No Locale', " \
185 "PRIMARY KEY(app_id,app_locale) " \
186 "FOREIGN KEY(app_id) " \
187 "REFERENCES package_app_info(app_id) " \
190 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
191 "(app_id text not null, " \
193 "app_icon_section text, " \
194 "app_icon_resolution text, " \
195 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
196 "FOREIGN KEY(app_id) " \
197 "REFERENCES package_app_info(app_id) " \
200 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
201 "(app_id text not null, " \
202 "app_locale text DEFAULT 'No Locale', " \
203 "app_image_section text, " \
205 "PRIMARY KEY(app_id,app_image_section) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
211 "(app_id text not null, " \
212 "app_control text not null, " \
213 "PRIMARY KEY(app_id,app_control) " \
214 "FOREIGN KEY(app_id) " \
215 "REFERENCES package_app_info(app_id) " \
218 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
219 "(app_id text not null, " \
220 "category text not null, " \
221 "PRIMARY KEY(app_id,category) " \
222 "FOREIGN KEY(app_id) " \
223 "REFERENCES package_app_info(app_id) " \
226 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
227 "(app_id text not null, " \
228 "md_key text not null, " \
229 "md_value text not null, " \
230 "PRIMARY KEY(app_id, md_key, md_value) " \
231 "FOREIGN KEY(app_id) " \
232 "REFERENCES package_app_info(app_id) " \
235 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
236 "(app_id text not null, " \
237 "pm_type text not null, " \
238 "pm_value text not null, " \
239 "PRIMARY KEY(app_id, pm_type, pm_value) " \
240 "FOREIGN KEY(app_id) " \
241 "REFERENCES package_app_info(app_id) " \
244 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
245 "(app_id text not null, " \
246 "data_share_path text not null, " \
247 "data_share_allowed text not null, " \
248 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
249 "FOREIGN KEY(app_id) " \
250 "REFERENCES package_app_info(app_id) " \
253 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
254 "(app_id text not null, " \
255 "data_share_request text not null, " \
256 "PRIMARY KEY(app_id,data_share_request) " \
257 "FOREIGN KEY(app_id) " \
258 "REFERENCES package_app_info(app_id) " \
261 /* FIXME: duplicated at pkgmgrinfo_db.c */
262 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
263 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
264 " cert_info TEXT UNIQUE, " \
265 " cert_id INTEGER PRIMARY KEY, " \
266 " cert_ref_count INTEGER NOT NULL)"
268 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
269 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
270 " package TEXT PRIMARY KEY, " \
271 " author_root_cert INTEGER, " \
272 " author_im_cert INTEGER, " \
273 " author_signer_cert INTEGER, " \
274 " dist_root_cert INTEGER, " \
275 " dist_im_cert INTEGER, " \
276 " dist_signer_cert INTEGER, " \
277 " dist2_root_cert INTEGER, " \
278 " dist2_im_cert INTEGER, " \
279 " dist2_signer_cert INTEGER)"
281 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
282 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
283 "AFTER DELETE ON package_cert_info " \
285 " UPDATE package_cert_index_info SET" \
286 " cert_ref_count = cert_ref_count - 1" \
287 " WHERE cert_id = OLD.author_root_cert" \
288 " OR cert_id = OLD.author_im_cert" \
289 " OR cert_id = OLD.author_signer_cert" \
290 " OR cert_id = OLD.dist_root_cert" \
291 " OR cert_id = OLD.dist_im_cert" \
292 " OR cert_id = OLD.dist_signer_cert" \
293 " OR cert_id = OLD.dist2_root_cert" \
294 " OR cert_id = OLD.dist2_im_cert" \
295 " OR cert_id = OLD.dist2_signer_cert;" \
298 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
299 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
300 "AFTER UPDATE ON package_cert_index_info " \
301 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
302 " WHERE cert_id = OLD.cert_id) = 0) "\
304 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
307 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
308 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
309 "AFTER UPDATE ON package_cert_info " \
310 "WHEN (OLD.%s IS NOT NULL) " \
312 " UPDATE package_cert_index_info SET" \
313 " cert_ref_count = cert_ref_count - 1" \
314 " WHERE cert_id = OLD.%s;" \
317 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
318 "(app_id text not null, " \
319 "providerid text not null, " \
320 "access text not null, " \
321 "type text not null, " \
322 "PRIMARY KEY(app_id, providerid, access, type) " \
323 "FOREIGN KEY(app_id) " \
324 "REFERENCES package_app_info(app_id) " \
327 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
328 "(app_id text not null, " \
329 "uid text not null, " \
330 "PRIMARY KEY(app_id, uid))"
332 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
333 "create table if not exists package_app_splash_screen " \
334 "(app_id text not null, " \
335 "src text not null, " \
336 "type text not null, " \
337 "orientation text not null, " \
338 "indicatordisplay text, " \
340 "PRIMARY KEY(app_id, orientation, operation) " \
341 "FOREIGN KEY(app_id) " \
342 "REFERENCES package_app_info(app_id) " \
345 static int __insert_application_info(manifest_x *mfx);
346 static int __insert_application_appcategory_info(manifest_x *mfx);
347 static int __insert_application_appcontrol_info(manifest_x *mfx);
348 static int __insert_application_appmetadata_info(manifest_x *mfx);
349 static int __insert_application_share_allowed_info(manifest_x *mfx);
350 static int __insert_application_share_request_info(manifest_x *mfx);
351 static int __insert_application_datacontrol_info(manifest_x *mfx);
352 static void __insert_application_locale_info(gpointer data, gpointer userdata);
353 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
354 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
355 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
356 static int __delete_subpkg_info_from_db(char *appid);
357 static int __delete_appinfo_from_db(char *db_table, const char *appid);
358 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
359 static int __exec_query(char *query);
360 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
361 char **label, char **license, char **icon, char **description, char **author);
362 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
363 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
364 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
365 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
366 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
367 static int __parserdb_change_perm(const char *db_file, uid_t uid);
369 #define REGULAR_USER 5000
370 static inline uid_t _getuid(void)
372 uid_t uid = getuid();
374 if (uid < REGULAR_USER)
375 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
380 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
383 __delete_subpkg_info_from_db(coltxt[0]);
388 static const char *__get_str(const char *str)
392 return PKGMGR_PARSER_EMPTY_STR;
398 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
403 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
404 if (ret != SQLITE_OK) {
405 _LOGD("connect db [%s] failed!\n", db_path);
413 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
415 manifest_x *mfx = (manifest_x *)data;
421 if (mfx->application == NULL)
423 app = (application_x *)mfx->application->data;
424 for(i = 0; i < ncols; i++)
426 if (strcmp(colname[i], "app_id") == 0) {
428 appid = strdup(coltxt[i]);
429 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
431 status = strdup(coltxt[i]);
437 _LOGD("app id is NULL\n");
440 /*update guest mode visibility*/
441 for (tmp = mfx->application; tmp; tmp = tmp->next) {
442 app = (application_x *)tmp->data;
445 if (strcmp(app->appid, appid) == 0) {
446 free((void *)app->guestmode_visibility);
447 app->guestmode_visibility = strdup(status);
463 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
465 char *error_message = NULL;
466 char query[MAX_QUERY_LEN] = {'\0'};
467 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
469 sqlite3_exec(pkgmgr_parser_db, query,
470 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
471 _LOGD("Don't execute query = %s error message = %s\n",
472 query, error_message);
473 sqlite3_free(error_message);
478 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
480 char *error_message = NULL;
482 sqlite3_exec(db_handle, db_query,
483 NULL, NULL, &error_message)) {
484 _LOGD("Don't execute query = %s error message = %s\n",
485 db_query, error_message);
486 sqlite3_free(error_message);
489 sqlite3_free(error_message);
493 static int __exec_query(char *query)
495 char *error_message = NULL;
497 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
498 _LOGE("Don't execute query = %s error message = %s\n", query,
500 sqlite3_free(error_message);
503 sqlite3_free(error_message);
507 static int __exec_query_no_msg(char *query)
509 char *error_message = NULL;
511 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
512 sqlite3_free(error_message);
515 sqlite3_free(error_message);
519 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
527 for (tmp = lbls; tmp; tmp = tmp->next) {
528 lbl = (label_x *)tmp->data;
532 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
534 for (tmp = lcns; tmp; tmp = tmp->next) {
535 lcn = (license_x *)tmp->data;
539 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
541 for (tmp = icns; tmp; tmp = tmp->next) {
542 icn = (icon_x *)tmp->data;
546 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
548 for (tmp = dcns; tmp; tmp = tmp->next) {
549 dcn = (description_x *)tmp->data;
553 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
555 for (tmp = aths; tmp; tmp = tmp->next) {
556 ath = (author_x *)tmp->data;
560 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
566 static GList *__create_icon_list(GList *appicon, GList *icns)
571 for (tmp = icns; tmp; tmp = tmp->next) {
572 icn = (icon_x *)tmp->data;
576 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
581 static GList *__create_image_list(GList *appimage, GList *imgs)
586 for (tmp = imgs; tmp; tmp = tmp->next) {
587 img = (image_x *)tmp->data;
591 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
596 static void __trimfunc(GList* trim_list)
598 char *trim_data = NULL;
602 list = g_list_first(trim_list);
605 trim_data = (char *)list->data;
608 if (strcmp(trim_data, prev) == 0) {
609 trim_list = g_list_remove(trim_list, trim_data);
610 list = g_list_first(trim_list);
619 list = g_list_next(list);
623 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
625 if (a == NULL || b == NULL)
627 if (strcmp((char*)a, (char*)b) == 0)
629 if (strcmp((char*)a, (char*)b) < 0)
631 if (strcmp((char*)a, (char*)b) > 0)
636 static int __check_dpi(const char *dpi_char, int dpi_int)
638 if (dpi_char == NULL)
641 if (strcasecmp(dpi_char, LDPI) == 0) {
642 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
646 } else if (strcasecmp(dpi_char, MDPI) == 0) {
647 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
651 } else if (strcasecmp(dpi_char, HDPI) == 0) {
652 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
656 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
657 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
661 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
662 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
670 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
673 char *icon_filename = NULL;
674 char modified_iconpath[BUFSIZE] = { '\0' };
675 char icon_path[BUFSIZE] = { '\0' };
679 if (orig_icon_path == NULL)
682 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
686 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
687 dpi_path[0] = "LDPI";
688 dpi_path[1] = "ldpi";
689 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
690 dpi_path[0] = "MDPI";
691 dpi_path[1] = "mdpi";
692 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
693 dpi_path[0] = "HDPI";
694 dpi_path[1] = "hdpi";
695 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
696 dpi_path[0] = "XHDPI";
697 dpi_path[1] = "xhdpi";
698 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
699 dpi_path[0] = "XXHDPI";
700 dpi_path[1] = "xxhdpi";
702 _LOGE("Unidentified dpi[%d]", dpi);
706 icon_filename = strrchr(orig_icon_path, '/');
707 if (icon_filename == NULL)
710 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
711 for (i = 0; i < 2; i++) {
712 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
713 if (access(modified_iconpath, F_OK) != -1) {
714 // if exists, return modified icon path
715 *new_icon_path = strdup(modified_iconpath);
723 static gint __compare_icon(gconstpointer a, gconstpointer b)
725 icon_x *icon = (icon_x *)a;
727 char *icon_folder_path = NULL;
729 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
732 if (icon->dpi != NULL)
735 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
737 icon->text = icon_folder_path;
743 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
745 icon_x *icon = (icon_x *)a;
746 int dpi = GPOINTER_TO_INT(b);
748 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
751 if (icon->dpi == NULL)
754 if (__check_dpi(icon->dpi, dpi) == 0)
760 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
762 icon_x *icon = (icon_x *)a;
763 char *lang = (char *)b;
764 char *icon_folder_path = NULL;
766 if (icon->dpi != NULL)
769 if (strcasecmp(icon->lang, lang) == 0) {
770 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
771 //icon for no locale. check existance of folder-hierachied default icons
772 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
774 icon->text = icon_folder_path;
783 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
785 icon_x *icon = (icon_x *)a;
786 char *lang = (char *)b;
789 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
793 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
799 static char *__find_icon(GList *icons, const char *lang)
805 // first, find icon whose locale and dpi with given lang and system's dpi has matched
806 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
808 icon = (icon_x *)tmp->data;
809 return (char *)icon->text;
812 // if first has failed, find icon whose locale has matched
813 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
815 icon = (icon_x *)tmp->data;
816 return (char *)icon->text;
819 // if second has failed, find icon whose dpi has matched with system's dpi
820 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
823 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
825 icon = (icon_x *)tmp->data;
826 return (char *)icon->text;
829 // last, find default icon marked as "No Locale"
830 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
832 icon = (icon_x *)tmp->data;
833 return (char *)icon->text;
839 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
840 char **label, char **license, char **icon, char **description, char **author)
847 for (tmp = lbls; tmp; tmp = tmp->next) {
848 lbl = (label_x *)tmp->data;
852 if (strcmp(lbl->lang, (char *)data) == 0) {
853 *label = (char*)lbl->text;
858 for (tmp = lcns; tmp; tmp = tmp->next) {
859 lcn = (license_x *)tmp->data;
863 if (strcmp(lcn->lang, (char *)data) == 0) {
864 *license = (char*)lcn->text;
870 *icon = __find_icon(icns, (char *)data);
872 for (tmp = dcns; tmp; tmp = tmp->next) {
873 dcn = (description_x *)tmp->data;
877 if (strcmp(dcn->lang, (char *)data) == 0) {
878 *description = (char*)dcn->text;
883 for (tmp = aths; tmp; tmp = tmp->next) {
884 ath = (author_x *)tmp->data;
888 if (strcmp(ath->lang, (char *)data) == 0) {
889 *author = (char*)ath->text;
897 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
901 for (tmp = icns; tmp; tmp = tmp->next) {
902 icn = (icon_x *)tmp->data;
906 if (strcmp(icn->section, (char *)data) == 0) {
907 *icon = (char*)icn->text;
908 *resolution = (char*)icn->resolution;
915 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
919 for (tmp = imgs; tmp; tmp = tmp->next) {
920 img = (image_x *)tmp->data;
924 if (strcmp(img->section, (char *)data) == 0) {
925 *lang = (char*)img->lang;
926 *image = (char*)img->text;
933 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
938 char *description = NULL;
939 char *license = NULL;
943 manifest_x *mfx = (manifest_x *)userdata;
944 GList *lbl = mfx->label;
945 GList *lcn = mfx->license;
946 GList *icn = mfx->icon;
947 GList *dcn = mfx->description;
948 GList *ath = mfx->author;
950 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
951 if (!label && !description && !icon && !license && !author)
954 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
955 "package_label, package_icon, package_description, package_license, package_author) values " \
956 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
961 __get_str(description),
965 ret = __exec_query(query);
967 _LOGD("Package Localized Info DB Insert failed\n");
972 static void __insert_application_locale_info(gpointer data, gpointer userdata)
979 application_x *app = (application_x*)userdata;
980 GList *lbl = app->label;
981 GList *icn = app->icon;
983 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
987 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
988 "app_label, app_icon) values " \
989 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
990 __get_str(label), __get_str(icon));
991 ret = __exec_query(query);
993 _LOGD("Package UiApp Localized Info DB Insert failed\n");
997 /*insert ui app locale info to pkg locale to get mainapp data */
998 if (strcasecmp(app->mainapp, "true")==0) {
999 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
1000 "package_label, package_icon, package_description, package_license, package_author) values " \
1001 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1006 PKGMGR_PARSER_EMPTY_STR,
1007 PKGMGR_PARSER_EMPTY_STR,
1008 PKGMGR_PARSER_EMPTY_STR);
1010 ret = __exec_query_no_msg(query);
1011 sqlite3_free(query);
1014 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1015 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1016 ret = __exec_query_no_msg(query);
1017 sqlite3_free(query);
1022 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1026 char *resolution = NULL;
1027 char query[MAX_QUERY_LEN] = {'\0'};
1029 application_x *app = (application_x*)userdata;
1030 GList *icn = app->icon;
1032 __extract_icon_data(data, icn, &icon, &resolution);
1033 if (!icon && !resolution)
1035 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1036 "app_icon, app_icon_section, app_icon_resolution) values " \
1037 "('%q', '%q', '%q', '%q')", app->appid,
1038 icon, (char*)data, resolution);
1040 ret = __exec_query(query);
1042 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1046 static void __insert_application_image_info(gpointer data, gpointer userdata)
1051 char query[MAX_QUERY_LEN] = {'\0'};
1053 application_x *app = (application_x*)userdata;
1054 GList *image = app->image;
1056 __extract_image_data(data, image, &lang, &img);
1059 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1060 "app_image_section, app_image) values " \
1061 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1063 ret = __exec_query(query);
1065 _LOGD("Package UiApp image Info DB Insert failed\n");
1070 static int __insert_mainapp_info(manifest_x *mfx)
1075 char query[MAX_QUERY_LEN] = {'\0'};
1076 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1077 app = (application_x *)tmp->data;
1080 snprintf(query, MAX_QUERY_LEN,
1081 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1083 ret = __exec_query(query);
1085 _LOGD("Package App Info DB Insert Failed\n");
1088 if (strcasecmp(app->mainapp, "True")==0)
1089 mfx->mainapp_id = strdup(app->appid);
1092 if (mfx->mainapp_id == NULL) {
1093 if (mfx->application == NULL)
1095 app = (application_x *)mfx->application->data;
1099 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1101 _LOGD("Not valid appid\n");
1105 ret = __exec_query(query);
1107 _LOGD("Package UiApp Info DB Insert Failed\n");
1111 free((void *)app->mainapp);
1112 app->mainapp= strdup("true");
1113 mfx->mainapp_id = strdup(app->appid);
1116 memset(query, '\0', MAX_QUERY_LEN);
1117 snprintf(query, MAX_QUERY_LEN,
1118 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1119 ret = __exec_query(query);
1121 _LOGD("Package Info DB update Failed\n");
1128 static int __convert_background_category(GList *category_list)
1131 GList *tmp_list = category_list;
1132 char *category_data = NULL;
1134 if (category_list == NULL)
1137 while (tmp_list != NULL) {
1138 category_data = (char *)tmp_list->data;
1139 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1140 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1141 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1142 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1143 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1144 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1145 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1146 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1147 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1148 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1149 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1150 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1151 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1152 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1154 _LOGE("Unidentified category [%s]", category_data);
1156 tmp_list = g_list_next(tmp_list);
1162 static const char *__find_effective_appid(GList *metadata_list)
1167 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1168 md = (metadata_x *)tmp_list->data;
1169 if (md == NULL || md->key == NULL)
1172 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1181 /* _PRODUCT_LAUNCHING_ENHANCED_
1182 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1184 static int __insert_application_info(manifest_x *mfx)
1189 int background_value = 0;
1190 char query[MAX_QUERY_LEN] = {'\0'};
1192 const char *effective_appid;
1195 type = strdup(mfx->type);
1197 type = strdup("tpk");
1199 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1200 app = (application_x *)tmp->data;
1204 background_value = __convert_background_category(app->background_category);
1205 if (background_value < 0) {
1206 _LOGE("Failed to retrieve background value[%d]", background_value);
1207 background_value = 0;
1210 effective_appid = __find_effective_appid(app->metadata);
1212 snprintf(query, MAX_QUERY_LEN,
1213 "insert into package_app_info(" \
1214 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1215 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1216 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1217 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1218 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1219 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1220 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1221 "app_effective_appid, app_splash_screen_display) " \
1223 "'%s', '%s', '%s', '%s', '%s', " \
1224 "'%s', '%s', '%s', '%s', '%s', " \
1225 "'%s', '%s', '%s', '%s', '%s', " \
1226 "'%s', '%s', '%s', '%s', '%s', " \
1227 "'%s', '%s', '%s', '%s', '%s', " \
1228 "'%s', '%s', '%s', '%s', '%s', " \
1229 "'%s', '%d', '%s', '%s', '%s', " \
1231 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1232 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1233 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1234 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1235 app->guestmode_visibility, app->permission_type,
1236 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1237 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1238 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1239 __get_str(effective_appid), app->splash_screen_display);
1241 ret = __exec_query(query);
1243 _LOGD("Package UiApp Info DB Insert Failed\n");
1248 memset(query, '\0', MAX_QUERY_LEN);
1257 static int __insert_application_appcategory_info(manifest_x *mfx)
1264 char query[MAX_QUERY_LEN] = {'\0'};
1265 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1266 app = (application_x *)app_tmp->data;
1269 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1270 ct = (const char *)ct_tmp->data;
1273 snprintf(query, MAX_QUERY_LEN,
1274 "insert into package_app_app_category(app_id, category) " \
1275 "values('%s','%s')",\
1277 ret = __exec_query(query);
1279 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1282 memset(query, '\0', MAX_QUERY_LEN);
1288 static int __insert_application_appmetadata_info(manifest_x *mfx)
1295 char query[MAX_QUERY_LEN] = {'\0'};
1296 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1297 app = (application_x *)app_tmp->data;
1300 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1301 md = (metadata_x *)md_tmp->data;
1305 snprintf(query, MAX_QUERY_LEN,
1306 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1307 "values('%s','%s', '%s')",\
1308 app->appid, md->key, md->value ? md->value : "");
1309 ret = __exec_query(query);
1311 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1315 memset(query, '\0', MAX_QUERY_LEN);
1321 static int __insert_application_apppermission_info(manifest_x *mfx)
1328 char query[MAX_QUERY_LEN] = {'\0'};
1329 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1330 app = (application_x *)app_tmp->data;
1333 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1334 pm = (permission_x *)pm_tmp->data;
1337 snprintf(query, MAX_QUERY_LEN,
1338 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1339 "values('%s','%s', '%s')",\
1340 app->appid, pm->type, pm->value);
1341 ret = __exec_query(query);
1343 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1346 memset(query, '\0', MAX_QUERY_LEN);
1352 static int __insert_application_appcontrol_info(manifest_x *mfx)
1356 GList *acontrol_tmp;
1357 appcontrol_x *acontrol;
1359 char query[MAX_QUERY_LEN] = {'\0'};
1360 char buf[BUFSIZE] = {'\0'};
1361 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1362 app = (application_x *)app_tmp->data;
1365 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1366 acontrol = (appcontrol_x *)acontrol_tmp->data;
1367 if (acontrol == NULL)
1369 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1370 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1371 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1372 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1373 snprintf(query, MAX_QUERY_LEN,
1374 "insert into package_app_app_control(app_id, app_control) " \
1375 "values('%s', '%s')",\
1377 ret = __exec_query(query);
1379 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1382 memset(query, '\0', MAX_QUERY_LEN);
1388 static int __insert_application_datacontrol_info(manifest_x *mfx)
1395 char query[MAX_QUERY_LEN] = {'\0'};
1397 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1398 app = (application_x *)app_tmp->data;
1401 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1402 dc = (datacontrol_x *)dc_tmp->data;
1405 snprintf(query, MAX_QUERY_LEN,
1406 "insert into package_app_data_control(app_id, providerid, access, type) " \
1407 "values('%s', '%s', '%s', '%s')",\
1413 ret = __exec_query(query);
1415 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1418 memset(query, '\0', MAX_QUERY_LEN);
1424 static int __insert_application_share_request_info(manifest_x *mfx)
1433 char query[MAX_QUERY_LEN] = {'\0'};
1434 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1435 app = (application_x *)app_tmp->data;
1438 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1439 ds = (datashare_x *)ds_tmp->data;
1442 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1443 rq = (const char *)rq_tmp->data;
1446 snprintf(query, MAX_QUERY_LEN,
1447 "insert into package_app_share_request(app_id, data_share_request) " \
1448 "values('%s', '%s')",\
1450 ret = __exec_query(query);
1452 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1455 memset(query, '\0', MAX_QUERY_LEN);
1462 static int __insert_application_share_allowed_info(manifest_x *mfx)
1473 char query[MAX_QUERY_LEN] = {'\0'};
1474 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1475 app = (application_x *)app_tmp->data;
1478 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1479 ds = (datashare_x *)ds_tmp->data;
1482 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1483 df = (define_x *)df_tmp->data;
1486 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1487 al = (const char *)al_tmp->data;
1490 snprintf(query, MAX_QUERY_LEN,
1491 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1492 "values('%s', '%s', '%s')",\
1493 app->appid, df->path, al);
1494 ret = __exec_query(query);
1496 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1499 memset(query, '\0', MAX_QUERY_LEN);
1507 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1509 splashscreen_x *ss = (splashscreen_x *)a;
1510 const char *orientation = (const char *)b;
1513 if (ss->operation || ss->dpi == NULL)
1516 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1520 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1526 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1528 splashscreen_x *ss = (splashscreen_x *)a;
1529 const char *orientation = (const char *)b;
1531 if (ss->operation || ss->dpi)
1534 if (strcasecmp(ss->orientation, orientation) == 0)
1540 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1541 const char *orientation)
1545 tmp = g_list_find_custom(splashscreens, orientation,
1546 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1548 return (splashscreen_x *)tmp->data;
1550 tmp = g_list_find_custom(splashscreens, orientation,
1551 (GCompareFunc)__compare_splashscreen_with_orientation);
1553 return (splashscreen_x *)tmp->data;
1558 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1560 splashscreen_x *ss = (splashscreen_x *)data;
1561 GList **list = (GList **)user_data;
1564 if (ss->operation == NULL || ss->dpi == NULL)
1567 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1571 if (__check_dpi(ss->dpi, dpi) != 0)
1574 *list = g_list_append(*list, ss);
1577 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1579 splashscreen_x *ss = (splashscreen_x *)data;
1580 GList **list = (GList **)user_data;
1581 splashscreen_x *ss_tmp;
1584 if (ss->operation == NULL || ss->dpi)
1587 for (tmp = *list; tmp; tmp = tmp->next) {
1588 ss_tmp = (splashscreen_x *)tmp->data;
1589 if (ss_tmp->operation
1590 && strcmp(ss_tmp->operation, ss->operation) == 0
1591 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1595 *list = g_list_append(*list, ss);
1598 static GList *__find_splashscreens(GList *splashscreens)
1603 g_list_foreach(splashscreens,
1604 __find_appcontrol_splashscreen_with_dpi, &list);
1605 g_list_foreach(splashscreens,
1606 __find_appcontrol_splashscreen, &list);
1608 ss = __find_default_splashscreen(splashscreens, "portrait");
1610 list = g_list_append(list, ss);
1611 ss = __find_default_splashscreen(splashscreens, "landscape");
1613 list = g_list_append(list, ss);
1618 static int __insert_application_splashscreen_info(manifest_x *mfx)
1626 char query[MAX_QUERY_LEN];
1628 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1629 app = (application_x *)app_tmp->data;
1630 if (app == NULL || app->splashscreens == NULL)
1633 ss_tmp = __find_splashscreens(app->splashscreens);
1637 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1638 ss = (splashscreen_x *)tmp->data;
1639 snprintf(query, sizeof(query),
1640 "insert into package_app_splash_screen" \
1641 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1642 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1643 app->appid, ss->src, ss->type, ss->orientation,
1644 ss->indicatordisplay, __get_str(ss->operation));
1645 ret = __exec_query(query);
1647 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1650 memset(query, '\0', MAX_QUERY_LEN);
1652 g_list_free(ss_tmp);
1657 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1662 char query[MAX_QUERY_LEN];
1664 const char *image_type;
1665 const char *indicatordisplay;
1666 const char *orientation;
1667 const char *operation = NULL;
1669 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1670 app = (application_x *)app_tmp->data;
1672 (app->portraitimg == NULL && app->landscapeimg == NULL))
1674 image_type = "img"; /* default */
1675 if (app->effectimage_type) {
1676 tmp = strstr(app->effectimage_type, "edj");
1680 indicatordisplay = "true"; /* default */
1681 if (app->indicatordisplay)
1682 indicatordisplay = app->indicatordisplay;
1683 if (app->portraitimg) {
1684 orientation = "portrait";
1685 snprintf(query, sizeof(query),
1686 "insert into package_app_splash_screen" \
1687 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1688 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1689 app->appid, app->portraitimg, image_type,
1690 orientation, indicatordisplay, __get_str(operation));
1691 ret = __exec_query(query);
1693 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1696 memset(query, '\0', MAX_QUERY_LEN);
1698 if (app->landscapeimg) {
1699 orientation = "landscape";
1700 snprintf(query, sizeof(query),
1701 "insert into package_app_splash_screen" \
1702 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1703 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1704 app->appid, app->landscapeimg, image_type,
1705 orientation, indicatordisplay, __get_str(operation));
1706 ret = __exec_query(query);
1708 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1711 memset(query, '\0', MAX_QUERY_LEN);
1717 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1724 char query[MAX_QUERY_LEN];
1726 char *tmpptr = NULL;
1727 const char *operation;
1728 const char *portraitimg;
1729 const char *landscapeimg;
1730 const char *indicatordisplay;
1731 const char *orientation;
1732 const char *image_type;
1734 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1735 app = (application_x *)app_tmp->data;
1739 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1740 md = (metadata_x *)md_tmp->data;
1741 if (md == NULL || md->key == NULL || md->value == NULL)
1744 if (strcasestr(md->key, "operation_effect=")) {
1745 operation = index(md->key, '=');
1746 if ((operation + 1) != NULL)
1750 } else if (strcasestr(md->key, "launch_effect")) {
1757 landscapeimg = NULL;
1758 indicatordisplay = "true"; /* default */
1759 token = strtok_r(md->value, "|", &tmpptr);
1760 while (token != NULL) {
1761 if (strcasestr(token, "portrait-effectimage=")) {
1762 portraitimg = index(token, '=');
1763 if ((portraitimg + 1) != NULL)
1767 } else if (strcasestr(token, "landscape-effectimage=")) {
1768 landscapeimg = index(token, '=');
1769 if ((landscapeimg + 1) != NULL)
1772 landscapeimg = NULL;
1773 } else if (strcasestr(token, "indicatordisplay=")) {
1774 indicatordisplay = index(token, '=');
1775 if ((indicatordisplay + 1) != NULL)
1778 indicatordisplay = "true";
1781 token = strtok_r(NULL, "|", &tmpptr);
1785 orientation = "portrait";
1787 if (strcasestr(portraitimg, "edj"))
1789 snprintf(query, sizeof(query),
1790 "insert into package_app_splash_screen" \
1791 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1792 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1793 app->appid, portraitimg, image_type,
1794 orientation, indicatordisplay, __get_str(operation));
1795 ret = __exec_query(query);
1797 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1800 memset(query, '\0', MAX_QUERY_LEN);
1803 orientation = "landscape";
1805 if (strcasestr(landscapeimg, "edj"))
1807 snprintf(query, sizeof(query),
1808 "insert into package_app_splash_screen" \
1809 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1810 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1811 app->appid, landscapeimg, image_type,
1812 orientation, indicatordisplay, __get_str(operation));
1813 ret = __exec_query(query);
1815 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1818 memset(query, '\0', MAX_QUERY_LEN);
1826 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1830 const char *pv = NULL;
1831 char query[MAX_QUERY_LEN] = { '\0' };
1834 const char *auth_name = NULL;
1835 const char *auth_email = NULL;
1836 const char *auth_href = NULL;
1838 GList *pkglocale = NULL;
1839 GList *applocale = NULL;
1840 GList *appicon = NULL;
1841 GList *appimage = NULL;
1843 if (mfx->author && mfx->author->data) {
1844 author = (author_x *)mfx->author->data;
1846 auth_name = author->text;
1848 auth_email = author->email;
1850 auth_href = author->href;
1853 /*Insert in the package_cert_info CERT_DB*/
1854 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1855 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1856 if (ret != PMINFO_R_OK) {
1857 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1858 _LOGE("Cert Info DB create handle failed\n");
1861 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1862 if (ret != PMINFO_R_OK) {
1863 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1864 _LOGE("Cert Info DB Insert Failed\n");
1868 /*Insert in the package_info DB*/
1869 snprintf(query, MAX_QUERY_LEN,
1870 "insert into package_info(" \
1871 "package, package_type, package_version, package_api_version, package_tep_name, " \
1872 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1873 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1874 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1875 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1877 "'%s', '%s', '%s', '%s', '%s', " \
1878 "'%s', '%s', '%s', '%s', '%s', " \
1879 "'%s', '%s', '%s', '%s', '%s', " \
1880 "'%s', '%s', '%s', '%s', '%s', " \
1881 "'%s', '%s', '%s', '%s', '%s')", \
1882 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1883 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1884 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1885 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1886 __get_str(mfx->storeclient_id),
1887 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1889 ret = __exec_query(query);
1891 _LOGD("Package Info DB Insert Failed\n");
1895 /*Insert in the package_privilege_info DB*/
1896 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1897 pv = (const char *)tmp->data;
1900 memset(query, '\0', MAX_QUERY_LEN);
1901 snprintf(query, MAX_QUERY_LEN,
1902 "insert into package_privilege_info(package, privilege) " \
1903 "values('%s','%s')",\
1905 ret = __exec_query(query);
1907 _LOGD("Package Privilege Info DB Insert Failed\n");
1912 if (mfx->application != NULL) {
1913 ret = __insert_mainapp_info(mfx);
1918 /*Insert the package locale*/
1919 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1920 /*remove duplicated data in pkglocale*/
1921 __trimfunc(pkglocale);
1923 /*Insert the app locale, icon, image info */
1924 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1925 app = (application_x *)tmp->data;
1928 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1929 appicon = __create_icon_list(appicon, app->icon);
1930 appimage = __create_image_list(appimage, app->image);
1932 /*remove duplicated data in applocale*/
1933 __trimfunc(applocale);
1934 __trimfunc(appicon);
1935 __trimfunc(appimage);
1937 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1939 /*native app locale info*/
1940 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1941 app = (application_x *)tmp->data;
1944 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1945 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1946 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1949 g_list_free(pkglocale);
1951 g_list_free(applocale);
1953 g_list_free(appicon);
1955 g_list_free(appimage);
1958 /*Insert in the package_app_info DB*/
1959 ret = __insert_application_info(mfx);
1962 /*Insert in the package_app_app_control DB*/
1963 ret = __insert_application_appcontrol_info(mfx);
1967 /*Insert in the package_app_app_category DB*/
1968 ret = __insert_application_appcategory_info(mfx);
1972 /*Insert in the package_app_app_metadata DB*/
1973 ret = __insert_application_appmetadata_info(mfx);
1977 /*Insert in the package_app_app_permission DB*/
1978 ret = __insert_application_apppermission_info(mfx);
1982 /*Insert in the package_app_share_allowed DB*/
1983 ret = __insert_application_share_allowed_info(mfx);
1987 /*Insert in the package_app_share_request DB*/
1988 ret = __insert_application_share_request_info(mfx);
1992 /*Insert in the package_app_data_control DB*/
1993 ret = __insert_application_datacontrol_info(mfx);
1997 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1998 ret = __insert_application_legacy_splashscreen_info(mfx);
2002 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2003 ret = __insert_application_metadata_splashscreen_info(mfx);
2007 /*Insert in the package_app_splash_screen DB*/
2008 ret = __insert_application_splashscreen_info(mfx);
2016 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2018 char query[MAX_QUERY_LEN] = { '\0' };
2020 memset(query, '\0', MAX_QUERY_LEN);
2021 snprintf(query, MAX_QUERY_LEN,
2022 "delete from %s where app_id='%s'", db_table, appid);
2023 ret = __exec_query(query);
2025 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2031 static int __delete_subpkg_info_from_db(char *appid)
2035 ret = __delete_appinfo_from_db("package_app_info", appid);
2038 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2041 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2044 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2047 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2050 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2053 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2056 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2059 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2062 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2065 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2068 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2075 static int __delete_subpkg_from_db(manifest_x *mfx)
2077 char query[MAX_QUERY_LEN] = { '\0' };
2078 char *error_message = NULL;
2080 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2082 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2083 _LOGE("Don't execute query = %s error message = %s\n", query,
2085 sqlite3_free(error_message);
2088 sqlite3_free(error_message);
2093 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2095 char query[MAX_QUERY_LEN] = { '\0' };
2099 /*Delete from cert table*/
2100 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2102 _LOGD("Cert Info DB Delete Failed\n");
2106 /*Delete from Package Info DB*/
2107 snprintf(query, MAX_QUERY_LEN,
2108 "delete from package_info where package='%s'", mfx->package);
2109 ret = __exec_query(query);
2111 _LOGD("Package Info DB Delete Failed\n");
2114 memset(query, '\0', MAX_QUERY_LEN);
2116 /*Delete from Package Localized Info*/
2117 snprintf(query, MAX_QUERY_LEN,
2118 "delete from package_localized_info where package='%s'", mfx->package);
2119 ret = __exec_query(query);
2121 _LOGD("Package Localized Info DB Delete Failed\n");
2125 /*Delete from Package Privilege Info*/
2126 snprintf(query, MAX_QUERY_LEN,
2127 "delete from package_privilege_info where package='%s'", mfx->package);
2128 ret = __exec_query(query);
2130 _LOGD("Package Privilege Info DB Delete Failed\n");
2134 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2135 app = (application_x *)tmp->data;
2138 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2141 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2144 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2147 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2150 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2153 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2156 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2159 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2162 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2165 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2168 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2171 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2176 /* if main package has sub pkg, delete sub pkg data*/
2177 __delete_subpkg_from_db(mfx);
2182 static int __disable_app(const char *appid)
2185 char query[MAX_QUERY_LEN] = {'\0'};
2186 sqlite3_snprintf(MAX_QUERY_LEN, query,
2187 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2189 ret = __exec_query(query);
2191 _LOGD("Insert global app disable failed\n");
2196 static int __enable_app(const char *appid)
2199 char query[MAX_QUERY_LEN] = {'\0'};
2200 sqlite3_snprintf(MAX_QUERY_LEN, query,
2201 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2203 ret = __exec_query(query);
2205 _LOGD("Insert global app disable failed\n");
2210 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2213 char query[MAX_QUERY_LEN] = {'\0'};
2215 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2216 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2218 ret = __exec_query(query);
2220 _LOGD("Insert global app disable failed\n");
2225 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2228 char query[MAX_QUERY_LEN] = {'\0'};
2230 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2231 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2233 ret = __exec_query(query);
2235 _LOGD("Delete global app disable failed\n");
2240 static int __update_preload_condition_in_db()
2243 char query[MAX_QUERY_LEN] = {'\0'};
2245 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2247 ret = __exec_query(query);
2249 _LOGD("Package preload_condition update failed\n");
2254 API int pkgmgr_parser_initialize_db(uid_t uid)
2258 char query[MAX_QUERY_LEN];
2259 static const char *columns[] = {
2260 "author_root_cert", "author_im_cert", "author_signer_cert",
2261 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2262 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2266 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2268 _LOGD("package info DB initialization failed\n");
2271 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2273 _LOGD("package localized info DB initialization failed\n");
2276 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2278 _LOGD("package app app privilege DB initialization failed\n");
2281 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2283 _LOGD("package app info DB initialization failed\n");
2286 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2288 _LOGD("package app localized info DB initialization failed\n");
2291 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2293 _LOGD("package app icon localized info DB initialization failed\n");
2296 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2298 _LOGD("package app image info DB initialization failed\n");
2301 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2303 _LOGD("package app app control DB initialization failed\n");
2306 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2308 _LOGD("package app app category DB initialization failed\n");
2311 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2313 _LOGD("package app app category DB initialization failed\n");
2316 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2318 _LOGD("package app app permission DB initialization failed\n");
2321 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2323 _LOGD("package app share allowed DB initialization failed\n");
2326 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2328 _LOGD("package app share request DB initialization failed\n");
2331 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2333 _LOGD("package app data control DB initialization failed\n");
2337 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2339 _LOGD("package app disable for user DB initialization failed\n");
2343 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2345 _LOGD("package app splash screen DB initialization failed\n");
2350 /* TODO: refactor this code */
2351 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2353 _LOGD("package cert info DB initialization failed\n");
2356 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2358 _LOGD("package cert index info DB initialization failed\n");
2361 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2363 _LOGD("package cert info DB initialization failed\n");
2366 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2368 _LOGD("package cert index info DB initialization failed\n");
2371 for (i = 0; columns[i] != NULL; i++) {
2372 snprintf(query, sizeof(query),
2373 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2374 columns[i], columns[i], columns[i]);
2375 ret = __initialize_db(pkgmgr_cert_db, query);
2377 _LOGD("package cert index info DB initialization failed\n");
2382 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2383 _LOGD("Failed to change cert db permission\n");
2385 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2386 _LOGD("Failed to change parser db permission\n");
2392 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2395 char pwuid_buf[1024];
2396 char journal_file[BUFSIZE];
2399 struct passwd userinfo, *result = NULL;
2400 files[0] = (char *)db_file;
2401 files[1] = journal_file;
2405 if (db_file == NULL)
2408 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2410 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2411 if (uid == OWNER_ROOT)
2413 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2414 if (ret != 0 || result == NULL) {
2415 _LOGE("FAIL: user %d doesn't exist", uid);
2418 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2420 for (i = 0; files[i]; i++) {
2421 ret = chown(files[i], uid, userinfo.pw_gid);
2423 if (strerror_r(errno, buf, sizeof(buf)))
2424 strncpy(buf, "", BUFSIZE - 1);
2425 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2426 userinfo.pw_gid, buf);
2430 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2431 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2433 ret = chmod(files[i], mode);
2435 if (strerror_r(errno, buf, sizeof(buf)))
2436 strncpy(buf, "", BUFSIZE - 1);
2437 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2440 SET_SMACK_LABEL(files[i]);
2445 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2449 if (getuid() != OWNER_ROOT) {
2450 _LOGE("Only root user is allowed");
2454 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2455 _LOGE("Manifest db for user %d is already exists", uid);
2459 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2460 _LOGE("Cert db for user %d is already exists", uid);
2464 ret = pkgmgr_parser_check_and_create_db(uid);
2467 ret = pkgmgr_parser_initialize_db(uid);
2469 pkgmgr_parser_close_db();
2472 pkgmgr_parser_close_db();
2477 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2481 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2483 _LOGD("Manifest DB creation Failed\n");
2488 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2490 _LOGD("Cert DB creation Failed\n");
2496 void pkgmgr_parser_close_db(void)
2498 sqlite3_close(pkgmgr_parser_db);
2499 sqlite3_close(pkgmgr_cert_db);
2503 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2505 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2507 _LOGD("manifest pointer is NULL\n");
2511 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2513 _LOGD("Failed to open DB\n");
2516 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2519 /*Begin transaction*/
2520 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2521 if (ret != SQLITE_OK) {
2522 _LOGD("Failed to begin transaction\n");
2526 _LOGD("Transaction Begin\n");
2527 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2529 _LOGD("Insert into DB failed. Rollback now\n");
2530 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2533 /*Commit transaction*/
2534 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2535 if (ret != SQLITE_OK) {
2536 _LOGD("Failed to commit transaction. Rollback now\n");
2537 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2541 _LOGD("Transaction Commit and End\n");
2543 pkgmgr_parser_close_db();
2547 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2549 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2551 _LOGD("manifest pointer is NULL\n");
2555 ret = pkgmgr_parser_check_and_create_db(uid);
2557 _LOGD("Failed to open DB\n");
2560 ret = pkgmgr_parser_initialize_db(uid);
2563 /*Begin transaction*/
2564 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2565 if (ret != SQLITE_OK) {
2566 _LOGD("Failed to begin transaction\n");
2570 _LOGD("Transaction Begin\n");
2571 ret = __insert_manifest_info_in_db(mfx, uid);
2573 _LOGD("Insert into DB failed. Rollback now\n");
2574 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2577 /*Commit transaction*/
2578 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2579 if (ret != SQLITE_OK) {
2580 _LOGD("Failed to commit transaction. Rollback now\n");
2581 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2585 _LOGD("Transaction Commit and End\n");
2587 pkgmgr_parser_close_db();
2591 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2593 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2596 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2598 if (pkgid == NULL || tep_path == NULL) {
2599 _LOGE("invalid parameter");
2606 ret = pkgmgr_parser_check_and_create_db(uid);
2608 _LOGD("Failed to open DB\n");
2611 ret = pkgmgr_parser_initialize_db(uid);
2615 /*Begin transaction*/
2616 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2617 if (ret != SQLITE_OK) {
2618 _LOGD("Failed to begin transaction\n");
2622 _LOGD("Transaction Begin\n");
2625 /* Updating TEP info in "package_info" table */
2626 query = sqlite3_mprintf("UPDATE package_info "\
2627 "SET package_tep_name = %Q "\
2628 "WHERE package = %Q", tep_path, pkgid);
2630 ret = __exec_query(query);
2631 sqlite3_free(query);
2632 if (ret != SQLITE_OK) {
2633 ret = PM_PARSER_R_ERROR;
2634 _LOGE("sqlite exec failed to insert entries into package_info!!");
2638 /* Updating TEP info in "package_app_info" table */
2639 query = sqlite3_mprintf("UPDATE package_app_info "\
2640 "SET app_tep_name = %Q "\
2641 "WHERE package = %Q", tep_path, pkgid);
2643 ret = __exec_query(query);
2644 sqlite3_free(query);
2645 if (ret != SQLITE_OK) {
2646 ret = PM_PARSER_R_ERROR;
2647 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2651 /*Commit transaction*/
2652 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2653 if (ret != SQLITE_OK) {
2654 _LOGE("Failed to commit transaction, Rollback now\n");
2655 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2656 if (ret != SQLITE_OK)
2657 _LOGE("Failed to Rollback\n");
2659 ret = PM_PARSER_R_ERROR;
2662 _LOGD("Transaction Commit and End\n");
2663 ret = PM_PARSER_R_OK;
2666 pkgmgr_parser_close_db();
2671 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2674 _LOGD("manifest pointer is NULL\n");
2678 ret = pkgmgr_parser_check_and_create_db(uid);
2680 _LOGD("Failed to open DB\n");
2683 ret = pkgmgr_parser_initialize_db(uid);
2686 /*Preserve guest mode visibility*/
2687 __preserve_guestmode_visibility_value( mfx);
2688 /*Begin transaction*/
2689 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2690 if (ret != SQLITE_OK) {
2691 _LOGD("Failed to begin transaction\n");
2695 _LOGD("Transaction Begin\n");
2696 ret = __delete_manifest_info_from_db(mfx, uid);
2698 _LOGD("Delete from DB failed. Rollback now\n");
2699 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2702 ret = __insert_manifest_info_in_db(mfx, uid);
2704 _LOGD("Insert into DB failed. Rollback now\n");
2705 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2709 /*Commit transaction*/
2710 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2711 if (ret != SQLITE_OK) {
2712 _LOGD("Failed to commit transaction. Rollback now\n");
2713 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2717 _LOGD("Transaction Commit and End\n");
2719 pkgmgr_parser_close_db();
2723 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2725 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2728 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2731 _LOGD("manifest pointer is NULL\n");
2735 ret = pkgmgr_parser_check_and_create_db(uid);
2737 _LOGD("Failed to open DB\n");
2740 /*Begin transaction*/
2741 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2742 if (ret != SQLITE_OK) {
2743 _LOGD("Failed to begin transaction\n");
2747 _LOGD("Transaction Begin\n");
2748 ret = __delete_manifest_info_from_db(mfx, uid);
2750 _LOGD("Delete from DB failed. Rollback now\n");
2751 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2754 /*Commit transaction*/
2755 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2756 if (ret != SQLITE_OK) {
2757 _LOGD("Failed to commit transaction, Rollback now\n");
2758 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2762 _LOGD("Transaction Commit and End\n");
2764 pkgmgr_parser_close_db();
2768 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2770 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2773 API int pkgmgr_parser_update_preload_info_in_db()
2776 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2778 _LOGD("Failed to open DB\n");
2781 /*Begin transaction*/
2782 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2783 if (ret != SQLITE_OK) {
2784 _LOGD("Failed to begin transaction\n");
2788 _LOGD("Transaction Begin\n");
2789 ret = __update_preload_condition_in_db();
2791 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2792 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2795 /*Commit transaction*/
2796 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2797 if (ret != SQLITE_OK) {
2798 _LOGD("Failed to commit transaction, Rollback now\n");
2799 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2803 _LOGD("Transaction Commit and End\n");
2805 pkgmgr_parser_close_db();
2809 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2812 ret = pkgmgr_parser_check_and_create_db(uid);
2814 _LOGD("Failed to open DB\n");
2817 /*Begin transaction*/
2818 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2819 if (ret != SQLITE_OK) {
2820 _LOGD("Failed to begin transaction\n");
2824 _LOGD("Transaction Begin\n");
2825 ret = __update_preload_condition_in_db();
2827 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2828 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2831 /*Commit transaction*/
2832 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2833 if (ret != SQLITE_OK) {
2834 _LOGD("Failed to commit transaction, Rollback now\n");
2835 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2839 _LOGD("Transaction Commit and End\n");
2841 pkgmgr_parser_close_db();
2845 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2849 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2851 _LOGD("Failed to open DB\n");
2855 /*Begin transaction*/
2856 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2857 if (ret != SQLITE_OK) {
2858 _LOGD("Failed to begin transaction\n");
2862 _LOGD("Transaction Begin\n");
2864 ret = __disable_global_app_for_user(appid, uid);
2866 ret = __enable_global_app_for_user(appid, uid);
2868 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2869 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2872 /*Commit transaction*/
2873 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2874 if (ret != SQLITE_OK) {
2875 _LOGD("Failed to commit transaction, Rollback now\n");
2876 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2880 _LOGD("Transaction Commit and End\n");
2882 pkgmgr_parser_close_db();
2887 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2889 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2892 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2896 ret = pkgmgr_parser_check_and_create_db(uid);
2898 _LOGD("Failed to open DB\n");
2902 /*Begin transaction*/
2903 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2904 if (ret != SQLITE_OK) {
2905 _LOGD("Failed to begin transaction\n");
2909 _LOGD("Transaction Begin\n");
2911 ret = __disable_app(appid);
2913 ret = __enable_app(appid);
2915 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2916 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2919 /*Commit transaction*/
2920 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2921 if (ret != SQLITE_OK) {
2922 _LOGD("Failed to commit transaction, Rollback now\n");
2923 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2927 _LOGD("Transaction Commit and End\n");
2929 pkgmgr_parser_close_db();