4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include <sys/types.h>
27 #include <sys/smack.h>
35 #include <system_info.h>
37 /* For multi-user support */
38 #include <tzplatform_config.h>
40 #include "pkgmgr-info.h"
41 #include "pkgmgrinfo_basic.h"
42 #include "pkgmgrinfo_debug.h"
43 #include "pkgmgr_parser_internal.h"
44 #include "pkgmgr_parser_db.h"
49 #define LOG_TAG "PKGMGR_PARSER"
51 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
52 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
53 #define MAX_QUERY_LEN 4096
61 #define XXHDPI "xxhdpi"
71 #define XXHDPI_MIN 481
72 #define XXHDPI_MAX 600
74 #define DB_LABEL "User::Home"
75 #define SET_SMACK_LABEL(x) \
77 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
78 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
80 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
83 sqlite3 *pkgmgr_parser_db;
84 sqlite3 *pkgmgr_cert_db;
87 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
88 "(package text primary key not null, " \
89 "package_type text DEFAULT 'tpk', " \
90 "package_version text, " \
91 "package_api_version text, " \
92 "package_tep_name text, " \
93 "install_location text, " \
94 "package_size text, " \
95 "package_removable text DEFAULT 'true', " \
96 "package_preload text DEFAULT 'false', " \
97 "package_readonly text DEFAULT 'false', " \
98 "package_update text DEFAULT 'false', " \
99 "package_appsetting text DEFAULT 'false', " \
100 "package_nodisplay text DEFAULT 'false', " \
101 "package_system text DEFAULT 'false', " \
102 "author_name text, " \
103 "author_email text, " \
104 "author_href text," \
105 "installed_time text," \
106 "installed_storage text," \
107 "storeclient_id text," \
109 "package_url text," \
112 "package_support_disable text DEFAULT 'false', " \
113 "package_disable text DEFAULT 'false')"
115 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
116 "(package text not null, " \
117 "package_locale text DEFAULT 'No Locale', " \
118 "package_label text, " \
119 "package_icon text, " \
120 "package_description text, " \
121 "package_license text, " \
123 "PRIMARY KEY(package, package_locale), " \
124 "FOREIGN KEY(package) " \
125 "REFERENCES package_info(package) " \
128 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
129 "(package text not null, " \
130 "privilege text not null, " \
131 "PRIMARY KEY(package, privilege) " \
132 "FOREIGN KEY(package) " \
133 "REFERENCES package_info(package) " \
136 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
137 "(app_id text primary key not null, " \
138 "app_component text, " \
140 "app_nodisplay text DEFAULT 'false', " \
142 "app_onboot text DEFAULT 'false', " \
143 "app_multiple text DEFAULT 'false', " \
144 "app_autorestart text DEFAULT 'false', " \
145 "app_taskmanage text DEFAULT 'false', " \
146 "app_enabled text DEFAULT 'true', " \
147 "app_hwacceleration text DEFAULT 'use-system-setting', " \
148 "app_screenreader text DEFAULT 'use-system-setting', " \
149 "app_mainapp text, " \
150 "app_recentimage text, " \
151 "app_launchcondition text, " \
152 "app_indicatordisplay text DEFAULT 'true', " \
153 "app_portraitimg text, " \
154 "app_landscapeimg text, " \
155 "app_guestmodevisibility text DEFAULT 'true', " \
156 "app_permissiontype text DEFAULT 'normal', " \
157 "app_preload text DEFAULT 'false', " \
158 "app_submode text DEFAULT 'false', " \
159 "app_submode_mainid text, " \
160 "app_installed_storage text, " \
161 "app_process_pool text DEFAULT 'false', " \
162 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
163 "app_ui_gadget text DEFAULT 'false', " \
164 "app_support_disable text DEFAULT 'false', " \
165 "app_disable text DEFAULT 'false', " \
166 "app_package_type text DEFAULT 'tpk', " \
167 "component_type text, " \
168 "package text not null, " \
169 "app_tep_name text, " \
170 "app_background_category INTEGER DEFAULT 0, " \
171 "app_root_path text, " \
172 "app_api_version text, " \
173 "FOREIGN KEY(package) " \
174 "REFERENCES package_info(package) " \
177 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
178 "(app_id text not null, " \
179 "app_locale text DEFAULT 'No Locale', " \
182 "PRIMARY KEY(app_id,app_locale) " \
183 "FOREIGN KEY(app_id) " \
184 "REFERENCES package_app_info(app_id) " \
187 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
188 "(app_id text not null, " \
190 "app_icon_section text, " \
191 "app_icon_resolution text, " \
192 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
198 "(app_id text not null, " \
199 "app_locale text DEFAULT 'No Locale', " \
200 "app_image_section text, " \
202 "PRIMARY KEY(app_id,app_image_section) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
208 "(app_id text not null, " \
209 "app_control text not null, " \
210 "PRIMARY KEY(app_id,app_control) " \
211 "FOREIGN KEY(app_id) " \
212 "REFERENCES package_app_info(app_id) " \
215 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
216 "(app_id text not null, " \
217 "category text not null, " \
218 "PRIMARY KEY(app_id,category) " \
219 "FOREIGN KEY(app_id) " \
220 "REFERENCES package_app_info(app_id) " \
223 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
224 "(app_id text not null, " \
225 "md_key text not null, " \
226 "md_value text not null, " \
227 "PRIMARY KEY(app_id, md_key, md_value) " \
228 "FOREIGN KEY(app_id) " \
229 "REFERENCES package_app_info(app_id) " \
232 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
233 "(app_id text not null, " \
234 "pm_type text not null, " \
235 "pm_value text not null, " \
236 "PRIMARY KEY(app_id, pm_type, pm_value) " \
237 "FOREIGN KEY(app_id) " \
238 "REFERENCES package_app_info(app_id) " \
241 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
242 "(app_id text not null, " \
243 "data_share_path text not null, " \
244 "data_share_allowed text not null, " \
245 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
246 "FOREIGN KEY(app_id) " \
247 "REFERENCES package_app_info(app_id) " \
250 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
251 "(app_id text not null, " \
252 "data_share_request text not null, " \
253 "PRIMARY KEY(app_id,data_share_request) " \
254 "FOREIGN KEY(app_id) " \
255 "REFERENCES package_app_info(app_id) " \
258 /* FIXME: duplicated at pkgmgrinfo_db.c */
259 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
260 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
261 " cert_info TEXT UNIQUE, " \
262 " cert_id INTEGER PRIMARY KEY, " \
263 " cert_ref_count INTEGER NOT NULL)"
265 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
266 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
267 " package TEXT PRIMARY KEY, " \
268 " author_root_cert INTEGER, " \
269 " author_im_cert INTEGER, " \
270 " author_signer_cert INTEGER, " \
271 " dist_root_cert INTEGER, " \
272 " dist_im_cert INTEGER, " \
273 " dist_signer_cert INTEGER, " \
274 " dist2_root_cert INTEGER, " \
275 " dist2_im_cert INTEGER, " \
276 " dist2_signer_cert INTEGER)"
278 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
279 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
280 "AFTER DELETE ON package_cert_info " \
282 " UPDATE package_cert_index_info SET" \
283 " cert_ref_count = cert_ref_count - 1" \
284 " WHERE cert_id = OLD.author_root_cert" \
285 " OR cert_id = OLD.author_im_cert" \
286 " OR cert_id = OLD.author_signer_cert" \
287 " OR cert_id = OLD.dist_root_cert" \
288 " OR cert_id = OLD.dist_im_cert" \
289 " OR cert_id = OLD.dist_signer_cert" \
290 " OR cert_id = OLD.dist2_root_cert" \
291 " OR cert_id = OLD.dist2_im_cert" \
292 " OR cert_id = OLD.dist2_signer_cert;" \
295 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
296 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
297 "AFTER UPDATE ON package_cert_index_info " \
298 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
299 " WHERE cert_id = OLD.cert_id) = 0) "\
301 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
304 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
305 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
306 "AFTER UPDATE ON package_cert_info " \
307 "WHEN (OLD.%s IS NOT NULL) " \
309 " UPDATE package_cert_index_info SET" \
310 " cert_ref_count = cert_ref_count - 1" \
311 " WHERE cert_id = OLD.%s;" \
314 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
315 "(app_id text not null, " \
316 "providerid text not null, " \
317 "access text not null, " \
318 "type text not null, " \
319 "PRIMARY KEY(app_id, providerid, access, type) " \
320 "FOREIGN KEY(app_id) " \
321 "REFERENCES package_app_info(app_id) " \
324 #define QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
325 "(app_id text not null, " \
326 "uid text not null, " \
327 "PRIMARY KEY(app_id, uid))"
329 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
330 "create table if not exists package_app_splash_screen " \
331 "(app_id text not null, " \
332 "src text not null, " \
333 "type text not null, " \
334 "orientation text not null, " \
335 "indicatordisplay text, " \
337 "PRIMARY KEY(app_id, orientation, operation) " \
338 "FOREIGN KEY(app_id) " \
339 "REFERENCES package_app_info(app_id) " \
342 static int __insert_application_info(manifest_x *mfx);
343 static int __insert_application_appcategory_info(manifest_x *mfx);
344 static int __insert_application_appcontrol_info(manifest_x *mfx);
345 static int __insert_application_appmetadata_info(manifest_x *mfx);
346 static int __insert_application_share_allowed_info(manifest_x *mfx);
347 static int __insert_application_share_request_info(manifest_x *mfx);
348 static int __insert_application_datacontrol_info(manifest_x *mfx);
349 static void __insert_application_locale_info(gpointer data, gpointer userdata);
350 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
351 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
352 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
353 static int __delete_subpkg_info_from_db(char *appid);
354 static int __delete_appinfo_from_db(char *db_table, const char *appid);
355 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
356 static int __exec_query(char *query);
357 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
358 char **label, char **license, char **icon, char **description, char **author);
359 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
360 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
361 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
362 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
363 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
364 static int __parserdb_change_perm(const char *db_file, uid_t uid);
366 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
369 __delete_subpkg_info_from_db(coltxt[0]);
374 static const char *__get_str(const char *str)
378 return PKGMGR_PARSER_EMPTY_STR;
384 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
389 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
390 if (ret != SQLITE_OK) {
391 _LOGD("connect db [%s] failed!\n", db_path);
399 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
401 manifest_x *mfx = (manifest_x *)data;
407 if (mfx->application == NULL)
409 app = (application_x *)mfx->application->data;
410 for(i = 0; i < ncols; i++)
412 if (strcmp(colname[i], "app_id") == 0) {
414 appid = strdup(coltxt[i]);
415 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
417 status = strdup(coltxt[i]);
423 _LOGD("app id is NULL\n");
426 /*update guest mode visibility*/
427 for (tmp = mfx->application; tmp; tmp = tmp->next) {
428 app = (application_x *)tmp->data;
431 if (strcmp(app->appid, appid) == 0) {
432 free((void *)app->guestmode_visibility);
433 app->guestmode_visibility = strdup(status);
449 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
451 char *error_message = NULL;
452 char query[MAX_QUERY_LEN] = {'\0'};
453 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
455 sqlite3_exec(pkgmgr_parser_db, query,
456 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
457 _LOGD("Don't execute query = %s error message = %s\n",
458 query, error_message);
459 sqlite3_free(error_message);
464 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
466 char *error_message = NULL;
468 sqlite3_exec(db_handle, db_query,
469 NULL, NULL, &error_message)) {
470 _LOGD("Don't execute query = %s error message = %s\n",
471 db_query, error_message);
472 sqlite3_free(error_message);
475 sqlite3_free(error_message);
479 static int __exec_query(char *query)
481 char *error_message = NULL;
483 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
484 _LOGE("Don't execute query = %s error message = %s\n", query,
486 sqlite3_free(error_message);
489 sqlite3_free(error_message);
493 static int __exec_query_no_msg(char *query)
495 char *error_message = NULL;
497 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
498 sqlite3_free(error_message);
501 sqlite3_free(error_message);
505 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
513 for (tmp = lbls; tmp; tmp = tmp->next) {
514 lbl = (label_x *)tmp->data;
518 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
520 for (tmp = lcns; tmp; tmp = tmp->next) {
521 lcn = (license_x *)tmp->data;
525 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
527 for (tmp = icns; tmp; tmp = tmp->next) {
528 icn = (icon_x *)tmp->data;
532 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
534 for (tmp = dcns; tmp; tmp = tmp->next) {
535 dcn = (description_x *)tmp->data;
539 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
541 for (tmp = aths; tmp; tmp = tmp->next) {
542 ath = (author_x *)tmp->data;
546 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
552 static GList *__create_icon_list(GList *appicon, GList *icns)
557 for (tmp = icns; tmp; tmp = tmp->next) {
558 icn = (icon_x *)tmp->data;
562 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
567 static GList *__create_image_list(GList *appimage, GList *imgs)
572 for (tmp = imgs; tmp; tmp = tmp->next) {
573 img = (image_x *)tmp->data;
577 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
582 static void __trimfunc(GList* trim_list)
584 char *trim_data = NULL;
588 list = g_list_first(trim_list);
591 trim_data = (char *)list->data;
594 if (strcmp(trim_data, prev) == 0) {
595 trim_list = g_list_remove(trim_list, trim_data);
596 list = g_list_first(trim_list);
605 list = g_list_next(list);
609 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
611 if (a == NULL || b == NULL)
613 if (strcmp((char*)a, (char*)b) == 0)
615 if (strcmp((char*)a, (char*)b) < 0)
617 if (strcmp((char*)a, (char*)b) > 0)
622 static int __check_dpi(const char *dpi_char, int dpi_int)
624 if (dpi_char == NULL)
627 if (strcasecmp(dpi_char, LDPI) == 0) {
628 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
632 } else if (strcasecmp(dpi_char, MDPI) == 0) {
633 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
637 } else if (strcasecmp(dpi_char, HDPI) == 0) {
638 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
642 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
643 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
647 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
648 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
656 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
659 char *icon_filename = NULL;
660 char modified_iconpath[BUFSIZE] = { '\0' };
661 char icon_path[BUFSIZE] = { '\0' };
665 if (orig_icon_path == NULL)
668 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
672 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
673 dpi_path[0] = "LDPI";
674 dpi_path[1] = "ldpi";
675 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
676 dpi_path[0] = "MDPI";
677 dpi_path[1] = "mdpi";
678 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
679 dpi_path[0] = "HDPI";
680 dpi_path[1] = "hdpi";
681 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
682 dpi_path[0] = "XHDPI";
683 dpi_path[1] = "xhdpi";
684 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
685 dpi_path[0] = "XXHDPI";
686 dpi_path[1] = "xxhdpi";
688 _LOGE("Unidentified dpi[%d]", dpi);
692 icon_filename = strrchr(orig_icon_path, '/');
693 if (icon_filename == NULL)
696 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), orig_icon_path);
697 for (i = 0; i < 2; i++) {
698 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
699 if (access(modified_iconpath, F_OK) != -1) {
700 // if exists, return modified icon path
701 *new_icon_path = strdup(modified_iconpath);
709 static gint __compare_icon(gconstpointer a, gconstpointer b)
711 icon_x *icon = (icon_x *)a;
713 char *icon_folder_path = NULL;
715 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
718 if (icon->dpi != NULL)
721 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
723 icon->text = icon_folder_path;
729 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
731 icon_x *icon = (icon_x *)a;
732 int dpi = GPOINTER_TO_INT(b);
734 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
737 if (icon->dpi == NULL)
740 if (__check_dpi(icon->dpi, dpi) == 0)
746 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
748 icon_x *icon = (icon_x *)a;
749 char *lang = (char *)b;
750 char *icon_folder_path = NULL;
752 if (icon->dpi != NULL)
755 if (strcasecmp(icon->lang, lang) == 0) {
756 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
757 //icon for no locale. check existance of folder-hierachied default icons
758 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
760 icon->text = icon_folder_path;
769 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
771 icon_x *icon = (icon_x *)a;
772 char *lang = (char *)b;
775 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
779 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
785 static char *__find_icon(GList *icons, const char *lang)
791 // first, find icon whose locale and dpi with given lang and system's dpi has matched
792 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
794 icon = (icon_x *)tmp->data;
795 return (char *)icon->text;
798 // if first has failed, find icon whose locale has matched
799 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
801 icon = (icon_x *)tmp->data;
802 return (char *)icon->text;
805 // if second has failed, find icon whose dpi has matched with system's dpi
806 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
809 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
811 icon = (icon_x *)tmp->data;
812 return (char *)icon->text;
815 // last, find default icon marked as "No Locale"
816 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
818 icon = (icon_x *)tmp->data;
819 return (char *)icon->text;
825 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
826 char **label, char **license, char **icon, char **description, char **author)
833 for (tmp = lbls; tmp; tmp = tmp->next) {
834 lbl = (label_x *)tmp->data;
838 if (strcmp(lbl->lang, (char *)data) == 0) {
839 *label = (char*)lbl->text;
844 for (tmp = lcns; tmp; tmp = tmp->next) {
845 lcn = (license_x *)tmp->data;
849 if (strcmp(lcn->lang, (char *)data) == 0) {
850 *license = (char*)lcn->text;
856 *icon = __find_icon(icns, (char *)data);
858 for (tmp = dcns; tmp; tmp = tmp->next) {
859 dcn = (description_x *)tmp->data;
863 if (strcmp(dcn->lang, (char *)data) == 0) {
864 *description = (char*)dcn->text;
869 for (tmp = aths; tmp; tmp = tmp->next) {
870 ath = (author_x *)tmp->data;
874 if (strcmp(ath->lang, (char *)data) == 0) {
875 *author = (char*)ath->text;
883 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
887 for (tmp = icns; tmp; tmp = tmp->next) {
888 icn = (icon_x *)tmp->data;
892 if (strcmp(icn->section, (char *)data) == 0) {
893 *icon = (char*)icn->text;
894 *resolution = (char*)icn->resolution;
901 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
905 for (tmp = imgs; tmp; tmp = tmp->next) {
906 img = (image_x *)tmp->data;
910 if (strcmp(img->section, (char *)data) == 0) {
911 *lang = (char*)img->lang;
912 *image = (char*)img->text;
919 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
924 char *description = NULL;
925 char *license = NULL;
929 manifest_x *mfx = (manifest_x *)userdata;
930 GList *lbl = mfx->label;
931 GList *lcn = mfx->license;
932 GList *icn = mfx->icon;
933 GList *dcn = mfx->description;
934 GList *ath = mfx->author;
936 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
937 if (!label && !description && !icon && !license && !author)
940 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
941 "package_label, package_icon, package_description, package_license, package_author) values " \
942 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
947 __get_str(description),
951 ret = __exec_query(query);
953 _LOGD("Package Localized Info DB Insert failed\n");
958 static void __insert_application_locale_info(gpointer data, gpointer userdata)
965 application_x *app = (application_x*)userdata;
966 GList *lbl = app->label;
967 GList *icn = app->icon;
969 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
973 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
974 "app_label, app_icon) values " \
975 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
976 __get_str(label), __get_str(icon));
977 ret = __exec_query(query);
979 _LOGD("Package UiApp Localized Info DB Insert failed\n");
983 /*insert ui app locale info to pkg locale to get mainapp data */
984 if (strcasecmp(app->mainapp, "true")==0) {
985 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
986 "package_label, package_icon, package_description, package_license, package_author) values " \
987 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
992 PKGMGR_PARSER_EMPTY_STR,
993 PKGMGR_PARSER_EMPTY_STR,
994 PKGMGR_PARSER_EMPTY_STR);
996 ret = __exec_query_no_msg(query);
1000 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1001 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1002 ret = __exec_query_no_msg(query);
1003 sqlite3_free(query);
1008 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1012 char *resolution = NULL;
1013 char query[MAX_QUERY_LEN] = {'\0'};
1015 application_x *app = (application_x*)userdata;
1016 GList *icn = app->icon;
1018 __extract_icon_data(data, icn, &icon, &resolution);
1019 if (!icon && !resolution)
1021 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1022 "app_icon, app_icon_section, app_icon_resolution) values " \
1023 "('%q', '%q', '%q', '%q')", app->appid,
1024 icon, (char*)data, resolution);
1026 ret = __exec_query(query);
1028 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1032 static void __insert_application_image_info(gpointer data, gpointer userdata)
1037 char query[MAX_QUERY_LEN] = {'\0'};
1039 application_x *app = (application_x*)userdata;
1040 GList *image = app->image;
1042 __extract_image_data(data, image, &lang, &img);
1045 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1046 "app_image_section, app_image) values " \
1047 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1049 ret = __exec_query(query);
1051 _LOGD("Package UiApp image Info DB Insert failed\n");
1056 static int __insert_mainapp_info(manifest_x *mfx)
1061 char query[MAX_QUERY_LEN] = {'\0'};
1062 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1063 app = (application_x *)tmp->data;
1066 snprintf(query, MAX_QUERY_LEN,
1067 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1069 ret = __exec_query(query);
1071 _LOGD("Package App Info DB Insert Failed\n");
1074 if (strcasecmp(app->mainapp, "True")==0)
1075 mfx->mainapp_id = strdup(app->appid);
1078 if (mfx->mainapp_id == NULL) {
1079 if (mfx->application == NULL)
1081 app = (application_x *)mfx->application->data;
1085 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1087 _LOGD("Not valid appid\n");
1091 ret = __exec_query(query);
1093 _LOGD("Package UiApp Info DB Insert Failed\n");
1097 free((void *)app->mainapp);
1098 app->mainapp= strdup("true");
1099 mfx->mainapp_id = strdup(app->appid);
1102 memset(query, '\0', MAX_QUERY_LEN);
1103 snprintf(query, MAX_QUERY_LEN,
1104 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1105 ret = __exec_query(query);
1107 _LOGD("Package Info DB update Failed\n");
1114 static int __convert_background_category(GList *category_list)
1117 GList *tmp_list = category_list;
1118 char *category_data = NULL;
1120 if (category_list == NULL)
1123 while (tmp_list != NULL) {
1124 category_data = (char *)tmp_list->data;
1125 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1126 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1127 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1128 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1129 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1130 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1131 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1132 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1133 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1134 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1135 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1136 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1137 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1138 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1140 _LOGE("Unidentified category [%s]", category_data);
1142 tmp_list = g_list_next(tmp_list);
1148 /* _PRODUCT_LAUNCHING_ENHANCED_
1149 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1151 static int __insert_application_info(manifest_x *mfx)
1156 int background_value = 0;
1157 char query[MAX_QUERY_LEN] = {'\0'};
1161 type = strdup(mfx->type);
1163 type = strdup("tpk");
1165 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1166 app = (application_x *)tmp->data;
1170 background_value = __convert_background_category(app->background_category);
1171 if (background_value < 0) {
1172 _LOGE("Failed to retrieve background value[%d]", background_value);
1173 background_value = 0;
1176 snprintf(query, MAX_QUERY_LEN,
1177 "insert into package_app_info(" \
1178 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1179 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1180 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1181 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1182 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1183 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1184 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version) " \
1186 "'%s', '%s', '%s', '%s', '%s', " \
1187 "'%s', '%s', '%s', '%s', '%s', " \
1188 "'%s', '%s', '%s', '%s', '%s', " \
1189 "'%s', '%s', '%s', '%s', '%s', " \
1190 "'%s', '%s', '%s', '%s', '%s', " \
1191 "'%s', '%s', '%s', '%s', '%s', " \
1192 "'%s', '%d', '%s', '%s', '%s')", \
1193 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1194 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1195 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1196 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1197 app->guestmode_visibility, app->permission_type,
1198 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1199 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1200 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version));
1202 ret = __exec_query(query);
1204 _LOGD("Package UiApp Info DB Insert Failed\n");
1209 memset(query, '\0', MAX_QUERY_LEN);
1218 static int __insert_application_appcategory_info(manifest_x *mfx)
1225 char query[MAX_QUERY_LEN] = {'\0'};
1226 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1227 app = (application_x *)app_tmp->data;
1230 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1231 ct = (const char *)ct_tmp->data;
1234 snprintf(query, MAX_QUERY_LEN,
1235 "insert into package_app_app_category(app_id, category) " \
1236 "values('%s','%s')",\
1238 ret = __exec_query(query);
1240 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1243 memset(query, '\0', MAX_QUERY_LEN);
1249 static int __insert_application_appmetadata_info(manifest_x *mfx)
1256 char query[MAX_QUERY_LEN] = {'\0'};
1257 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1258 app = (application_x *)app_tmp->data;
1261 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1262 md = (metadata_x *)md_tmp->data;
1266 snprintf(query, MAX_QUERY_LEN,
1267 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1268 "values('%s','%s', '%s')",\
1269 app->appid, md->key, md->value ? md->value : "");
1270 ret = __exec_query(query);
1272 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1276 memset(query, '\0', MAX_QUERY_LEN);
1282 static int __insert_application_apppermission_info(manifest_x *mfx)
1289 char query[MAX_QUERY_LEN] = {'\0'};
1290 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1291 app = (application_x *)app_tmp->data;
1294 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1295 pm = (permission_x *)pm_tmp->data;
1298 snprintf(query, MAX_QUERY_LEN,
1299 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1300 "values('%s','%s', '%s')",\
1301 app->appid, pm->type, pm->value);
1302 ret = __exec_query(query);
1304 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1307 memset(query, '\0', MAX_QUERY_LEN);
1313 static int __insert_application_appcontrol_info(manifest_x *mfx)
1317 GList *acontrol_tmp;
1318 appcontrol_x *acontrol;
1320 char query[MAX_QUERY_LEN] = {'\0'};
1321 char buf[BUFSIZE] = {'\0'};
1322 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1323 app = (application_x *)app_tmp->data;
1326 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1327 acontrol = (appcontrol_x *)acontrol_tmp->data;
1328 if (acontrol == NULL)
1330 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1331 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1332 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1333 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1334 snprintf(query, MAX_QUERY_LEN,
1335 "insert into package_app_app_control(app_id, app_control) " \
1336 "values('%s', '%s')",\
1338 ret = __exec_query(query);
1340 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1343 memset(query, '\0', MAX_QUERY_LEN);
1349 static int __insert_application_datacontrol_info(manifest_x *mfx)
1356 char query[MAX_QUERY_LEN] = {'\0'};
1358 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1359 app = (application_x *)app_tmp->data;
1362 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1363 dc = (datacontrol_x *)dc_tmp->data;
1366 snprintf(query, MAX_QUERY_LEN,
1367 "insert into package_app_data_control(app_id, providerid, access, type) " \
1368 "values('%s', '%s', '%s', '%s')",\
1374 ret = __exec_query(query);
1376 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1379 memset(query, '\0', MAX_QUERY_LEN);
1385 static int __insert_application_share_request_info(manifest_x *mfx)
1394 char query[MAX_QUERY_LEN] = {'\0'};
1395 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1396 app = (application_x *)app_tmp->data;
1399 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1400 ds = (datashare_x *)ds_tmp->data;
1403 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1404 rq = (const char *)rq_tmp->data;
1407 snprintf(query, MAX_QUERY_LEN,
1408 "insert into package_app_share_request(app_id, data_share_request) " \
1409 "values('%s', '%s')",\
1411 ret = __exec_query(query);
1413 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1416 memset(query, '\0', MAX_QUERY_LEN);
1423 static int __insert_application_share_allowed_info(manifest_x *mfx)
1434 char query[MAX_QUERY_LEN] = {'\0'};
1435 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1436 app = (application_x *)app_tmp->data;
1439 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1440 ds = (datashare_x *)ds_tmp->data;
1443 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1444 df = (define_x *)df_tmp->data;
1447 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1448 al = (const char *)al_tmp->data;
1451 snprintf(query, MAX_QUERY_LEN,
1452 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1453 "values('%s', '%s', '%s')",\
1454 app->appid, df->path, al);
1455 ret = __exec_query(query);
1457 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1460 memset(query, '\0', MAX_QUERY_LEN);
1468 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1470 splashscreen_x *ss = (splashscreen_x *)a;
1471 const char *orientation = (const char *)b;
1474 if (ss->operation || ss->dpi == NULL)
1477 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1481 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1487 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1489 splashscreen_x *ss = (splashscreen_x *)a;
1490 const char *orientation = (const char *)b;
1492 if (ss->operation || ss->dpi)
1495 if (strcasecmp(ss->orientation, orientation) == 0)
1501 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1502 const char *orientation)
1506 tmp = g_list_find_custom(splashscreens, orientation,
1507 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1509 return (splashscreen_x *)tmp->data;
1511 tmp = g_list_find_custom(splashscreens, orientation,
1512 (GCompareFunc)__compare_splashscreen_with_orientation);
1514 return (splashscreen_x *)tmp->data;
1519 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1521 splashscreen_x *ss = (splashscreen_x *)data;
1522 GList **list = (GList **)user_data;
1525 if (ss->operation == NULL || ss->dpi == NULL)
1528 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1532 if (__check_dpi(ss->dpi, dpi) != 0)
1535 *list = g_list_append(*list, ss);
1538 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1540 splashscreen_x *ss = (splashscreen_x *)data;
1541 GList **list = (GList **)user_data;
1542 splashscreen_x *ss_tmp;
1545 if (ss->operation == NULL || ss->dpi)
1548 for (tmp = *list; tmp; tmp = tmp->next) {
1549 ss_tmp = (splashscreen_x *)tmp->data;
1550 if (ss_tmp->operation
1551 && strcmp(ss_tmp->operation, ss->operation) == 0
1552 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1556 *list = g_list_append(*list, ss);
1559 static GList *__find_splashscreens(GList *splashscreens)
1564 g_list_foreach(splashscreens,
1565 __find_appcontrol_splashscreen_with_dpi, &list);
1566 g_list_foreach(splashscreens,
1567 __find_appcontrol_splashscreen, &list);
1569 ss = __find_default_splashscreen(splashscreens, "portrait");
1571 list = g_list_append(list, ss);
1572 ss = __find_default_splashscreen(splashscreens, "landscape");
1574 list = g_list_append(list, ss);
1579 static int __insert_application_splashscreen_info(manifest_x *mfx)
1587 char query[MAX_QUERY_LEN];
1589 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1590 app = (application_x *)app_tmp->data;
1591 if (app == NULL || app->splashscreens == NULL)
1594 ss_tmp = __find_splashscreens(app->splashscreens);
1598 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1599 ss = (splashscreen_x *)tmp->data;
1600 snprintf(query, sizeof(query),
1601 "insert into package_app_splash_screen" \
1602 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1603 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1604 app->appid, ss->src, ss->type, ss->orientation,
1605 ss->indicatordisplay, __get_str(ss->operation));
1606 ret = __exec_query(query);
1608 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1611 memset(query, '\0', MAX_QUERY_LEN);
1613 g_list_free(ss_tmp);
1618 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1623 char query[MAX_QUERY_LEN];
1625 const char *image_type;
1626 const char *indicatordisplay;
1627 const char *orientation;
1628 const char *operation = NULL;
1630 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1631 app = (application_x *)app_tmp->data;
1633 (app->portraitimg == NULL && app->landscapeimg == NULL))
1635 image_type = "img"; /* default */
1636 if (app->effectimage_type) {
1637 tmp = strstr(app->effectimage_type, "edj");
1641 indicatordisplay = "true"; /* default */
1642 if (app->indicatordisplay)
1643 indicatordisplay = app->indicatordisplay;
1644 if (app->portraitimg) {
1645 orientation = "portrait";
1646 snprintf(query, sizeof(query),
1647 "insert into package_app_splash_screen" \
1648 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1649 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1650 app->appid, app->portraitimg, image_type,
1651 orientation, indicatordisplay, __get_str(operation));
1652 ret = __exec_query(query);
1654 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1657 memset(query, '\0', MAX_QUERY_LEN);
1658 } else if (app->landscapeimg) {
1659 orientation = "landscape";
1660 snprintf(query, sizeof(query),
1661 "insert into package_app_splash_screen" \
1662 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1663 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1664 app->appid, app->landscapeimg, image_type,
1665 orientation, indicatordisplay, __get_str(operation));
1666 ret = __exec_query(query);
1668 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1671 memset(query, '\0', MAX_QUERY_LEN);
1677 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1681 const char *pv = NULL;
1682 char query[MAX_QUERY_LEN] = { '\0' };
1685 const char *auth_name = NULL;
1686 const char *auth_email = NULL;
1687 const char *auth_href = NULL;
1689 GList *pkglocale = NULL;
1690 GList *applocale = NULL;
1691 GList *appicon = NULL;
1692 GList *appimage = NULL;
1694 if (mfx->author && mfx->author->data) {
1695 author = (author_x *)mfx->author->data;
1697 auth_name = author->text;
1699 auth_email = author->email;
1701 auth_href = author->href;
1704 /*Insert in the package_cert_info CERT_DB*/
1705 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1706 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1707 if (ret != PMINFO_R_OK) {
1708 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1709 _LOGE("Cert Info DB create handle failed\n");
1712 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1713 if (ret != PMINFO_R_OK) {
1714 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1715 _LOGE("Cert Info DB Insert Failed\n");
1719 /*Insert in the package_info DB*/
1720 snprintf(query, MAX_QUERY_LEN,
1721 "insert into package_info(" \
1722 "package, package_type, package_version, package_api_version, package_tep_name, " \
1723 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1724 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1725 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1726 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1728 "'%s', '%s', '%s', '%s', '%s', " \
1729 "'%s', '%s', '%s', '%s', '%s', " \
1730 "'%s', '%s', '%s', '%s', '%s', " \
1731 "'%s', '%s', '%s', '%s', '%s', " \
1732 "'%s', '%s', '%s', '%s', '%s')", \
1733 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1734 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1735 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1736 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1737 __get_str(mfx->storeclient_id),
1738 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1740 ret = __exec_query(query);
1742 _LOGD("Package Info DB Insert Failed\n");
1746 /*Insert in the package_privilege_info DB*/
1747 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1748 pv = (const char *)tmp->data;
1751 memset(query, '\0', MAX_QUERY_LEN);
1752 snprintf(query, MAX_QUERY_LEN,
1753 "insert into package_privilege_info(package, privilege) " \
1754 "values('%s','%s')",\
1756 ret = __exec_query(query);
1758 _LOGD("Package Privilege Info DB Insert Failed\n");
1763 if (mfx->application != NULL) {
1764 ret = __insert_mainapp_info(mfx);
1769 /*Insert the package locale*/
1770 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1771 /*remove duplicated data in pkglocale*/
1772 __trimfunc(pkglocale);
1774 /*Insert the app locale, icon, image info */
1775 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1776 app = (application_x *)tmp->data;
1779 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1780 appicon = __create_icon_list(appicon, app->icon);
1781 appimage = __create_image_list(appimage, app->image);
1783 /*remove duplicated data in applocale*/
1784 __trimfunc(applocale);
1785 __trimfunc(appicon);
1786 __trimfunc(appimage);
1788 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1790 /*native app locale info*/
1791 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1792 app = (application_x *)tmp->data;
1795 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1796 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1797 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1800 g_list_free(pkglocale);
1802 g_list_free(applocale);
1804 g_list_free(appicon);
1806 g_list_free(appimage);
1809 /*Insert in the package_app_info DB*/
1810 ret = __insert_application_info(mfx);
1813 /*Insert in the package_app_app_control DB*/
1814 ret = __insert_application_appcontrol_info(mfx);
1818 /*Insert in the package_app_app_category DB*/
1819 ret = __insert_application_appcategory_info(mfx);
1823 /*Insert in the package_app_app_metadata DB*/
1824 ret = __insert_application_appmetadata_info(mfx);
1828 /*Insert in the package_app_app_permission DB*/
1829 ret = __insert_application_apppermission_info(mfx);
1833 /*Insert in the package_app_share_allowed DB*/
1834 ret = __insert_application_share_allowed_info(mfx);
1838 /*Insert in the package_app_share_request DB*/
1839 ret = __insert_application_share_request_info(mfx);
1843 /*Insert in the package_app_data_control DB*/
1844 ret = __insert_application_datacontrol_info(mfx);
1848 /*Insert in the package_app_splash_screen DB*/
1849 ret = __insert_application_legacy_splashscreen_info(mfx);
1853 /*Insert in the package_app_splash_screen DB*/
1854 ret = __insert_application_splashscreen_info(mfx);
1862 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1864 char query[MAX_QUERY_LEN] = { '\0' };
1866 memset(query, '\0', MAX_QUERY_LEN);
1867 snprintf(query, MAX_QUERY_LEN,
1868 "delete from %s where app_id='%s'", db_table, appid);
1869 ret = __exec_query(query);
1871 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1877 static int __delete_subpkg_info_from_db(char *appid)
1881 ret = __delete_appinfo_from_db("package_app_info", appid);
1884 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1887 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1890 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1893 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1896 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1899 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1902 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1905 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1908 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1911 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1914 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1921 static int __delete_subpkg_from_db(manifest_x *mfx)
1923 char query[MAX_QUERY_LEN] = { '\0' };
1924 char *error_message = NULL;
1926 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
1928 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1929 _LOGE("Don't execute query = %s error message = %s\n", query,
1931 sqlite3_free(error_message);
1934 sqlite3_free(error_message);
1939 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1941 char query[MAX_QUERY_LEN] = { '\0' };
1945 /*Delete from cert table*/
1946 ret = pkgmgrinfo_delete_certinfo(mfx->package);
1948 _LOGD("Cert Info DB Delete Failed\n");
1952 /*Delete from Package Info DB*/
1953 snprintf(query, MAX_QUERY_LEN,
1954 "delete from package_info where package='%s'", mfx->package);
1955 ret = __exec_query(query);
1957 _LOGD("Package Info DB Delete Failed\n");
1960 memset(query, '\0', MAX_QUERY_LEN);
1962 /*Delete from Package Localized Info*/
1963 snprintf(query, MAX_QUERY_LEN,
1964 "delete from package_localized_info where package='%s'", mfx->package);
1965 ret = __exec_query(query);
1967 _LOGD("Package Localized Info DB Delete Failed\n");
1971 /*Delete from Package Privilege Info*/
1972 snprintf(query, MAX_QUERY_LEN,
1973 "delete from package_privilege_info where package='%s'", mfx->package);
1974 ret = __exec_query(query);
1976 _LOGD("Package Privilege Info DB Delete Failed\n");
1980 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1981 app = (application_x *)tmp->data;
1984 ret = __delete_appinfo_from_db("package_app_info", app->appid);
1987 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
1990 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
1993 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
1996 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
1999 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2002 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2005 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2008 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2011 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2014 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2017 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2022 /* if main package has sub pkg, delete sub pkg data*/
2023 __delete_subpkg_from_db(mfx);
2028 static int __disable_app(const char *appid)
2031 char query[MAX_QUERY_LEN] = {'\0'};
2032 sqlite3_snprintf(MAX_QUERY_LEN, query,
2033 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2035 ret = __exec_query(query);
2037 _LOGD("Insert global app disable failed\n");
2042 static int __enable_app(const char *appid)
2045 char query[MAX_QUERY_LEN] = {'\0'};
2046 sqlite3_snprintf(MAX_QUERY_LEN, query,
2047 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2049 ret = __exec_query(query);
2051 _LOGD("Insert global app disable failed\n");
2056 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2059 char query[MAX_QUERY_LEN] = {'\0'};
2061 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2062 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2064 ret = __exec_query(query);
2066 _LOGD("Insert global app disable failed\n");
2071 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2074 char query[MAX_QUERY_LEN] = {'\0'};
2076 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2077 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2079 ret = __exec_query(query);
2081 _LOGD("Delete global app disable failed\n");
2086 static int __update_preload_condition_in_db()
2089 char query[MAX_QUERY_LEN] = {'\0'};
2091 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2093 ret = __exec_query(query);
2095 _LOGD("Package preload_condition update failed\n");
2100 API int pkgmgr_parser_initialize_db(uid_t uid)
2104 char query[MAX_QUERY_LEN];
2105 static const char *columns[] = {
2106 "author_root_cert", "author_im_cert", "author_signer_cert",
2107 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2108 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2112 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2114 _LOGD("package info DB initialization failed\n");
2117 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2119 _LOGD("package localized info DB initialization failed\n");
2122 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2124 _LOGD("package app app privilege DB initialization failed\n");
2127 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2129 _LOGD("package app info DB initialization failed\n");
2132 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2134 _LOGD("package app localized info DB initialization failed\n");
2137 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2139 _LOGD("package app icon localized info DB initialization failed\n");
2142 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2144 _LOGD("package app image info DB initialization failed\n");
2147 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2149 _LOGD("package app app control DB initialization failed\n");
2152 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2154 _LOGD("package app app category DB initialization failed\n");
2157 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2159 _LOGD("package app app category DB initialization failed\n");
2162 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2164 _LOGD("package app app permission DB initialization failed\n");
2167 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2169 _LOGD("package app share allowed DB initialization failed\n");
2172 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2174 _LOGD("package app share request DB initialization failed\n");
2177 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2179 _LOGD("package app data control DB initialization failed\n");
2183 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2185 _LOGD("package app disable for user DB initialization failed\n");
2189 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2191 _LOGD("package app splash screen DB initialization failed\n");
2196 /* TODO: refactor this code */
2197 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2199 _LOGD("package cert info DB initialization failed\n");
2202 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2204 _LOGD("package cert index info DB initialization failed\n");
2207 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2209 _LOGD("package cert info DB initialization failed\n");
2212 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2214 _LOGD("package cert index info DB initialization failed\n");
2217 for (i = 0; columns[i] != NULL; i++) {
2218 snprintf(query, sizeof(query),
2219 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2220 columns[i], columns[i], columns[i]);
2221 ret = __initialize_db(pkgmgr_cert_db, query);
2223 _LOGD("package cert index info DB initialization failed\n");
2228 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2229 _LOGD("Failed to change cert db permission\n");
2231 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2232 _LOGD("Failed to change parser db permission\n");
2238 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2241 char journal_file[BUFSIZE];
2244 struct passwd *userinfo = NULL;
2245 files[0] = (char *)db_file;
2246 files[1] = journal_file;
2250 if (db_file == NULL)
2253 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2255 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2256 if (uid == OWNER_ROOT)
2258 userinfo = getpwuid(uid);
2260 _LOGE("FAIL: user %d doesn't exist", uid);
2263 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2265 for (i = 0; files[i]; i++) {
2266 ret = chown(files[i], uid, userinfo->pw_gid);
2268 if (strerror_r(errno, buf, sizeof(buf)))
2269 strncpy(buf, "", BUFSIZE - 1);
2270 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2271 userinfo->pw_gid, buf);
2275 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2276 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2278 ret = chmod(files[i], mode);
2280 if (strerror_r(errno, buf, sizeof(buf)))
2281 strncpy(buf, "", BUFSIZE - 1);
2282 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2285 SET_SMACK_LABEL(files[i]);
2290 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2294 if (getuid() != OWNER_ROOT) {
2295 _LOGE("Only root user is allowed");
2299 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2300 _LOGE("Manifest db for user %d is already exists", uid);
2304 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2305 _LOGE("Cert db for user %d is already exists", uid);
2309 ret = pkgmgr_parser_check_and_create_db(uid);
2312 ret = pkgmgr_parser_initialize_db(uid);
2314 pkgmgr_parser_close_db();
2317 pkgmgr_parser_close_db();
2322 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2326 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2328 _LOGD("Manifest DB creation Failed\n");
2333 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2335 _LOGD("Cert DB creation Failed\n");
2341 void pkgmgr_parser_close_db(void)
2343 sqlite3_close(pkgmgr_parser_db);
2344 sqlite3_close(pkgmgr_cert_db);
2348 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2350 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2352 _LOGD("manifest pointer is NULL\n");
2356 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2358 _LOGD("Failed to open DB\n");
2361 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2364 /*Begin transaction*/
2365 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2366 if (ret != SQLITE_OK) {
2367 _LOGD("Failed to begin transaction\n");
2371 _LOGD("Transaction Begin\n");
2372 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2374 _LOGD("Insert into DB failed. Rollback now\n");
2375 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2378 /*Commit transaction*/
2379 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2380 if (ret != SQLITE_OK) {
2381 _LOGD("Failed to commit transaction. Rollback now\n");
2382 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2386 _LOGD("Transaction Commit and End\n");
2388 pkgmgr_parser_close_db();
2392 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2394 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2396 _LOGD("manifest pointer is NULL\n");
2400 ret = pkgmgr_parser_check_and_create_db(uid);
2402 _LOGD("Failed to open DB\n");
2405 ret = pkgmgr_parser_initialize_db(uid);
2408 /*Begin transaction*/
2409 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2410 if (ret != SQLITE_OK) {
2411 _LOGD("Failed to begin transaction\n");
2415 _LOGD("Transaction Begin\n");
2416 ret = __insert_manifest_info_in_db(mfx, uid);
2418 _LOGD("Insert into DB failed. Rollback now\n");
2419 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2422 /*Commit transaction*/
2423 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2424 if (ret != SQLITE_OK) {
2425 _LOGD("Failed to commit transaction. Rollback now\n");
2426 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2430 _LOGD("Transaction Commit and End\n");
2432 pkgmgr_parser_close_db();
2436 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2438 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2441 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2443 if (pkgid == NULL || tep_path == NULL) {
2444 _LOGE("invalid parameter");
2451 ret = pkgmgr_parser_check_and_create_db(uid);
2453 _LOGD("Failed to open DB\n");
2456 ret = pkgmgr_parser_initialize_db(uid);
2460 /*Begin transaction*/
2461 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2462 if (ret != SQLITE_OK) {
2463 _LOGD("Failed to begin transaction\n");
2467 _LOGD("Transaction Begin\n");
2470 /* Updating TEP info in "package_info" table */
2471 query = sqlite3_mprintf("UPDATE package_info "\
2472 "SET package_tep_name = %Q "\
2473 "WHERE package = %Q", tep_path, pkgid);
2475 ret = __exec_query(query);
2476 sqlite3_free(query);
2477 if (ret != SQLITE_OK) {
2478 ret = PM_PARSER_R_ERROR;
2479 _LOGE("sqlite exec failed to insert entries into package_info!!");
2483 /* Updating TEP info in "package_app_info" table */
2484 query = sqlite3_mprintf("UPDATE package_app_info "\
2485 "SET app_tep_name = %Q "\
2486 "WHERE package = %Q", tep_path, pkgid);
2488 ret = __exec_query(query);
2489 sqlite3_free(query);
2490 if (ret != SQLITE_OK) {
2491 ret = PM_PARSER_R_ERROR;
2492 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2496 /*Commit transaction*/
2497 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2498 if (ret != SQLITE_OK) {
2499 _LOGE("Failed to commit transaction, Rollback now\n");
2500 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2501 if (ret != SQLITE_OK)
2502 _LOGE("Failed to Rollback\n");
2504 ret = PM_PARSER_R_ERROR;
2507 _LOGD("Transaction Commit and End\n");
2508 ret = PM_PARSER_R_OK;
2511 pkgmgr_parser_close_db();
2516 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2519 _LOGD("manifest pointer is NULL\n");
2523 ret = pkgmgr_parser_check_and_create_db(uid);
2525 _LOGD("Failed to open DB\n");
2528 ret = pkgmgr_parser_initialize_db(uid);
2531 /*Preserve guest mode visibility*/
2532 __preserve_guestmode_visibility_value( mfx);
2533 /*Begin transaction*/
2534 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2535 if (ret != SQLITE_OK) {
2536 _LOGD("Failed to begin transaction\n");
2540 _LOGD("Transaction Begin\n");
2541 ret = __delete_manifest_info_from_db(mfx, uid);
2543 _LOGD("Delete from DB failed. Rollback now\n");
2544 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2547 ret = __insert_manifest_info_in_db(mfx, uid);
2549 _LOGD("Insert into DB failed. Rollback now\n");
2550 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2554 /*Commit transaction*/
2555 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2556 if (ret != SQLITE_OK) {
2557 _LOGD("Failed to commit transaction. Rollback now\n");
2558 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2562 _LOGD("Transaction Commit and End\n");
2564 pkgmgr_parser_close_db();
2568 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2570 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2573 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2576 _LOGD("manifest pointer is NULL\n");
2580 ret = pkgmgr_parser_check_and_create_db(uid);
2582 _LOGD("Failed to open DB\n");
2585 /*Begin transaction*/
2586 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2587 if (ret != SQLITE_OK) {
2588 _LOGD("Failed to begin transaction\n");
2592 _LOGD("Transaction Begin\n");
2593 ret = __delete_manifest_info_from_db(mfx, uid);
2595 _LOGD("Delete from DB failed. Rollback now\n");
2596 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2599 /*Commit transaction*/
2600 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2601 if (ret != SQLITE_OK) {
2602 _LOGD("Failed to commit transaction, Rollback now\n");
2603 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2607 _LOGD("Transaction Commit and End\n");
2609 pkgmgr_parser_close_db();
2613 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2615 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2618 API int pkgmgr_parser_update_preload_info_in_db()
2621 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2623 _LOGD("Failed to open DB\n");
2626 /*Begin transaction*/
2627 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2628 if (ret != SQLITE_OK) {
2629 _LOGD("Failed to begin transaction\n");
2633 _LOGD("Transaction Begin\n");
2634 ret = __update_preload_condition_in_db();
2636 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2637 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2640 /*Commit transaction*/
2641 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2642 if (ret != SQLITE_OK) {
2643 _LOGD("Failed to commit transaction, Rollback now\n");
2644 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2648 _LOGD("Transaction Commit and End\n");
2650 pkgmgr_parser_close_db();
2654 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2657 ret = pkgmgr_parser_check_and_create_db(uid);
2659 _LOGD("Failed to open DB\n");
2662 /*Begin transaction*/
2663 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2664 if (ret != SQLITE_OK) {
2665 _LOGD("Failed to begin transaction\n");
2669 _LOGD("Transaction Begin\n");
2670 ret = __update_preload_condition_in_db();
2672 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2673 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2676 /*Commit transaction*/
2677 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2678 if (ret != SQLITE_OK) {
2679 _LOGD("Failed to commit transaction, Rollback now\n");
2680 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2684 _LOGD("Transaction Commit and End\n");
2686 pkgmgr_parser_close_db();
2690 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2694 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2696 _LOGD("Failed to open DB\n");
2700 /*Begin transaction*/
2701 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2702 if (ret != SQLITE_OK) {
2703 _LOGD("Failed to begin transaction\n");
2707 _LOGD("Transaction Begin\n");
2709 ret = __disable_global_app_for_user(appid, uid);
2711 ret = __enable_global_app_for_user(appid, uid);
2713 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2714 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2717 /*Commit transaction*/
2718 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2719 if (ret != SQLITE_OK) {
2720 _LOGD("Failed to commit transaction, Rollback now\n");
2721 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2725 _LOGD("Transaction Commit and End\n");
2727 pkgmgr_parser_close_db();
2732 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2734 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2737 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2741 ret = pkgmgr_parser_check_and_create_db(uid);
2743 _LOGD("Failed to open DB\n");
2747 /*Begin transaction*/
2748 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2749 if (ret != SQLITE_OK) {
2750 _LOGD("Failed to begin transaction\n");
2754 _LOGD("Transaction Begin\n");
2756 ret = __disable_app(appid);
2758 ret = __enable_app(appid);
2760 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2761 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2764 /*Commit transaction*/
2765 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2766 if (ret != SQLITE_OK) {
2767 _LOGD("Failed to commit transaction, Rollback now\n");
2768 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2772 _LOGD("Transaction Commit and End\n");
2774 pkgmgr_parser_close_db();