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>
37 #include <system_info.h>
39 /* For multi-user support */
40 #include <tzplatform_config.h>
42 #include "pkgmgr-info.h"
43 #include "pkgmgrinfo_basic.h"
44 #include "pkgmgrinfo_debug.h"
45 #include "pkgmgr_parser_internal.h"
46 #include "pkgmgr_parser_db.h"
51 #define LOG_TAG "PKGMGR_PARSER"
53 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
54 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
55 #define MAX_QUERY_LEN 4096
63 #define XXHDPI "xxhdpi"
73 #define XXHDPI_MIN 481
74 #define XXHDPI_MAX 600
76 #define DB_LABEL "User::Home"
77 #define SET_SMACK_LABEL(x) \
79 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
80 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
82 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
85 sqlite3 *pkgmgr_parser_db;
86 sqlite3 *pkgmgr_cert_db;
89 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
90 "(package text primary key not null, " \
91 "package_type text DEFAULT 'tpk', " \
92 "package_version text, " \
93 "package_api_version text, " \
94 "package_tep_name text, " \
95 "package_zip_mount_file text, " \
96 "install_location text, " \
97 "package_size text, " \
98 "package_removable text DEFAULT 'true', " \
99 "package_preload text DEFAULT 'false', " \
100 "package_readonly text DEFAULT 'false', " \
101 "package_update text DEFAULT 'false', " \
102 "package_appsetting text DEFAULT 'false', " \
103 "package_nodisplay text DEFAULT 'false', " \
104 "package_system text DEFAULT 'false', " \
105 "author_name text, " \
106 "author_email text, " \
107 "author_href text," \
108 "installed_time text," \
109 "installed_storage text," \
110 "storeclient_id text," \
112 "package_url text," \
115 "package_support_disable text DEFAULT 'false', " \
116 "package_disable text DEFAULT 'false')"
118 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
119 "(package text not null, " \
120 "package_locale text DEFAULT 'No Locale', " \
121 "package_label text, " \
122 "package_icon text, " \
123 "package_description text, " \
124 "package_license text, " \
126 "PRIMARY KEY(package, package_locale), " \
127 "FOREIGN KEY(package) " \
128 "REFERENCES package_info(package) " \
131 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
132 "(package text not null, " \
133 "privilege text not null, " \
134 "PRIMARY KEY(package, privilege) " \
135 "FOREIGN KEY(package) " \
136 "REFERENCES package_info(package) " \
139 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
140 "(app_id text primary key not null, " \
141 "app_component text, " \
143 "app_nodisplay text DEFAULT 'false', " \
145 "app_onboot text DEFAULT 'false', " \
146 "app_multiple text DEFAULT 'false', " \
147 "app_autorestart text DEFAULT 'false', " \
148 "app_taskmanage text DEFAULT 'false', " \
149 "app_enabled text DEFAULT 'true', " \
150 "app_hwacceleration text DEFAULT 'use-system-setting', " \
151 "app_screenreader text DEFAULT 'use-system-setting', " \
152 "app_mainapp text, " \
153 "app_recentimage text, " \
154 "app_launchcondition text, " \
155 "app_indicatordisplay text DEFAULT 'true', " \
156 "app_portraitimg text, " \
157 "app_landscapeimg text, " \
158 "app_guestmodevisibility text DEFAULT 'true', " \
159 "app_permissiontype text DEFAULT 'normal', " \
160 "app_preload text DEFAULT 'false', " \
161 "app_submode text DEFAULT 'false', " \
162 "app_submode_mainid text, " \
163 "app_installed_storage text, " \
164 "app_process_pool text DEFAULT 'false', " \
165 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
166 "app_ui_gadget text DEFAULT 'false', " \
167 "app_support_disable text DEFAULT 'false', " \
168 "app_disable text DEFAULT 'false', " \
169 "app_package_type text DEFAULT 'tpk', " \
170 "component_type text, " \
171 "package text not null, " \
172 "app_tep_name text, " \
173 "app_zip_mount_file text, " \
174 "app_background_category INTEGER DEFAULT 0, " \
175 "app_root_path text, " \
176 "app_api_version text, " \
177 "app_effective_appid text, " \
178 "app_splash_screen_display text DEFAULT 'true', " \
179 "FOREIGN KEY(package) " \
180 "REFERENCES package_info(package) " \
183 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
184 "(app_id text not null, " \
185 "app_locale text DEFAULT 'No Locale', " \
188 "PRIMARY KEY(app_id,app_locale) " \
189 "FOREIGN KEY(app_id) " \
190 "REFERENCES package_app_info(app_id) " \
193 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
194 "(app_id text not null, " \
196 "app_icon_section text, " \
197 "app_icon_resolution text, " \
198 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
199 "FOREIGN KEY(app_id) " \
200 "REFERENCES package_app_info(app_id) " \
203 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
204 "(app_id text not null, " \
205 "app_locale text DEFAULT 'No Locale', " \
206 "app_image_section text, " \
208 "PRIMARY KEY(app_id,app_image_section) " \
209 "FOREIGN KEY(app_id) " \
210 "REFERENCES package_app_info(app_id) " \
213 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
214 "(app_id text not null, " \
215 "app_control text not null, " \
216 "PRIMARY KEY(app_id,app_control) " \
217 "FOREIGN KEY(app_id) " \
218 "REFERENCES package_app_info(app_id) " \
221 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
222 "(app_id text not null, " \
223 "category text not null, " \
224 "PRIMARY KEY(app_id,category) " \
225 "FOREIGN KEY(app_id) " \
226 "REFERENCES package_app_info(app_id) " \
229 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
230 "(app_id text not null, " \
231 "md_key text not null, " \
232 "md_value text not null, " \
233 "PRIMARY KEY(app_id, md_key, md_value) " \
234 "FOREIGN KEY(app_id) " \
235 "REFERENCES package_app_info(app_id) " \
238 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
239 "(app_id text not null, " \
240 "pm_type text not null, " \
241 "pm_value text not null, " \
242 "PRIMARY KEY(app_id, pm_type, pm_value) " \
243 "FOREIGN KEY(app_id) " \
244 "REFERENCES package_app_info(app_id) " \
247 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
248 "(app_id text not null, " \
249 "data_share_path text not null, " \
250 "data_share_allowed text not null, " \
251 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
252 "FOREIGN KEY(app_id) " \
253 "REFERENCES package_app_info(app_id) " \
256 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
257 "(app_id text not null, " \
258 "data_share_request text not null, " \
259 "PRIMARY KEY(app_id,data_share_request) " \
260 "FOREIGN KEY(app_id) " \
261 "REFERENCES package_app_info(app_id) " \
264 /* FIXME: duplicated at pkgmgrinfo_db.c */
265 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
266 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
267 " cert_info TEXT UNIQUE, " \
268 " cert_id INTEGER PRIMARY KEY, " \
269 " cert_ref_count INTEGER NOT NULL)"
271 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
272 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
273 " package TEXT PRIMARY KEY, " \
274 " author_root_cert INTEGER, " \
275 " author_im_cert INTEGER, " \
276 " author_signer_cert INTEGER, " \
277 " dist_root_cert INTEGER, " \
278 " dist_im_cert INTEGER, " \
279 " dist_signer_cert INTEGER, " \
280 " dist2_root_cert INTEGER, " \
281 " dist2_im_cert INTEGER, " \
282 " dist2_signer_cert INTEGER)"
284 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
285 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
286 "AFTER DELETE ON package_cert_info " \
288 " UPDATE package_cert_index_info SET" \
289 " cert_ref_count = cert_ref_count - 1" \
290 " WHERE cert_id = OLD.author_root_cert" \
291 " OR cert_id = OLD.author_im_cert" \
292 " OR cert_id = OLD.author_signer_cert" \
293 " OR cert_id = OLD.dist_root_cert" \
294 " OR cert_id = OLD.dist_im_cert" \
295 " OR cert_id = OLD.dist_signer_cert" \
296 " OR cert_id = OLD.dist2_root_cert" \
297 " OR cert_id = OLD.dist2_im_cert" \
298 " OR cert_id = OLD.dist2_signer_cert;" \
301 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
302 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
303 "AFTER UPDATE ON package_cert_index_info " \
304 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
305 " WHERE cert_id = OLD.cert_id) = 0) "\
307 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
310 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
311 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
312 "AFTER UPDATE ON package_cert_info " \
313 "WHEN (OLD.%s IS NOT NULL) " \
315 " UPDATE package_cert_index_info SET" \
316 " cert_ref_count = cert_ref_count - 1" \
317 " WHERE cert_id = OLD.%s;" \
320 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
321 "(app_id text not null, " \
322 "providerid text not null, " \
323 "access text not null, " \
324 "type text not null, " \
325 "PRIMARY KEY(app_id, providerid, access, type) " \
326 "FOREIGN KEY(app_id) " \
327 "REFERENCES package_app_info(app_id) " \
330 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
331 "(app_id TEXT NOT NULL, " \
332 "uid TEXT NOT NULL, " \
333 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
334 "is_splash_screen_enabled TEXT NOT NULL, " \
335 "PRIMARY KEY(app_id, uid))"
336 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
337 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
338 "AFTER UPDATE ON package_app_info_for_uid " \
340 " DELETE FROM package_app_info_for_uid WHERE " \
341 " is_splash_screen_enabled=" \
342 " (SELECT package_app_info.app_splash_screen_display FROM " \
343 " package_app_info, package_app_info_for_uid WHERE " \
344 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
347 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
348 "create table if not exists package_app_splash_screen " \
349 "(app_id text not null, " \
350 "src text not null, " \
351 "type text not null, " \
352 "orientation text not null, " \
353 "indicatordisplay text, " \
355 "color_depth text not null DEFAULT '24', " \
356 "PRIMARY KEY(app_id, orientation, operation) " \
357 "FOREIGN KEY(app_id) " \
358 "REFERENCES package_app_info(app_id) " \
361 static int __insert_application_info(manifest_x *mfx);
362 static int __insert_application_appcategory_info(manifest_x *mfx);
363 static int __insert_application_appcontrol_info(manifest_x *mfx);
364 static int __insert_application_appmetadata_info(manifest_x *mfx);
365 static int __insert_application_share_allowed_info(manifest_x *mfx);
366 static int __insert_application_share_request_info(manifest_x *mfx);
367 static int __insert_application_datacontrol_info(manifest_x *mfx);
368 static void __insert_application_locale_info(gpointer data, gpointer userdata);
369 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
370 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
371 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
372 static int __delete_subpkg_info_from_db(char *appid);
373 static int __delete_appinfo_from_db(char *db_table, const char *appid);
374 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
375 static int __exec_query(char *query);
376 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
377 char **label, char **license, char **icon, char **description, char **author);
378 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
379 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
380 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
381 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
382 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
383 static int __parserdb_change_perm(const char *db_file, uid_t uid);
385 #define REGULAR_USER 5000
386 static inline uid_t _getuid(void)
388 uid_t uid = getuid();
390 if (uid < REGULAR_USER)
391 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
396 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
399 __delete_subpkg_info_from_db(coltxt[0]);
404 static const char *__get_str(const char *str)
408 return PKGMGR_PARSER_EMPTY_STR;
414 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
419 char *error_message = NULL;
421 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
422 if (ret != SQLITE_OK) {
423 _LOGD("connect db [%s] failed!\n", db_path);
428 /* add user_version for db upgrade*/
429 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
431 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
432 _LOGE("Don't execute query = %s error message = %s\n", query,
435 sqlite3_free(error_message);
441 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
443 manifest_x *mfx = (manifest_x *)data;
449 if (mfx->application == NULL)
451 app = (application_x *)mfx->application->data;
452 for(i = 0; i < ncols; i++)
454 if (strcmp(colname[i], "app_id") == 0) {
456 appid = strdup(coltxt[i]);
457 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
459 status = strdup(coltxt[i]);
465 _LOGD("app id is NULL\n");
468 /*update guest mode visibility*/
469 for (tmp = mfx->application; tmp; tmp = tmp->next) {
470 app = (application_x *)tmp->data;
473 if (strcmp(app->appid, appid) == 0) {
474 free((void *)app->guestmode_visibility);
475 app->guestmode_visibility = strdup(status);
491 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
493 char *error_message = NULL;
494 char query[MAX_QUERY_LEN] = {'\0'};
495 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
497 sqlite3_exec(pkgmgr_parser_db, query,
498 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
499 _LOGD("Don't execute query = %s error message = %s\n",
500 query, error_message);
501 sqlite3_free(error_message);
506 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
508 char *error_message = NULL;
510 sqlite3_exec(db_handle, db_query,
511 NULL, NULL, &error_message)) {
512 _LOGD("Don't execute query = %s error message = %s\n",
513 db_query, error_message);
514 sqlite3_free(error_message);
517 sqlite3_free(error_message);
521 static int __exec_query(char *query)
523 char *error_message = NULL;
525 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
526 _LOGE("Don't execute query = %s error message = %s\n", query,
528 sqlite3_free(error_message);
531 sqlite3_free(error_message);
535 static int __exec_query_no_msg(char *query)
537 char *error_message = NULL;
539 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
540 sqlite3_free(error_message);
543 sqlite3_free(error_message);
547 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
555 for (tmp = lbls; tmp; tmp = tmp->next) {
556 lbl = (label_x *)tmp->data;
560 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
562 for (tmp = lcns; tmp; tmp = tmp->next) {
563 lcn = (license_x *)tmp->data;
567 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
569 for (tmp = icns; tmp; tmp = tmp->next) {
570 icn = (icon_x *)tmp->data;
574 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
576 for (tmp = dcns; tmp; tmp = tmp->next) {
577 dcn = (description_x *)tmp->data;
581 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
583 for (tmp = aths; tmp; tmp = tmp->next) {
584 ath = (author_x *)tmp->data;
588 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
594 static GList *__create_icon_list(GList *appicon, GList *icns)
599 for (tmp = icns; tmp; tmp = tmp->next) {
600 icn = (icon_x *)tmp->data;
604 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
609 static GList *__create_image_list(GList *appimage, GList *imgs)
614 for (tmp = imgs; tmp; tmp = tmp->next) {
615 img = (image_x *)tmp->data;
619 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
624 static void __trimfunc(GList* trim_list)
626 char *trim_data = NULL;
630 list = g_list_first(trim_list);
633 trim_data = (char *)list->data;
636 if (strcmp(trim_data, prev) == 0) {
637 trim_list = g_list_remove(trim_list, trim_data);
638 list = g_list_first(trim_list);
647 list = g_list_next(list);
651 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
653 if (a == NULL || b == NULL)
655 if (strcmp((char*)a, (char*)b) == 0)
657 if (strcmp((char*)a, (char*)b) < 0)
659 if (strcmp((char*)a, (char*)b) > 0)
664 static int __check_dpi(const char *dpi_char, int dpi_int)
666 if (dpi_char == NULL)
669 if (strcasecmp(dpi_char, LDPI) == 0) {
670 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
674 } else if (strcasecmp(dpi_char, MDPI) == 0) {
675 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
679 } else if (strcasecmp(dpi_char, HDPI) == 0) {
680 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
684 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
685 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
689 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
690 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
698 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
701 char *icon_filename = NULL;
702 char modified_iconpath[BUFSIZE] = { '\0' };
703 char icon_path[BUFSIZE] = { '\0' };
707 if (orig_icon_path == NULL)
710 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
714 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
715 dpi_path[0] = "LDPI";
716 dpi_path[1] = "ldpi";
717 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
718 dpi_path[0] = "MDPI";
719 dpi_path[1] = "mdpi";
720 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
721 dpi_path[0] = "HDPI";
722 dpi_path[1] = "hdpi";
723 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
724 dpi_path[0] = "XHDPI";
725 dpi_path[1] = "xhdpi";
726 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
727 dpi_path[0] = "XXHDPI";
728 dpi_path[1] = "xxhdpi";
730 _LOGE("Unidentified dpi[%d]", dpi);
734 icon_filename = strrchr(orig_icon_path, '/');
735 if (icon_filename == NULL)
738 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
739 for (i = 0; i < 2; i++) {
740 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
741 if (access(modified_iconpath, F_OK) != -1) {
742 // if exists, return modified icon path
743 *new_icon_path = strdup(modified_iconpath);
751 static gint __compare_icon(gconstpointer a, gconstpointer b)
753 icon_x *icon = (icon_x *)a;
755 char *icon_folder_path = NULL;
757 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
760 if (icon->dpi != NULL)
763 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
765 icon->text = icon_folder_path;
771 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
773 icon_x *icon = (icon_x *)a;
774 int dpi = GPOINTER_TO_INT(b);
776 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
779 if (icon->dpi == NULL)
782 if (__check_dpi(icon->dpi, dpi) == 0)
788 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
790 icon_x *icon = (icon_x *)a;
791 char *lang = (char *)b;
792 char *icon_folder_path = NULL;
794 if (icon->dpi != NULL)
797 if (strcasecmp(icon->lang, lang) == 0) {
798 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
799 //icon for no locale. check existance of folder-hierachied default icons
800 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
802 icon->text = icon_folder_path;
811 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
813 icon_x *icon = (icon_x *)a;
814 char *lang = (char *)b;
817 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
821 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
827 static char *__find_icon(GList *icons, const char *lang)
833 // first, find icon whose locale and dpi with given lang and system's dpi has matched
834 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
836 icon = (icon_x *)tmp->data;
837 return (char *)icon->text;
840 // if first has failed, find icon whose locale has matched
841 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
843 icon = (icon_x *)tmp->data;
844 return (char *)icon->text;
847 // if second has failed, find icon whose dpi has matched with system's dpi
848 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
851 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
853 icon = (icon_x *)tmp->data;
854 return (char *)icon->text;
857 // last, find default icon marked as "No Locale"
858 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
860 icon = (icon_x *)tmp->data;
861 return (char *)icon->text;
867 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
868 char **label, char **license, char **icon, char **description, char **author)
875 for (tmp = lbls; tmp; tmp = tmp->next) {
876 lbl = (label_x *)tmp->data;
880 if (strcmp(lbl->lang, (char *)data) == 0) {
881 *label = (char*)lbl->text;
886 for (tmp = lcns; tmp; tmp = tmp->next) {
887 lcn = (license_x *)tmp->data;
891 if (strcmp(lcn->lang, (char *)data) == 0) {
892 *license = (char*)lcn->text;
898 *icon = __find_icon(icns, (char *)data);
900 for (tmp = dcns; tmp; tmp = tmp->next) {
901 dcn = (description_x *)tmp->data;
905 if (strcmp(dcn->lang, (char *)data) == 0) {
906 *description = (char*)dcn->text;
911 for (tmp = aths; tmp; tmp = tmp->next) {
912 ath = (author_x *)tmp->data;
916 if (strcmp(ath->lang, (char *)data) == 0) {
917 *author = (char*)ath->text;
925 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
929 for (tmp = icns; tmp; tmp = tmp->next) {
930 icn = (icon_x *)tmp->data;
934 if (strcmp(icn->section, (char *)data) == 0) {
935 *icon = (char*)icn->text;
936 *resolution = (char*)icn->resolution;
943 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
947 for (tmp = imgs; tmp; tmp = tmp->next) {
948 img = (image_x *)tmp->data;
952 if (strcmp(img->section, (char *)data) == 0) {
953 *lang = (char*)img->lang;
954 *image = (char*)img->text;
961 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
966 char *description = NULL;
967 char *license = NULL;
971 manifest_x *mfx = (manifest_x *)userdata;
972 GList *lbl = mfx->label;
973 GList *lcn = mfx->license;
974 GList *icn = mfx->icon;
975 GList *dcn = mfx->description;
976 GList *ath = mfx->author;
978 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
979 if (!label && !description && !icon && !license && !author)
982 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
983 "package_label, package_icon, package_description, package_license, package_author) values " \
984 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
989 __get_str(description),
993 ret = __exec_query(query);
995 _LOGD("Package Localized Info DB Insert failed\n");
1000 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1007 application_x *app = (application_x*)userdata;
1008 GList *lbl = app->label;
1009 GList *icn = app->icon;
1011 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1012 if (!label && !icon)
1015 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
1016 "app_label, app_icon) values " \
1017 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1018 __get_str(label), __get_str(icon));
1019 ret = __exec_query(query);
1021 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1023 sqlite3_free(query);
1025 /*insert ui app locale info to pkg locale to get mainapp data */
1026 if (strcasecmp(app->mainapp, "true")==0) {
1027 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
1028 "package_label, package_icon, package_description, package_license, package_author) values " \
1029 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1034 PKGMGR_PARSER_EMPTY_STR,
1035 PKGMGR_PARSER_EMPTY_STR,
1036 PKGMGR_PARSER_EMPTY_STR);
1038 ret = __exec_query_no_msg(query);
1039 sqlite3_free(query);
1042 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1043 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1044 ret = __exec_query_no_msg(query);
1045 sqlite3_free(query);
1050 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1054 char *resolution = NULL;
1055 char query[MAX_QUERY_LEN] = {'\0'};
1057 application_x *app = (application_x*)userdata;
1058 GList *icn = app->icon;
1060 __extract_icon_data(data, icn, &icon, &resolution);
1061 if (!icon && !resolution)
1063 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1064 "app_icon, app_icon_section, app_icon_resolution) values " \
1065 "('%q', '%q', '%q', '%q')", app->appid,
1066 icon, (char*)data, resolution);
1068 ret = __exec_query(query);
1070 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1074 static void __insert_application_image_info(gpointer data, gpointer userdata)
1079 char query[MAX_QUERY_LEN] = {'\0'};
1081 application_x *app = (application_x*)userdata;
1082 GList *image = app->image;
1084 __extract_image_data(data, image, &lang, &img);
1087 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1088 "app_image_section, app_image) values " \
1089 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1091 ret = __exec_query(query);
1093 _LOGD("Package UiApp image Info DB Insert failed\n");
1098 static int __insert_mainapp_info(manifest_x *mfx)
1103 char query[MAX_QUERY_LEN] = {'\0'};
1104 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1105 app = (application_x *)tmp->data;
1108 snprintf(query, MAX_QUERY_LEN,
1109 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1111 ret = __exec_query(query);
1113 _LOGD("Package App Info DB Insert Failed\n");
1116 if (strcasecmp(app->mainapp, "True")==0)
1117 mfx->mainapp_id = strdup(app->appid);
1120 if (mfx->mainapp_id == NULL) {
1121 if (mfx->application == NULL)
1123 app = (application_x *)mfx->application->data;
1127 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1129 _LOGD("Not valid appid\n");
1133 ret = __exec_query(query);
1135 _LOGD("Package UiApp Info DB Insert Failed\n");
1139 free((void *)app->mainapp);
1140 app->mainapp= strdup("true");
1141 mfx->mainapp_id = strdup(app->appid);
1144 memset(query, '\0', MAX_QUERY_LEN);
1145 snprintf(query, MAX_QUERY_LEN,
1146 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1147 ret = __exec_query(query);
1149 _LOGD("Package Info DB update Failed\n");
1156 static int __convert_background_category(GList *category_list)
1159 GList *tmp_list = category_list;
1160 char *category_data = NULL;
1162 if (category_list == NULL)
1165 while (tmp_list != NULL) {
1166 category_data = (char *)tmp_list->data;
1167 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1168 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1169 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1170 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1171 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1172 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1173 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1174 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1175 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1176 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1177 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1178 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1179 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1180 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1182 _LOGE("Unidentified category [%s]", category_data);
1184 tmp_list = g_list_next(tmp_list);
1190 static const char *__find_effective_appid(GList *metadata_list)
1195 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1196 md = (metadata_x *)tmp_list->data;
1197 if (md == NULL || md->key == NULL)
1200 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1209 /* _PRODUCT_LAUNCHING_ENHANCED_
1210 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1212 static int __insert_application_info(manifest_x *mfx)
1217 int background_value = 0;
1218 char query[MAX_QUERY_LEN] = {'\0'};
1220 const char *effective_appid;
1223 type = strdup(mfx->type);
1225 type = strdup("tpk");
1227 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1228 app = (application_x *)tmp->data;
1232 background_value = __convert_background_category(app->background_category);
1233 if (background_value < 0) {
1234 _LOGE("Failed to retrieve background value[%d]", background_value);
1235 background_value = 0;
1238 effective_appid = __find_effective_appid(app->metadata);
1240 snprintf(query, MAX_QUERY_LEN,
1241 "insert into package_app_info(" \
1242 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1243 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1244 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1245 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1246 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1247 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1248 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, app_api_version, " \
1249 "app_effective_appid, app_splash_screen_display) " \
1251 "'%s', '%s', '%s', '%s', '%s', " \
1252 "'%s', '%s', '%s', '%s', '%s', " \
1253 "'%s', '%s', '%s', '%s', '%s', " \
1254 "'%s', '%s', '%s', '%s', '%s', " \
1255 "'%s', '%s', '%s', '%s', '%s', " \
1256 "'%s', '%s', '%s', '%s', '%s', " \
1257 "'%s', '%s', '%d', '%s', '%s', " \
1258 "'%s', '%s', '%s')", \
1259 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1260 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1261 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1262 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1263 app->guestmode_visibility, app->permission_type,
1264 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1265 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1266 __get_str(mfx->tep_name), __get_str(mfx->zip_mount_file), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1267 __get_str(effective_appid), app->splash_screen_display);
1269 ret = __exec_query(query);
1271 _LOGD("Package UiApp Info DB Insert Failed\n");
1276 memset(query, '\0', MAX_QUERY_LEN);
1285 static int __insert_application_appcategory_info(manifest_x *mfx)
1292 char query[MAX_QUERY_LEN] = {'\0'};
1293 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1294 app = (application_x *)app_tmp->data;
1297 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1298 ct = (const char *)ct_tmp->data;
1301 snprintf(query, MAX_QUERY_LEN,
1302 "insert into package_app_app_category(app_id, category) " \
1303 "values('%s','%s')",\
1305 ret = __exec_query(query);
1307 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1310 memset(query, '\0', MAX_QUERY_LEN);
1316 static int __insert_application_appmetadata_info(manifest_x *mfx)
1323 char query[MAX_QUERY_LEN] = {'\0'};
1324 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1325 app = (application_x *)app_tmp->data;
1328 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1329 md = (metadata_x *)md_tmp->data;
1333 snprintf(query, MAX_QUERY_LEN,
1334 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1335 "values('%s','%s', '%s')",\
1336 app->appid, md->key, md->value ? md->value : "");
1337 ret = __exec_query(query);
1339 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1343 memset(query, '\0', MAX_QUERY_LEN);
1349 static int __insert_application_apppermission_info(manifest_x *mfx)
1356 char query[MAX_QUERY_LEN] = {'\0'};
1357 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1358 app = (application_x *)app_tmp->data;
1361 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1362 pm = (permission_x *)pm_tmp->data;
1365 snprintf(query, MAX_QUERY_LEN,
1366 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1367 "values('%s','%s', '%s')",\
1368 app->appid, pm->type, pm->value);
1369 ret = __exec_query(query);
1371 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1374 memset(query, '\0', MAX_QUERY_LEN);
1380 static int __insert_application_appcontrol_info(manifest_x *mfx)
1384 GList *acontrol_tmp;
1385 appcontrol_x *acontrol;
1387 char query[MAX_QUERY_LEN] = {'\0'};
1388 char buf[BUFSIZE] = {'\0'};
1389 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1390 app = (application_x *)app_tmp->data;
1393 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1394 acontrol = (appcontrol_x *)acontrol_tmp->data;
1395 if (acontrol == NULL)
1397 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1398 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1399 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1400 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1401 snprintf(query, MAX_QUERY_LEN,
1402 "insert into package_app_app_control(app_id, app_control) " \
1403 "values('%s', '%s')",\
1405 ret = __exec_query(query);
1407 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1410 memset(query, '\0', MAX_QUERY_LEN);
1416 static int __insert_application_datacontrol_info(manifest_x *mfx)
1423 char query[MAX_QUERY_LEN] = {'\0'};
1425 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1426 app = (application_x *)app_tmp->data;
1429 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1430 dc = (datacontrol_x *)dc_tmp->data;
1433 snprintf(query, MAX_QUERY_LEN,
1434 "insert into package_app_data_control(app_id, providerid, access, type) " \
1435 "values('%s', '%s', '%s', '%s')",\
1441 ret = __exec_query(query);
1443 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1446 memset(query, '\0', MAX_QUERY_LEN);
1452 static int __insert_application_share_request_info(manifest_x *mfx)
1461 char query[MAX_QUERY_LEN] = {'\0'};
1462 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1463 app = (application_x *)app_tmp->data;
1466 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1467 ds = (datashare_x *)ds_tmp->data;
1470 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1471 rq = (const char *)rq_tmp->data;
1474 snprintf(query, MAX_QUERY_LEN,
1475 "insert into package_app_share_request(app_id, data_share_request) " \
1476 "values('%s', '%s')",\
1478 ret = __exec_query(query);
1480 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1483 memset(query, '\0', MAX_QUERY_LEN);
1490 static int __insert_application_share_allowed_info(manifest_x *mfx)
1501 char query[MAX_QUERY_LEN] = {'\0'};
1502 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1503 app = (application_x *)app_tmp->data;
1506 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1507 ds = (datashare_x *)ds_tmp->data;
1510 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1511 df = (define_x *)df_tmp->data;
1514 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1515 al = (const char *)al_tmp->data;
1518 snprintf(query, MAX_QUERY_LEN,
1519 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1520 "values('%s', '%s', '%s')",\
1521 app->appid, df->path, al);
1522 ret = __exec_query(query);
1524 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1527 memset(query, '\0', MAX_QUERY_LEN);
1535 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1537 splashscreen_x *ss = (splashscreen_x *)a;
1538 const char *orientation = (const char *)b;
1541 if (ss->operation || ss->dpi == NULL)
1544 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1548 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1554 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1556 splashscreen_x *ss = (splashscreen_x *)a;
1557 const char *orientation = (const char *)b;
1559 if (ss->operation || ss->dpi)
1562 if (strcasecmp(ss->orientation, orientation) == 0)
1568 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1569 const char *orientation)
1573 tmp = g_list_find_custom(splashscreens, orientation,
1574 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1576 return (splashscreen_x *)tmp->data;
1578 tmp = g_list_find_custom(splashscreens, orientation,
1579 (GCompareFunc)__compare_splashscreen_with_orientation);
1581 return (splashscreen_x *)tmp->data;
1586 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1588 splashscreen_x *ss = (splashscreen_x *)data;
1589 GList **list = (GList **)user_data;
1592 if (ss->operation == NULL || ss->dpi == NULL)
1595 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1599 if (__check_dpi(ss->dpi, dpi) != 0)
1602 *list = g_list_append(*list, ss);
1605 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1607 splashscreen_x *ss = (splashscreen_x *)data;
1608 GList **list = (GList **)user_data;
1609 splashscreen_x *ss_tmp;
1612 if (ss->operation == NULL || ss->dpi)
1615 for (tmp = *list; tmp; tmp = tmp->next) {
1616 ss_tmp = (splashscreen_x *)tmp->data;
1617 if (ss_tmp->operation
1618 && strcmp(ss_tmp->operation, ss->operation) == 0
1619 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1623 *list = g_list_append(*list, ss);
1626 static GList *__find_splashscreens(GList *splashscreens)
1631 g_list_foreach(splashscreens,
1632 __find_appcontrol_splashscreen_with_dpi, &list);
1633 g_list_foreach(splashscreens,
1634 __find_appcontrol_splashscreen, &list);
1636 ss = __find_default_splashscreen(splashscreens, "portrait");
1638 list = g_list_append(list, ss);
1639 ss = __find_default_splashscreen(splashscreens, "landscape");
1641 list = g_list_append(list, ss);
1646 static int __insert_application_splashscreen_info(manifest_x *mfx)
1654 char query[MAX_QUERY_LEN];
1656 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1657 app = (application_x *)app_tmp->data;
1658 if (app == NULL || app->splashscreens == NULL)
1661 ss_tmp = __find_splashscreens(app->splashscreens);
1665 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1666 ss = (splashscreen_x *)tmp->data;
1667 snprintf(query, sizeof(query),
1668 "insert into package_app_splash_screen" \
1669 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1670 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1671 app->appid, ss->src, ss->type, ss->orientation,
1672 ss->indicatordisplay, __get_str(ss->operation),
1674 ret = __exec_query(query);
1676 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1679 memset(query, '\0', MAX_QUERY_LEN);
1681 g_list_free(ss_tmp);
1686 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1691 char query[MAX_QUERY_LEN];
1693 const char *image_type;
1694 const char *indicatordisplay;
1695 const char *orientation;
1696 const char *operation = NULL;
1697 const char *color_depth = "24"; /* default */
1699 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1700 app = (application_x *)app_tmp->data;
1702 (app->portraitimg == NULL && app->landscapeimg == NULL))
1704 image_type = "img"; /* default */
1705 if (app->effectimage_type) {
1706 tmp = strstr(app->effectimage_type, "edj");
1710 indicatordisplay = "true"; /* default */
1711 if (app->indicatordisplay)
1712 indicatordisplay = app->indicatordisplay;
1713 if (app->portraitimg) {
1714 orientation = "portrait";
1715 snprintf(query, sizeof(query),
1716 "insert into package_app_splash_screen" \
1717 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1718 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1719 app->appid, app->portraitimg, image_type,
1720 orientation, indicatordisplay, __get_str(operation),
1722 ret = __exec_query(query);
1724 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1727 memset(query, '\0', MAX_QUERY_LEN);
1729 if (app->landscapeimg) {
1730 orientation = "landscape";
1731 snprintf(query, sizeof(query),
1732 "insert into package_app_splash_screen" \
1733 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1734 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1735 app->appid, app->landscapeimg, image_type,
1736 orientation, indicatordisplay, __get_str(operation),
1738 ret = __exec_query(query);
1740 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1743 memset(query, '\0', MAX_QUERY_LEN);
1749 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1756 char query[MAX_QUERY_LEN];
1758 char *tmpptr = NULL;
1759 const char *operation;
1760 const char *portraitimg;
1761 const char *landscapeimg;
1762 const char *indicatordisplay;
1763 const char *orientation;
1764 const char *image_type;
1765 const char *color_depth = "24"; /* default */
1767 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1768 app = (application_x *)app_tmp->data;
1772 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1773 md = (metadata_x *)md_tmp->data;
1774 if (md == NULL || md->key == NULL || md->value == NULL)
1777 if (strcasestr(md->key, "operation_effect=")) {
1778 operation = index(md->key, '=');
1779 if ((operation + 1) != NULL)
1783 } else if (strcasestr(md->key, "launch_effect")) {
1790 landscapeimg = NULL;
1791 indicatordisplay = "true"; /* default */
1792 token = strtok_r(md->value, "|", &tmpptr);
1793 while (token != NULL) {
1794 if (strcasestr(token, "portrait-effectimage=")) {
1795 portraitimg = index(token, '=');
1796 if ((portraitimg + 1) != NULL)
1800 } else if (strcasestr(token, "landscape-effectimage=")) {
1801 landscapeimg = index(token, '=');
1802 if ((landscapeimg + 1) != NULL)
1805 landscapeimg = NULL;
1806 } else if (strcasestr(token, "indicatordisplay=")) {
1807 indicatordisplay = index(token, '=');
1808 if ((indicatordisplay + 1) != NULL)
1811 indicatordisplay = "true";
1814 token = strtok_r(NULL, "|", &tmpptr);
1818 orientation = "portrait";
1820 if (strcasestr(portraitimg, "edj"))
1822 snprintf(query, sizeof(query),
1823 "insert into package_app_splash_screen" \
1824 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1825 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1826 app->appid, portraitimg, image_type,
1827 orientation, indicatordisplay, __get_str(operation),
1829 ret = __exec_query(query);
1831 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1834 memset(query, '\0', MAX_QUERY_LEN);
1837 orientation = "landscape";
1839 if (strcasestr(landscapeimg, "edj"))
1841 snprintf(query, sizeof(query),
1842 "insert into package_app_splash_screen" \
1843 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1844 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1845 app->appid, landscapeimg, image_type,
1846 orientation, indicatordisplay, __get_str(operation),
1848 ret = __exec_query(query);
1850 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1853 memset(query, '\0', MAX_QUERY_LEN);
1861 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1865 const char *pv = NULL;
1866 char query[MAX_QUERY_LEN] = { '\0' };
1869 const char *auth_name = NULL;
1870 const char *auth_email = NULL;
1871 const char *auth_href = NULL;
1873 GList *pkglocale = NULL;
1874 GList *applocale = NULL;
1875 GList *appicon = NULL;
1876 GList *appimage = NULL;
1878 if (mfx->author && mfx->author->data) {
1879 author = (author_x *)mfx->author->data;
1881 auth_name = author->text;
1883 auth_email = author->email;
1885 auth_href = author->href;
1888 /*Insert in the package_cert_info CERT_DB*/
1889 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1890 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1891 if (ret != PMINFO_R_OK) {
1892 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1893 _LOGE("Cert Info DB create handle failed\n");
1896 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1897 if (ret != PMINFO_R_OK) {
1898 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1899 _LOGE("Cert Info DB Insert Failed\n");
1903 /*Insert in the package_info DB*/
1904 snprintf(query, MAX_QUERY_LEN,
1905 "insert into package_info(" \
1906 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1907 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1908 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1909 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1910 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1912 "'%s', '%s', '%s', '%s', '%s', " \
1913 "'%s', '%s', '%s', '%s', '%s', " \
1914 "'%s', '%s', '%s', '%s', '%s', " \
1915 "'%s', '%s', '%s', '%s', '%s', " \
1916 "'%s', '%s', '%s', '%s', '%s', " \
1918 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name), __get_str(mfx->zip_mount_file),
1919 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1920 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1921 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1922 __get_str(mfx->storeclient_id),
1923 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1925 ret = __exec_query(query);
1927 _LOGD("Package Info DB Insert Failed\n");
1931 /*Insert in the package_privilege_info DB*/
1932 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1933 pv = (const char *)tmp->data;
1936 memset(query, '\0', MAX_QUERY_LEN);
1937 snprintf(query, MAX_QUERY_LEN,
1938 "insert into package_privilege_info(package, privilege) " \
1939 "values('%s','%s')",\
1941 ret = __exec_query(query);
1943 _LOGD("Package Privilege Info DB Insert Failed\n");
1948 if (mfx->application != NULL) {
1949 ret = __insert_mainapp_info(mfx);
1954 /*Insert the package locale*/
1955 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1956 /*remove duplicated data in pkglocale*/
1957 __trimfunc(pkglocale);
1959 /*Insert the app locale, icon, image info */
1960 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1961 app = (application_x *)tmp->data;
1964 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1965 appicon = __create_icon_list(appicon, app->icon);
1966 appimage = __create_image_list(appimage, app->image);
1968 /*remove duplicated data in applocale*/
1969 __trimfunc(applocale);
1970 __trimfunc(appicon);
1971 __trimfunc(appimage);
1973 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1975 /*native app locale info*/
1976 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1977 app = (application_x *)tmp->data;
1980 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1981 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1982 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1985 g_list_free(pkglocale);
1987 g_list_free(applocale);
1989 g_list_free(appicon);
1991 g_list_free(appimage);
1994 /*Insert in the package_app_info DB*/
1995 ret = __insert_application_info(mfx);
1998 /*Insert in the package_app_app_control DB*/
1999 ret = __insert_application_appcontrol_info(mfx);
2003 /*Insert in the package_app_app_category DB*/
2004 ret = __insert_application_appcategory_info(mfx);
2008 /*Insert in the package_app_app_metadata DB*/
2009 ret = __insert_application_appmetadata_info(mfx);
2013 /*Insert in the package_app_app_permission DB*/
2014 ret = __insert_application_apppermission_info(mfx);
2018 /*Insert in the package_app_share_allowed DB*/
2019 ret = __insert_application_share_allowed_info(mfx);
2023 /*Insert in the package_app_share_request DB*/
2024 ret = __insert_application_share_request_info(mfx);
2028 /*Insert in the package_app_data_control DB*/
2029 ret = __insert_application_datacontrol_info(mfx);
2033 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2034 ret = __insert_application_legacy_splashscreen_info(mfx);
2038 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2039 ret = __insert_application_metadata_splashscreen_info(mfx);
2043 /*Insert in the package_app_splash_screen DB*/
2044 ret = __insert_application_splashscreen_info(mfx);
2052 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2054 char query[MAX_QUERY_LEN] = { '\0' };
2056 memset(query, '\0', MAX_QUERY_LEN);
2057 snprintf(query, MAX_QUERY_LEN,
2058 "delete from %s where app_id='%s'", db_table, appid);
2059 ret = __exec_query(query);
2061 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2067 static int __delete_subpkg_info_from_db(char *appid)
2071 ret = __delete_appinfo_from_db("package_app_info", appid);
2074 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2077 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2080 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2083 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2086 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2089 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2092 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2095 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2098 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2101 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2104 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2111 static int __delete_subpkg_from_db(manifest_x *mfx)
2113 char query[MAX_QUERY_LEN] = { '\0' };
2114 char *error_message = NULL;
2116 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2118 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2119 _LOGE("Don't execute query = %s error message = %s\n", query,
2121 sqlite3_free(error_message);
2124 sqlite3_free(error_message);
2129 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2131 char query[MAX_QUERY_LEN] = { '\0' };
2135 /*Delete from cert table*/
2136 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2138 _LOGD("Cert Info DB Delete Failed\n");
2142 /*Delete from Package Info DB*/
2143 snprintf(query, MAX_QUERY_LEN,
2144 "delete from package_info where package='%s'", mfx->package);
2145 ret = __exec_query(query);
2147 _LOGD("Package Info DB Delete Failed\n");
2150 memset(query, '\0', MAX_QUERY_LEN);
2152 /*Delete from Package Localized Info*/
2153 snprintf(query, MAX_QUERY_LEN,
2154 "delete from package_localized_info where package='%s'", mfx->package);
2155 ret = __exec_query(query);
2157 _LOGD("Package Localized Info DB Delete Failed\n");
2161 /*Delete from Package Privilege Info*/
2162 snprintf(query, MAX_QUERY_LEN,
2163 "delete from package_privilege_info where package='%s'", mfx->package);
2164 ret = __exec_query(query);
2166 _LOGD("Package Privilege Info DB Delete Failed\n");
2170 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2171 app = (application_x *)tmp->data;
2174 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2177 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2180 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2183 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2186 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2189 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2192 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2195 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2198 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2201 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2204 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2207 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2212 /* if main package has sub pkg, delete sub pkg data*/
2213 __delete_subpkg_from_db(mfx);
2218 static int __disable_app(const char *appid)
2221 char query[MAX_QUERY_LEN] = {'\0'};
2222 sqlite3_snprintf(MAX_QUERY_LEN, query,
2223 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2225 ret = __exec_query(query);
2227 _LOGD("Insert global app disable failed\n");
2232 static int __enable_app(const char *appid)
2235 char query[MAX_QUERY_LEN] = {'\0'};
2236 sqlite3_snprintf(MAX_QUERY_LEN, query,
2237 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2239 ret = __exec_query(query);
2241 _LOGD("Insert global app disable failed\n");
2246 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2249 char query[MAX_QUERY_LEN] = { '\0', };
2251 const char *val = NULL;
2256 sqlite3_snprintf(MAX_QUERY_LEN, query,
2257 "SELECT COUNT(*) FROM "
2258 "package_app_info_for_uid WHERE app_id=%Q "
2259 "AND uid='%d'", appid, (int)uid);
2261 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2262 if (ret != SQLITE_OK) {
2263 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2264 return PMINFO_R_ERROR;
2267 if (sqlite3_step(stmt) != SQLITE_ROW) {
2268 LOGE("failed to step");
2269 sqlite3_finalize(stmt);
2270 return PMINFO_R_ERROR;
2273 val = (const char *)sqlite3_column_text(stmt, 0);
2275 sqlite3_finalize(stmt);
2280 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2283 char query[MAX_QUERY_LEN] = { '\0', };
2285 ret = __check_appinfo_for_uid_table(appid, uid);
2287 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2290 } else if (ret == 0) {
2291 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2292 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2293 "VALUES(%Q, '%d', 'true', "
2294 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2295 appid, (int)uid, appid);
2297 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2298 "package_app_info_for_uid SET is_disabled='true' "
2299 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2302 ret = __exec_query(query);
2304 _LOGD("Add global app disable info failed\n");
2309 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2312 char query[MAX_QUERY_LEN] = {'\0'};
2314 ret = __check_appinfo_for_uid_table(appid, uid);
2316 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2319 } else if (ret > 0) {
2320 sqlite3_snprintf(MAX_QUERY_LEN, query,
2321 "UPDATE package_app_info_for_uid SET "
2322 "is_disabled='false' WHERE app_id=%Q AND "
2323 "uid='%d'", appid, (int)uid);
2326 ret = __exec_query(query);
2328 _LOGD("Remove global app disable info failed\n");
2333 static int __update_global_app_splash_screen_for_user(const char *appid,
2334 uid_t uid, int flag)
2337 char query[MAX_QUERY_LEN] = { '\0', };
2339 ret = __check_appinfo_for_uid_table(appid, uid);
2341 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2344 } else if (ret == 0) {
2345 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2346 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2347 "VALUES(%Q, '%d', %Q)", appid, (int)uid,
2348 flag ? "true" : "false");
2350 sqlite3_snprintf(MAX_QUERY_LEN, query,
2351 "UPDATE package_app_info_for_uid SET "
2352 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2353 "uid='%d'", flag ? "true" : "false", appid, (int)uid);
2356 ret = __exec_query(query);
2358 _LOGD("update global app splash screen info failed\n");
2363 static int __disable_app_splash_screen(const char *appid)
2366 char query[MAX_QUERY_LEN] = {'\0'};
2368 sqlite3_snprintf(MAX_QUERY_LEN, query,
2369 "UPDATE package_app_info set app_splash_screen_display='false' where app_id=%Q",
2371 ret = __exec_query(query);
2373 _LOGD("Failed to update app_palsh_screen_display");
2378 static int __enable_app_splash_screen(const char *appid)
2381 char query[MAX_QUERY_LEN] = {'\0'};
2383 sqlite3_snprintf(MAX_QUERY_LEN, query,
2384 "UPDATE package_app_info set app_splash_screen_display='true' where app_id=%Q",
2386 ret = __exec_query(query);
2388 _LOGD("Failed to update app_splash_screen_display");
2393 static int __update_preload_condition_in_db()
2396 char query[MAX_QUERY_LEN] = {'\0'};
2398 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2400 ret = __exec_query(query);
2402 _LOGD("Package preload_condition update failed\n");
2407 API int pkgmgr_parser_initialize_db(uid_t uid)
2411 char query[MAX_QUERY_LEN];
2412 static const char *columns[] = {
2413 "author_root_cert", "author_im_cert", "author_signer_cert",
2414 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2415 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2419 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2421 _LOGD("package info DB initialization failed\n");
2424 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2426 _LOGD("package localized info DB initialization failed\n");
2429 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2431 _LOGD("package app app privilege DB initialization failed\n");
2434 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2436 _LOGD("package app info DB initialization failed\n");
2439 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2441 _LOGD("package app localized info DB initialization failed\n");
2444 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2446 _LOGD("package app icon localized info DB initialization failed\n");
2449 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2451 _LOGD("package app image info DB initialization failed\n");
2454 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2456 _LOGD("package app app control DB initialization failed\n");
2459 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2461 _LOGD("package app app category DB initialization failed\n");
2464 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2466 _LOGD("package app app category DB initialization failed\n");
2469 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2471 _LOGD("package app app permission DB initialization failed\n");
2474 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2476 _LOGD("package app share allowed DB initialization failed\n");
2479 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2481 _LOGD("package app share request DB initialization failed\n");
2484 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2486 _LOGD("package app data control DB initialization failed\n");
2490 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2492 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2496 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2498 _LOGD("package app splash screen DB initialization failed\n");
2502 /* Trigger package_app_info_for_uid */
2503 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2505 _LOGD("package app info for uid DB initialization failed\n");
2510 /* TODO: refactor this code */
2511 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2513 _LOGD("package cert info DB initialization failed\n");
2516 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2518 _LOGD("package cert index info DB initialization failed\n");
2521 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2523 _LOGD("package cert info DB initialization failed\n");
2526 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2528 _LOGD("package cert index info DB initialization failed\n");
2531 for (i = 0; columns[i] != NULL; i++) {
2532 snprintf(query, sizeof(query),
2533 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2534 columns[i], columns[i], columns[i]);
2535 ret = __initialize_db(pkgmgr_cert_db, query);
2537 _LOGD("package cert index info DB initialization failed\n");
2542 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2543 _LOGD("Failed to change cert db permission\n");
2545 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2546 _LOGD("Failed to change parser db permission\n");
2552 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2555 char pwuid_buf[1024];
2556 char journal_file[BUFSIZE];
2561 struct passwd userinfo, *result = NULL;
2562 files[0] = (char *)db_file;
2563 files[1] = journal_file;
2567 if (db_file == NULL)
2570 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2572 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2573 if (uid == OWNER_ROOT)
2575 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2576 if (ret != 0 || result == NULL) {
2577 _LOGE("FAIL: user %d doesn't exist", uid);
2580 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2582 for (i = 0; files[i]; i++) {
2583 fd = open(files[i], O_RDONLY);
2585 if (strerror_r(errno, buf, sizeof(buf)))
2586 strncpy(buf, "", BUFSIZE - 1);
2587 _LOGD("FAIL : open %s : %s", files[i], buf);
2590 ret = fstat(fd, &sb);
2592 if (strerror_r(errno, buf, sizeof(buf)))
2593 strncpy(buf, "", BUFSIZE - 1);
2594 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2598 if (S_ISLNK(sb.st_mode)) {
2599 _LOGE("FAIL : %s is symlink!", files[i]);
2603 ret = fchown(fd, uid, userinfo.pw_gid);
2605 if (strerror_r(errno, buf, sizeof(buf)))
2606 strncpy(buf, "", BUFSIZE - 1);
2607 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2608 userinfo.pw_gid, buf);
2613 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2614 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2616 ret = fchmod(fd, mode);
2618 if (strerror_r(errno, buf, sizeof(buf)))
2619 strncpy(buf, "", BUFSIZE - 1);
2620 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2625 SET_SMACK_LABEL(files[i]);
2630 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2634 if (getuid() != OWNER_ROOT) {
2635 _LOGE("Only root user is allowed");
2639 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2640 _LOGE("Manifest db for user %d is already exists", uid);
2644 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2645 _LOGE("Cert db for user %d is already exists", uid);
2649 ret = pkgmgr_parser_check_and_create_db(uid);
2652 ret = pkgmgr_parser_initialize_db(uid);
2654 pkgmgr_parser_close_db();
2657 pkgmgr_parser_close_db();
2662 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2666 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2668 _LOGD("Manifest DB creation Failed\n");
2673 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2675 _LOGD("Cert DB creation Failed\n");
2681 void pkgmgr_parser_close_db(void)
2683 sqlite3_close(pkgmgr_parser_db);
2684 sqlite3_close(pkgmgr_cert_db);
2688 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2690 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2692 _LOGD("manifest pointer is NULL\n");
2696 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2698 _LOGD("Failed to open DB\n");
2701 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2704 /*Begin transaction*/
2705 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2706 if (ret != SQLITE_OK) {
2707 _LOGD("Failed to begin transaction\n");
2711 _LOGD("Transaction Begin\n");
2712 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2714 _LOGD("Insert into DB failed. Rollback now\n");
2715 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2718 /*Commit transaction*/
2719 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2720 if (ret != SQLITE_OK) {
2721 _LOGD("Failed to commit transaction. Rollback now\n");
2722 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2726 _LOGD("Transaction Commit and End\n");
2728 pkgmgr_parser_close_db();
2732 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2734 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2736 _LOGD("manifest pointer is NULL\n");
2740 ret = pkgmgr_parser_check_and_create_db(uid);
2742 _LOGD("Failed to open DB\n");
2745 ret = pkgmgr_parser_initialize_db(uid);
2748 /*Begin transaction*/
2749 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2750 if (ret != SQLITE_OK) {
2751 _LOGD("Failed to begin transaction\n");
2755 _LOGD("Transaction Begin\n");
2756 ret = __insert_manifest_info_in_db(mfx, uid);
2758 _LOGD("Insert into DB failed. Rollback now\n");
2759 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2762 /*Commit transaction*/
2763 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2764 if (ret != SQLITE_OK) {
2765 _LOGD("Failed to commit transaction. Rollback now\n");
2766 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2770 _LOGD("Transaction Commit and End\n");
2772 pkgmgr_parser_close_db();
2776 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2779 _LOGD("manifest pointer is NULL\n");
2783 ret = pkgmgr_parser_check_and_create_db(uid);
2785 _LOGD("Failed to open DB\n");
2788 ret = pkgmgr_parser_initialize_db(uid);
2791 /*Preserve guest mode visibility*/
2792 __preserve_guestmode_visibility_value( mfx);
2793 /*Begin transaction*/
2794 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2795 if (ret != SQLITE_OK) {
2796 _LOGD("Failed to begin transaction\n");
2800 _LOGD("Transaction Begin\n");
2801 ret = __delete_manifest_info_from_db(mfx, uid);
2803 _LOGD("Delete from DB failed. Rollback now\n");
2804 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2807 ret = __insert_manifest_info_in_db(mfx, uid);
2809 _LOGD("Insert into DB failed. Rollback now\n");
2810 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2814 /*Commit transaction*/
2815 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2816 if (ret != SQLITE_OK) {
2817 _LOGD("Failed to commit transaction. Rollback now\n");
2818 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2822 _LOGD("Transaction Commit and End\n");
2824 pkgmgr_parser_close_db();
2828 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2830 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2833 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2836 _LOGD("manifest pointer is NULL\n");
2840 ret = pkgmgr_parser_check_and_create_db(uid);
2842 _LOGD("Failed to open DB\n");
2845 /*Begin transaction*/
2846 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2847 if (ret != SQLITE_OK) {
2848 _LOGD("Failed to begin transaction\n");
2852 _LOGD("Transaction Begin\n");
2853 ret = __delete_manifest_info_from_db(mfx, uid);
2855 _LOGD("Delete from DB failed. Rollback now\n");
2856 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2859 /*Commit transaction*/
2860 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2861 if (ret != SQLITE_OK) {
2862 _LOGD("Failed to commit transaction, Rollback now\n");
2863 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2867 _LOGD("Transaction Commit and End\n");
2869 pkgmgr_parser_close_db();
2873 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2875 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2878 API int pkgmgr_parser_update_preload_info_in_db()
2881 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2883 _LOGD("Failed to open DB\n");
2886 /*Begin transaction*/
2887 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2888 if (ret != SQLITE_OK) {
2889 _LOGD("Failed to begin transaction\n");
2893 _LOGD("Transaction Begin\n");
2894 ret = __update_preload_condition_in_db();
2896 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2897 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2900 /*Commit transaction*/
2901 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2902 if (ret != SQLITE_OK) {
2903 _LOGD("Failed to commit transaction, Rollback now\n");
2904 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2908 _LOGD("Transaction Commit and End\n");
2910 pkgmgr_parser_close_db();
2914 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2917 ret = pkgmgr_parser_check_and_create_db(uid);
2919 _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");
2930 ret = __update_preload_condition_in_db();
2932 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2933 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2936 /*Commit transaction*/
2937 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2938 if (ret != SQLITE_OK) {
2939 _LOGD("Failed to commit transaction, Rollback now\n");
2940 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2944 _LOGD("Transaction Commit and End\n");
2946 pkgmgr_parser_close_db();
2950 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2954 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2956 _LOGD("Failed to open DB\n");
2960 /*Begin transaction*/
2961 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2962 if (ret != SQLITE_OK) {
2963 _LOGD("Failed to begin transaction\n");
2967 _LOGD("Transaction Begin\n");
2969 ret = __disable_global_app_for_user(appid, uid);
2971 ret = __enable_global_app_for_user(appid, uid);
2973 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2974 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2977 /*Commit transaction*/
2978 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2979 if (ret != SQLITE_OK) {
2980 _LOGD("Failed to commit transaction, Rollback now\n");
2981 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2985 _LOGD("Transaction Commit and End\n");
2987 pkgmgr_parser_close_db();
2992 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2994 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2997 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3001 ret = pkgmgr_parser_check_and_create_db(uid);
3003 _LOGD("Failed to open DB\n");
3007 /*Begin transaction*/
3008 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3009 if (ret != SQLITE_OK) {
3010 _LOGD("Failed to begin transaction\n");
3014 _LOGD("Transaction Begin\n");
3016 ret = __disable_app(appid);
3018 ret = __enable_app(appid);
3020 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3021 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3024 /*Commit transaction*/
3025 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3026 if (ret != SQLITE_OK) {
3027 _LOGD("Failed to commit transaction, Rollback now\n");
3028 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3032 _LOGD("Transaction Commit and End\n");
3034 pkgmgr_parser_close_db();
3039 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3043 if (appid == NULL) {
3044 _LOGD("Invalid parameter");
3048 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3050 _LOGD("Failed to open DB\n");
3054 /* Begin transaction */
3055 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3056 if (ret != SQLITE_OK) {
3057 _LOGD("Failed to begin transaction\n");
3061 _LOGD("Transaction Begin\n");
3063 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3065 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3066 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3069 /* Commit transaction */
3070 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3071 if (ret != SQLITE_OK) {
3072 _LOGD("Failed to commit transaction, Rollback now\n");
3073 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3077 _LOGD("Transaction Commit and End\n");
3079 pkgmgr_parser_close_db();
3083 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3085 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3088 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3092 if (appid == NULL) {
3093 _LOGD("Invalid parameter");
3097 ret = pkgmgr_parser_check_and_create_db(uid);
3099 _LOGD("Failed to open DB");
3103 /* Begin transaction */
3104 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3105 if (ret != SQLITE_OK) {
3106 _LOGD("Failed to begin transaction");
3110 _LOGD("Transaction Begin");
3113 ret = __enable_app_splash_screen(appid);
3115 ret = __disable_app_splash_screen(appid);
3117 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3118 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3121 /* Commit transaction */
3122 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3123 if (ret != SQLITE_OK) {
3124 _LOGD("Failed to commit transaction, Rollback now");
3125 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3129 _LOGD("Transaction Commit and End");
3132 pkgmgr_parser_close_db();