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 "FOREIGN KEY(package) " \
176 "REFERENCES package_info(package) " \
179 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
180 "(app_id text not null, " \
181 "app_locale text DEFAULT 'No Locale', " \
184 "PRIMARY KEY(app_id,app_locale) " \
185 "FOREIGN KEY(app_id) " \
186 "REFERENCES package_app_info(app_id) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
190 "(app_id text not null, " \
192 "app_icon_section text, " \
193 "app_icon_resolution text, " \
194 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
195 "FOREIGN KEY(app_id) " \
196 "REFERENCES package_app_info(app_id) " \
199 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
200 "(app_id text not null, " \
201 "app_locale text DEFAULT 'No Locale', " \
202 "app_image_section text, " \
204 "PRIMARY KEY(app_id,app_image_section) " \
205 "FOREIGN KEY(app_id) " \
206 "REFERENCES package_app_info(app_id) " \
209 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
210 "(app_id text not null, " \
211 "app_control text not null, " \
212 "PRIMARY KEY(app_id,app_control) " \
213 "FOREIGN KEY(app_id) " \
214 "REFERENCES package_app_info(app_id) " \
217 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
218 "(app_id text not null, " \
219 "category text not null, " \
220 "PRIMARY KEY(app_id,category) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
226 "(app_id text not null, " \
227 "md_key text not null, " \
228 "md_value text not null, " \
229 "PRIMARY KEY(app_id, md_key, md_value) " \
230 "FOREIGN KEY(app_id) " \
231 "REFERENCES package_app_info(app_id) " \
234 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
235 "(app_id text not null, " \
236 "pm_type text not null, " \
237 "pm_value text not null, " \
238 "PRIMARY KEY(app_id, pm_type, pm_value) " \
239 "FOREIGN KEY(app_id) " \
240 "REFERENCES package_app_info(app_id) " \
243 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
244 "(app_id text not null, " \
245 "data_share_path text not null, " \
246 "data_share_allowed text not null, " \
247 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
248 "FOREIGN KEY(app_id) " \
249 "REFERENCES package_app_info(app_id) " \
252 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
253 "(app_id text not null, " \
254 "data_share_request text not null, " \
255 "PRIMARY KEY(app_id,data_share_request) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
260 /* FIXME: duplicated at pkgmgrinfo_db.c */
261 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
262 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
263 " cert_info TEXT UNIQUE, " \
264 " cert_id INTEGER PRIMARY KEY, " \
265 " cert_ref_count INTEGER NOT NULL)"
267 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
268 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
269 " package TEXT PRIMARY KEY, " \
270 " author_root_cert INTEGER, " \
271 " author_im_cert INTEGER, " \
272 " author_signer_cert INTEGER, " \
273 " dist_root_cert INTEGER, " \
274 " dist_im_cert INTEGER, " \
275 " dist_signer_cert INTEGER, " \
276 " dist2_root_cert INTEGER, " \
277 " dist2_im_cert INTEGER, " \
278 " dist2_signer_cert INTEGER)"
280 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
281 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
282 "AFTER DELETE ON package_cert_info " \
284 " UPDATE package_cert_index_info SET" \
285 " cert_ref_count = cert_ref_count - 1" \
286 " WHERE cert_id = OLD.author_root_cert" \
287 " OR cert_id = OLD.author_im_cert" \
288 " OR cert_id = OLD.author_signer_cert" \
289 " OR cert_id = OLD.dist_root_cert" \
290 " OR cert_id = OLD.dist_im_cert" \
291 " OR cert_id = OLD.dist_signer_cert" \
292 " OR cert_id = OLD.dist2_root_cert" \
293 " OR cert_id = OLD.dist2_im_cert" \
294 " OR cert_id = OLD.dist2_signer_cert;" \
297 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
298 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
299 "AFTER UPDATE ON package_cert_index_info " \
300 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
301 " WHERE cert_id = OLD.cert_id) = 0) "\
303 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
306 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
307 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
308 "AFTER UPDATE ON package_cert_info " \
309 "WHEN (OLD.%s IS NOT NULL) " \
311 " UPDATE package_cert_index_info SET" \
312 " cert_ref_count = cert_ref_count - 1" \
313 " WHERE cert_id = OLD.%s;" \
316 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
317 "(app_id text not null, " \
318 "providerid text not null, " \
319 "access text not null, " \
320 "type text not null, " \
321 "PRIMARY KEY(app_id, providerid, access, type) " \
322 "FOREIGN KEY(app_id) " \
323 "REFERENCES package_app_info(app_id) " \
326 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
327 "(app_id text not null, " \
328 "uid text not null, " \
329 "PRIMARY KEY(app_id, uid))"
331 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
332 "create table if not exists package_app_splash_screen " \
333 "(app_id text not null, " \
334 "src text not null, " \
335 "type text not null, " \
336 "orientation text not null, " \
337 "indicatordisplay text, " \
339 "PRIMARY KEY(app_id, orientation, operation) " \
340 "FOREIGN KEY(app_id) " \
341 "REFERENCES package_app_info(app_id) " \
344 static int __insert_application_info(manifest_x *mfx);
345 static int __insert_application_appcategory_info(manifest_x *mfx);
346 static int __insert_application_appcontrol_info(manifest_x *mfx);
347 static int __insert_application_appmetadata_info(manifest_x *mfx);
348 static int __insert_application_share_allowed_info(manifest_x *mfx);
349 static int __insert_application_share_request_info(manifest_x *mfx);
350 static int __insert_application_datacontrol_info(manifest_x *mfx);
351 static void __insert_application_locale_info(gpointer data, gpointer userdata);
352 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
353 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
354 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
355 static int __delete_subpkg_info_from_db(char *appid);
356 static int __delete_appinfo_from_db(char *db_table, const char *appid);
357 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
358 static int __exec_query(char *query);
359 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
360 char **label, char **license, char **icon, char **description, char **author);
361 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
362 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
363 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
364 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
365 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
366 static int __parserdb_change_perm(const char *db_file, uid_t uid);
368 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
371 __delete_subpkg_info_from_db(coltxt[0]);
376 static const char *__get_str(const char *str)
380 return PKGMGR_PARSER_EMPTY_STR;
386 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
391 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
392 if (ret != SQLITE_OK) {
393 _LOGD("connect db [%s] failed!\n", db_path);
401 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
403 manifest_x *mfx = (manifest_x *)data;
409 if (mfx->application == NULL)
411 app = (application_x *)mfx->application->data;
412 for(i = 0; i < ncols; i++)
414 if (strcmp(colname[i], "app_id") == 0) {
416 appid = strdup(coltxt[i]);
417 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
419 status = strdup(coltxt[i]);
425 _LOGD("app id is NULL\n");
428 /*update guest mode visibility*/
429 for (tmp = mfx->application; tmp; tmp = tmp->next) {
430 app = (application_x *)tmp->data;
433 if (strcmp(app->appid, appid) == 0) {
434 free((void *)app->guestmode_visibility);
435 app->guestmode_visibility = strdup(status);
451 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
453 char *error_message = NULL;
454 char query[MAX_QUERY_LEN] = {'\0'};
455 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
457 sqlite3_exec(pkgmgr_parser_db, query,
458 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
459 _LOGD("Don't execute query = %s error message = %s\n",
460 query, error_message);
461 sqlite3_free(error_message);
466 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
468 char *error_message = NULL;
470 sqlite3_exec(db_handle, db_query,
471 NULL, NULL, &error_message)) {
472 _LOGD("Don't execute query = %s error message = %s\n",
473 db_query, error_message);
474 sqlite3_free(error_message);
477 sqlite3_free(error_message);
481 static int __exec_query(char *query)
483 char *error_message = NULL;
485 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
486 _LOGE("Don't execute query = %s error message = %s\n", query,
488 sqlite3_free(error_message);
491 sqlite3_free(error_message);
495 static int __exec_query_no_msg(char *query)
497 char *error_message = NULL;
499 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
500 sqlite3_free(error_message);
503 sqlite3_free(error_message);
507 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
515 for (tmp = lbls; tmp; tmp = tmp->next) {
516 lbl = (label_x *)tmp->data;
520 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
522 for (tmp = lcns; tmp; tmp = tmp->next) {
523 lcn = (license_x *)tmp->data;
527 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
529 for (tmp = icns; tmp; tmp = tmp->next) {
530 icn = (icon_x *)tmp->data;
534 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
536 for (tmp = dcns; tmp; tmp = tmp->next) {
537 dcn = (description_x *)tmp->data;
541 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
543 for (tmp = aths; tmp; tmp = tmp->next) {
544 ath = (author_x *)tmp->data;
548 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
554 static GList *__create_icon_list(GList *appicon, GList *icns)
559 for (tmp = icns; tmp; tmp = tmp->next) {
560 icn = (icon_x *)tmp->data;
564 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
569 static GList *__create_image_list(GList *appimage, GList *imgs)
574 for (tmp = imgs; tmp; tmp = tmp->next) {
575 img = (image_x *)tmp->data;
579 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
584 static void __trimfunc(GList* trim_list)
586 char *trim_data = NULL;
590 list = g_list_first(trim_list);
593 trim_data = (char *)list->data;
596 if (strcmp(trim_data, prev) == 0) {
597 trim_list = g_list_remove(trim_list, trim_data);
598 list = g_list_first(trim_list);
607 list = g_list_next(list);
611 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
613 if (a == NULL || b == NULL)
615 if (strcmp((char*)a, (char*)b) == 0)
617 if (strcmp((char*)a, (char*)b) < 0)
619 if (strcmp((char*)a, (char*)b) > 0)
624 static int __check_dpi(const char *dpi_char, int dpi_int)
626 if (dpi_char == NULL)
629 if (strcasecmp(dpi_char, LDPI) == 0) {
630 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
634 } else if (strcasecmp(dpi_char, MDPI) == 0) {
635 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
639 } else if (strcasecmp(dpi_char, HDPI) == 0) {
640 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
644 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
645 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
649 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
650 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
658 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
661 char *icon_filename = NULL;
662 char modified_iconpath[BUFSIZE] = { '\0' };
663 char icon_path[BUFSIZE] = { '\0' };
667 if (orig_icon_path == NULL)
670 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
674 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
675 dpi_path[0] = "LDPI";
676 dpi_path[1] = "ldpi";
677 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
678 dpi_path[0] = "MDPI";
679 dpi_path[1] = "mdpi";
680 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
681 dpi_path[0] = "HDPI";
682 dpi_path[1] = "hdpi";
683 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
684 dpi_path[0] = "XHDPI";
685 dpi_path[1] = "xhdpi";
686 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
687 dpi_path[0] = "XXHDPI";
688 dpi_path[1] = "xxhdpi";
690 _LOGE("Unidentified dpi[%d]", dpi);
694 icon_filename = strrchr(orig_icon_path, '/');
695 if (icon_filename == NULL)
698 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
699 for (i = 0; i < 2; i++) {
700 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
701 if (access(modified_iconpath, F_OK) != -1) {
702 // if exists, return modified icon path
703 *new_icon_path = strdup(modified_iconpath);
711 static gint __compare_icon(gconstpointer a, gconstpointer b)
713 icon_x *icon = (icon_x *)a;
715 char *icon_folder_path = NULL;
717 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
720 if (icon->dpi != NULL)
723 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
725 icon->text = icon_folder_path;
731 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
733 icon_x *icon = (icon_x *)a;
734 int dpi = GPOINTER_TO_INT(b);
736 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
739 if (icon->dpi == NULL)
742 if (__check_dpi(icon->dpi, dpi) == 0)
748 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
750 icon_x *icon = (icon_x *)a;
751 char *lang = (char *)b;
752 char *icon_folder_path = NULL;
754 if (icon->dpi != NULL)
757 if (strcasecmp(icon->lang, lang) == 0) {
758 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
759 //icon for no locale. check existance of folder-hierachied default icons
760 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
762 icon->text = icon_folder_path;
771 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
773 icon_x *icon = (icon_x *)a;
774 char *lang = (char *)b;
777 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
781 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
787 static char *__find_icon(GList *icons, const char *lang)
793 // first, find icon whose locale and dpi with given lang and system's dpi has matched
794 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
796 icon = (icon_x *)tmp->data;
797 return (char *)icon->text;
800 // if first has failed, find icon whose locale has matched
801 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
803 icon = (icon_x *)tmp->data;
804 return (char *)icon->text;
807 // if second has failed, find icon whose dpi has matched with system's dpi
808 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
811 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
813 icon = (icon_x *)tmp->data;
814 return (char *)icon->text;
817 // last, find default icon marked as "No Locale"
818 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
820 icon = (icon_x *)tmp->data;
821 return (char *)icon->text;
827 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
828 char **label, char **license, char **icon, char **description, char **author)
835 for (tmp = lbls; tmp; tmp = tmp->next) {
836 lbl = (label_x *)tmp->data;
840 if (strcmp(lbl->lang, (char *)data) == 0) {
841 *label = (char*)lbl->text;
846 for (tmp = lcns; tmp; tmp = tmp->next) {
847 lcn = (license_x *)tmp->data;
851 if (strcmp(lcn->lang, (char *)data) == 0) {
852 *license = (char*)lcn->text;
858 *icon = __find_icon(icns, (char *)data);
860 for (tmp = dcns; tmp; tmp = tmp->next) {
861 dcn = (description_x *)tmp->data;
865 if (strcmp(dcn->lang, (char *)data) == 0) {
866 *description = (char*)dcn->text;
871 for (tmp = aths; tmp; tmp = tmp->next) {
872 ath = (author_x *)tmp->data;
876 if (strcmp(ath->lang, (char *)data) == 0) {
877 *author = (char*)ath->text;
885 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
889 for (tmp = icns; tmp; tmp = tmp->next) {
890 icn = (icon_x *)tmp->data;
894 if (strcmp(icn->section, (char *)data) == 0) {
895 *icon = (char*)icn->text;
896 *resolution = (char*)icn->resolution;
903 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
907 for (tmp = imgs; tmp; tmp = tmp->next) {
908 img = (image_x *)tmp->data;
912 if (strcmp(img->section, (char *)data) == 0) {
913 *lang = (char*)img->lang;
914 *image = (char*)img->text;
921 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
926 char *description = NULL;
927 char *license = NULL;
931 manifest_x *mfx = (manifest_x *)userdata;
932 GList *lbl = mfx->label;
933 GList *lcn = mfx->license;
934 GList *icn = mfx->icon;
935 GList *dcn = mfx->description;
936 GList *ath = mfx->author;
938 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
939 if (!label && !description && !icon && !license && !author)
942 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
943 "package_label, package_icon, package_description, package_license, package_author) values " \
944 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
949 __get_str(description),
953 ret = __exec_query(query);
955 _LOGD("Package Localized Info DB Insert failed\n");
960 static void __insert_application_locale_info(gpointer data, gpointer userdata)
967 application_x *app = (application_x*)userdata;
968 GList *lbl = app->label;
969 GList *icn = app->icon;
971 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
975 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
976 "app_label, app_icon) values " \
977 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
978 __get_str(label), __get_str(icon));
979 ret = __exec_query(query);
981 _LOGD("Package UiApp Localized Info DB Insert failed\n");
985 /*insert ui app locale info to pkg locale to get mainapp data */
986 if (strcasecmp(app->mainapp, "true")==0) {
987 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
988 "package_label, package_icon, package_description, package_license, package_author) values " \
989 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
994 PKGMGR_PARSER_EMPTY_STR,
995 PKGMGR_PARSER_EMPTY_STR,
996 PKGMGR_PARSER_EMPTY_STR);
998 ret = __exec_query_no_msg(query);
1002 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1003 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1004 ret = __exec_query_no_msg(query);
1005 sqlite3_free(query);
1010 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1014 char *resolution = NULL;
1015 char query[MAX_QUERY_LEN] = {'\0'};
1017 application_x *app = (application_x*)userdata;
1018 GList *icn = app->icon;
1020 __extract_icon_data(data, icn, &icon, &resolution);
1021 if (!icon && !resolution)
1023 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1024 "app_icon, app_icon_section, app_icon_resolution) values " \
1025 "('%q', '%q', '%q', '%q')", app->appid,
1026 icon, (char*)data, resolution);
1028 ret = __exec_query(query);
1030 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1034 static void __insert_application_image_info(gpointer data, gpointer userdata)
1039 char query[MAX_QUERY_LEN] = {'\0'};
1041 application_x *app = (application_x*)userdata;
1042 GList *image = app->image;
1044 __extract_image_data(data, image, &lang, &img);
1047 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1048 "app_image_section, app_image) values " \
1049 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1051 ret = __exec_query(query);
1053 _LOGD("Package UiApp image Info DB Insert failed\n");
1058 static int __insert_mainapp_info(manifest_x *mfx)
1063 char query[MAX_QUERY_LEN] = {'\0'};
1064 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1065 app = (application_x *)tmp->data;
1068 snprintf(query, MAX_QUERY_LEN,
1069 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1071 ret = __exec_query(query);
1073 _LOGD("Package App Info DB Insert Failed\n");
1076 if (strcasecmp(app->mainapp, "True")==0)
1077 mfx->mainapp_id = strdup(app->appid);
1080 if (mfx->mainapp_id == NULL) {
1081 if (mfx->application == NULL)
1083 app = (application_x *)mfx->application->data;
1087 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1089 _LOGD("Not valid appid\n");
1093 ret = __exec_query(query);
1095 _LOGD("Package UiApp Info DB Insert Failed\n");
1099 free((void *)app->mainapp);
1100 app->mainapp= strdup("true");
1101 mfx->mainapp_id = strdup(app->appid);
1104 memset(query, '\0', MAX_QUERY_LEN);
1105 snprintf(query, MAX_QUERY_LEN,
1106 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1107 ret = __exec_query(query);
1109 _LOGD("Package Info DB update Failed\n");
1116 static int __convert_background_category(GList *category_list)
1119 GList *tmp_list = category_list;
1120 char *category_data = NULL;
1122 if (category_list == NULL)
1125 while (tmp_list != NULL) {
1126 category_data = (char *)tmp_list->data;
1127 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1128 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1129 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1130 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1131 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1132 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1133 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1134 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1135 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1136 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1137 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1138 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1139 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1140 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1142 _LOGE("Unidentified category [%s]", category_data);
1144 tmp_list = g_list_next(tmp_list);
1150 static const char *__find_effective_appid(GList *metadata_list)
1155 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1156 md = (metadata_x *)tmp_list->data;
1157 if (md == NULL || md->key == NULL)
1160 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1169 /* _PRODUCT_LAUNCHING_ENHANCED_
1170 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1172 static int __insert_application_info(manifest_x *mfx)
1177 int background_value = 0;
1178 char query[MAX_QUERY_LEN] = {'\0'};
1180 const char *effective_appid;
1183 type = strdup(mfx->type);
1185 type = strdup("tpk");
1187 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1188 app = (application_x *)tmp->data;
1192 background_value = __convert_background_category(app->background_category);
1193 if (background_value < 0) {
1194 _LOGE("Failed to retrieve background value[%d]", background_value);
1195 background_value = 0;
1198 effective_appid = __find_effective_appid(app->metadata);
1200 snprintf(query, MAX_QUERY_LEN,
1201 "insert into package_app_info(" \
1202 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1203 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1204 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1205 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1206 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1207 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1208 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1209 "app_effective_appid) " \
1211 "'%s', '%s', '%s', '%s', '%s', " \
1212 "'%s', '%s', '%s', '%s', '%s', " \
1213 "'%s', '%s', '%s', '%s', '%s', " \
1214 "'%s', '%s', '%s', '%s', '%s', " \
1215 "'%s', '%s', '%s', '%s', '%s', " \
1216 "'%s', '%s', '%s', '%s', '%s', " \
1217 "'%s', '%d', '%s', '%s', '%s', " \
1219 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1220 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1221 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1222 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1223 app->guestmode_visibility, app->permission_type,
1224 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1225 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1226 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1227 __get_str(effective_appid));
1229 ret = __exec_query(query);
1231 _LOGD("Package UiApp Info DB Insert Failed\n");
1236 memset(query, '\0', MAX_QUERY_LEN);
1245 static int __insert_application_appcategory_info(manifest_x *mfx)
1252 char query[MAX_QUERY_LEN] = {'\0'};
1253 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1254 app = (application_x *)app_tmp->data;
1257 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1258 ct = (const char *)ct_tmp->data;
1261 snprintf(query, MAX_QUERY_LEN,
1262 "insert into package_app_app_category(app_id, category) " \
1263 "values('%s','%s')",\
1265 ret = __exec_query(query);
1267 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1270 memset(query, '\0', MAX_QUERY_LEN);
1276 static int __insert_application_appmetadata_info(manifest_x *mfx)
1283 char query[MAX_QUERY_LEN] = {'\0'};
1284 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1285 app = (application_x *)app_tmp->data;
1288 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1289 md = (metadata_x *)md_tmp->data;
1293 snprintf(query, MAX_QUERY_LEN,
1294 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1295 "values('%s','%s', '%s')",\
1296 app->appid, md->key, md->value ? md->value : "");
1297 ret = __exec_query(query);
1299 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1303 memset(query, '\0', MAX_QUERY_LEN);
1309 static int __insert_application_apppermission_info(manifest_x *mfx)
1316 char query[MAX_QUERY_LEN] = {'\0'};
1317 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1318 app = (application_x *)app_tmp->data;
1321 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1322 pm = (permission_x *)pm_tmp->data;
1325 snprintf(query, MAX_QUERY_LEN,
1326 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1327 "values('%s','%s', '%s')",\
1328 app->appid, pm->type, pm->value);
1329 ret = __exec_query(query);
1331 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1334 memset(query, '\0', MAX_QUERY_LEN);
1340 static int __insert_application_appcontrol_info(manifest_x *mfx)
1344 GList *acontrol_tmp;
1345 appcontrol_x *acontrol;
1347 char query[MAX_QUERY_LEN] = {'\0'};
1348 char buf[BUFSIZE] = {'\0'};
1349 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1350 app = (application_x *)app_tmp->data;
1353 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1354 acontrol = (appcontrol_x *)acontrol_tmp->data;
1355 if (acontrol == NULL)
1357 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1358 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1359 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1360 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1361 snprintf(query, MAX_QUERY_LEN,
1362 "insert into package_app_app_control(app_id, app_control) " \
1363 "values('%s', '%s')",\
1365 ret = __exec_query(query);
1367 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1370 memset(query, '\0', MAX_QUERY_LEN);
1376 static int __insert_application_datacontrol_info(manifest_x *mfx)
1383 char query[MAX_QUERY_LEN] = {'\0'};
1385 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1386 app = (application_x *)app_tmp->data;
1389 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1390 dc = (datacontrol_x *)dc_tmp->data;
1393 snprintf(query, MAX_QUERY_LEN,
1394 "insert into package_app_data_control(app_id, providerid, access, type) " \
1395 "values('%s', '%s', '%s', '%s')",\
1401 ret = __exec_query(query);
1403 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1406 memset(query, '\0', MAX_QUERY_LEN);
1412 static int __insert_application_share_request_info(manifest_x *mfx)
1421 char query[MAX_QUERY_LEN] = {'\0'};
1422 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1423 app = (application_x *)app_tmp->data;
1426 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1427 ds = (datashare_x *)ds_tmp->data;
1430 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1431 rq = (const char *)rq_tmp->data;
1434 snprintf(query, MAX_QUERY_LEN,
1435 "insert into package_app_share_request(app_id, data_share_request) " \
1436 "values('%s', '%s')",\
1438 ret = __exec_query(query);
1440 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1443 memset(query, '\0', MAX_QUERY_LEN);
1450 static int __insert_application_share_allowed_info(manifest_x *mfx)
1461 char query[MAX_QUERY_LEN] = {'\0'};
1462 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1463 app = (application_x *)app_tmp->data;
1466 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1467 ds = (datashare_x *)ds_tmp->data;
1470 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1471 df = (define_x *)df_tmp->data;
1474 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1475 al = (const char *)al_tmp->data;
1478 snprintf(query, MAX_QUERY_LEN,
1479 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1480 "values('%s', '%s', '%s')",\
1481 app->appid, df->path, al);
1482 ret = __exec_query(query);
1484 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1487 memset(query, '\0', MAX_QUERY_LEN);
1495 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1497 splashscreen_x *ss = (splashscreen_x *)a;
1498 const char *orientation = (const char *)b;
1501 if (ss->operation || ss->dpi == NULL)
1504 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1508 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1514 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1516 splashscreen_x *ss = (splashscreen_x *)a;
1517 const char *orientation = (const char *)b;
1519 if (ss->operation || ss->dpi)
1522 if (strcasecmp(ss->orientation, orientation) == 0)
1528 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1529 const char *orientation)
1533 tmp = g_list_find_custom(splashscreens, orientation,
1534 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1536 return (splashscreen_x *)tmp->data;
1538 tmp = g_list_find_custom(splashscreens, orientation,
1539 (GCompareFunc)__compare_splashscreen_with_orientation);
1541 return (splashscreen_x *)tmp->data;
1546 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1548 splashscreen_x *ss = (splashscreen_x *)data;
1549 GList **list = (GList **)user_data;
1552 if (ss->operation == NULL || ss->dpi == NULL)
1555 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1559 if (__check_dpi(ss->dpi, dpi) != 0)
1562 *list = g_list_append(*list, ss);
1565 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1567 splashscreen_x *ss = (splashscreen_x *)data;
1568 GList **list = (GList **)user_data;
1569 splashscreen_x *ss_tmp;
1572 if (ss->operation == NULL || ss->dpi)
1575 for (tmp = *list; tmp; tmp = tmp->next) {
1576 ss_tmp = (splashscreen_x *)tmp->data;
1577 if (ss_tmp->operation
1578 && strcmp(ss_tmp->operation, ss->operation) == 0
1579 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1583 *list = g_list_append(*list, ss);
1586 static GList *__find_splashscreens(GList *splashscreens)
1591 g_list_foreach(splashscreens,
1592 __find_appcontrol_splashscreen_with_dpi, &list);
1593 g_list_foreach(splashscreens,
1594 __find_appcontrol_splashscreen, &list);
1596 ss = __find_default_splashscreen(splashscreens, "portrait");
1598 list = g_list_append(list, ss);
1599 ss = __find_default_splashscreen(splashscreens, "landscape");
1601 list = g_list_append(list, ss);
1606 static int __insert_application_splashscreen_info(manifest_x *mfx)
1614 char query[MAX_QUERY_LEN];
1616 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1617 app = (application_x *)app_tmp->data;
1618 if (app == NULL || app->splashscreens == NULL)
1621 ss_tmp = __find_splashscreens(app->splashscreens);
1625 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1626 ss = (splashscreen_x *)tmp->data;
1627 snprintf(query, sizeof(query),
1628 "insert into package_app_splash_screen" \
1629 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1630 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1631 app->appid, ss->src, ss->type, ss->orientation,
1632 ss->indicatordisplay, __get_str(ss->operation));
1633 ret = __exec_query(query);
1635 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1638 memset(query, '\0', MAX_QUERY_LEN);
1640 g_list_free(ss_tmp);
1645 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1650 char query[MAX_QUERY_LEN];
1652 const char *image_type;
1653 const char *indicatordisplay;
1654 const char *orientation;
1655 const char *operation = NULL;
1657 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1658 app = (application_x *)app_tmp->data;
1660 (app->portraitimg == NULL && app->landscapeimg == NULL))
1662 image_type = "img"; /* default */
1663 if (app->effectimage_type) {
1664 tmp = strstr(app->effectimage_type, "edj");
1668 indicatordisplay = "true"; /* default */
1669 if (app->indicatordisplay)
1670 indicatordisplay = app->indicatordisplay;
1671 if (app->portraitimg) {
1672 orientation = "portrait";
1673 snprintf(query, sizeof(query),
1674 "insert into package_app_splash_screen" \
1675 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1676 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1677 app->appid, app->portraitimg, image_type,
1678 orientation, indicatordisplay, __get_str(operation));
1679 ret = __exec_query(query);
1681 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1684 memset(query, '\0', MAX_QUERY_LEN);
1686 if (app->landscapeimg) {
1687 orientation = "landscape";
1688 snprintf(query, sizeof(query),
1689 "insert into package_app_splash_screen" \
1690 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1691 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1692 app->appid, app->landscapeimg, image_type,
1693 orientation, indicatordisplay, __get_str(operation));
1694 ret = __exec_query(query);
1696 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1699 memset(query, '\0', MAX_QUERY_LEN);
1705 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1712 char query[MAX_QUERY_LEN];
1714 char *tmpptr = NULL;
1715 const char *operation;
1716 const char *portraitimg;
1717 const char *landscapeimg;
1718 const char *indicatordisplay;
1719 const char *orientation;
1720 const char *image_type;
1722 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1723 app = (application_x *)app_tmp->data;
1727 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1728 md = (metadata_x *)md_tmp->data;
1729 if (md == NULL || md->key == NULL || md->value == NULL)
1732 if (strcasestr(md->key, "operation_effect=")) {
1733 operation = index(md->key, '=');
1734 if ((operation + 1) != NULL)
1738 } else if (strcasestr(md->key, "launch_effect")) {
1745 landscapeimg = NULL;
1746 indicatordisplay = "true"; /* default */
1747 token = strtok_r(md->value, "|", &tmpptr);
1748 while (token != NULL) {
1749 if (strcasestr(token, "portrait-effectimage=")) {
1750 portraitimg = index(token, '=');
1751 if ((portraitimg + 1) != NULL)
1755 } else if (strcasestr(token, "landscape-effectimage=")) {
1756 landscapeimg = index(token, '=');
1757 if ((landscapeimg + 1) != NULL)
1760 landscapeimg = NULL;
1761 } else if (strcasestr(token, "indicatordisplay=")) {
1762 indicatordisplay = index(token, '=');
1763 if ((indicatordisplay + 1) != NULL)
1766 indicatordisplay = "true";
1769 token = strtok_r(NULL, "|", &tmpptr);
1773 orientation = "portrait";
1775 if (strcasestr(portraitimg, "edj"))
1777 snprintf(query, sizeof(query),
1778 "insert into package_app_splash_screen" \
1779 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1780 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1781 app->appid, portraitimg, image_type,
1782 orientation, indicatordisplay, __get_str(operation));
1783 ret = __exec_query(query);
1785 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1788 memset(query, '\0', MAX_QUERY_LEN);
1791 orientation = "landscape";
1793 if (strcasestr(landscapeimg, "edj"))
1795 snprintf(query, sizeof(query),
1796 "insert into package_app_splash_screen" \
1797 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1798 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1799 app->appid, landscapeimg, image_type,
1800 orientation, indicatordisplay, __get_str(operation));
1801 ret = __exec_query(query);
1803 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1806 memset(query, '\0', MAX_QUERY_LEN);
1814 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1818 const char *pv = NULL;
1819 char query[MAX_QUERY_LEN] = { '\0' };
1822 const char *auth_name = NULL;
1823 const char *auth_email = NULL;
1824 const char *auth_href = NULL;
1826 GList *pkglocale = NULL;
1827 GList *applocale = NULL;
1828 GList *appicon = NULL;
1829 GList *appimage = NULL;
1831 if (mfx->author && mfx->author->data) {
1832 author = (author_x *)mfx->author->data;
1834 auth_name = author->text;
1836 auth_email = author->email;
1838 auth_href = author->href;
1841 /*Insert in the package_cert_info CERT_DB*/
1842 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1843 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1844 if (ret != PMINFO_R_OK) {
1845 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1846 _LOGE("Cert Info DB create handle failed\n");
1849 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1850 if (ret != PMINFO_R_OK) {
1851 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1852 _LOGE("Cert Info DB Insert Failed\n");
1856 /*Insert in the package_info DB*/
1857 snprintf(query, MAX_QUERY_LEN,
1858 "insert into package_info(" \
1859 "package, package_type, package_version, package_api_version, package_tep_name, " \
1860 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1861 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1862 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1863 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1865 "'%s', '%s', '%s', '%s', '%s', " \
1866 "'%s', '%s', '%s', '%s', '%s', " \
1867 "'%s', '%s', '%s', '%s', '%s', " \
1868 "'%s', '%s', '%s', '%s', '%s', " \
1869 "'%s', '%s', '%s', '%s', '%s')", \
1870 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1871 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1872 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1873 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1874 __get_str(mfx->storeclient_id),
1875 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1877 ret = __exec_query(query);
1879 _LOGD("Package Info DB Insert Failed\n");
1883 /*Insert in the package_privilege_info DB*/
1884 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1885 pv = (const char *)tmp->data;
1888 memset(query, '\0', MAX_QUERY_LEN);
1889 snprintf(query, MAX_QUERY_LEN,
1890 "insert into package_privilege_info(package, privilege) " \
1891 "values('%s','%s')",\
1893 ret = __exec_query(query);
1895 _LOGD("Package Privilege Info DB Insert Failed\n");
1900 if (mfx->application != NULL) {
1901 ret = __insert_mainapp_info(mfx);
1906 /*Insert the package locale*/
1907 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1908 /*remove duplicated data in pkglocale*/
1909 __trimfunc(pkglocale);
1911 /*Insert the app locale, icon, image info */
1912 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1913 app = (application_x *)tmp->data;
1916 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1917 appicon = __create_icon_list(appicon, app->icon);
1918 appimage = __create_image_list(appimage, app->image);
1920 /*remove duplicated data in applocale*/
1921 __trimfunc(applocale);
1922 __trimfunc(appicon);
1923 __trimfunc(appimage);
1925 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1927 /*native app locale info*/
1928 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1929 app = (application_x *)tmp->data;
1932 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1933 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1934 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1937 g_list_free(pkglocale);
1939 g_list_free(applocale);
1941 g_list_free(appicon);
1943 g_list_free(appimage);
1946 /*Insert in the package_app_info DB*/
1947 ret = __insert_application_info(mfx);
1950 /*Insert in the package_app_app_control DB*/
1951 ret = __insert_application_appcontrol_info(mfx);
1955 /*Insert in the package_app_app_category DB*/
1956 ret = __insert_application_appcategory_info(mfx);
1960 /*Insert in the package_app_app_metadata DB*/
1961 ret = __insert_application_appmetadata_info(mfx);
1965 /*Insert in the package_app_app_permission DB*/
1966 ret = __insert_application_apppermission_info(mfx);
1970 /*Insert in the package_app_share_allowed DB*/
1971 ret = __insert_application_share_allowed_info(mfx);
1975 /*Insert in the package_app_share_request DB*/
1976 ret = __insert_application_share_request_info(mfx);
1980 /*Insert in the package_app_data_control DB*/
1981 ret = __insert_application_datacontrol_info(mfx);
1985 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1986 ret = __insert_application_legacy_splashscreen_info(mfx);
1990 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1991 ret = __insert_application_metadata_splashscreen_info(mfx);
1995 /*Insert in the package_app_splash_screen DB*/
1996 ret = __insert_application_splashscreen_info(mfx);
2004 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2006 char query[MAX_QUERY_LEN] = { '\0' };
2008 memset(query, '\0', MAX_QUERY_LEN);
2009 snprintf(query, MAX_QUERY_LEN,
2010 "delete from %s where app_id='%s'", db_table, appid);
2011 ret = __exec_query(query);
2013 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2019 static int __delete_subpkg_info_from_db(char *appid)
2023 ret = __delete_appinfo_from_db("package_app_info", appid);
2026 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2029 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2032 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2035 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2038 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2041 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2044 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2047 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2050 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2053 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2056 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2063 static int __delete_subpkg_from_db(manifest_x *mfx)
2065 char query[MAX_QUERY_LEN] = { '\0' };
2066 char *error_message = NULL;
2068 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2070 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2071 _LOGE("Don't execute query = %s error message = %s\n", query,
2073 sqlite3_free(error_message);
2076 sqlite3_free(error_message);
2081 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2083 char query[MAX_QUERY_LEN] = { '\0' };
2087 /*Delete from cert table*/
2088 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2090 _LOGD("Cert Info DB Delete Failed\n");
2094 /*Delete from Package Info DB*/
2095 snprintf(query, MAX_QUERY_LEN,
2096 "delete from package_info where package='%s'", mfx->package);
2097 ret = __exec_query(query);
2099 _LOGD("Package Info DB Delete Failed\n");
2102 memset(query, '\0', MAX_QUERY_LEN);
2104 /*Delete from Package Localized Info*/
2105 snprintf(query, MAX_QUERY_LEN,
2106 "delete from package_localized_info where package='%s'", mfx->package);
2107 ret = __exec_query(query);
2109 _LOGD("Package Localized Info DB Delete Failed\n");
2113 /*Delete from Package Privilege Info*/
2114 snprintf(query, MAX_QUERY_LEN,
2115 "delete from package_privilege_info where package='%s'", mfx->package);
2116 ret = __exec_query(query);
2118 _LOGD("Package Privilege Info DB Delete Failed\n");
2122 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2123 app = (application_x *)tmp->data;
2126 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2129 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2132 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2135 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2138 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2141 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2144 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2147 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2150 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2153 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2156 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2159 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2164 /* if main package has sub pkg, delete sub pkg data*/
2165 __delete_subpkg_from_db(mfx);
2170 static int __disable_app(const char *appid)
2173 char query[MAX_QUERY_LEN] = {'\0'};
2174 sqlite3_snprintf(MAX_QUERY_LEN, query,
2175 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2177 ret = __exec_query(query);
2179 _LOGD("Insert global app disable failed\n");
2184 static int __enable_app(const char *appid)
2187 char query[MAX_QUERY_LEN] = {'\0'};
2188 sqlite3_snprintf(MAX_QUERY_LEN, query,
2189 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2191 ret = __exec_query(query);
2193 _LOGD("Insert global app disable failed\n");
2198 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2201 char query[MAX_QUERY_LEN] = {'\0'};
2203 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2204 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2206 ret = __exec_query(query);
2208 _LOGD("Insert global app disable failed\n");
2213 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2216 char query[MAX_QUERY_LEN] = {'\0'};
2218 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2219 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2221 ret = __exec_query(query);
2223 _LOGD("Delete global app disable failed\n");
2228 static int __update_preload_condition_in_db()
2231 char query[MAX_QUERY_LEN] = {'\0'};
2233 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2235 ret = __exec_query(query);
2237 _LOGD("Package preload_condition update failed\n");
2242 API int pkgmgr_parser_initialize_db(uid_t uid)
2246 char query[MAX_QUERY_LEN];
2247 static const char *columns[] = {
2248 "author_root_cert", "author_im_cert", "author_signer_cert",
2249 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2250 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2254 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2256 _LOGD("package info DB initialization failed\n");
2259 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2261 _LOGD("package localized info DB initialization failed\n");
2264 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2266 _LOGD("package app app privilege DB initialization failed\n");
2269 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2271 _LOGD("package app info DB initialization failed\n");
2274 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2276 _LOGD("package app localized info DB initialization failed\n");
2279 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2281 _LOGD("package app icon localized info DB initialization failed\n");
2284 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2286 _LOGD("package app image info DB initialization failed\n");
2289 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2291 _LOGD("package app app control DB initialization failed\n");
2294 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2296 _LOGD("package app app category DB initialization failed\n");
2299 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2301 _LOGD("package app app category DB initialization failed\n");
2304 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2306 _LOGD("package app app permission DB initialization failed\n");
2309 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2311 _LOGD("package app share allowed DB initialization failed\n");
2314 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2316 _LOGD("package app share request DB initialization failed\n");
2319 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2321 _LOGD("package app data control DB initialization failed\n");
2325 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2327 _LOGD("package app disable for user DB initialization failed\n");
2331 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2333 _LOGD("package app splash screen DB initialization failed\n");
2338 /* TODO: refactor this code */
2339 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2341 _LOGD("package cert info DB initialization failed\n");
2344 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2346 _LOGD("package cert index info DB initialization failed\n");
2349 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2351 _LOGD("package cert info DB initialization failed\n");
2354 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2356 _LOGD("package cert index info DB initialization failed\n");
2359 for (i = 0; columns[i] != NULL; i++) {
2360 snprintf(query, sizeof(query),
2361 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2362 columns[i], columns[i], columns[i]);
2363 ret = __initialize_db(pkgmgr_cert_db, query);
2365 _LOGD("package cert index info DB initialization failed\n");
2370 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2371 _LOGD("Failed to change cert db permission\n");
2373 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2374 _LOGD("Failed to change parser db permission\n");
2380 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2383 char pwuid_buf[1024] = {0, };
2384 char journal_file[BUFSIZE];
2387 struct passwd userinfo, *result = NULL;
2388 files[0] = (char *)db_file;
2389 files[1] = journal_file;
2393 if (db_file == NULL)
2396 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2398 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2399 if (uid == OWNER_ROOT)
2401 ret = getpwuid_r(uid, &userinfo, &pwuid_buf, sizeof(pwuid_buf), &result);
2402 if (ret != 0 || result == NULL) {
2403 _LOGE("FAIL: user %d doesn't exist", uid);
2406 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2408 for (i = 0; files[i]; i++) {
2409 ret = chown(files[i], uid, userinfo.pw_gid);
2411 if (strerror_r(errno, buf, sizeof(buf)))
2412 strncpy(buf, "", BUFSIZE - 1);
2413 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2414 userinfo.pw_gid, buf);
2418 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2419 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2421 ret = chmod(files[i], mode);
2423 if (strerror_r(errno, buf, sizeof(buf)))
2424 strncpy(buf, "", BUFSIZE - 1);
2425 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2428 SET_SMACK_LABEL(files[i]);
2433 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2437 if (getuid() != OWNER_ROOT) {
2438 _LOGE("Only root user is allowed");
2442 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2443 _LOGE("Manifest db for user %d is already exists", uid);
2447 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2448 _LOGE("Cert db for user %d is already exists", uid);
2452 ret = pkgmgr_parser_check_and_create_db(uid);
2455 ret = pkgmgr_parser_initialize_db(uid);
2457 pkgmgr_parser_close_db();
2460 pkgmgr_parser_close_db();
2465 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2469 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2471 _LOGD("Manifest DB creation Failed\n");
2476 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2478 _LOGD("Cert DB creation Failed\n");
2484 void pkgmgr_parser_close_db(void)
2486 sqlite3_close(pkgmgr_parser_db);
2487 sqlite3_close(pkgmgr_cert_db);
2491 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2493 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2495 _LOGD("manifest pointer is NULL\n");
2499 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2501 _LOGD("Failed to open DB\n");
2504 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2507 /*Begin transaction*/
2508 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2509 if (ret != SQLITE_OK) {
2510 _LOGD("Failed to begin transaction\n");
2514 _LOGD("Transaction Begin\n");
2515 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2517 _LOGD("Insert into DB failed. Rollback now\n");
2518 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2521 /*Commit transaction*/
2522 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2523 if (ret != SQLITE_OK) {
2524 _LOGD("Failed to commit transaction. Rollback now\n");
2525 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2529 _LOGD("Transaction Commit and End\n");
2531 pkgmgr_parser_close_db();
2535 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2537 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2539 _LOGD("manifest pointer is NULL\n");
2543 ret = pkgmgr_parser_check_and_create_db(uid);
2545 _LOGD("Failed to open DB\n");
2548 ret = pkgmgr_parser_initialize_db(uid);
2551 /*Begin transaction*/
2552 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2553 if (ret != SQLITE_OK) {
2554 _LOGD("Failed to begin transaction\n");
2558 _LOGD("Transaction Begin\n");
2559 ret = __insert_manifest_info_in_db(mfx, uid);
2561 _LOGD("Insert into DB failed. Rollback now\n");
2562 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2565 /*Commit transaction*/
2566 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2567 if (ret != SQLITE_OK) {
2568 _LOGD("Failed to commit transaction. Rollback now\n");
2569 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2573 _LOGD("Transaction Commit and End\n");
2575 pkgmgr_parser_close_db();
2579 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2581 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2584 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2586 if (pkgid == NULL || tep_path == NULL) {
2587 _LOGE("invalid parameter");
2594 ret = pkgmgr_parser_check_and_create_db(uid);
2596 _LOGD("Failed to open DB\n");
2599 ret = pkgmgr_parser_initialize_db(uid);
2603 /*Begin transaction*/
2604 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2605 if (ret != SQLITE_OK) {
2606 _LOGD("Failed to begin transaction\n");
2610 _LOGD("Transaction Begin\n");
2613 /* Updating TEP info in "package_info" table */
2614 query = sqlite3_mprintf("UPDATE package_info "\
2615 "SET package_tep_name = %Q "\
2616 "WHERE package = %Q", tep_path, pkgid);
2618 ret = __exec_query(query);
2619 sqlite3_free(query);
2620 if (ret != SQLITE_OK) {
2621 ret = PM_PARSER_R_ERROR;
2622 _LOGE("sqlite exec failed to insert entries into package_info!!");
2626 /* Updating TEP info in "package_app_info" table */
2627 query = sqlite3_mprintf("UPDATE package_app_info "\
2628 "SET app_tep_name = %Q "\
2629 "WHERE package = %Q", tep_path, pkgid);
2631 ret = __exec_query(query);
2632 sqlite3_free(query);
2633 if (ret != SQLITE_OK) {
2634 ret = PM_PARSER_R_ERROR;
2635 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2639 /*Commit transaction*/
2640 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2641 if (ret != SQLITE_OK) {
2642 _LOGE("Failed to commit transaction, Rollback now\n");
2643 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2644 if (ret != SQLITE_OK)
2645 _LOGE("Failed to Rollback\n");
2647 ret = PM_PARSER_R_ERROR;
2650 _LOGD("Transaction Commit and End\n");
2651 ret = PM_PARSER_R_OK;
2654 pkgmgr_parser_close_db();
2659 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2662 _LOGD("manifest pointer is NULL\n");
2666 ret = pkgmgr_parser_check_and_create_db(uid);
2668 _LOGD("Failed to open DB\n");
2671 ret = pkgmgr_parser_initialize_db(uid);
2674 /*Preserve guest mode visibility*/
2675 __preserve_guestmode_visibility_value( mfx);
2676 /*Begin transaction*/
2677 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2678 if (ret != SQLITE_OK) {
2679 _LOGD("Failed to begin transaction\n");
2683 _LOGD("Transaction Begin\n");
2684 ret = __delete_manifest_info_from_db(mfx, uid);
2686 _LOGD("Delete from DB failed. Rollback now\n");
2687 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2690 ret = __insert_manifest_info_in_db(mfx, uid);
2692 _LOGD("Insert into DB failed. Rollback now\n");
2693 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2697 /*Commit transaction*/
2698 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2699 if (ret != SQLITE_OK) {
2700 _LOGD("Failed to commit transaction. Rollback now\n");
2701 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2705 _LOGD("Transaction Commit and End\n");
2707 pkgmgr_parser_close_db();
2711 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2713 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2716 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2719 _LOGD("manifest pointer is NULL\n");
2723 ret = pkgmgr_parser_check_and_create_db(uid);
2725 _LOGD("Failed to open DB\n");
2728 /*Begin transaction*/
2729 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2730 if (ret != SQLITE_OK) {
2731 _LOGD("Failed to begin transaction\n");
2735 _LOGD("Transaction Begin\n");
2736 ret = __delete_manifest_info_from_db(mfx, uid);
2738 _LOGD("Delete from DB failed. Rollback now\n");
2739 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2742 /*Commit transaction*/
2743 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2744 if (ret != SQLITE_OK) {
2745 _LOGD("Failed to commit transaction, Rollback now\n");
2746 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2750 _LOGD("Transaction Commit and End\n");
2752 pkgmgr_parser_close_db();
2756 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2758 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2761 API int pkgmgr_parser_update_preload_info_in_db()
2764 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2766 _LOGD("Failed to open DB\n");
2769 /*Begin transaction*/
2770 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2771 if (ret != SQLITE_OK) {
2772 _LOGD("Failed to begin transaction\n");
2776 _LOGD("Transaction Begin\n");
2777 ret = __update_preload_condition_in_db();
2779 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2780 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2783 /*Commit transaction*/
2784 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2785 if (ret != SQLITE_OK) {
2786 _LOGD("Failed to commit transaction, Rollback now\n");
2787 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2791 _LOGD("Transaction Commit and End\n");
2793 pkgmgr_parser_close_db();
2797 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2800 ret = pkgmgr_parser_check_and_create_db(uid);
2802 _LOGD("Failed to open DB\n");
2805 /*Begin transaction*/
2806 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2807 if (ret != SQLITE_OK) {
2808 _LOGD("Failed to begin transaction\n");
2812 _LOGD("Transaction Begin\n");
2813 ret = __update_preload_condition_in_db();
2815 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2816 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2819 /*Commit transaction*/
2820 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2821 if (ret != SQLITE_OK) {
2822 _LOGD("Failed to commit transaction, Rollback now\n");
2823 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2827 _LOGD("Transaction Commit and End\n");
2829 pkgmgr_parser_close_db();
2833 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2837 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2839 _LOGD("Failed to open DB\n");
2843 /*Begin transaction*/
2844 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2845 if (ret != SQLITE_OK) {
2846 _LOGD("Failed to begin transaction\n");
2850 _LOGD("Transaction Begin\n");
2852 ret = __disable_global_app_for_user(appid, uid);
2854 ret = __enable_global_app_for_user(appid, uid);
2856 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2857 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2860 /*Commit transaction*/
2861 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2862 if (ret != SQLITE_OK) {
2863 _LOGD("Failed to commit transaction, Rollback now\n");
2864 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2868 _LOGD("Transaction Commit and End\n");
2870 pkgmgr_parser_close_db();
2875 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2877 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2880 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2884 ret = pkgmgr_parser_check_and_create_db(uid);
2886 _LOGD("Failed to open DB\n");
2890 /*Begin transaction*/
2891 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2892 if (ret != SQLITE_OK) {
2893 _LOGD("Failed to begin transaction\n");
2897 _LOGD("Transaction Begin\n");
2899 ret = __disable_app(appid);
2901 ret = __enable_app(appid);
2903 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2904 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2907 /*Commit transaction*/
2908 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2909 if (ret != SQLITE_OK) {
2910 _LOGD("Failed to commit transaction, Rollback now\n");
2911 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2915 _LOGD("Transaction Commit and End\n");
2917 pkgmgr_parser_close_db();