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 NOT NULL , " \
97 "package_size TEXT, " \
98 "package_removable TEXT NOT NULL DEFAULT 'true', " \
99 "package_preload TEXT NOT NULL DEFAULT 'false', " \
100 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
101 "package_update TEXT NOT NULL DEFAULT 'false', " \
102 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
103 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
104 "package_system TEXT NOT NULL 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, " \
111 "mainapp_id TEXT, " \
112 "package_url TEXT, " \
115 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
116 "package_disable TEXT NOT NULL 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 NOT NULL DEFAULT 'No Locale', " \
121 "package_label TEXT, " \
122 "package_icon TEXT, " \
123 "package_description TEXT, " \
124 "package_license TEXT, " \
125 "package_author 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 NOT NULL DEFAULT 'false', " \
145 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
146 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
147 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
148 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
149 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
150 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
151 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
152 "app_mainapp TEXT, " \
153 "app_recentimage TEXT, " \
154 "app_launchcondition TEXT, " \
155 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
156 "app_portraitimg TEXT, " \
157 "app_landscapeimg TEXT, " \
158 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
159 "app_permissiontype TEXT DEFAULT 'normal', " \
160 "app_preload TEXT NOT NULL DEFAULT 'false', " \
161 "app_submode TEXT NOT NULL DEFAULT 'false', " \
162 "app_submode_mainid TEXT, " \
163 "app_installed_storage TEXT, " \
164 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
165 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
166 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
167 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_disable TEXT NOT NULL 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 NOT NULL 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 NOT NULL 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 NOT NULL, " \
197 "app_icon_resolution TEXT NOT NULL, " \
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 NOT NULL, " \
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, " \
233 "PRIMARY KEY(app_id, md_key) " \
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 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
265 "(app_id TEXT NOT NULL, " \
266 "providerid TEXT NOT NULL, " \
267 "access TEXT NOT NULL, " \
268 "type TEXT NOT NULL, " \
269 "PRIMARY KEY(app_id, providerid, access, type) " \
270 "FOREIGN KEY(app_id) " \
271 "REFERENCES package_app_info(app_id) " \
274 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
275 "(app_id TEXT NOT NULL, " \
276 "uid INTEGER NOT NULL, " \
277 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
278 "is_splash_screen_enabled TEXT NOT NULL, " \
279 "PRIMARY KEY(app_id, uid))"
281 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
282 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
283 "AFTER UPDATE ON package_app_info_for_uid " \
285 " DELETE FROM package_app_info_for_uid WHERE " \
286 " is_splash_screen_enabled=" \
287 " (SELECT package_app_info.app_splash_screen_display FROM " \
288 " package_app_info, package_app_info_for_uid WHERE " \
289 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
292 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
293 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
294 "(app_id TEXT NOT NULL, " \
295 "src TEXT NOT NULL, " \
296 "type TEXT NOT NULL, " \
297 "orientation TEXT NOT NULL, " \
298 "indicatordisplay TEXT, " \
300 "color_depth TEXT NOT NULL DEFAULT '24', " \
301 "PRIMARY KEY(app_id, orientation) " \
302 "FOREIGN KEY(app_id) " \
303 "REFERENCES package_app_info(app_id) " \
307 /* FIXME: duplicated at pkgmgrinfo_db.c */
308 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
309 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
310 " cert_info TEXT UNIQUE, " \
311 " cert_id INTEGER PRIMARY KEY, " \
312 " cert_ref_count INTEGER NOT NULL)"
314 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
315 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
316 " package TEXT PRIMARY KEY, " \
317 " author_root_cert INTEGER, " \
318 " author_im_cert INTEGER, " \
319 " author_signer_cert INTEGER, " \
320 " dist_root_cert INTEGER, " \
321 " dist_im_cert INTEGER, " \
322 " dist_signer_cert INTEGER, " \
323 " dist2_root_cert INTEGER, " \
324 " dist2_im_cert INTEGER, " \
325 " dist2_signer_cert INTEGER)"
327 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
328 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
329 "AFTER DELETE ON package_cert_info " \
331 " UPDATE package_cert_index_info SET" \
332 " cert_ref_count = cert_ref_count - 1" \
333 " WHERE cert_id = OLD.author_root_cert" \
334 " OR cert_id = OLD.author_im_cert" \
335 " OR cert_id = OLD.author_signer_cert" \
336 " OR cert_id = OLD.dist_root_cert" \
337 " OR cert_id = OLD.dist_im_cert" \
338 " OR cert_id = OLD.dist_signer_cert" \
339 " OR cert_id = OLD.dist2_root_cert" \
340 " OR cert_id = OLD.dist2_im_cert" \
341 " OR cert_id = OLD.dist2_signer_cert;" \
344 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
345 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
346 "AFTER UPDATE ON package_cert_index_info " \
347 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
348 " WHERE cert_id = OLD.cert_id) = 0) "\
350 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
353 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
354 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
355 "AFTER UPDATE ON package_cert_info " \
356 "WHEN (OLD.%s IS NOT NULL) " \
358 " UPDATE package_cert_index_info SET" \
359 " cert_ref_count = cert_ref_count - 1" \
360 " WHERE cert_id = OLD.%s;" \
363 static int __insert_application_info(manifest_x *mfx);
364 static int __insert_application_appcategory_info(manifest_x *mfx);
365 static int __insert_application_appcontrol_info(manifest_x *mfx);
366 static int __insert_application_appmetadata_info(manifest_x *mfx);
367 static int __insert_application_share_allowed_info(manifest_x *mfx);
368 static int __insert_application_share_request_info(manifest_x *mfx);
369 static int __insert_application_datacontrol_info(manifest_x *mfx);
370 static void __insert_application_locale_info(gpointer data, gpointer userdata);
371 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
372 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
373 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
374 static int __delete_subpkg_info_from_db(char *appid);
375 static int __delete_appinfo_from_db(char *db_table, const char *appid);
376 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
377 static int __exec_query(char *query);
378 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
379 char **label, char **license, char **icon, char **description, char **author);
380 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
381 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
382 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
383 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
384 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
385 static int __parserdb_change_perm(const char *db_file, uid_t uid);
387 #define REGULAR_USER 5000
388 static inline uid_t _getuid(void)
390 uid_t uid = getuid();
392 if (uid < REGULAR_USER)
393 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
398 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
401 __delete_subpkg_info_from_db(coltxt[0]);
406 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
411 char *error_message = NULL;
413 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
414 if (ret != SQLITE_OK) {
415 _LOGD("connect db [%s] failed!\n", db_path);
420 /* add user_version for db upgrade*/
421 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
423 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
424 _LOGE("Don't execute query = %s error message = %s\n", query,
427 sqlite3_free(error_message);
433 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
435 manifest_x *mfx = (manifest_x *)data;
441 if (mfx->application == NULL)
443 app = (application_x *)mfx->application->data;
444 for(i = 0; i < ncols; i++)
446 if (strcmp(colname[i], "app_id") == 0) {
448 appid = strdup(coltxt[i]);
449 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
451 status = strdup(coltxt[i]);
457 _LOGD("app id is NULL\n");
460 /*update guest mode visibility*/
461 for (tmp = mfx->application; tmp; tmp = tmp->next) {
462 app = (application_x *)tmp->data;
465 if (strcmp(app->appid, appid) == 0) {
466 free((void *)app->guestmode_visibility);
467 app->guestmode_visibility = strdup(status);
483 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
485 char *error_message = NULL;
486 char query[MAX_QUERY_LEN] = {'\0'};
487 sqlite3_snprintf(MAX_QUERY_LEN, query,
488 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
489 "WHERE package=%Q", mfx->package);
491 sqlite3_exec(pkgmgr_parser_db, query,
492 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
493 _LOGD("Don't execute query = %s error message = %s\n",
494 query, error_message);
495 sqlite3_free(error_message);
500 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
502 char *error_message = NULL;
504 sqlite3_exec(db_handle, db_query,
505 NULL, NULL, &error_message)) {
506 _LOGD("Don't execute query = %s error message = %s\n",
507 db_query, error_message);
508 sqlite3_free(error_message);
511 sqlite3_free(error_message);
515 static int __exec_query(char *query)
517 char *error_message = NULL;
519 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
520 _LOGE("Don't execute query = %s error message = %s\n", query,
522 sqlite3_free(error_message);
525 sqlite3_free(error_message);
529 static int __exec_query_no_msg(char *query)
531 char *error_message = NULL;
533 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
534 sqlite3_free(error_message);
537 sqlite3_free(error_message);
541 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
549 for (tmp = lbls; tmp; tmp = tmp->next) {
550 lbl = (label_x *)tmp->data;
554 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
556 for (tmp = lcns; tmp; tmp = tmp->next) {
557 lcn = (license_x *)tmp->data;
561 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
563 for (tmp = icns; tmp; tmp = tmp->next) {
564 icn = (icon_x *)tmp->data;
568 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
570 for (tmp = dcns; tmp; tmp = tmp->next) {
571 dcn = (description_x *)tmp->data;
575 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
577 for (tmp = aths; tmp; tmp = tmp->next) {
578 ath = (author_x *)tmp->data;
582 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
588 static GList *__create_icon_list(GList *appicon, GList *icns)
593 for (tmp = icns; tmp; tmp = tmp->next) {
594 icn = (icon_x *)tmp->data;
598 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
603 static GList *__create_image_list(GList *appimage, GList *imgs)
608 for (tmp = imgs; tmp; tmp = tmp->next) {
609 img = (image_x *)tmp->data;
613 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
618 static void __trimfunc(GList* trim_list)
620 char *trim_data = NULL;
624 list = g_list_first(trim_list);
627 trim_data = (char *)list->data;
630 if (strcmp(trim_data, prev) == 0) {
631 trim_list = g_list_remove(trim_list, trim_data);
632 list = g_list_first(trim_list);
641 list = g_list_next(list);
645 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
647 if (a == NULL || b == NULL)
649 if (strcmp((char*)a, (char*)b) == 0)
651 if (strcmp((char*)a, (char*)b) < 0)
653 if (strcmp((char*)a, (char*)b) > 0)
658 static int __check_dpi(const char *dpi_char, int dpi_int)
660 if (dpi_char == NULL)
663 if (strcasecmp(dpi_char, LDPI) == 0) {
664 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
668 } else if (strcasecmp(dpi_char, MDPI) == 0) {
669 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
673 } else if (strcasecmp(dpi_char, HDPI) == 0) {
674 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
678 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
679 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
683 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
684 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
692 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
695 char *icon_filename = NULL;
696 char modified_iconpath[BUFSIZE] = { '\0' };
697 char icon_path[BUFSIZE] = { '\0' };
701 if (orig_icon_path == NULL)
704 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
708 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
709 dpi_path[0] = "LDPI";
710 dpi_path[1] = "ldpi";
711 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
712 dpi_path[0] = "MDPI";
713 dpi_path[1] = "mdpi";
714 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
715 dpi_path[0] = "HDPI";
716 dpi_path[1] = "hdpi";
717 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
718 dpi_path[0] = "XHDPI";
719 dpi_path[1] = "xhdpi";
720 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
721 dpi_path[0] = "XXHDPI";
722 dpi_path[1] = "xxhdpi";
724 _LOGE("Unidentified dpi[%d]", dpi);
728 icon_filename = strrchr(orig_icon_path, '/');
729 if (icon_filename == NULL)
732 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
733 for (i = 0; i < 2; i++) {
734 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
735 if (access(modified_iconpath, F_OK) != -1) {
736 // if exists, return modified icon path
737 *new_icon_path = strdup(modified_iconpath);
745 static gint __compare_icon(gconstpointer a, gconstpointer b)
747 icon_x *icon = (icon_x *)a;
749 char *icon_folder_path = NULL;
751 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
754 if (icon->dpi != NULL)
757 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
759 icon->text = icon_folder_path;
765 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
767 icon_x *icon = (icon_x *)a;
768 int dpi = GPOINTER_TO_INT(b);
770 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
773 if (icon->dpi == NULL)
776 if (__check_dpi(icon->dpi, dpi) == 0)
782 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
784 icon_x *icon = (icon_x *)a;
785 char *lang = (char *)b;
786 char *icon_folder_path = NULL;
788 if (icon->dpi != NULL)
791 if (strcasecmp(icon->lang, lang) == 0) {
792 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
793 //icon for no locale. check existance of folder-hierachied default icons
794 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
796 icon->text = icon_folder_path;
805 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
807 icon_x *icon = (icon_x *)a;
808 char *lang = (char *)b;
811 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
815 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
821 static char *__find_icon(GList *icons, const char *lang)
827 // first, find icon whose locale and dpi with given lang and system's dpi has matched
828 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
830 icon = (icon_x *)tmp->data;
831 return (char *)icon->text;
834 // if first has failed, find icon whose locale has matched
835 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
837 icon = (icon_x *)tmp->data;
838 return (char *)icon->text;
841 // if second has failed, find icon whose dpi has matched with system's dpi
842 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
845 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
847 icon = (icon_x *)tmp->data;
848 return (char *)icon->text;
851 // last, find default icon marked as "No Locale"
852 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
854 icon = (icon_x *)tmp->data;
855 return (char *)icon->text;
861 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
862 char **label, char **license, char **icon, char **description, char **author)
869 for (tmp = lbls; tmp; tmp = tmp->next) {
870 lbl = (label_x *)tmp->data;
874 if (strcmp(lbl->lang, (char *)data) == 0) {
875 *label = (char*)lbl->text;
880 for (tmp = lcns; tmp; tmp = tmp->next) {
881 lcn = (license_x *)tmp->data;
885 if (strcmp(lcn->lang, (char *)data) == 0) {
886 *license = (char*)lcn->text;
892 *icon = __find_icon(icns, (char *)data);
894 for (tmp = dcns; tmp; tmp = tmp->next) {
895 dcn = (description_x *)tmp->data;
899 if (strcmp(dcn->lang, (char *)data) == 0) {
900 *description = (char*)dcn->text;
905 for (tmp = aths; tmp; tmp = tmp->next) {
906 ath = (author_x *)tmp->data;
910 if (strcmp(ath->lang, (char *)data) == 0) {
911 *author = (char*)ath->text;
919 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
923 for (tmp = icns; tmp; tmp = tmp->next) {
924 icn = (icon_x *)tmp->data;
928 if (strcmp(icn->section, (char *)data) == 0) {
929 *icon = (char*)icn->text;
930 *resolution = (char*)icn->resolution;
937 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
941 for (tmp = imgs; tmp; tmp = tmp->next) {
942 img = (image_x *)tmp->data;
946 if (strcmp(img->section, (char *)data) == 0) {
947 *lang = (char*)img->lang;
948 *image = (char*)img->text;
955 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
960 char *description = NULL;
961 char *license = NULL;
965 manifest_x *mfx = (manifest_x *)userdata;
966 GList *lbl = mfx->label;
967 GList *lcn = mfx->license;
968 GList *icn = mfx->icon;
969 GList *dcn = mfx->description;
970 GList *ath = mfx->author;
972 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
973 if (!label && !description && !icon && !license && !author)
976 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
977 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
978 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
987 ret = __exec_query(query);
989 _LOGD("Package Localized Info DB Insert failed\n");
994 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1001 application_x *app = (application_x*)userdata;
1002 GList *lbl = app->label;
1003 GList *icn = app->icon;
1005 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1006 if (!label && !icon)
1009 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1010 "app_label, app_icon) VALUES" \
1011 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1013 ret = __exec_query(query);
1015 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1017 sqlite3_free(query);
1019 /*insert ui app locale info to pkg locale to get mainapp data */
1020 if (strcasecmp(app->mainapp, "true")==0) {
1021 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
1022 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
1023 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1032 ret = __exec_query_no_msg(query);
1033 sqlite3_free(query);
1036 query = sqlite3_mprintf("UPDATE package_localized_info SET package_icon=%Q "\
1037 "WHERE package=%Q AND package_locale=%Q", icon, app->package, (char*)data);
1038 ret = __exec_query_no_msg(query);
1039 sqlite3_free(query);
1044 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1048 char *resolution = NULL;
1049 char query[MAX_QUERY_LEN] = {'\0'};
1051 application_x *app = (application_x*)userdata;
1052 GList *icn = app->icon;
1054 __extract_icon_data(data, icn, &icon, &resolution);
1055 if (!icon && !resolution)
1057 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1058 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1059 "(%Q, %Q, %Q, %Q)", app->appid,
1060 icon, (char*)data, resolution);
1062 ret = __exec_query(query);
1064 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1068 static void __insert_application_image_info(gpointer data, gpointer userdata)
1073 char query[MAX_QUERY_LEN] = {'\0'};
1075 application_x *app = (application_x*)userdata;
1076 GList *image = app->image;
1078 __extract_image_data(data, image, &lang, &img);
1081 sqlite3_snprintf(MAX_QUERY_LEN, query,
1082 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1083 "app_image_section, app_image) VALUES" \
1084 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char*)data, img);
1086 ret = __exec_query(query);
1088 _LOGD("Package UiApp image Info DB Insert failed\n");
1093 static int __insert_mainapp_info(manifest_x *mfx)
1098 char query[MAX_QUERY_LEN] = {'\0'};
1099 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1100 app = (application_x *)tmp->data;
1104 sqlite3_snprintf(MAX_QUERY_LEN, query,
1105 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1106 app->mainapp, app->appid);
1107 ret = __exec_query(query);
1109 _LOGD("Package App Info DB Insert Failed\n");
1112 if (strcasecmp(app->mainapp, "True")==0)
1113 mfx->mainapp_id = strdup(app->appid);
1116 if (mfx->mainapp_id == NULL) {
1117 if (mfx->application == NULL)
1119 app = (application_x *)mfx->application->data;
1123 sqlite3_snprintf(MAX_QUERY_LEN, query,
1124 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1127 _LOGD("Not valid appid\n");
1131 ret = __exec_query(query);
1133 _LOGD("Package UiApp Info DB Insert Failed\n");
1137 free((void *)app->mainapp);
1138 app->mainapp= strdup("true");
1139 mfx->mainapp_id = strdup(app->appid);
1142 memset(query, '\0', MAX_QUERY_LEN);
1143 sqlite3_snprintf(MAX_QUERY_LEN, query,
1144 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1145 ret = __exec_query(query);
1147 _LOGD("Package Info DB update Failed\n");
1154 static int __convert_background_category(GList *category_list)
1157 GList *tmp_list = category_list;
1158 char *category_data = NULL;
1160 if (category_list == NULL)
1163 while (tmp_list != NULL) {
1164 category_data = (char *)tmp_list->data;
1165 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1166 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1167 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1168 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1169 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1170 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1171 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1172 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1173 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1174 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1175 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1176 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1177 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1178 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1180 _LOGE("Unidentified category [%s]", category_data);
1182 tmp_list = g_list_next(tmp_list);
1188 static const char *__find_effective_appid(GList *metadata_list)
1193 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1194 md = (metadata_x *)tmp_list->data;
1195 if (md == NULL || md->key == NULL)
1198 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1207 static char *__get_bool(char *value, bool is_true)
1212 return (is_true) ? "true" : "false";
1215 /* _PRODUCT_LAUNCHING_ENHANCED_
1216 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1218 static int __insert_application_info(manifest_x *mfx)
1223 int background_value = 0;
1224 char query[MAX_QUERY_LEN] = {'\0'};
1226 const char *effective_appid;
1229 type = strdup(mfx->type);
1231 type = strdup("tpk");
1233 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1234 app = (application_x *)tmp->data;
1238 background_value = __convert_background_category(app->background_category);
1239 if (background_value < 0) {
1240 _LOGE("Failed to retrieve background value[%d]", background_value);
1241 background_value = 0;
1244 effective_appid = __find_effective_appid(app->metadata);
1246 sqlite3_snprintf(MAX_QUERY_LEN, query,
1247 "INSERT INTO package_app_info(" \
1248 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1249 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1250 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1251 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1252 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1253 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1254 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1255 "app_api_version, app_effective_appid, app_splash_screen_display) " \
1257 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1258 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1259 "%Q, %Q, %Q, %Q, %Q, " \
1260 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1261 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1262 "COALESCE(%Q, 'caller'), LOWER(%Q), LOWER(%Q), %Q, %Q, " \
1263 "%Q, %Q, %d, %Q, %Q, " \
1264 "%Q, %Q, LOWER(%Q))", \
1265 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1266 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false), __get_bool(app->enabled, true),
1267 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1268 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1269 __get_bool(app->guestmode_visibility, true), app->permission_type,
1270 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1271 app->launch_mode, __get_bool(app->ui_gadget, false), __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1272 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1273 effective_appid, __get_bool(app->splash_screen_display, false));
1275 ret = __exec_query(query);
1277 _LOGD("Package UiApp Info DB Insert Failed\n");
1282 memset(query, '\0', MAX_QUERY_LEN);
1291 static int __insert_application_appcategory_info(manifest_x *mfx)
1298 char query[MAX_QUERY_LEN] = {'\0'};
1299 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1300 app = (application_x *)app_tmp->data;
1303 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1304 ct = (const char *)ct_tmp->data;
1307 sqlite3_snprintf(MAX_QUERY_LEN, query,
1308 "INSERT INTO package_app_app_category(app_id, category) " \
1311 ret = __exec_query(query);
1313 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1316 memset(query, '\0', MAX_QUERY_LEN);
1322 static int __insert_application_appmetadata_info(manifest_x *mfx)
1329 char query[MAX_QUERY_LEN] = {'\0'};
1330 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1331 app = (application_x *)app_tmp->data;
1334 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1335 md = (metadata_x *)md_tmp->data;
1339 sqlite3_snprintf(MAX_QUERY_LEN, query,
1340 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1341 "VALUES(%Q, %Q, %Q)",\
1342 app->appid, md->key, md->value ? md->value : NULL);
1343 ret = __exec_query(query);
1345 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1349 memset(query, '\0', MAX_QUERY_LEN);
1355 static int __insert_application_apppermission_info(manifest_x *mfx)
1362 char query[MAX_QUERY_LEN] = {'\0'};
1363 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1364 app = (application_x *)app_tmp->data;
1367 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1368 pm = (permission_x *)pm_tmp->data;
1371 sqlite3_snprintf(MAX_QUERY_LEN, query,
1372 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1373 "VALUES(%Q, %Q, %Q)",\
1374 app->appid, pm->type, pm->value);
1375 ret = __exec_query(query);
1377 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1380 memset(query, '\0', MAX_QUERY_LEN);
1386 static int __insert_application_appcontrol_info(manifest_x *mfx)
1390 GList *acontrol_tmp;
1391 appcontrol_x *acontrol;
1393 char query[MAX_QUERY_LEN] = {'\0'};
1394 char buf[BUFSIZE] = {'\0'};
1395 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1396 app = (application_x *)app_tmp->data;
1399 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1400 acontrol = (appcontrol_x *)acontrol_tmp->data;
1401 if (acontrol == NULL)
1403 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1404 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1405 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1406 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1407 sqlite3_snprintf(MAX_QUERY_LEN, query,
1408 "INSERT INTO package_app_app_control(app_id, app_control) " \
1411 ret = __exec_query(query);
1413 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1416 memset(query, '\0', MAX_QUERY_LEN);
1422 static int __insert_application_datacontrol_info(manifest_x *mfx)
1429 char query[MAX_QUERY_LEN] = {'\0'};
1431 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1432 app = (application_x *)app_tmp->data;
1435 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1436 dc = (datacontrol_x *)dc_tmp->data;
1439 sqlite3_snprintf(MAX_QUERY_LEN, query,
1440 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1441 "VALUES(%Q, %Q, %Q, %Q)",\
1447 ret = __exec_query(query);
1449 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1452 memset(query, '\0', MAX_QUERY_LEN);
1458 static int __insert_application_share_request_info(manifest_x *mfx)
1467 char query[MAX_QUERY_LEN] = {'\0'};
1468 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1469 app = (application_x *)app_tmp->data;
1472 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1473 ds = (datashare_x *)ds_tmp->data;
1476 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1477 rq = (const char *)rq_tmp->data;
1480 sqlite3_snprintf(MAX_QUERY_LEN, query,
1481 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1484 ret = __exec_query(query);
1486 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1489 memset(query, '\0', MAX_QUERY_LEN);
1496 static int __insert_application_share_allowed_info(manifest_x *mfx)
1507 char query[MAX_QUERY_LEN] = {'\0'};
1508 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1509 app = (application_x *)app_tmp->data;
1512 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1513 ds = (datashare_x *)ds_tmp->data;
1516 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1517 df = (define_x *)df_tmp->data;
1520 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1521 al = (const char *)al_tmp->data;
1524 sqlite3_snprintf(MAX_QUERY_LEN, query,
1525 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1526 "VALUES(%Q, %Q, %Q)",\
1527 app->appid, df->path, al);
1528 ret = __exec_query(query);
1530 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1533 memset(query, '\0', MAX_QUERY_LEN);
1541 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1543 splashscreen_x *ss = (splashscreen_x *)a;
1544 const char *orientation = (const char *)b;
1547 if (ss->operation || ss->dpi == NULL)
1550 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1554 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1560 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1562 splashscreen_x *ss = (splashscreen_x *)a;
1563 const char *orientation = (const char *)b;
1565 if (ss->operation || ss->dpi)
1568 if (strcasecmp(ss->orientation, orientation) == 0)
1574 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1575 const char *orientation)
1579 tmp = g_list_find_custom(splashscreens, orientation,
1580 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1582 return (splashscreen_x *)tmp->data;
1584 tmp = g_list_find_custom(splashscreens, orientation,
1585 (GCompareFunc)__compare_splashscreen_with_orientation);
1587 return (splashscreen_x *)tmp->data;
1592 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1594 splashscreen_x *ss = (splashscreen_x *)data;
1595 GList **list = (GList **)user_data;
1598 if (ss->operation == NULL || ss->dpi == NULL)
1601 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1605 if (__check_dpi(ss->dpi, dpi) != 0)
1608 *list = g_list_append(*list, ss);
1611 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1613 splashscreen_x *ss = (splashscreen_x *)data;
1614 GList **list = (GList **)user_data;
1615 splashscreen_x *ss_tmp;
1618 if (ss->operation == NULL || ss->dpi)
1621 for (tmp = *list; tmp; tmp = tmp->next) {
1622 ss_tmp = (splashscreen_x *)tmp->data;
1623 if (ss_tmp->operation
1624 && strcmp(ss_tmp->operation, ss->operation) == 0
1625 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1629 *list = g_list_append(*list, ss);
1632 static GList *__find_splashscreens(GList *splashscreens)
1637 g_list_foreach(splashscreens,
1638 __find_appcontrol_splashscreen_with_dpi, &list);
1639 g_list_foreach(splashscreens,
1640 __find_appcontrol_splashscreen, &list);
1642 ss = __find_default_splashscreen(splashscreens, "portrait");
1644 list = g_list_append(list, ss);
1645 ss = __find_default_splashscreen(splashscreens, "landscape");
1647 list = g_list_append(list, ss);
1652 static int __insert_application_splashscreen_info(manifest_x *mfx)
1660 char query[MAX_QUERY_LEN] = {'\0'};
1662 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1663 app = (application_x *)app_tmp->data;
1664 if (app == NULL || app->splashscreens == NULL)
1667 ss_tmp = __find_splashscreens(app->splashscreens);
1671 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1672 ss = (splashscreen_x *)tmp->data;
1673 sqlite3_snprintf(MAX_QUERY_LEN, query,
1674 "INSERT INTO package_app_splash_screen" \
1675 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1676 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1677 app->appid, ss->src, ss->type, ss->orientation,
1678 ss->indicatordisplay, ss->operation,
1680 ret = __exec_query(query);
1682 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1685 memset(query, '\0', MAX_QUERY_LEN);
1687 g_list_free(ss_tmp);
1692 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1697 char query[MAX_QUERY_LEN] = {'\0'};
1699 const char *image_type;
1700 const char *indicatordisplay;
1701 const char *orientation;
1702 const char *operation = NULL;
1703 const char *color_depth = "24"; /* default */
1705 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1706 app = (application_x *)app_tmp->data;
1708 (app->portraitimg == NULL && app->landscapeimg == NULL))
1710 image_type = "img"; /* default */
1711 if (app->effectimage_type) {
1712 tmp = strstr(app->effectimage_type, "edj");
1716 indicatordisplay = "true"; /* default */
1717 if (app->indicatordisplay)
1718 indicatordisplay = app->indicatordisplay;
1719 if (app->portraitimg) {
1720 orientation = "portrait";
1721 sqlite3_snprintf(MAX_QUERY_LEN, query,
1722 "INSERT INTO package_app_splash_screen" \
1723 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1724 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1725 app->appid, app->portraitimg, image_type,
1726 orientation, indicatordisplay, operation,
1728 ret = __exec_query(query);
1730 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1733 memset(query, '\0', MAX_QUERY_LEN);
1735 if (app->landscapeimg) {
1736 orientation = "landscape";
1737 sqlite3_snprintf(MAX_QUERY_LEN, query,
1738 "INSERT INTO package_app_splash_screen" \
1739 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1740 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1741 app->appid, app->landscapeimg, image_type,
1742 orientation, indicatordisplay, operation,
1744 ret = __exec_query(query);
1746 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1749 memset(query, '\0', MAX_QUERY_LEN);
1755 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1762 char query[MAX_QUERY_LEN] = {'\0'};
1764 char *tmpptr = NULL;
1765 const char *operation;
1766 const char *portraitimg;
1767 const char *landscapeimg;
1768 const char *indicatordisplay;
1769 const char *orientation;
1770 const char *image_type;
1771 const char *color_depth = "24"; /* default */
1773 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1774 app = (application_x *)app_tmp->data;
1778 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1779 md = (metadata_x *)md_tmp->data;
1780 if (md == NULL || md->key == NULL || md->value == NULL)
1783 if (strcasestr(md->key, "operation_effect=")) {
1784 operation = index(md->key, '=');
1785 if ((operation + 1) != NULL)
1789 } else if (strcasestr(md->key, "launch_effect")) {
1796 landscapeimg = NULL;
1797 indicatordisplay = "true"; /* default */
1798 token = strtok_r(md->value, "|", &tmpptr);
1799 while (token != NULL) {
1800 if (strcasestr(token, "portrait-effectimage=")) {
1801 portraitimg = index(token, '=');
1802 if ((portraitimg + 1) != NULL)
1806 } else if (strcasestr(token, "landscape-effectimage=")) {
1807 landscapeimg = index(token, '=');
1808 if ((landscapeimg + 1) != NULL)
1811 landscapeimg = NULL;
1812 } else if (strcasestr(token, "indicatordisplay=")) {
1813 indicatordisplay = index(token, '=');
1814 if ((indicatordisplay + 1) != NULL)
1817 indicatordisplay = "true";
1820 token = strtok_r(NULL, "|", &tmpptr);
1824 orientation = "portrait";
1826 if (strcasestr(portraitimg, "edj"))
1828 sqlite3_snprintf(MAX_QUERY_LEN, query,
1829 "INSERT INTO package_app_splash_screen" \
1830 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1831 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1832 app->appid, portraitimg, image_type,
1833 orientation, indicatordisplay, operation,
1835 ret = __exec_query(query);
1837 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1840 memset(query, '\0', MAX_QUERY_LEN);
1843 orientation = "landscape";
1845 if (strcasestr(landscapeimg, "edj"))
1847 sqlite3_snprintf(MAX_QUERY_LEN, query,
1848 "INSERT INTO package_app_splash_screen" \
1849 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1850 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1851 app->appid, landscapeimg, image_type,
1852 orientation, indicatordisplay, operation,
1854 ret = __exec_query(query);
1856 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1859 memset(query, '\0', MAX_QUERY_LEN);
1867 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1871 const char *pv = NULL;
1872 char query[MAX_QUERY_LEN] = { '\0' };
1875 const char *auth_name = NULL;
1876 const char *auth_email = NULL;
1877 const char *auth_href = NULL;
1879 GList *pkglocale = NULL;
1880 GList *applocale = NULL;
1881 GList *appicon = NULL;
1882 GList *appimage = NULL;
1884 if (mfx->author && mfx->author->data) {
1885 author = (author_x *)mfx->author->data;
1887 auth_name = author->text;
1889 auth_email = author->email;
1891 auth_href = author->href;
1894 /*Insert in the package_cert_info CERT_DB*/
1895 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1896 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1897 if (ret != PMINFO_R_OK) {
1898 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1899 _LOGE("Cert Info DB create handle failed\n");
1902 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1903 if (ret != PMINFO_R_OK) {
1904 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1905 _LOGE("Cert Info DB Insert Failed\n");
1909 if (ret != PMINFO_R_OK) {
1910 _LOGE("Failed to set default values");
1914 /*Insert in the package_info DB*/
1915 sqlite3_snprintf(MAX_QUERY_LEN, query,
1916 "INSERT INTO package_info(" \
1917 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1918 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1919 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1920 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1921 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1923 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1924 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1925 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1926 "%Q, %Q, %Q, %Q, %Q, " \
1927 "%Q, %Q, %Q, %Q, LOWER(%Q))",
1928 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1929 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1930 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1931 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1932 mfx->storeclient_id,
1933 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, __get_bool(mfx->support_disable, false));
1935 ret = __exec_query(query);
1937 _LOGD("Package Info DB Insert Failed\n");
1941 /*Insert in the package_privilege_info DB*/
1942 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1943 pv = (const char *)tmp->data;
1946 memset(query, '\0', MAX_QUERY_LEN);
1947 sqlite3_snprintf(MAX_QUERY_LEN, query,
1948 "INSERT INTO package_privilege_info(package, privilege) " \
1951 ret = __exec_query(query);
1953 _LOGD("Package Privilege Info DB Insert Failed\n");
1958 if (mfx->application != NULL) {
1959 ret = __insert_mainapp_info(mfx);
1964 /*Insert the package locale*/
1965 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1966 /*remove duplicated data in pkglocale*/
1967 __trimfunc(pkglocale);
1969 /*Insert the app locale, icon, image info */
1970 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1971 app = (application_x *)tmp->data;
1974 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1975 appicon = __create_icon_list(appicon, app->icon);
1976 appimage = __create_image_list(appimage, app->image);
1978 /*remove duplicated data in applocale*/
1979 __trimfunc(applocale);
1980 __trimfunc(appicon);
1981 __trimfunc(appimage);
1983 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1985 /*native app locale info*/
1986 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1987 app = (application_x *)tmp->data;
1990 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1991 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1992 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1995 g_list_free(pkglocale);
1997 g_list_free(applocale);
1999 g_list_free(appicon);
2001 g_list_free(appimage);
2004 /*Insert in the package_app_info DB*/
2005 ret = __insert_application_info(mfx);
2008 /*Insert in the package_app_app_control DB*/
2009 ret = __insert_application_appcontrol_info(mfx);
2013 /*Insert in the package_app_app_category DB*/
2014 ret = __insert_application_appcategory_info(mfx);
2018 /*Insert in the package_app_app_metadata DB*/
2019 ret = __insert_application_appmetadata_info(mfx);
2023 /*Insert in the package_app_app_permission DB*/
2024 ret = __insert_application_apppermission_info(mfx);
2028 /*Insert in the package_app_share_allowed DB*/
2029 ret = __insert_application_share_allowed_info(mfx);
2033 /*Insert in the package_app_share_request DB*/
2034 ret = __insert_application_share_request_info(mfx);
2038 /*Insert in the package_app_data_control DB*/
2039 ret = __insert_application_datacontrol_info(mfx);
2043 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2044 ret = __insert_application_legacy_splashscreen_info(mfx);
2048 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2049 ret = __insert_application_metadata_splashscreen_info(mfx);
2053 /*Insert in the package_app_splash_screen DB*/
2054 ret = __insert_application_splashscreen_info(mfx);
2062 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2064 char query[MAX_QUERY_LEN] = { '\0' };
2067 sqlite3_snprintf(MAX_QUERY_LEN, query,
2068 "DELETE FROM %q where app_id=%Q", db_table, appid);
2069 ret = __exec_query(query);
2071 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2077 static int __delete_subpkg_info_from_db(char *appid)
2081 ret = __delete_appinfo_from_db("package_app_info", appid);
2084 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2087 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2090 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2093 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2096 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2099 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2102 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2105 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2108 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2111 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2114 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2121 static int __delete_subpkg_from_db(manifest_x *mfx)
2123 char query[MAX_QUERY_LEN] = { '\0' };
2124 char *error_message = NULL;
2126 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2128 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2129 _LOGE("Don't execute query = %s error message = %s\n", query,
2131 sqlite3_free(error_message);
2134 sqlite3_free(error_message);
2139 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2141 char query[MAX_QUERY_LEN] = { '\0' };
2145 /*Delete from cert table*/
2146 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2148 _LOGD("Cert Info DB Delete Failed\n");
2152 /*Delete from Package Info DB*/
2153 sqlite3_snprintf(MAX_QUERY_LEN, query,
2154 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2155 ret = __exec_query(query);
2157 _LOGD("Package Info DB Delete Failed\n");
2160 memset(query, '\0', MAX_QUERY_LEN);
2162 /*Delete from Package Localized Info*/
2163 sqlite3_snprintf(MAX_QUERY_LEN, query,
2164 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2165 ret = __exec_query(query);
2167 _LOGD("Package Localized Info DB Delete Failed\n");
2171 /*Delete from Package Privilege Info*/
2172 sqlite3_snprintf(MAX_QUERY_LEN, query,
2173 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2174 ret = __exec_query(query);
2176 _LOGD("Package Privilege Info DB Delete Failed\n");
2180 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2181 app = (application_x *)tmp->data;
2184 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2187 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2190 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2193 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2196 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2199 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2202 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2205 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2208 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2211 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2214 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2217 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2222 /* if main package has sub pkg, delete sub pkg data*/
2223 __delete_subpkg_from_db(mfx);
2228 static int __disable_app(const char *appid)
2231 char query[MAX_QUERY_LEN] = {'\0'};
2232 sqlite3_snprintf(MAX_QUERY_LEN, query,
2233 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2235 ret = __exec_query(query);
2237 _LOGD("Insert global app disable failed\n");
2242 static int __enable_app(const char *appid)
2245 char query[MAX_QUERY_LEN] = {'\0'};
2246 sqlite3_snprintf(MAX_QUERY_LEN, query,
2247 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2249 ret = __exec_query(query);
2251 _LOGD("Insert global app disable failed\n");
2256 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2259 char query[MAX_QUERY_LEN] = { '\0', };
2261 const char *val = NULL;
2266 sqlite3_snprintf(MAX_QUERY_LEN, query,
2267 "SELECT COUNT(*) FROM "
2268 "package_app_info_for_uid WHERE app_id=%Q "
2269 "AND uid=%d", appid, (int)uid);
2271 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2272 if (ret != SQLITE_OK) {
2273 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2274 return PMINFO_R_ERROR;
2277 if (sqlite3_step(stmt) != SQLITE_ROW) {
2278 LOGE("failed to step");
2279 sqlite3_finalize(stmt);
2280 return PMINFO_R_ERROR;
2283 val = (const char *)sqlite3_column_text(stmt, 0);
2285 sqlite3_finalize(stmt);
2290 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2293 char query[MAX_QUERY_LEN] = { '\0', };
2295 ret = __check_appinfo_for_uid_table(appid, uid);
2297 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2300 } else if (ret == 0) {
2301 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2302 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2303 "VALUES(%Q, %d, 'true', "
2304 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2305 appid, (int)uid, appid);
2307 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2308 "package_app_info_for_uid SET is_disabled='true' "
2309 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2312 ret = __exec_query(query);
2314 _LOGD("Add global app disable info failed\n");
2319 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2322 char query[MAX_QUERY_LEN] = {'\0'};
2324 ret = __check_appinfo_for_uid_table(appid, uid);
2326 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2329 } else if (ret > 0) {
2330 sqlite3_snprintf(MAX_QUERY_LEN, query,
2331 "UPDATE package_app_info_for_uid SET "
2332 "is_disabled='false' WHERE app_id=%Q AND "
2333 "uid=%d", appid, (int)uid);
2336 ret = __exec_query(query);
2338 _LOGD("Remove global app disable info failed\n");
2343 static int __update_global_app_splash_screen_for_user(const char *appid,
2344 uid_t uid, int flag)
2347 char query[MAX_QUERY_LEN] = { '\0', };
2349 ret = __check_appinfo_for_uid_table(appid, uid);
2351 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2354 } else if (ret == 0) {
2355 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2356 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2357 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2358 flag ? "true" : "false");
2360 sqlite3_snprintf(MAX_QUERY_LEN, query,
2361 "UPDATE package_app_info_for_uid SET "
2362 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2363 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2366 ret = __exec_query(query);
2368 _LOGD("update global app splash screen info failed\n");
2373 static int __disable_app_splash_screen(const char *appid)
2376 char query[MAX_QUERY_LEN] = {'\0'};
2378 sqlite3_snprintf(MAX_QUERY_LEN, query,
2379 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2381 ret = __exec_query(query);
2383 _LOGD("Failed to update app_palsh_screen_display");
2388 static int __enable_app_splash_screen(const char *appid)
2391 char query[MAX_QUERY_LEN] = {'\0'};
2393 sqlite3_snprintf(MAX_QUERY_LEN, query,
2394 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2396 ret = __exec_query(query);
2398 _LOGD("Failed to update app_splash_screen_display");
2403 API int pkgmgr_parser_initialize_db(uid_t uid)
2407 char query[MAX_QUERY_LEN];
2408 static const char *columns[] = {
2409 "author_root_cert", "author_im_cert", "author_signer_cert",
2410 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2411 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2415 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2417 _LOGD("package info DB initialization failed\n");
2420 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2422 _LOGD("package localized info DB initialization failed\n");
2425 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2427 _LOGD("package app app privilege DB initialization failed\n");
2430 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2432 _LOGD("package app info DB initialization failed\n");
2435 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2437 _LOGD("package app localized info DB initialization failed\n");
2440 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2442 _LOGD("package app icon localized info DB initialization failed\n");
2445 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2447 _LOGD("package app image info DB initialization failed\n");
2450 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2452 _LOGD("package app app control DB initialization failed\n");
2455 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2457 _LOGD("package app app category DB initialization failed\n");
2460 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2462 _LOGD("package app app category DB initialization failed\n");
2465 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2467 _LOGD("package app app permission DB initialization failed\n");
2470 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2472 _LOGD("package app share allowed DB initialization failed\n");
2475 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2477 _LOGD("package app share request DB initialization failed\n");
2480 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2482 _LOGD("package app data control DB initialization failed\n");
2486 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2488 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2492 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2494 _LOGD("package app splash screen DB initialization failed\n");
2498 /* Trigger package_app_info_for_uid */
2499 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2501 _LOGD("package app info for uid DB initialization failed\n");
2506 /* TODO: refactor this code */
2507 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2509 _LOGD("package cert info DB initialization failed\n");
2512 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2514 _LOGD("package cert index info DB initialization failed\n");
2517 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2519 _LOGD("package cert info DB initialization failed\n");
2522 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2524 _LOGD("package cert index info DB initialization failed\n");
2527 for (i = 0; columns[i] != NULL; i++) {
2528 snprintf(query, sizeof(query),
2529 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2530 columns[i], columns[i], columns[i]);
2531 ret = __initialize_db(pkgmgr_cert_db, query);
2533 _LOGD("package cert index info DB initialization failed\n");
2538 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2539 _LOGD("Failed to change cert db permission\n");
2541 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2542 _LOGD("Failed to change parser db permission\n");
2548 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2551 char pwuid_buf[1024];
2552 char journal_file[BUFSIZE];
2557 struct passwd userinfo, *result = NULL;
2558 files[0] = (char *)db_file;
2559 files[1] = journal_file;
2563 if (db_file == NULL)
2566 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2568 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2569 if (uid == OWNER_ROOT)
2571 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2572 if (ret != 0 || result == NULL) {
2573 _LOGE("FAIL: user %d doesn't exist", uid);
2576 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2578 for (i = 0; files[i]; i++) {
2579 fd = open(files[i], O_RDONLY);
2581 if (strerror_r(errno, buf, sizeof(buf)))
2582 strncpy(buf, "", BUFSIZE - 1);
2583 _LOGD("FAIL : open %s : %s", files[i], buf);
2586 ret = fstat(fd, &sb);
2588 if (strerror_r(errno, buf, sizeof(buf)))
2589 strncpy(buf, "", BUFSIZE - 1);
2590 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2594 if (S_ISLNK(sb.st_mode)) {
2595 _LOGE("FAIL : %s is symlink!", files[i]);
2599 ret = fchown(fd, uid, userinfo.pw_gid);
2601 if (strerror_r(errno, buf, sizeof(buf)))
2602 strncpy(buf, "", BUFSIZE - 1);
2603 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2604 userinfo.pw_gid, buf);
2609 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2610 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2612 ret = fchmod(fd, mode);
2614 if (strerror_r(errno, buf, sizeof(buf)))
2615 strncpy(buf, "", BUFSIZE - 1);
2616 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2621 SET_SMACK_LABEL(files[i]);
2626 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2630 if (getuid() != OWNER_ROOT) {
2631 _LOGE("Only root user is allowed");
2635 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2636 _LOGE("Manifest db for user %d is already exists", uid);
2640 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2641 _LOGE("Cert db for user %d is already exists", uid);
2645 ret = pkgmgr_parser_check_and_create_db(uid);
2648 ret = pkgmgr_parser_initialize_db(uid);
2650 pkgmgr_parser_close_db();
2653 pkgmgr_parser_close_db();
2658 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2662 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2664 _LOGD("Manifest DB creation Failed\n");
2669 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2671 _LOGD("Cert DB creation Failed\n");
2677 void pkgmgr_parser_close_db(void)
2679 sqlite3_close(pkgmgr_parser_db);
2680 sqlite3_close(pkgmgr_cert_db);
2684 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2686 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2688 _LOGD("manifest pointer is NULL\n");
2692 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2694 _LOGD("Failed to open DB\n");
2697 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2700 /*Begin transaction*/
2701 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2702 if (ret != SQLITE_OK) {
2703 _LOGD("Failed to begin transaction\n");
2707 _LOGD("Transaction Begin\n");
2708 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2710 _LOGD("Insert into DB failed. Rollback now\n");
2711 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2714 /*Commit transaction*/
2715 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2716 if (ret != SQLITE_OK) {
2717 _LOGD("Failed to commit transaction. Rollback now\n");
2718 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2722 _LOGD("Transaction Commit and End\n");
2724 pkgmgr_parser_close_db();
2728 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2730 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2732 _LOGD("manifest pointer is NULL\n");
2736 ret = pkgmgr_parser_check_and_create_db(uid);
2738 _LOGD("Failed to open DB\n");
2741 ret = pkgmgr_parser_initialize_db(uid);
2744 /*Begin transaction*/
2745 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2746 if (ret != SQLITE_OK) {
2747 _LOGD("Failed to begin transaction\n");
2751 _LOGD("Transaction Begin\n");
2752 ret = __insert_manifest_info_in_db(mfx, uid);
2754 _LOGD("Insert into DB failed. Rollback now\n");
2755 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2758 /*Commit transaction*/
2759 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2760 if (ret != SQLITE_OK) {
2761 _LOGD("Failed to commit transaction. Rollback now\n");
2762 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2766 _LOGD("Transaction Commit and End\n");
2768 pkgmgr_parser_close_db();
2772 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2775 _LOGD("manifest pointer is NULL\n");
2779 ret = pkgmgr_parser_check_and_create_db(uid);
2781 _LOGD("Failed to open DB\n");
2784 ret = pkgmgr_parser_initialize_db(uid);
2787 /*Preserve guest mode visibility*/
2788 __preserve_guestmode_visibility_value( mfx);
2789 /*Begin transaction*/
2790 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2791 if (ret != SQLITE_OK) {
2792 _LOGD("Failed to begin transaction\n");
2796 _LOGD("Transaction Begin\n");
2797 ret = __delete_manifest_info_from_db(mfx, uid);
2799 _LOGD("Delete from DB failed. Rollback now\n");
2800 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2803 ret = __insert_manifest_info_in_db(mfx, uid);
2805 _LOGD("Insert into DB failed. Rollback now\n");
2806 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2810 /*Commit transaction*/
2811 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2812 if (ret != SQLITE_OK) {
2813 _LOGD("Failed to commit transaction. Rollback now\n");
2814 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2818 _LOGD("Transaction Commit and End\n");
2820 pkgmgr_parser_close_db();
2824 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2826 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2829 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2832 _LOGD("manifest pointer is NULL\n");
2836 ret = pkgmgr_parser_check_and_create_db(uid);
2838 _LOGD("Failed to open DB\n");
2841 /*Begin transaction*/
2842 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2843 if (ret != SQLITE_OK) {
2844 _LOGD("Failed to begin transaction\n");
2848 _LOGD("Transaction Begin\n");
2849 ret = __delete_manifest_info_from_db(mfx, uid);
2851 _LOGD("Delete from DB failed. Rollback now\n");
2852 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2855 /*Commit transaction*/
2856 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2857 if (ret != SQLITE_OK) {
2858 _LOGD("Failed to commit transaction, Rollback now\n");
2859 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2863 _LOGD("Transaction Commit and End\n");
2865 pkgmgr_parser_close_db();
2869 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2871 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2874 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2878 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2880 _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");
2893 ret = __disable_global_app_for_user(appid, uid);
2895 ret = __enable_global_app_for_user(appid, uid);
2897 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2898 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2901 /*Commit transaction*/
2902 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2903 if (ret != SQLITE_OK) {
2904 _LOGD("Failed to commit transaction, Rollback now\n");
2905 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2909 _LOGD("Transaction Commit and End\n");
2911 pkgmgr_parser_close_db();
2916 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2918 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2921 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2925 ret = pkgmgr_parser_check_and_create_db(uid);
2927 _LOGD("Failed to open DB\n");
2931 /*Begin transaction*/
2932 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2933 if (ret != SQLITE_OK) {
2934 _LOGD("Failed to begin transaction\n");
2938 _LOGD("Transaction Begin\n");
2940 ret = __disable_app(appid);
2942 ret = __enable_app(appid);
2944 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2945 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2948 /*Commit transaction*/
2949 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2950 if (ret != SQLITE_OK) {
2951 _LOGD("Failed to commit transaction, Rollback now\n");
2952 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2956 _LOGD("Transaction Commit and End\n");
2958 pkgmgr_parser_close_db();
2963 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2967 if (appid == NULL) {
2968 _LOGD("Invalid parameter");
2972 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2974 _LOGD("Failed to open DB\n");
2978 /* Begin transaction */
2979 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2980 if (ret != SQLITE_OK) {
2981 _LOGD("Failed to begin transaction\n");
2985 _LOGD("Transaction Begin\n");
2987 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
2989 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
2990 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2993 /* Commit transaction */
2994 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2995 if (ret != SQLITE_OK) {
2996 _LOGD("Failed to commit transaction, Rollback now\n");
2997 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3001 _LOGD("Transaction Commit and End\n");
3003 pkgmgr_parser_close_db();
3007 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3009 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3012 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3016 if (appid == NULL) {
3017 _LOGD("Invalid parameter");
3021 ret = pkgmgr_parser_check_and_create_db(uid);
3023 _LOGD("Failed to open DB");
3027 /* Begin transaction */
3028 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3029 if (ret != SQLITE_OK) {
3030 _LOGD("Failed to begin transaction");
3034 _LOGD("Transaction Begin");
3037 ret = __enable_app_splash_screen(appid);
3039 ret = __disable_app_splash_screen(appid);
3041 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3042 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3045 /* Commit transaction */
3046 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3047 if (ret != SQLITE_OK) {
3048 _LOGD("Failed to commit transaction, Rollback now");
3049 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3053 _LOGD("Transaction Commit and End");
3056 pkgmgr_parser_close_db();