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 "package_zip_mount_file text, " \
95 "install_location text, " \
96 "package_size text, " \
97 "package_removable text DEFAULT 'true', " \
98 "package_preload text DEFAULT 'false', " \
99 "package_readonly text DEFAULT 'false', " \
100 "package_update text DEFAULT 'false', " \
101 "package_appsetting text DEFAULT 'false', " \
102 "package_nodisplay text DEFAULT 'false', " \
103 "package_system text DEFAULT 'false', " \
104 "author_name text, " \
105 "author_email text, " \
106 "author_href text," \
107 "installed_time text," \
108 "installed_storage text," \
109 "storeclient_id text," \
111 "package_url text," \
114 "package_support_disable text DEFAULT 'false', " \
115 "package_disable text DEFAULT 'false')"
117 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
118 "(package text not null, " \
119 "package_locale text DEFAULT 'No Locale', " \
120 "package_label text, " \
121 "package_icon text, " \
122 "package_description text, " \
123 "package_license text, " \
125 "PRIMARY KEY(package, package_locale), " \
126 "FOREIGN KEY(package) " \
127 "REFERENCES package_info(package) " \
130 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
131 "(package text not null, " \
132 "privilege text not null, " \
133 "PRIMARY KEY(package, privilege) " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
139 "(app_id text primary key not null, " \
140 "app_component text, " \
142 "app_nodisplay text DEFAULT 'false', " \
144 "app_onboot text DEFAULT 'false', " \
145 "app_multiple text DEFAULT 'false', " \
146 "app_autorestart text DEFAULT 'false', " \
147 "app_taskmanage text DEFAULT 'false', " \
148 "app_enabled text DEFAULT 'true', " \
149 "app_hwacceleration text DEFAULT 'use-system-setting', " \
150 "app_screenreader text DEFAULT 'use-system-setting', " \
151 "app_mainapp text, " \
152 "app_recentimage text, " \
153 "app_launchcondition text, " \
154 "app_indicatordisplay text DEFAULT 'true', " \
155 "app_portraitimg text, " \
156 "app_landscapeimg text, " \
157 "app_guestmodevisibility text DEFAULT 'true', " \
158 "app_permissiontype text DEFAULT 'normal', " \
159 "app_preload text DEFAULT 'false', " \
160 "app_submode text DEFAULT 'false', " \
161 "app_submode_mainid text, " \
162 "app_installed_storage text, " \
163 "app_process_pool text DEFAULT 'false', " \
164 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
165 "app_ui_gadget text DEFAULT 'false', " \
166 "app_support_disable text DEFAULT 'false', " \
167 "app_disable text DEFAULT 'false', " \
168 "app_package_type text DEFAULT 'tpk', " \
169 "component_type text, " \
170 "package text not null, " \
171 "app_tep_name text, " \
172 "app_zip_mount_file text, " \
173 "app_background_category INTEGER DEFAULT 0, " \
174 "app_root_path text, " \
175 "app_api_version text, " \
176 "app_effective_appid text, " \
177 "app_splash_screen_display text DEFAULT 'true', " \
178 "FOREIGN KEY(package) " \
179 "REFERENCES package_info(package) " \
182 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
183 "(app_id text not null, " \
184 "app_locale text DEFAULT 'No Locale', " \
187 "PRIMARY KEY(app_id,app_locale) " \
188 "FOREIGN KEY(app_id) " \
189 "REFERENCES package_app_info(app_id) " \
192 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
193 "(app_id text not null, " \
195 "app_icon_section text, " \
196 "app_icon_resolution text, " \
197 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
198 "FOREIGN KEY(app_id) " \
199 "REFERENCES package_app_info(app_id) " \
202 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
203 "(app_id text not null, " \
204 "app_locale text DEFAULT 'No Locale', " \
205 "app_image_section text, " \
207 "PRIMARY KEY(app_id,app_image_section) " \
208 "FOREIGN KEY(app_id) " \
209 "REFERENCES package_app_info(app_id) " \
212 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
213 "(app_id text not null, " \
214 "app_control text not null, " \
215 "PRIMARY KEY(app_id,app_control) " \
216 "FOREIGN KEY(app_id) " \
217 "REFERENCES package_app_info(app_id) " \
220 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
221 "(app_id text not null, " \
222 "category text not null, " \
223 "PRIMARY KEY(app_id,category) " \
224 "FOREIGN KEY(app_id) " \
225 "REFERENCES package_app_info(app_id) " \
228 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
229 "(app_id text not null, " \
230 "md_key text not null, " \
231 "md_value text not null, " \
232 "PRIMARY KEY(app_id, md_key, md_value) " \
233 "FOREIGN KEY(app_id) " \
234 "REFERENCES package_app_info(app_id) " \
237 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
238 "(app_id text not null, " \
239 "pm_type text not null, " \
240 "pm_value text not null, " \
241 "PRIMARY KEY(app_id, pm_type, pm_value) " \
242 "FOREIGN KEY(app_id) " \
243 "REFERENCES package_app_info(app_id) " \
246 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
247 "(app_id text not null, " \
248 "data_share_path text not null, " \
249 "data_share_allowed text not null, " \
250 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
251 "FOREIGN KEY(app_id) " \
252 "REFERENCES package_app_info(app_id) " \
255 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
256 "(app_id text not null, " \
257 "data_share_request text not null, " \
258 "PRIMARY KEY(app_id,data_share_request) " \
259 "FOREIGN KEY(app_id) " \
260 "REFERENCES package_app_info(app_id) " \
263 /* FIXME: duplicated at pkgmgrinfo_db.c */
264 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
265 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
266 " cert_info TEXT UNIQUE, " \
267 " cert_id INTEGER PRIMARY KEY, " \
268 " cert_ref_count INTEGER NOT NULL)"
270 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
271 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
272 " package TEXT PRIMARY KEY, " \
273 " author_root_cert INTEGER, " \
274 " author_im_cert INTEGER, " \
275 " author_signer_cert INTEGER, " \
276 " dist_root_cert INTEGER, " \
277 " dist_im_cert INTEGER, " \
278 " dist_signer_cert INTEGER, " \
279 " dist2_root_cert INTEGER, " \
280 " dist2_im_cert INTEGER, " \
281 " dist2_signer_cert INTEGER)"
283 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
284 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
285 "AFTER DELETE ON package_cert_info " \
287 " UPDATE package_cert_index_info SET" \
288 " cert_ref_count = cert_ref_count - 1" \
289 " WHERE cert_id = OLD.author_root_cert" \
290 " OR cert_id = OLD.author_im_cert" \
291 " OR cert_id = OLD.author_signer_cert" \
292 " OR cert_id = OLD.dist_root_cert" \
293 " OR cert_id = OLD.dist_im_cert" \
294 " OR cert_id = OLD.dist_signer_cert" \
295 " OR cert_id = OLD.dist2_root_cert" \
296 " OR cert_id = OLD.dist2_im_cert" \
297 " OR cert_id = OLD.dist2_signer_cert;" \
300 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
301 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
302 "AFTER UPDATE ON package_cert_index_info " \
303 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
304 " WHERE cert_id = OLD.cert_id) = 0) "\
306 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
309 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
310 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
311 "AFTER UPDATE ON package_cert_info " \
312 "WHEN (OLD.%s IS NOT NULL) " \
314 " UPDATE package_cert_index_info SET" \
315 " cert_ref_count = cert_ref_count - 1" \
316 " WHERE cert_id = OLD.%s;" \
319 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
320 "(app_id text not null, " \
321 "providerid text not null, " \
322 "access text not null, " \
323 "type text not null, " \
324 "PRIMARY KEY(app_id, providerid, access, type) " \
325 "FOREIGN KEY(app_id) " \
326 "REFERENCES package_app_info(app_id) " \
329 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
330 "(app_id TEXT NOT NULL, " \
331 "uid TEXT NOT NULL, " \
332 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
333 "is_splash_screen_enabled TEXT NOT NULL, " \
334 "PRIMARY KEY(app_id, uid))"
335 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
336 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
337 "AFTER UPDATE ON package_app_info_for_uid " \
339 " DELETE FROM package_app_info_for_uid WHERE " \
340 " is_splash_screen_enabled=" \
341 " (SELECT package_app_info.app_splash_screen_display FROM " \
342 " package_app_info, package_app_info_for_uid WHERE " \
343 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
346 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
347 "create table if not exists package_app_splash_screen " \
348 "(app_id text not null, " \
349 "src text not null, " \
350 "type text not null, " \
351 "orientation text not null, " \
352 "indicatordisplay text, " \
354 "color_depth text not null DEFAULT '24', " \
355 "PRIMARY KEY(app_id, orientation, operation) " \
356 "FOREIGN KEY(app_id) " \
357 "REFERENCES package_app_info(app_id) " \
360 static int __insert_application_info(manifest_x *mfx);
361 static int __insert_application_appcategory_info(manifest_x *mfx);
362 static int __insert_application_appcontrol_info(manifest_x *mfx);
363 static int __insert_application_appmetadata_info(manifest_x *mfx);
364 static int __insert_application_share_allowed_info(manifest_x *mfx);
365 static int __insert_application_share_request_info(manifest_x *mfx);
366 static int __insert_application_datacontrol_info(manifest_x *mfx);
367 static void __insert_application_locale_info(gpointer data, gpointer userdata);
368 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
369 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
370 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
371 static int __delete_subpkg_info_from_db(char *appid);
372 static int __delete_appinfo_from_db(char *db_table, const char *appid);
373 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
374 static int __exec_query(char *query);
375 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
376 char **label, char **license, char **icon, char **description, char **author);
377 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
378 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
379 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
380 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
381 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
382 static int __parserdb_change_perm(const char *db_file, uid_t uid);
384 #define REGULAR_USER 5000
385 static inline uid_t _getuid(void)
387 uid_t uid = getuid();
389 if (uid < REGULAR_USER)
390 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
395 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
398 __delete_subpkg_info_from_db(coltxt[0]);
403 static const char *__get_str(const char *str)
407 return PKGMGR_PARSER_EMPTY_STR;
413 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
418 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
419 if (ret != SQLITE_OK) {
420 _LOGD("connect db [%s] failed!\n", db_path);
428 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
430 manifest_x *mfx = (manifest_x *)data;
436 if (mfx->application == NULL)
438 app = (application_x *)mfx->application->data;
439 for(i = 0; i < ncols; i++)
441 if (strcmp(colname[i], "app_id") == 0) {
443 appid = strdup(coltxt[i]);
444 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
446 status = strdup(coltxt[i]);
452 _LOGD("app id is NULL\n");
455 /*update guest mode visibility*/
456 for (tmp = mfx->application; tmp; tmp = tmp->next) {
457 app = (application_x *)tmp->data;
460 if (strcmp(app->appid, appid) == 0) {
461 free((void *)app->guestmode_visibility);
462 app->guestmode_visibility = strdup(status);
478 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
480 char *error_message = NULL;
481 char query[MAX_QUERY_LEN] = {'\0'};
482 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
484 sqlite3_exec(pkgmgr_parser_db, query,
485 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
486 _LOGD("Don't execute query = %s error message = %s\n",
487 query, error_message);
488 sqlite3_free(error_message);
493 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
495 char *error_message = NULL;
497 sqlite3_exec(db_handle, db_query,
498 NULL, NULL, &error_message)) {
499 _LOGD("Don't execute query = %s error message = %s\n",
500 db_query, error_message);
501 sqlite3_free(error_message);
504 sqlite3_free(error_message);
508 static int __exec_query(char *query)
510 char *error_message = NULL;
512 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
513 _LOGE("Don't execute query = %s error message = %s\n", query,
515 sqlite3_free(error_message);
518 sqlite3_free(error_message);
522 static int __exec_query_no_msg(char *query)
524 char *error_message = NULL;
526 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
527 sqlite3_free(error_message);
530 sqlite3_free(error_message);
534 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
542 for (tmp = lbls; tmp; tmp = tmp->next) {
543 lbl = (label_x *)tmp->data;
547 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
549 for (tmp = lcns; tmp; tmp = tmp->next) {
550 lcn = (license_x *)tmp->data;
554 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
556 for (tmp = icns; tmp; tmp = tmp->next) {
557 icn = (icon_x *)tmp->data;
561 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
563 for (tmp = dcns; tmp; tmp = tmp->next) {
564 dcn = (description_x *)tmp->data;
568 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
570 for (tmp = aths; tmp; tmp = tmp->next) {
571 ath = (author_x *)tmp->data;
575 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
581 static GList *__create_icon_list(GList *appicon, GList *icns)
586 for (tmp = icns; tmp; tmp = tmp->next) {
587 icn = (icon_x *)tmp->data;
591 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
596 static GList *__create_image_list(GList *appimage, GList *imgs)
601 for (tmp = imgs; tmp; tmp = tmp->next) {
602 img = (image_x *)tmp->data;
606 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
611 static void __trimfunc(GList* trim_list)
613 char *trim_data = NULL;
617 list = g_list_first(trim_list);
620 trim_data = (char *)list->data;
623 if (strcmp(trim_data, prev) == 0) {
624 trim_list = g_list_remove(trim_list, trim_data);
625 list = g_list_first(trim_list);
634 list = g_list_next(list);
638 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
640 if (a == NULL || b == NULL)
642 if (strcmp((char*)a, (char*)b) == 0)
644 if (strcmp((char*)a, (char*)b) < 0)
646 if (strcmp((char*)a, (char*)b) > 0)
651 static int __check_dpi(const char *dpi_char, int dpi_int)
653 if (dpi_char == NULL)
656 if (strcasecmp(dpi_char, LDPI) == 0) {
657 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
661 } else if (strcasecmp(dpi_char, MDPI) == 0) {
662 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
666 } else if (strcasecmp(dpi_char, HDPI) == 0) {
667 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
671 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
672 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
676 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
677 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
685 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
688 char *icon_filename = NULL;
689 char modified_iconpath[BUFSIZE] = { '\0' };
690 char icon_path[BUFSIZE] = { '\0' };
694 if (orig_icon_path == NULL)
697 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
701 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
702 dpi_path[0] = "LDPI";
703 dpi_path[1] = "ldpi";
704 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
705 dpi_path[0] = "MDPI";
706 dpi_path[1] = "mdpi";
707 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
708 dpi_path[0] = "HDPI";
709 dpi_path[1] = "hdpi";
710 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
711 dpi_path[0] = "XHDPI";
712 dpi_path[1] = "xhdpi";
713 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
714 dpi_path[0] = "XXHDPI";
715 dpi_path[1] = "xxhdpi";
717 _LOGE("Unidentified dpi[%d]", dpi);
721 icon_filename = strrchr(orig_icon_path, '/');
722 if (icon_filename == NULL)
725 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
726 for (i = 0; i < 2; i++) {
727 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
728 if (access(modified_iconpath, F_OK) != -1) {
729 // if exists, return modified icon path
730 *new_icon_path = strdup(modified_iconpath);
738 static gint __compare_icon(gconstpointer a, gconstpointer b)
740 icon_x *icon = (icon_x *)a;
742 char *icon_folder_path = NULL;
744 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
747 if (icon->dpi != NULL)
750 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
752 icon->text = icon_folder_path;
758 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
760 icon_x *icon = (icon_x *)a;
761 int dpi = GPOINTER_TO_INT(b);
763 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
766 if (icon->dpi == NULL)
769 if (__check_dpi(icon->dpi, dpi) == 0)
775 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
777 icon_x *icon = (icon_x *)a;
778 char *lang = (char *)b;
779 char *icon_folder_path = NULL;
781 if (icon->dpi != NULL)
784 if (strcasecmp(icon->lang, lang) == 0) {
785 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
786 //icon for no locale. check existance of folder-hierachied default icons
787 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
789 icon->text = icon_folder_path;
798 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
800 icon_x *icon = (icon_x *)a;
801 char *lang = (char *)b;
804 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
808 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
814 static char *__find_icon(GList *icons, const char *lang)
820 // first, find icon whose locale and dpi with given lang and system's dpi has matched
821 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
823 icon = (icon_x *)tmp->data;
824 return (char *)icon->text;
827 // if first has failed, find icon whose locale has matched
828 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
830 icon = (icon_x *)tmp->data;
831 return (char *)icon->text;
834 // if second has failed, find icon whose dpi has matched with system's dpi
835 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
838 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
840 icon = (icon_x *)tmp->data;
841 return (char *)icon->text;
844 // last, find default icon marked as "No Locale"
845 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
847 icon = (icon_x *)tmp->data;
848 return (char *)icon->text;
854 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
855 char **label, char **license, char **icon, char **description, char **author)
862 for (tmp = lbls; tmp; tmp = tmp->next) {
863 lbl = (label_x *)tmp->data;
867 if (strcmp(lbl->lang, (char *)data) == 0) {
868 *label = (char*)lbl->text;
873 for (tmp = lcns; tmp; tmp = tmp->next) {
874 lcn = (license_x *)tmp->data;
878 if (strcmp(lcn->lang, (char *)data) == 0) {
879 *license = (char*)lcn->text;
885 *icon = __find_icon(icns, (char *)data);
887 for (tmp = dcns; tmp; tmp = tmp->next) {
888 dcn = (description_x *)tmp->data;
892 if (strcmp(dcn->lang, (char *)data) == 0) {
893 *description = (char*)dcn->text;
898 for (tmp = aths; tmp; tmp = tmp->next) {
899 ath = (author_x *)tmp->data;
903 if (strcmp(ath->lang, (char *)data) == 0) {
904 *author = (char*)ath->text;
912 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
916 for (tmp = icns; tmp; tmp = tmp->next) {
917 icn = (icon_x *)tmp->data;
921 if (strcmp(icn->section, (char *)data) == 0) {
922 *icon = (char*)icn->text;
923 *resolution = (char*)icn->resolution;
930 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
934 for (tmp = imgs; tmp; tmp = tmp->next) {
935 img = (image_x *)tmp->data;
939 if (strcmp(img->section, (char *)data) == 0) {
940 *lang = (char*)img->lang;
941 *image = (char*)img->text;
948 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
953 char *description = NULL;
954 char *license = NULL;
958 manifest_x *mfx = (manifest_x *)userdata;
959 GList *lbl = mfx->label;
960 GList *lcn = mfx->license;
961 GList *icn = mfx->icon;
962 GList *dcn = mfx->description;
963 GList *ath = mfx->author;
965 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
966 if (!label && !description && !icon && !license && !author)
969 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
970 "package_label, package_icon, package_description, package_license, package_author) values " \
971 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
976 __get_str(description),
980 ret = __exec_query(query);
982 _LOGD("Package Localized Info DB Insert failed\n");
987 static void __insert_application_locale_info(gpointer data, gpointer userdata)
994 application_x *app = (application_x*)userdata;
995 GList *lbl = app->label;
996 GList *icn = app->icon;
998 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1002 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
1003 "app_label, app_icon) values " \
1004 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1005 __get_str(label), __get_str(icon));
1006 ret = __exec_query(query);
1008 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1010 sqlite3_free(query);
1012 /*insert ui app locale info to pkg locale to get mainapp data */
1013 if (strcasecmp(app->mainapp, "true")==0) {
1014 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
1015 "package_label, package_icon, package_description, package_license, package_author) values " \
1016 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1021 PKGMGR_PARSER_EMPTY_STR,
1022 PKGMGR_PARSER_EMPTY_STR,
1023 PKGMGR_PARSER_EMPTY_STR);
1025 ret = __exec_query_no_msg(query);
1026 sqlite3_free(query);
1029 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1030 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1031 ret = __exec_query_no_msg(query);
1032 sqlite3_free(query);
1037 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1041 char *resolution = NULL;
1042 char query[MAX_QUERY_LEN] = {'\0'};
1044 application_x *app = (application_x*)userdata;
1045 GList *icn = app->icon;
1047 __extract_icon_data(data, icn, &icon, &resolution);
1048 if (!icon && !resolution)
1050 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1051 "app_icon, app_icon_section, app_icon_resolution) values " \
1052 "('%q', '%q', '%q', '%q')", app->appid,
1053 icon, (char*)data, resolution);
1055 ret = __exec_query(query);
1057 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1061 static void __insert_application_image_info(gpointer data, gpointer userdata)
1066 char query[MAX_QUERY_LEN] = {'\0'};
1068 application_x *app = (application_x*)userdata;
1069 GList *image = app->image;
1071 __extract_image_data(data, image, &lang, &img);
1074 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1075 "app_image_section, app_image) values " \
1076 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1078 ret = __exec_query(query);
1080 _LOGD("Package UiApp image Info DB Insert failed\n");
1085 static int __insert_mainapp_info(manifest_x *mfx)
1090 char query[MAX_QUERY_LEN] = {'\0'};
1091 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1092 app = (application_x *)tmp->data;
1095 snprintf(query, MAX_QUERY_LEN,
1096 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1098 ret = __exec_query(query);
1100 _LOGD("Package App Info DB Insert Failed\n");
1103 if (strcasecmp(app->mainapp, "True")==0)
1104 mfx->mainapp_id = strdup(app->appid);
1107 if (mfx->mainapp_id == NULL) {
1108 if (mfx->application == NULL)
1110 app = (application_x *)mfx->application->data;
1114 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1116 _LOGD("Not valid appid\n");
1120 ret = __exec_query(query);
1122 _LOGD("Package UiApp Info DB Insert Failed\n");
1126 free((void *)app->mainapp);
1127 app->mainapp= strdup("true");
1128 mfx->mainapp_id = strdup(app->appid);
1131 memset(query, '\0', MAX_QUERY_LEN);
1132 snprintf(query, MAX_QUERY_LEN,
1133 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1134 ret = __exec_query(query);
1136 _LOGD("Package Info DB update Failed\n");
1143 static int __convert_background_category(GList *category_list)
1146 GList *tmp_list = category_list;
1147 char *category_data = NULL;
1149 if (category_list == NULL)
1152 while (tmp_list != NULL) {
1153 category_data = (char *)tmp_list->data;
1154 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1155 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1156 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1157 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1158 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1159 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1160 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1161 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1162 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1163 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1164 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1165 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1166 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1167 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1169 _LOGE("Unidentified category [%s]", category_data);
1171 tmp_list = g_list_next(tmp_list);
1177 static const char *__find_effective_appid(GList *metadata_list)
1182 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1183 md = (metadata_x *)tmp_list->data;
1184 if (md == NULL || md->key == NULL)
1187 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1196 /* _PRODUCT_LAUNCHING_ENHANCED_
1197 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1199 static int __insert_application_info(manifest_x *mfx)
1204 int background_value = 0;
1205 char query[MAX_QUERY_LEN] = {'\0'};
1207 const char *effective_appid;
1210 type = strdup(mfx->type);
1212 type = strdup("tpk");
1214 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1215 app = (application_x *)tmp->data;
1219 background_value = __convert_background_category(app->background_category);
1220 if (background_value < 0) {
1221 _LOGE("Failed to retrieve background value[%d]", background_value);
1222 background_value = 0;
1225 effective_appid = __find_effective_appid(app->metadata);
1227 snprintf(query, MAX_QUERY_LEN,
1228 "insert into package_app_info(" \
1229 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1230 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1231 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1232 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1233 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1234 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1235 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, app_api_version, " \
1236 "app_effective_appid, app_splash_screen_display) " \
1238 "'%s', '%s', '%s', '%s', '%s', " \
1239 "'%s', '%s', '%s', '%s', '%s', " \
1240 "'%s', '%s', '%s', '%s', '%s', " \
1241 "'%s', '%s', '%s', '%s', '%s', " \
1242 "'%s', '%s', '%s', '%s', '%s', " \
1243 "'%s', '%s', '%s', '%s', '%s', " \
1244 "'%s', '%s', '%d', '%s', '%s', " \
1245 "'%s', '%s', '%s')", \
1246 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1247 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1248 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1249 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1250 app->guestmode_visibility, app->permission_type,
1251 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1252 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1253 __get_str(mfx->tep_name), __get_str(mfx->zip_mount_file), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1254 __get_str(effective_appid), app->splash_screen_display);
1256 ret = __exec_query(query);
1258 _LOGD("Package UiApp Info DB Insert Failed\n");
1263 memset(query, '\0', MAX_QUERY_LEN);
1272 static int __insert_application_appcategory_info(manifest_x *mfx)
1279 char query[MAX_QUERY_LEN] = {'\0'};
1280 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1281 app = (application_x *)app_tmp->data;
1284 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1285 ct = (const char *)ct_tmp->data;
1288 snprintf(query, MAX_QUERY_LEN,
1289 "insert into package_app_app_category(app_id, category) " \
1290 "values('%s','%s')",\
1292 ret = __exec_query(query);
1294 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1297 memset(query, '\0', MAX_QUERY_LEN);
1303 static int __insert_application_appmetadata_info(manifest_x *mfx)
1310 char query[MAX_QUERY_LEN] = {'\0'};
1311 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1312 app = (application_x *)app_tmp->data;
1315 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1316 md = (metadata_x *)md_tmp->data;
1320 snprintf(query, MAX_QUERY_LEN,
1321 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1322 "values('%s','%s', '%s')",\
1323 app->appid, md->key, md->value ? md->value : "");
1324 ret = __exec_query(query);
1326 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1330 memset(query, '\0', MAX_QUERY_LEN);
1336 static int __insert_application_apppermission_info(manifest_x *mfx)
1343 char query[MAX_QUERY_LEN] = {'\0'};
1344 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1345 app = (application_x *)app_tmp->data;
1348 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1349 pm = (permission_x *)pm_tmp->data;
1352 snprintf(query, MAX_QUERY_LEN,
1353 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1354 "values('%s','%s', '%s')",\
1355 app->appid, pm->type, pm->value);
1356 ret = __exec_query(query);
1358 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1361 memset(query, '\0', MAX_QUERY_LEN);
1367 static int __insert_application_appcontrol_info(manifest_x *mfx)
1371 GList *acontrol_tmp;
1372 appcontrol_x *acontrol;
1374 char query[MAX_QUERY_LEN] = {'\0'};
1375 char buf[BUFSIZE] = {'\0'};
1376 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1377 app = (application_x *)app_tmp->data;
1380 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1381 acontrol = (appcontrol_x *)acontrol_tmp->data;
1382 if (acontrol == NULL)
1384 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1385 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1386 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1387 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1388 snprintf(query, MAX_QUERY_LEN,
1389 "insert into package_app_app_control(app_id, app_control) " \
1390 "values('%s', '%s')",\
1392 ret = __exec_query(query);
1394 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1397 memset(query, '\0', MAX_QUERY_LEN);
1403 static int __insert_application_datacontrol_info(manifest_x *mfx)
1410 char query[MAX_QUERY_LEN] = {'\0'};
1412 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1413 app = (application_x *)app_tmp->data;
1416 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1417 dc = (datacontrol_x *)dc_tmp->data;
1420 snprintf(query, MAX_QUERY_LEN,
1421 "insert into package_app_data_control(app_id, providerid, access, type) " \
1422 "values('%s', '%s', '%s', '%s')",\
1428 ret = __exec_query(query);
1430 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1433 memset(query, '\0', MAX_QUERY_LEN);
1439 static int __insert_application_share_request_info(manifest_x *mfx)
1448 char query[MAX_QUERY_LEN] = {'\0'};
1449 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1450 app = (application_x *)app_tmp->data;
1453 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1454 ds = (datashare_x *)ds_tmp->data;
1457 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1458 rq = (const char *)rq_tmp->data;
1461 snprintf(query, MAX_QUERY_LEN,
1462 "insert into package_app_share_request(app_id, data_share_request) " \
1463 "values('%s', '%s')",\
1465 ret = __exec_query(query);
1467 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1470 memset(query, '\0', MAX_QUERY_LEN);
1477 static int __insert_application_share_allowed_info(manifest_x *mfx)
1488 char query[MAX_QUERY_LEN] = {'\0'};
1489 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1490 app = (application_x *)app_tmp->data;
1493 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1494 ds = (datashare_x *)ds_tmp->data;
1497 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1498 df = (define_x *)df_tmp->data;
1501 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1502 al = (const char *)al_tmp->data;
1505 snprintf(query, MAX_QUERY_LEN,
1506 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1507 "values('%s', '%s', '%s')",\
1508 app->appid, df->path, al);
1509 ret = __exec_query(query);
1511 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1514 memset(query, '\0', MAX_QUERY_LEN);
1522 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1524 splashscreen_x *ss = (splashscreen_x *)a;
1525 const char *orientation = (const char *)b;
1528 if (ss->operation || ss->dpi == NULL)
1531 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1535 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1541 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1543 splashscreen_x *ss = (splashscreen_x *)a;
1544 const char *orientation = (const char *)b;
1546 if (ss->operation || ss->dpi)
1549 if (strcasecmp(ss->orientation, orientation) == 0)
1555 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1556 const char *orientation)
1560 tmp = g_list_find_custom(splashscreens, orientation,
1561 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1563 return (splashscreen_x *)tmp->data;
1565 tmp = g_list_find_custom(splashscreens, orientation,
1566 (GCompareFunc)__compare_splashscreen_with_orientation);
1568 return (splashscreen_x *)tmp->data;
1573 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1575 splashscreen_x *ss = (splashscreen_x *)data;
1576 GList **list = (GList **)user_data;
1579 if (ss->operation == NULL || ss->dpi == NULL)
1582 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1586 if (__check_dpi(ss->dpi, dpi) != 0)
1589 *list = g_list_append(*list, ss);
1592 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1594 splashscreen_x *ss = (splashscreen_x *)data;
1595 GList **list = (GList **)user_data;
1596 splashscreen_x *ss_tmp;
1599 if (ss->operation == NULL || ss->dpi)
1602 for (tmp = *list; tmp; tmp = tmp->next) {
1603 ss_tmp = (splashscreen_x *)tmp->data;
1604 if (ss_tmp->operation
1605 && strcmp(ss_tmp->operation, ss->operation) == 0
1606 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1610 *list = g_list_append(*list, ss);
1613 static GList *__find_splashscreens(GList *splashscreens)
1618 g_list_foreach(splashscreens,
1619 __find_appcontrol_splashscreen_with_dpi, &list);
1620 g_list_foreach(splashscreens,
1621 __find_appcontrol_splashscreen, &list);
1623 ss = __find_default_splashscreen(splashscreens, "portrait");
1625 list = g_list_append(list, ss);
1626 ss = __find_default_splashscreen(splashscreens, "landscape");
1628 list = g_list_append(list, ss);
1633 static int __insert_application_splashscreen_info(manifest_x *mfx)
1641 char query[MAX_QUERY_LEN];
1643 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1644 app = (application_x *)app_tmp->data;
1645 if (app == NULL || app->splashscreens == NULL)
1648 ss_tmp = __find_splashscreens(app->splashscreens);
1652 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1653 ss = (splashscreen_x *)tmp->data;
1654 snprintf(query, sizeof(query),
1655 "insert into package_app_splash_screen" \
1656 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1657 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1658 app->appid, ss->src, ss->type, ss->orientation,
1659 ss->indicatordisplay, __get_str(ss->operation),
1661 ret = __exec_query(query);
1663 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1666 memset(query, '\0', MAX_QUERY_LEN);
1668 g_list_free(ss_tmp);
1673 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1678 char query[MAX_QUERY_LEN];
1680 const char *image_type;
1681 const char *indicatordisplay;
1682 const char *orientation;
1683 const char *operation = NULL;
1684 const char *color_depth = "24"; /* default */
1686 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1687 app = (application_x *)app_tmp->data;
1689 (app->portraitimg == NULL && app->landscapeimg == NULL))
1691 image_type = "img"; /* default */
1692 if (app->effectimage_type) {
1693 tmp = strstr(app->effectimage_type, "edj");
1697 indicatordisplay = "true"; /* default */
1698 if (app->indicatordisplay)
1699 indicatordisplay = app->indicatordisplay;
1700 if (app->portraitimg) {
1701 orientation = "portrait";
1702 snprintf(query, sizeof(query),
1703 "insert into package_app_splash_screen" \
1704 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1705 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1706 app->appid, app->portraitimg, image_type,
1707 orientation, indicatordisplay, __get_str(operation),
1709 ret = __exec_query(query);
1711 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1714 memset(query, '\0', MAX_QUERY_LEN);
1716 if (app->landscapeimg) {
1717 orientation = "landscape";
1718 snprintf(query, sizeof(query),
1719 "insert into package_app_splash_screen" \
1720 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1721 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1722 app->appid, app->landscapeimg, image_type,
1723 orientation, indicatordisplay, __get_str(operation),
1725 ret = __exec_query(query);
1727 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1730 memset(query, '\0', MAX_QUERY_LEN);
1736 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1743 char query[MAX_QUERY_LEN];
1745 char *tmpptr = NULL;
1746 const char *operation;
1747 const char *portraitimg;
1748 const char *landscapeimg;
1749 const char *indicatordisplay;
1750 const char *orientation;
1751 const char *image_type;
1752 const char *color_depth = "24"; /* default */
1754 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1755 app = (application_x *)app_tmp->data;
1759 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1760 md = (metadata_x *)md_tmp->data;
1761 if (md == NULL || md->key == NULL || md->value == NULL)
1764 if (strcasestr(md->key, "operation_effect=")) {
1765 operation = index(md->key, '=');
1766 if ((operation + 1) != NULL)
1770 } else if (strcasestr(md->key, "launch_effect")) {
1777 landscapeimg = NULL;
1778 indicatordisplay = "true"; /* default */
1779 token = strtok_r(md->value, "|", &tmpptr);
1780 while (token != NULL) {
1781 if (strcasestr(token, "portrait-effectimage=")) {
1782 portraitimg = index(token, '=');
1783 if ((portraitimg + 1) != NULL)
1787 } else if (strcasestr(token, "landscape-effectimage=")) {
1788 landscapeimg = index(token, '=');
1789 if ((landscapeimg + 1) != NULL)
1792 landscapeimg = NULL;
1793 } else if (strcasestr(token, "indicatordisplay=")) {
1794 indicatordisplay = index(token, '=');
1795 if ((indicatordisplay + 1) != NULL)
1798 indicatordisplay = "true";
1801 token = strtok_r(NULL, "|", &tmpptr);
1805 orientation = "portrait";
1807 if (strcasestr(portraitimg, "edj"))
1809 snprintf(query, sizeof(query),
1810 "insert into package_app_splash_screen" \
1811 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1812 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1813 app->appid, portraitimg, image_type,
1814 orientation, indicatordisplay, __get_str(operation),
1816 ret = __exec_query(query);
1818 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1821 memset(query, '\0', MAX_QUERY_LEN);
1824 orientation = "landscape";
1826 if (strcasestr(landscapeimg, "edj"))
1828 snprintf(query, sizeof(query),
1829 "insert into package_app_splash_screen" \
1830 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1831 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1832 app->appid, landscapeimg, image_type,
1833 orientation, indicatordisplay, __get_str(operation),
1835 ret = __exec_query(query);
1837 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1840 memset(query, '\0', MAX_QUERY_LEN);
1848 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1852 const char *pv = NULL;
1853 char query[MAX_QUERY_LEN] = { '\0' };
1856 const char *auth_name = NULL;
1857 const char *auth_email = NULL;
1858 const char *auth_href = NULL;
1860 GList *pkglocale = NULL;
1861 GList *applocale = NULL;
1862 GList *appicon = NULL;
1863 GList *appimage = NULL;
1865 if (mfx->author && mfx->author->data) {
1866 author = (author_x *)mfx->author->data;
1868 auth_name = author->text;
1870 auth_email = author->email;
1872 auth_href = author->href;
1875 /*Insert in the package_cert_info CERT_DB*/
1876 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1877 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1878 if (ret != PMINFO_R_OK) {
1879 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1880 _LOGE("Cert Info DB create handle failed\n");
1883 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1884 if (ret != PMINFO_R_OK) {
1885 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1886 _LOGE("Cert Info DB Insert Failed\n");
1890 /*Insert in the package_info DB*/
1891 snprintf(query, MAX_QUERY_LEN,
1892 "insert into package_info(" \
1893 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1894 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1895 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1896 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1897 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1899 "'%s', '%s', '%s', '%s', '%s', " \
1900 "'%s', '%s', '%s', '%s', '%s', " \
1901 "'%s', '%s', '%s', '%s', '%s', " \
1902 "'%s', '%s', '%s', '%s', '%s', " \
1903 "'%s', '%s', '%s', '%s', '%s', " \
1905 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name), __get_str(mfx->zip_mount_file),
1906 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1907 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1908 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1909 __get_str(mfx->storeclient_id),
1910 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1912 ret = __exec_query(query);
1914 _LOGD("Package Info DB Insert Failed\n");
1918 /*Insert in the package_privilege_info DB*/
1919 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1920 pv = (const char *)tmp->data;
1923 memset(query, '\0', MAX_QUERY_LEN);
1924 snprintf(query, MAX_QUERY_LEN,
1925 "insert into package_privilege_info(package, privilege) " \
1926 "values('%s','%s')",\
1928 ret = __exec_query(query);
1930 _LOGD("Package Privilege Info DB Insert Failed\n");
1935 if (mfx->application != NULL) {
1936 ret = __insert_mainapp_info(mfx);
1941 /*Insert the package locale*/
1942 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1943 /*remove duplicated data in pkglocale*/
1944 __trimfunc(pkglocale);
1946 /*Insert the app locale, icon, image info */
1947 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1948 app = (application_x *)tmp->data;
1951 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1952 appicon = __create_icon_list(appicon, app->icon);
1953 appimage = __create_image_list(appimage, app->image);
1955 /*remove duplicated data in applocale*/
1956 __trimfunc(applocale);
1957 __trimfunc(appicon);
1958 __trimfunc(appimage);
1960 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1962 /*native app locale info*/
1963 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1964 app = (application_x *)tmp->data;
1967 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1968 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1969 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1972 g_list_free(pkglocale);
1974 g_list_free(applocale);
1976 g_list_free(appicon);
1978 g_list_free(appimage);
1981 /*Insert in the package_app_info DB*/
1982 ret = __insert_application_info(mfx);
1985 /*Insert in the package_app_app_control DB*/
1986 ret = __insert_application_appcontrol_info(mfx);
1990 /*Insert in the package_app_app_category DB*/
1991 ret = __insert_application_appcategory_info(mfx);
1995 /*Insert in the package_app_app_metadata DB*/
1996 ret = __insert_application_appmetadata_info(mfx);
2000 /*Insert in the package_app_app_permission DB*/
2001 ret = __insert_application_apppermission_info(mfx);
2005 /*Insert in the package_app_share_allowed DB*/
2006 ret = __insert_application_share_allowed_info(mfx);
2010 /*Insert in the package_app_share_request DB*/
2011 ret = __insert_application_share_request_info(mfx);
2015 /*Insert in the package_app_data_control DB*/
2016 ret = __insert_application_datacontrol_info(mfx);
2020 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2021 ret = __insert_application_legacy_splashscreen_info(mfx);
2025 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2026 ret = __insert_application_metadata_splashscreen_info(mfx);
2030 /*Insert in the package_app_splash_screen DB*/
2031 ret = __insert_application_splashscreen_info(mfx);
2039 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2041 char query[MAX_QUERY_LEN] = { '\0' };
2043 memset(query, '\0', MAX_QUERY_LEN);
2044 snprintf(query, MAX_QUERY_LEN,
2045 "delete from %s where app_id='%s'", db_table, appid);
2046 ret = __exec_query(query);
2048 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2054 static int __delete_subpkg_info_from_db(char *appid)
2058 ret = __delete_appinfo_from_db("package_app_info", appid);
2061 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2064 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2067 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2070 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2073 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2076 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2079 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2082 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2085 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2088 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2091 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2098 static int __delete_subpkg_from_db(manifest_x *mfx)
2100 char query[MAX_QUERY_LEN] = { '\0' };
2101 char *error_message = NULL;
2103 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2105 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2106 _LOGE("Don't execute query = %s error message = %s\n", query,
2108 sqlite3_free(error_message);
2111 sqlite3_free(error_message);
2116 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2118 char query[MAX_QUERY_LEN] = { '\0' };
2122 /*Delete from cert table*/
2123 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2125 _LOGD("Cert Info DB Delete Failed\n");
2129 /*Delete from Package Info DB*/
2130 snprintf(query, MAX_QUERY_LEN,
2131 "delete from package_info where package='%s'", mfx->package);
2132 ret = __exec_query(query);
2134 _LOGD("Package Info DB Delete Failed\n");
2137 memset(query, '\0', MAX_QUERY_LEN);
2139 /*Delete from Package Localized Info*/
2140 snprintf(query, MAX_QUERY_LEN,
2141 "delete from package_localized_info where package='%s'", mfx->package);
2142 ret = __exec_query(query);
2144 _LOGD("Package Localized Info DB Delete Failed\n");
2148 /*Delete from Package Privilege Info*/
2149 snprintf(query, MAX_QUERY_LEN,
2150 "delete from package_privilege_info where package='%s'", mfx->package);
2151 ret = __exec_query(query);
2153 _LOGD("Package Privilege Info DB Delete Failed\n");
2157 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2158 app = (application_x *)tmp->data;
2161 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2164 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2167 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2170 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2173 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2176 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2179 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2182 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2185 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2188 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2191 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2194 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2199 /* if main package has sub pkg, delete sub pkg data*/
2200 __delete_subpkg_from_db(mfx);
2205 static int __disable_app(const char *appid)
2208 char query[MAX_QUERY_LEN] = {'\0'};
2209 sqlite3_snprintf(MAX_QUERY_LEN, query,
2210 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2212 ret = __exec_query(query);
2214 _LOGD("Insert global app disable failed\n");
2219 static int __enable_app(const char *appid)
2222 char query[MAX_QUERY_LEN] = {'\0'};
2223 sqlite3_snprintf(MAX_QUERY_LEN, query,
2224 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2226 ret = __exec_query(query);
2228 _LOGD("Insert global app disable failed\n");
2233 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2236 char query[MAX_QUERY_LEN] = { '\0', };
2238 const char *val = NULL;
2243 sqlite3_snprintf(MAX_QUERY_LEN, query,
2244 "SELECT COUNT(*) FROM "
2245 "package_app_info_for_uid WHERE app_id=%Q "
2246 "AND uid='%d'", appid, (int)uid);
2248 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2249 if (ret != SQLITE_OK) {
2250 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2251 return PMINFO_R_ERROR;
2254 if (sqlite3_step(stmt) != SQLITE_ROW) {
2255 LOGE("failed to step");
2256 sqlite3_finalize(stmt);
2257 return PMINFO_R_ERROR;
2260 val = (const char *)sqlite3_column_text(stmt, 0);
2262 sqlite3_finalize(stmt);
2267 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2270 char query[MAX_QUERY_LEN] = { '\0', };
2272 ret = __check_appinfo_for_uid_table(appid, uid);
2274 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2277 } else if (ret == 0) {
2278 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2279 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2280 "VALUES(%Q, '%d', 'true', "
2281 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2282 appid, (int)uid, appid);
2284 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2285 "package_app_info_for_uid SET is_disabled='true' "
2286 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2289 ret = __exec_query(query);
2291 _LOGD("Add global app disable info failed\n");
2296 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2299 char query[MAX_QUERY_LEN] = {'\0'};
2301 ret = __check_appinfo_for_uid_table(appid, uid);
2303 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2306 } else if (ret > 0) {
2307 sqlite3_snprintf(MAX_QUERY_LEN, query,
2308 "UPDATE package_app_info_for_uid SET "
2309 "is_disabled='false' WHERE app_id=%Q AND "
2310 "uid='%d'", appid, (int)uid);
2313 ret = __exec_query(query);
2315 _LOGD("Remove global app disable info failed\n");
2320 static int __update_global_app_splash_screen_for_user(const char *appid,
2321 uid_t uid, int flag)
2324 char query[MAX_QUERY_LEN] = { '\0', };
2326 ret = __check_appinfo_for_uid_table(appid, uid);
2328 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2331 } else if (ret == 0) {
2332 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2333 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2334 "VALUES(%Q, '%d', %Q)", appid, (int)uid,
2335 flag ? "true" : "false");
2337 sqlite3_snprintf(MAX_QUERY_LEN, query,
2338 "UPDATE package_app_info_for_uid SET "
2339 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2340 "uid='%d'", flag ? "true" : "false", appid, (int)uid);
2343 ret = __exec_query(query);
2345 _LOGD("update global app splash screen info failed\n");
2350 static int __disable_app_splash_screen(const char *appid)
2353 char query[MAX_QUERY_LEN] = {'\0'};
2355 sqlite3_snprintf(MAX_QUERY_LEN, query,
2356 "UPDATE package_app_info set app_splash_screen_display='false' where app_id=%Q",
2358 ret = __exec_query(query);
2360 _LOGD("Failed to update app_palsh_screen_display");
2365 static int __enable_app_splash_screen(const char *appid)
2368 char query[MAX_QUERY_LEN] = {'\0'};
2370 sqlite3_snprintf(MAX_QUERY_LEN, query,
2371 "UPDATE package_app_info set app_splash_screen_display='true' where app_id=%Q",
2373 ret = __exec_query(query);
2375 _LOGD("Failed to update app_splash_screen_display");
2380 static int __update_preload_condition_in_db()
2383 char query[MAX_QUERY_LEN] = {'\0'};
2385 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2387 ret = __exec_query(query);
2389 _LOGD("Package preload_condition update failed\n");
2394 API int pkgmgr_parser_initialize_db(uid_t uid)
2398 char query[MAX_QUERY_LEN];
2399 static const char *columns[] = {
2400 "author_root_cert", "author_im_cert", "author_signer_cert",
2401 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2402 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2406 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2408 _LOGD("package info DB initialization failed\n");
2411 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2413 _LOGD("package localized info DB initialization failed\n");
2416 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2418 _LOGD("package app app privilege DB initialization failed\n");
2421 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2423 _LOGD("package app info DB initialization failed\n");
2426 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2428 _LOGD("package app localized info DB initialization failed\n");
2431 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2433 _LOGD("package app icon localized info DB initialization failed\n");
2436 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2438 _LOGD("package app image info DB initialization failed\n");
2441 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2443 _LOGD("package app app control DB initialization failed\n");
2446 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2448 _LOGD("package app app category DB initialization failed\n");
2451 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2453 _LOGD("package app app category DB initialization failed\n");
2456 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2458 _LOGD("package app app permission DB initialization failed\n");
2461 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2463 _LOGD("package app share allowed DB initialization failed\n");
2466 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2468 _LOGD("package app share request DB initialization failed\n");
2471 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2473 _LOGD("package app data control DB initialization failed\n");
2477 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2479 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2483 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2485 _LOGD("package app splash screen DB initialization failed\n");
2489 /* Trigger package_app_info_for_uid */
2490 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2492 _LOGD("package app info for uid DB initialization failed\n");
2497 /* TODO: refactor this code */
2498 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2500 _LOGD("package cert info DB initialization failed\n");
2503 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2505 _LOGD("package cert index info DB initialization failed\n");
2508 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2510 _LOGD("package cert info DB initialization failed\n");
2513 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2515 _LOGD("package cert index info DB initialization failed\n");
2518 for (i = 0; columns[i] != NULL; i++) {
2519 snprintf(query, sizeof(query),
2520 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2521 columns[i], columns[i], columns[i]);
2522 ret = __initialize_db(pkgmgr_cert_db, query);
2524 _LOGD("package cert index info DB initialization failed\n");
2529 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2530 _LOGD("Failed to change cert db permission\n");
2532 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2533 _LOGD("Failed to change parser db permission\n");
2539 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2542 char pwuid_buf[1024];
2543 char journal_file[BUFSIZE];
2546 struct passwd userinfo, *result = NULL;
2547 files[0] = (char *)db_file;
2548 files[1] = journal_file;
2552 if (db_file == NULL)
2555 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2557 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2558 if (uid == OWNER_ROOT)
2560 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2561 if (ret != 0 || result == NULL) {
2562 _LOGE("FAIL: user %d doesn't exist", uid);
2565 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2567 for (i = 0; files[i]; i++) {
2568 ret = chown(files[i], uid, userinfo.pw_gid);
2570 if (strerror_r(errno, buf, sizeof(buf)))
2571 strncpy(buf, "", BUFSIZE - 1);
2572 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2573 userinfo.pw_gid, buf);
2577 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2578 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2580 ret = chmod(files[i], mode);
2582 if (strerror_r(errno, buf, sizeof(buf)))
2583 strncpy(buf, "", BUFSIZE - 1);
2584 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2587 SET_SMACK_LABEL(files[i]);
2592 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2596 if (getuid() != OWNER_ROOT) {
2597 _LOGE("Only root user is allowed");
2601 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2602 _LOGE("Manifest db for user %d is already exists", uid);
2606 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2607 _LOGE("Cert db for user %d is already exists", uid);
2611 ret = pkgmgr_parser_check_and_create_db(uid);
2614 ret = pkgmgr_parser_initialize_db(uid);
2616 pkgmgr_parser_close_db();
2619 pkgmgr_parser_close_db();
2624 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2628 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2630 _LOGD("Manifest DB creation Failed\n");
2635 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2637 _LOGD("Cert DB creation Failed\n");
2643 void pkgmgr_parser_close_db(void)
2645 sqlite3_close(pkgmgr_parser_db);
2646 sqlite3_close(pkgmgr_cert_db);
2650 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2652 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2654 _LOGD("manifest pointer is NULL\n");
2658 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2660 _LOGD("Failed to open DB\n");
2663 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2666 /*Begin transaction*/
2667 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2668 if (ret != SQLITE_OK) {
2669 _LOGD("Failed to begin transaction\n");
2673 _LOGD("Transaction Begin\n");
2674 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2676 _LOGD("Insert into DB failed. Rollback now\n");
2677 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2680 /*Commit transaction*/
2681 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2682 if (ret != SQLITE_OK) {
2683 _LOGD("Failed to commit transaction. Rollback now\n");
2684 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2688 _LOGD("Transaction Commit and End\n");
2690 pkgmgr_parser_close_db();
2694 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2696 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2698 _LOGD("manifest pointer is NULL\n");
2702 ret = pkgmgr_parser_check_and_create_db(uid);
2704 _LOGD("Failed to open DB\n");
2707 ret = pkgmgr_parser_initialize_db(uid);
2710 /*Begin transaction*/
2711 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2712 if (ret != SQLITE_OK) {
2713 _LOGD("Failed to begin transaction\n");
2717 _LOGD("Transaction Begin\n");
2718 ret = __insert_manifest_info_in_db(mfx, uid);
2720 _LOGD("Insert into DB failed. Rollback now\n");
2721 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2724 /*Commit transaction*/
2725 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2726 if (ret != SQLITE_OK) {
2727 _LOGD("Failed to commit transaction. Rollback now\n");
2728 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2732 _LOGD("Transaction Commit and End\n");
2734 pkgmgr_parser_close_db();
2738 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2741 _LOGD("manifest pointer is NULL\n");
2745 ret = pkgmgr_parser_check_and_create_db(uid);
2747 _LOGD("Failed to open DB\n");
2750 ret = pkgmgr_parser_initialize_db(uid);
2753 /*Preserve guest mode visibility*/
2754 __preserve_guestmode_visibility_value( mfx);
2755 /*Begin transaction*/
2756 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2757 if (ret != SQLITE_OK) {
2758 _LOGD("Failed to begin transaction\n");
2762 _LOGD("Transaction Begin\n");
2763 ret = __delete_manifest_info_from_db(mfx, uid);
2765 _LOGD("Delete from DB failed. Rollback now\n");
2766 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2769 ret = __insert_manifest_info_in_db(mfx, uid);
2771 _LOGD("Insert into DB failed. Rollback now\n");
2772 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2776 /*Commit transaction*/
2777 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2778 if (ret != SQLITE_OK) {
2779 _LOGD("Failed to commit transaction. Rollback now\n");
2780 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2784 _LOGD("Transaction Commit and End\n");
2786 pkgmgr_parser_close_db();
2790 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2792 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2795 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2798 _LOGD("manifest pointer is NULL\n");
2802 ret = pkgmgr_parser_check_and_create_db(uid);
2804 _LOGD("Failed to open DB\n");
2807 /*Begin transaction*/
2808 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2809 if (ret != SQLITE_OK) {
2810 _LOGD("Failed to begin transaction\n");
2814 _LOGD("Transaction Begin\n");
2815 ret = __delete_manifest_info_from_db(mfx, uid);
2817 _LOGD("Delete from DB failed. Rollback now\n");
2818 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2821 /*Commit transaction*/
2822 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2823 if (ret != SQLITE_OK) {
2824 _LOGD("Failed to commit transaction, Rollback now\n");
2825 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2829 _LOGD("Transaction Commit and End\n");
2831 pkgmgr_parser_close_db();
2835 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2837 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2840 API int pkgmgr_parser_update_preload_info_in_db()
2843 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2845 _LOGD("Failed to open DB\n");
2848 /*Begin transaction*/
2849 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2850 if (ret != SQLITE_OK) {
2851 _LOGD("Failed to begin transaction\n");
2855 _LOGD("Transaction Begin\n");
2856 ret = __update_preload_condition_in_db();
2858 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2859 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2862 /*Commit transaction*/
2863 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2864 if (ret != SQLITE_OK) {
2865 _LOGD("Failed to commit transaction, Rollback now\n");
2866 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2870 _LOGD("Transaction Commit and End\n");
2872 pkgmgr_parser_close_db();
2876 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2879 ret = pkgmgr_parser_check_and_create_db(uid);
2881 _LOGD("Failed to open DB\n");
2884 /*Begin transaction*/
2885 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2886 if (ret != SQLITE_OK) {
2887 _LOGD("Failed to begin transaction\n");
2891 _LOGD("Transaction Begin\n");
2892 ret = __update_preload_condition_in_db();
2894 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2895 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2898 /*Commit transaction*/
2899 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2900 if (ret != SQLITE_OK) {
2901 _LOGD("Failed to commit transaction, Rollback now\n");
2902 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2906 _LOGD("Transaction Commit and End\n");
2908 pkgmgr_parser_close_db();
2912 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2916 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2918 _LOGD("Failed to open DB\n");
2922 /*Begin transaction*/
2923 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2924 if (ret != SQLITE_OK) {
2925 _LOGD("Failed to begin transaction\n");
2929 _LOGD("Transaction Begin\n");
2931 ret = __disable_global_app_for_user(appid, uid);
2933 ret = __enable_global_app_for_user(appid, uid);
2935 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2936 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2939 /*Commit transaction*/
2940 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2941 if (ret != SQLITE_OK) {
2942 _LOGD("Failed to commit transaction, Rollback now\n");
2943 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2947 _LOGD("Transaction Commit and End\n");
2949 pkgmgr_parser_close_db();
2954 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2956 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2959 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2963 ret = pkgmgr_parser_check_and_create_db(uid);
2965 _LOGD("Failed to open DB\n");
2969 /*Begin transaction*/
2970 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2971 if (ret != SQLITE_OK) {
2972 _LOGD("Failed to begin transaction\n");
2976 _LOGD("Transaction Begin\n");
2978 ret = __disable_app(appid);
2980 ret = __enable_app(appid);
2982 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2983 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2986 /*Commit transaction*/
2987 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2988 if (ret != SQLITE_OK) {
2989 _LOGD("Failed to commit transaction, Rollback now\n");
2990 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2994 _LOGD("Transaction Commit and End\n");
2996 pkgmgr_parser_close_db();
3001 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3005 if (appid == NULL) {
3006 _LOGD("Invalid parameter");
3010 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3012 _LOGD("Failed to open DB\n");
3016 /* Begin transaction */
3017 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3018 if (ret != SQLITE_OK) {
3019 _LOGD("Failed to begin transaction\n");
3023 _LOGD("Transaction Begin\n");
3025 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3027 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3028 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3031 /* Commit transaction */
3032 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3033 if (ret != SQLITE_OK) {
3034 _LOGD("Failed to commit transaction, Rollback now\n");
3035 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3039 _LOGD("Transaction Commit and End\n");
3041 pkgmgr_parser_close_db();
3045 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3047 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3050 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3054 if (appid == NULL) {
3055 _LOGD("Invalid parameter");
3059 ret = pkgmgr_parser_check_and_create_db(uid);
3061 _LOGD("Failed to open DB");
3065 /* Begin transaction */
3066 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3067 if (ret != SQLITE_OK) {
3068 _LOGD("Failed to begin transaction");
3072 _LOGD("Transaction Begin");
3075 ret = __enable_app_splash_screen(appid);
3077 ret = __disable_app_splash_screen(appid);
3079 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3080 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3083 /* Commit transaction */
3084 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3085 if (ret != SQLITE_OK) {
3086 _LOGD("Failed to commit transaction, Rollback now");
3087 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3091 _LOGD("Transaction Commit and End");
3094 pkgmgr_parser_close_db();