4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <sys/types.h>
28 #include <sys/smack.h>
36 #include <system_info.h>
38 /* For multi-user support */
39 #include <tzplatform_config.h>
41 #include "pkgmgr-info.h"
42 #include "pkgmgrinfo_basic.h"
43 #include "pkgmgrinfo_debug.h"
44 #include "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
50 #define LOG_TAG "PKGMGR_PARSER"
52 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
53 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
54 #define MAX_QUERY_LEN 4096
62 #define XXHDPI "xxhdpi"
72 #define XXHDPI_MIN 481
73 #define XXHDPI_MAX 600
75 #define DB_LABEL "User::Home"
76 #define SET_SMACK_LABEL(x) \
78 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
79 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
81 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
84 sqlite3 *pkgmgr_parser_db;
85 sqlite3 *pkgmgr_cert_db;
88 #define QUERY_CREATE_TABLE_PACKAGE_INFO "create table if not exists package_info " \
89 "(package text primary key not null, " \
90 "package_type text DEFAULT 'tpk', " \
91 "package_version text, " \
92 "package_api_version text, " \
93 "package_tep_name text, " \
94 "install_location text, " \
95 "package_size text, " \
96 "package_removable text DEFAULT 'true', " \
97 "package_preload text DEFAULT 'false', " \
98 "package_readonly text DEFAULT 'false', " \
99 "package_update text DEFAULT 'false', " \
100 "package_appsetting text DEFAULT 'false', " \
101 "package_nodisplay text DEFAULT 'false', " \
102 "package_system text DEFAULT 'false', " \
103 "author_name text, " \
104 "author_email text, " \
105 "author_href text," \
106 "installed_time text," \
107 "installed_storage text," \
108 "storeclient_id text," \
110 "package_url text," \
113 "package_support_disable text DEFAULT 'false', " \
114 "package_disable text DEFAULT 'false')"
116 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "create table if not exists package_localized_info " \
117 "(package text not null, " \
118 "package_locale text DEFAULT 'No Locale', " \
119 "package_label text, " \
120 "package_icon text, " \
121 "package_description text, " \
122 "package_license text, " \
124 "PRIMARY KEY(package, package_locale), " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "create table if not exists package_privilege_info " \
130 "(package text not null, " \
131 "privilege text not null, " \
132 "PRIMARY KEY(package, privilege) " \
133 "FOREIGN KEY(package) " \
134 "REFERENCES package_info(package) " \
137 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "create table if not exists package_app_info " \
138 "(app_id text primary key not null, " \
139 "app_component text, " \
141 "app_nodisplay text DEFAULT 'false', " \
143 "app_onboot text DEFAULT 'false', " \
144 "app_multiple text DEFAULT 'false', " \
145 "app_autorestart text DEFAULT 'false', " \
146 "app_taskmanage text DEFAULT 'false', " \
147 "app_enabled text DEFAULT 'true', " \
148 "app_hwacceleration text DEFAULT 'use-system-setting', " \
149 "app_screenreader text DEFAULT 'use-system-setting', " \
150 "app_mainapp text, " \
151 "app_recentimage text, " \
152 "app_launchcondition text, " \
153 "app_indicatordisplay text DEFAULT 'true', " \
154 "app_portraitimg text, " \
155 "app_landscapeimg text, " \
156 "app_guestmodevisibility text DEFAULT 'true', " \
157 "app_permissiontype text DEFAULT 'normal', " \
158 "app_preload text DEFAULT 'false', " \
159 "app_submode text DEFAULT 'false', " \
160 "app_submode_mainid text, " \
161 "app_installed_storage text, " \
162 "app_process_pool text DEFAULT 'false', " \
163 "app_launch_mode text NOT NULL DEFAULT 'caller', " \
164 "app_ui_gadget text DEFAULT 'false', " \
165 "app_support_disable text DEFAULT 'false', " \
166 "app_disable text DEFAULT 'false', " \
167 "app_package_type text DEFAULT 'tpk', " \
168 "component_type text, " \
169 "package text not null, " \
170 "app_tep_name text, " \
171 "app_background_category INTEGER DEFAULT 0, " \
172 "app_root_path text, " \
173 "app_api_version text, " \
174 "app_effective_appid text, " \
175 "app_splash_screen_display text DEFAULT 'true', " \
176 "FOREIGN KEY(package) " \
177 "REFERENCES package_info(package) " \
180 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "create table if not exists package_app_localized_info " \
181 "(app_id text not null, " \
182 "app_locale text DEFAULT 'No Locale', " \
185 "PRIMARY KEY(app_id,app_locale) " \
186 "FOREIGN KEY(app_id) " \
187 "REFERENCES package_app_info(app_id) " \
190 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "create table if not exists package_app_icon_section_info " \
191 "(app_id text not null, " \
193 "app_icon_section text, " \
194 "app_icon_resolution text, " \
195 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
196 "FOREIGN KEY(app_id) " \
197 "REFERENCES package_app_info(app_id) " \
200 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "create table if not exists package_app_image_info " \
201 "(app_id text not null, " \
202 "app_locale text DEFAULT 'No Locale', " \
203 "app_image_section text, " \
205 "PRIMARY KEY(app_id,app_image_section) " \
206 "FOREIGN KEY(app_id) " \
207 "REFERENCES package_app_info(app_id) " \
210 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "create table if not exists package_app_app_control " \
211 "(app_id text not null, " \
212 "app_control text not null, " \
213 "PRIMARY KEY(app_id,app_control) " \
214 "FOREIGN KEY(app_id) " \
215 "REFERENCES package_app_info(app_id) " \
218 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "create table if not exists package_app_app_category " \
219 "(app_id text not null, " \
220 "category text not null, " \
221 "PRIMARY KEY(app_id,category) " \
222 "FOREIGN KEY(app_id) " \
223 "REFERENCES package_app_info(app_id) " \
226 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "create table if not exists package_app_app_metadata " \
227 "(app_id text not null, " \
228 "md_key text not null, " \
229 "md_value text not null, " \
230 "PRIMARY KEY(app_id, md_key, md_value) " \
231 "FOREIGN KEY(app_id) " \
232 "REFERENCES package_app_info(app_id) " \
235 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "create table if not exists package_app_app_permission " \
236 "(app_id text not null, " \
237 "pm_type text not null, " \
238 "pm_value text not null, " \
239 "PRIMARY KEY(app_id, pm_type, pm_value) " \
240 "FOREIGN KEY(app_id) " \
241 "REFERENCES package_app_info(app_id) " \
244 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "create table if not exists package_app_share_allowed " \
245 "(app_id text not null, " \
246 "data_share_path text not null, " \
247 "data_share_allowed text not null, " \
248 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
249 "FOREIGN KEY(app_id) " \
250 "REFERENCES package_app_info(app_id) " \
253 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "create table if not exists package_app_share_request " \
254 "(app_id text not null, " \
255 "data_share_request text not null, " \
256 "PRIMARY KEY(app_id,data_share_request) " \
257 "FOREIGN KEY(app_id) " \
258 "REFERENCES package_app_info(app_id) " \
261 /* FIXME: duplicated at pkgmgrinfo_db.c */
262 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
263 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
264 " cert_info TEXT UNIQUE, " \
265 " cert_id INTEGER PRIMARY KEY, " \
266 " cert_ref_count INTEGER NOT NULL)"
268 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
269 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
270 " package TEXT PRIMARY KEY, " \
271 " author_root_cert INTEGER, " \
272 " author_im_cert INTEGER, " \
273 " author_signer_cert INTEGER, " \
274 " dist_root_cert INTEGER, " \
275 " dist_im_cert INTEGER, " \
276 " dist_signer_cert INTEGER, " \
277 " dist2_root_cert INTEGER, " \
278 " dist2_im_cert INTEGER, " \
279 " dist2_signer_cert INTEGER)"
281 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
282 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
283 "AFTER DELETE ON package_cert_info " \
285 " UPDATE package_cert_index_info SET" \
286 " cert_ref_count = cert_ref_count - 1" \
287 " WHERE cert_id = OLD.author_root_cert" \
288 " OR cert_id = OLD.author_im_cert" \
289 " OR cert_id = OLD.author_signer_cert" \
290 " OR cert_id = OLD.dist_root_cert" \
291 " OR cert_id = OLD.dist_im_cert" \
292 " OR cert_id = OLD.dist_signer_cert" \
293 " OR cert_id = OLD.dist2_root_cert" \
294 " OR cert_id = OLD.dist2_im_cert" \
295 " OR cert_id = OLD.dist2_signer_cert;" \
298 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
299 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
300 "AFTER UPDATE ON package_cert_index_info " \
301 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
302 " WHERE cert_id = OLD.cert_id) = 0) "\
304 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
307 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT \
308 "CREATE TRIGGER IF NOT EXISTS update_%s_info " \
309 "AFTER UPDATE ON package_cert_info " \
310 "WHEN (OLD.%s IS NOT NULL) " \
312 " UPDATE package_cert_index_info SET" \
313 " cert_ref_count = cert_ref_count - 1" \
314 " WHERE cert_id = OLD.%s;" \
317 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "create table if not exists package_app_data_control " \
318 "(app_id text not null, " \
319 "providerid text not null, " \
320 "access text not null, " \
321 "type text not null, " \
322 "PRIMARY KEY(app_id, providerid, access, type) " \
323 "FOREIGN KEY(app_id) " \
324 "REFERENCES package_app_info(app_id) " \
327 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
328 "(app_id TEXT NOT NULL, " \
329 "uid TEXT NOT NULL, " \
330 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
331 "is_splash_screen_enabled TEXT NOT NULL, " \
332 "PRIMARY KEY(app_id, uid))"
333 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
334 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
335 "AFTER UPDATE ON package_app_info_for_uid " \
337 " DELETE FROM package_app_info_for_uid WHERE " \
338 " is_splash_screen_enabled=" \
339 " (SELECT package_app_info.app_splash_screen_display FROM " \
340 " package_app_info, package_app_info_for_uid WHERE " \
341 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
344 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
345 "create table if not exists package_app_splash_screen " \
346 "(app_id text not null, " \
347 "src text not null, " \
348 "type text not null, " \
349 "orientation text not null, " \
350 "indicatordisplay text, " \
352 "color_depth text not null DEFAULT '24', " \
353 "PRIMARY KEY(app_id, orientation, operation) " \
354 "FOREIGN KEY(app_id) " \
355 "REFERENCES package_app_info(app_id) " \
358 static int __insert_application_info(manifest_x *mfx);
359 static int __insert_application_appcategory_info(manifest_x *mfx);
360 static int __insert_application_appcontrol_info(manifest_x *mfx);
361 static int __insert_application_appmetadata_info(manifest_x *mfx);
362 static int __insert_application_share_allowed_info(manifest_x *mfx);
363 static int __insert_application_share_request_info(manifest_x *mfx);
364 static int __insert_application_datacontrol_info(manifest_x *mfx);
365 static void __insert_application_locale_info(gpointer data, gpointer userdata);
366 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
367 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
368 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
369 static int __delete_subpkg_info_from_db(char *appid);
370 static int __delete_appinfo_from_db(char *db_table, const char *appid);
371 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
372 static int __exec_query(char *query);
373 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
374 char **label, char **license, char **icon, char **description, char **author);
375 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
376 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
377 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
378 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
379 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
380 static int __parserdb_change_perm(const char *db_file, uid_t uid);
382 #define REGULAR_USER 5000
383 static inline uid_t _getuid(void)
385 uid_t uid = getuid();
387 if (uid < REGULAR_USER)
388 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
393 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
396 __delete_subpkg_info_from_db(coltxt[0]);
401 static const char *__get_str(const char *str)
405 return PKGMGR_PARSER_EMPTY_STR;
411 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
416 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
417 if (ret != SQLITE_OK) {
418 _LOGD("connect db [%s] failed!\n", db_path);
426 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
428 manifest_x *mfx = (manifest_x *)data;
434 if (mfx->application == NULL)
436 app = (application_x *)mfx->application->data;
437 for(i = 0; i < ncols; i++)
439 if (strcmp(colname[i], "app_id") == 0) {
441 appid = strdup(coltxt[i]);
442 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
444 status = strdup(coltxt[i]);
450 _LOGD("app id is NULL\n");
453 /*update guest mode visibility*/
454 for (tmp = mfx->application; tmp; tmp = tmp->next) {
455 app = (application_x *)tmp->data;
458 if (strcmp(app->appid, appid) == 0) {
459 free((void *)app->guestmode_visibility);
460 app->guestmode_visibility = strdup(status);
476 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
478 char *error_message = NULL;
479 char query[MAX_QUERY_LEN] = {'\0'};
480 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
482 sqlite3_exec(pkgmgr_parser_db, query,
483 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
484 _LOGD("Don't execute query = %s error message = %s\n",
485 query, error_message);
486 sqlite3_free(error_message);
491 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
493 char *error_message = NULL;
495 sqlite3_exec(db_handle, db_query,
496 NULL, NULL, &error_message)) {
497 _LOGD("Don't execute query = %s error message = %s\n",
498 db_query, error_message);
499 sqlite3_free(error_message);
502 sqlite3_free(error_message);
506 static int __exec_query(char *query)
508 char *error_message = NULL;
510 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
511 _LOGE("Don't execute query = %s error message = %s\n", query,
513 sqlite3_free(error_message);
516 sqlite3_free(error_message);
520 static int __exec_query_no_msg(char *query)
522 char *error_message = NULL;
524 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
525 sqlite3_free(error_message);
528 sqlite3_free(error_message);
532 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
540 for (tmp = lbls; tmp; tmp = tmp->next) {
541 lbl = (label_x *)tmp->data;
545 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
547 for (tmp = lcns; tmp; tmp = tmp->next) {
548 lcn = (license_x *)tmp->data;
552 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
554 for (tmp = icns; tmp; tmp = tmp->next) {
555 icn = (icon_x *)tmp->data;
559 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
561 for (tmp = dcns; tmp; tmp = tmp->next) {
562 dcn = (description_x *)tmp->data;
566 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
568 for (tmp = aths; tmp; tmp = tmp->next) {
569 ath = (author_x *)tmp->data;
573 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
579 static GList *__create_icon_list(GList *appicon, GList *icns)
584 for (tmp = icns; tmp; tmp = tmp->next) {
585 icn = (icon_x *)tmp->data;
589 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
594 static GList *__create_image_list(GList *appimage, GList *imgs)
599 for (tmp = imgs; tmp; tmp = tmp->next) {
600 img = (image_x *)tmp->data;
604 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
609 static void __trimfunc(GList* trim_list)
611 char *trim_data = NULL;
615 list = g_list_first(trim_list);
618 trim_data = (char *)list->data;
621 if (strcmp(trim_data, prev) == 0) {
622 trim_list = g_list_remove(trim_list, trim_data);
623 list = g_list_first(trim_list);
632 list = g_list_next(list);
636 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
638 if (a == NULL || b == NULL)
640 if (strcmp((char*)a, (char*)b) == 0)
642 if (strcmp((char*)a, (char*)b) < 0)
644 if (strcmp((char*)a, (char*)b) > 0)
649 static int __check_dpi(const char *dpi_char, int dpi_int)
651 if (dpi_char == NULL)
654 if (strcasecmp(dpi_char, LDPI) == 0) {
655 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
659 } else if (strcasecmp(dpi_char, MDPI) == 0) {
660 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
664 } else if (strcasecmp(dpi_char, HDPI) == 0) {
665 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
669 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
670 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
674 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
675 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
683 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
686 char *icon_filename = NULL;
687 char modified_iconpath[BUFSIZE] = { '\0' };
688 char icon_path[BUFSIZE] = { '\0' };
692 if (orig_icon_path == NULL)
695 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
699 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
700 dpi_path[0] = "LDPI";
701 dpi_path[1] = "ldpi";
702 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
703 dpi_path[0] = "MDPI";
704 dpi_path[1] = "mdpi";
705 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
706 dpi_path[0] = "HDPI";
707 dpi_path[1] = "hdpi";
708 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
709 dpi_path[0] = "XHDPI";
710 dpi_path[1] = "xhdpi";
711 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
712 dpi_path[0] = "XXHDPI";
713 dpi_path[1] = "xxhdpi";
715 _LOGE("Unidentified dpi[%d]", dpi);
719 icon_filename = strrchr(orig_icon_path, '/');
720 if (icon_filename == NULL)
723 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
724 for (i = 0; i < 2; i++) {
725 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
726 if (access(modified_iconpath, F_OK) != -1) {
727 // if exists, return modified icon path
728 *new_icon_path = strdup(modified_iconpath);
736 static gint __compare_icon(gconstpointer a, gconstpointer b)
738 icon_x *icon = (icon_x *)a;
740 char *icon_folder_path = NULL;
742 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
745 if (icon->dpi != NULL)
748 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
750 icon->text = icon_folder_path;
756 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
758 icon_x *icon = (icon_x *)a;
759 int dpi = GPOINTER_TO_INT(b);
761 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
764 if (icon->dpi == NULL)
767 if (__check_dpi(icon->dpi, dpi) == 0)
773 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
775 icon_x *icon = (icon_x *)a;
776 char *lang = (char *)b;
777 char *icon_folder_path = NULL;
779 if (icon->dpi != NULL)
782 if (strcasecmp(icon->lang, lang) == 0) {
783 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
784 //icon for no locale. check existance of folder-hierachied default icons
785 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
787 icon->text = icon_folder_path;
796 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
798 icon_x *icon = (icon_x *)a;
799 char *lang = (char *)b;
802 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
806 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
812 static char *__find_icon(GList *icons, const char *lang)
818 // first, find icon whose locale and dpi with given lang and system's dpi has matched
819 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
821 icon = (icon_x *)tmp->data;
822 return (char *)icon->text;
825 // if first has failed, find icon whose locale has matched
826 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
828 icon = (icon_x *)tmp->data;
829 return (char *)icon->text;
832 // if second has failed, find icon whose dpi has matched with system's dpi
833 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
836 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
838 icon = (icon_x *)tmp->data;
839 return (char *)icon->text;
842 // last, find default icon marked as "No Locale"
843 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
845 icon = (icon_x *)tmp->data;
846 return (char *)icon->text;
852 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
853 char **label, char **license, char **icon, char **description, char **author)
860 for (tmp = lbls; tmp; tmp = tmp->next) {
861 lbl = (label_x *)tmp->data;
865 if (strcmp(lbl->lang, (char *)data) == 0) {
866 *label = (char*)lbl->text;
871 for (tmp = lcns; tmp; tmp = tmp->next) {
872 lcn = (license_x *)tmp->data;
876 if (strcmp(lcn->lang, (char *)data) == 0) {
877 *license = (char*)lcn->text;
883 *icon = __find_icon(icns, (char *)data);
885 for (tmp = dcns; tmp; tmp = tmp->next) {
886 dcn = (description_x *)tmp->data;
890 if (strcmp(dcn->lang, (char *)data) == 0) {
891 *description = (char*)dcn->text;
896 for (tmp = aths; tmp; tmp = tmp->next) {
897 ath = (author_x *)tmp->data;
901 if (strcmp(ath->lang, (char *)data) == 0) {
902 *author = (char*)ath->text;
910 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
914 for (tmp = icns; tmp; tmp = tmp->next) {
915 icn = (icon_x *)tmp->data;
919 if (strcmp(icn->section, (char *)data) == 0) {
920 *icon = (char*)icn->text;
921 *resolution = (char*)icn->resolution;
928 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
932 for (tmp = imgs; tmp; tmp = tmp->next) {
933 img = (image_x *)tmp->data;
937 if (strcmp(img->section, (char *)data) == 0) {
938 *lang = (char*)img->lang;
939 *image = (char*)img->text;
946 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
951 char *description = NULL;
952 char *license = NULL;
956 manifest_x *mfx = (manifest_x *)userdata;
957 GList *lbl = mfx->label;
958 GList *lcn = mfx->license;
959 GList *icn = mfx->icon;
960 GList *dcn = mfx->description;
961 GList *ath = mfx->author;
963 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
964 if (!label && !description && !icon && !license && !author)
967 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
968 "package_label, package_icon, package_description, package_license, package_author) values " \
969 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
974 __get_str(description),
978 ret = __exec_query(query);
980 _LOGD("Package Localized Info DB Insert failed\n");
985 static void __insert_application_locale_info(gpointer data, gpointer userdata)
992 application_x *app = (application_x*)userdata;
993 GList *lbl = app->label;
994 GList *icn = app->icon;
996 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1000 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
1001 "app_label, app_icon) values " \
1002 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
1003 __get_str(label), __get_str(icon));
1004 ret = __exec_query(query);
1006 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1008 sqlite3_free(query);
1010 /*insert ui app locale info to pkg locale to get mainapp data */
1011 if (strcasecmp(app->mainapp, "true")==0) {
1012 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
1013 "package_label, package_icon, package_description, package_license, package_author) values " \
1014 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1019 PKGMGR_PARSER_EMPTY_STR,
1020 PKGMGR_PARSER_EMPTY_STR,
1021 PKGMGR_PARSER_EMPTY_STR);
1023 ret = __exec_query_no_msg(query);
1024 sqlite3_free(query);
1027 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1028 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1029 ret = __exec_query_no_msg(query);
1030 sqlite3_free(query);
1035 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1039 char *resolution = NULL;
1040 char query[MAX_QUERY_LEN] = {'\0'};
1042 application_x *app = (application_x*)userdata;
1043 GList *icn = app->icon;
1045 __extract_icon_data(data, icn, &icon, &resolution);
1046 if (!icon && !resolution)
1048 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1049 "app_icon, app_icon_section, app_icon_resolution) values " \
1050 "('%q', '%q', '%q', '%q')", app->appid,
1051 icon, (char*)data, resolution);
1053 ret = __exec_query(query);
1055 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1059 static void __insert_application_image_info(gpointer data, gpointer userdata)
1064 char query[MAX_QUERY_LEN] = {'\0'};
1066 application_x *app = (application_x*)userdata;
1067 GList *image = app->image;
1069 __extract_image_data(data, image, &lang, &img);
1072 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1073 "app_image_section, app_image) values " \
1074 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1076 ret = __exec_query(query);
1078 _LOGD("Package UiApp image Info DB Insert failed\n");
1083 static int __insert_mainapp_info(manifest_x *mfx)
1088 char query[MAX_QUERY_LEN] = {'\0'};
1089 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1090 app = (application_x *)tmp->data;
1093 snprintf(query, MAX_QUERY_LEN,
1094 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1096 ret = __exec_query(query);
1098 _LOGD("Package App Info DB Insert Failed\n");
1101 if (strcasecmp(app->mainapp, "True")==0)
1102 mfx->mainapp_id = strdup(app->appid);
1105 if (mfx->mainapp_id == NULL) {
1106 if (mfx->application == NULL)
1108 app = (application_x *)mfx->application->data;
1112 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1114 _LOGD("Not valid appid\n");
1118 ret = __exec_query(query);
1120 _LOGD("Package UiApp Info DB Insert Failed\n");
1124 free((void *)app->mainapp);
1125 app->mainapp= strdup("true");
1126 mfx->mainapp_id = strdup(app->appid);
1129 memset(query, '\0', MAX_QUERY_LEN);
1130 snprintf(query, MAX_QUERY_LEN,
1131 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1132 ret = __exec_query(query);
1134 _LOGD("Package Info DB update Failed\n");
1141 static int __convert_background_category(GList *category_list)
1144 GList *tmp_list = category_list;
1145 char *category_data = NULL;
1147 if (category_list == NULL)
1150 while (tmp_list != NULL) {
1151 category_data = (char *)tmp_list->data;
1152 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1153 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1154 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1155 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1156 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1157 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1158 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1159 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1160 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1161 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1162 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1163 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1164 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1165 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1167 _LOGE("Unidentified category [%s]", category_data);
1169 tmp_list = g_list_next(tmp_list);
1175 static const char *__find_effective_appid(GList *metadata_list)
1180 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1181 md = (metadata_x *)tmp_list->data;
1182 if (md == NULL || md->key == NULL)
1185 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1194 /* _PRODUCT_LAUNCHING_ENHANCED_
1195 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1197 static int __insert_application_info(manifest_x *mfx)
1202 int background_value = 0;
1203 char query[MAX_QUERY_LEN] = {'\0'};
1205 const char *effective_appid;
1208 type = strdup(mfx->type);
1210 type = strdup("tpk");
1212 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1213 app = (application_x *)tmp->data;
1217 background_value = __convert_background_category(app->background_category);
1218 if (background_value < 0) {
1219 _LOGE("Failed to retrieve background value[%d]", background_value);
1220 background_value = 0;
1223 effective_appid = __find_effective_appid(app->metadata);
1225 snprintf(query, MAX_QUERY_LEN,
1226 "insert into package_app_info(" \
1227 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1228 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1229 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1230 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1231 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1232 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1233 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1234 "app_effective_appid, app_splash_screen_display) " \
1236 "'%s', '%s', '%s', '%s', '%s', " \
1237 "'%s', '%s', '%s', '%s', '%s', " \
1238 "'%s', '%s', '%s', '%s', '%s', " \
1239 "'%s', '%s', '%s', '%s', '%s', " \
1240 "'%s', '%s', '%s', '%s', '%s', " \
1241 "'%s', '%s', '%s', '%s', '%s', " \
1242 "'%s', '%d', '%s', '%s', '%s', " \
1244 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1245 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1246 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1247 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1248 app->guestmode_visibility, app->permission_type,
1249 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1250 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1251 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1252 __get_str(effective_appid), app->splash_screen_display);
1254 ret = __exec_query(query);
1256 _LOGD("Package UiApp Info DB Insert Failed\n");
1261 memset(query, '\0', MAX_QUERY_LEN);
1270 static int __insert_application_appcategory_info(manifest_x *mfx)
1277 char query[MAX_QUERY_LEN] = {'\0'};
1278 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1279 app = (application_x *)app_tmp->data;
1282 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1283 ct = (const char *)ct_tmp->data;
1286 snprintf(query, MAX_QUERY_LEN,
1287 "insert into package_app_app_category(app_id, category) " \
1288 "values('%s','%s')",\
1290 ret = __exec_query(query);
1292 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1295 memset(query, '\0', MAX_QUERY_LEN);
1301 static int __insert_application_appmetadata_info(manifest_x *mfx)
1308 char query[MAX_QUERY_LEN] = {'\0'};
1309 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1310 app = (application_x *)app_tmp->data;
1313 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1314 md = (metadata_x *)md_tmp->data;
1318 snprintf(query, MAX_QUERY_LEN,
1319 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1320 "values('%s','%s', '%s')",\
1321 app->appid, md->key, md->value ? md->value : "");
1322 ret = __exec_query(query);
1324 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1328 memset(query, '\0', MAX_QUERY_LEN);
1334 static int __insert_application_apppermission_info(manifest_x *mfx)
1341 char query[MAX_QUERY_LEN] = {'\0'};
1342 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1343 app = (application_x *)app_tmp->data;
1346 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1347 pm = (permission_x *)pm_tmp->data;
1350 snprintf(query, MAX_QUERY_LEN,
1351 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1352 "values('%s','%s', '%s')",\
1353 app->appid, pm->type, pm->value);
1354 ret = __exec_query(query);
1356 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1359 memset(query, '\0', MAX_QUERY_LEN);
1365 static int __insert_application_appcontrol_info(manifest_x *mfx)
1369 GList *acontrol_tmp;
1370 appcontrol_x *acontrol;
1372 char query[MAX_QUERY_LEN] = {'\0'};
1373 char buf[BUFSIZE] = {'\0'};
1374 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1375 app = (application_x *)app_tmp->data;
1378 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1379 acontrol = (appcontrol_x *)acontrol_tmp->data;
1380 if (acontrol == NULL)
1382 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1383 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1384 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1385 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1386 snprintf(query, MAX_QUERY_LEN,
1387 "insert into package_app_app_control(app_id, app_control) " \
1388 "values('%s', '%s')",\
1390 ret = __exec_query(query);
1392 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1395 memset(query, '\0', MAX_QUERY_LEN);
1401 static int __insert_application_datacontrol_info(manifest_x *mfx)
1408 char query[MAX_QUERY_LEN] = {'\0'};
1410 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1411 app = (application_x *)app_tmp->data;
1414 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1415 dc = (datacontrol_x *)dc_tmp->data;
1418 snprintf(query, MAX_QUERY_LEN,
1419 "insert into package_app_data_control(app_id, providerid, access, type) " \
1420 "values('%s', '%s', '%s', '%s')",\
1426 ret = __exec_query(query);
1428 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1431 memset(query, '\0', MAX_QUERY_LEN);
1437 static int __insert_application_share_request_info(manifest_x *mfx)
1446 char query[MAX_QUERY_LEN] = {'\0'};
1447 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1448 app = (application_x *)app_tmp->data;
1451 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1452 ds = (datashare_x *)ds_tmp->data;
1455 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1456 rq = (const char *)rq_tmp->data;
1459 snprintf(query, MAX_QUERY_LEN,
1460 "insert into package_app_share_request(app_id, data_share_request) " \
1461 "values('%s', '%s')",\
1463 ret = __exec_query(query);
1465 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1468 memset(query, '\0', MAX_QUERY_LEN);
1475 static int __insert_application_share_allowed_info(manifest_x *mfx)
1486 char query[MAX_QUERY_LEN] = {'\0'};
1487 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1488 app = (application_x *)app_tmp->data;
1491 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1492 ds = (datashare_x *)ds_tmp->data;
1495 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1496 df = (define_x *)df_tmp->data;
1499 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1500 al = (const char *)al_tmp->data;
1503 snprintf(query, MAX_QUERY_LEN,
1504 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1505 "values('%s', '%s', '%s')",\
1506 app->appid, df->path, al);
1507 ret = __exec_query(query);
1509 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1512 memset(query, '\0', MAX_QUERY_LEN);
1520 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1522 splashscreen_x *ss = (splashscreen_x *)a;
1523 const char *orientation = (const char *)b;
1526 if (ss->operation || ss->dpi == NULL)
1529 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1533 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1539 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1541 splashscreen_x *ss = (splashscreen_x *)a;
1542 const char *orientation = (const char *)b;
1544 if (ss->operation || ss->dpi)
1547 if (strcasecmp(ss->orientation, orientation) == 0)
1553 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1554 const char *orientation)
1558 tmp = g_list_find_custom(splashscreens, orientation,
1559 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1561 return (splashscreen_x *)tmp->data;
1563 tmp = g_list_find_custom(splashscreens, orientation,
1564 (GCompareFunc)__compare_splashscreen_with_orientation);
1566 return (splashscreen_x *)tmp->data;
1571 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1573 splashscreen_x *ss = (splashscreen_x *)data;
1574 GList **list = (GList **)user_data;
1577 if (ss->operation == NULL || ss->dpi == NULL)
1580 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1584 if (__check_dpi(ss->dpi, dpi) != 0)
1587 *list = g_list_append(*list, ss);
1590 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1592 splashscreen_x *ss = (splashscreen_x *)data;
1593 GList **list = (GList **)user_data;
1594 splashscreen_x *ss_tmp;
1597 if (ss->operation == NULL || ss->dpi)
1600 for (tmp = *list; tmp; tmp = tmp->next) {
1601 ss_tmp = (splashscreen_x *)tmp->data;
1602 if (ss_tmp->operation
1603 && strcmp(ss_tmp->operation, ss->operation) == 0
1604 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1608 *list = g_list_append(*list, ss);
1611 static GList *__find_splashscreens(GList *splashscreens)
1616 g_list_foreach(splashscreens,
1617 __find_appcontrol_splashscreen_with_dpi, &list);
1618 g_list_foreach(splashscreens,
1619 __find_appcontrol_splashscreen, &list);
1621 ss = __find_default_splashscreen(splashscreens, "portrait");
1623 list = g_list_append(list, ss);
1624 ss = __find_default_splashscreen(splashscreens, "landscape");
1626 list = g_list_append(list, ss);
1631 static int __insert_application_splashscreen_info(manifest_x *mfx)
1639 char query[MAX_QUERY_LEN];
1641 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1642 app = (application_x *)app_tmp->data;
1643 if (app == NULL || app->splashscreens == NULL)
1646 ss_tmp = __find_splashscreens(app->splashscreens);
1650 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1651 ss = (splashscreen_x *)tmp->data;
1652 snprintf(query, sizeof(query),
1653 "insert into package_app_splash_screen" \
1654 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1655 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1656 app->appid, ss->src, ss->type, ss->orientation,
1657 ss->indicatordisplay, __get_str(ss->operation),
1659 ret = __exec_query(query);
1661 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1664 memset(query, '\0', MAX_QUERY_LEN);
1666 g_list_free(ss_tmp);
1671 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1676 char query[MAX_QUERY_LEN];
1678 const char *image_type;
1679 const char *indicatordisplay;
1680 const char *orientation;
1681 const char *operation = NULL;
1682 const char *color_depth = "24"; /* default */
1684 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1685 app = (application_x *)app_tmp->data;
1687 (app->portraitimg == NULL && app->landscapeimg == NULL))
1689 image_type = "img"; /* default */
1690 if (app->effectimage_type) {
1691 tmp = strstr(app->effectimage_type, "edj");
1695 indicatordisplay = "true"; /* default */
1696 if (app->indicatordisplay)
1697 indicatordisplay = app->indicatordisplay;
1698 if (app->portraitimg) {
1699 orientation = "portrait";
1700 snprintf(query, sizeof(query),
1701 "insert into package_app_splash_screen" \
1702 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1703 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1704 app->appid, app->portraitimg, image_type,
1705 orientation, indicatordisplay, __get_str(operation),
1707 ret = __exec_query(query);
1709 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1712 memset(query, '\0', MAX_QUERY_LEN);
1714 if (app->landscapeimg) {
1715 orientation = "landscape";
1716 snprintf(query, sizeof(query),
1717 "insert into package_app_splash_screen" \
1718 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1719 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1720 app->appid, app->landscapeimg, image_type,
1721 orientation, indicatordisplay, __get_str(operation),
1723 ret = __exec_query(query);
1725 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1728 memset(query, '\0', MAX_QUERY_LEN);
1734 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1741 char query[MAX_QUERY_LEN];
1743 char *tmpptr = NULL;
1744 const char *operation;
1745 const char *portraitimg;
1746 const char *landscapeimg;
1747 const char *indicatordisplay;
1748 const char *orientation;
1749 const char *image_type;
1750 const char *color_depth = "24"; /* default */
1752 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1753 app = (application_x *)app_tmp->data;
1757 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1758 md = (metadata_x *)md_tmp->data;
1759 if (md == NULL || md->key == NULL || md->value == NULL)
1762 if (strcasestr(md->key, "operation_effect=")) {
1763 operation = index(md->key, '=');
1764 if ((operation + 1) != NULL)
1768 } else if (strcasestr(md->key, "launch_effect")) {
1775 landscapeimg = NULL;
1776 indicatordisplay = "true"; /* default */
1777 token = strtok_r(md->value, "|", &tmpptr);
1778 while (token != NULL) {
1779 if (strcasestr(token, "portrait-effectimage=")) {
1780 portraitimg = index(token, '=');
1781 if ((portraitimg + 1) != NULL)
1785 } else if (strcasestr(token, "landscape-effectimage=")) {
1786 landscapeimg = index(token, '=');
1787 if ((landscapeimg + 1) != NULL)
1790 landscapeimg = NULL;
1791 } else if (strcasestr(token, "indicatordisplay=")) {
1792 indicatordisplay = index(token, '=');
1793 if ((indicatordisplay + 1) != NULL)
1796 indicatordisplay = "true";
1799 token = strtok_r(NULL, "|", &tmpptr);
1803 orientation = "portrait";
1805 if (strcasestr(portraitimg, "edj"))
1807 snprintf(query, sizeof(query),
1808 "insert into package_app_splash_screen" \
1809 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1810 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1811 app->appid, portraitimg, image_type,
1812 orientation, indicatordisplay, __get_str(operation),
1814 ret = __exec_query(query);
1816 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1819 memset(query, '\0', MAX_QUERY_LEN);
1822 orientation = "landscape";
1824 if (strcasestr(landscapeimg, "edj"))
1826 snprintf(query, sizeof(query),
1827 "insert into package_app_splash_screen" \
1828 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1829 "values('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
1830 app->appid, landscapeimg, image_type,
1831 orientation, indicatordisplay, __get_str(operation),
1833 ret = __exec_query(query);
1835 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1838 memset(query, '\0', MAX_QUERY_LEN);
1846 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1850 const char *pv = NULL;
1851 char query[MAX_QUERY_LEN] = { '\0' };
1854 const char *auth_name = NULL;
1855 const char *auth_email = NULL;
1856 const char *auth_href = NULL;
1858 GList *pkglocale = NULL;
1859 GList *applocale = NULL;
1860 GList *appicon = NULL;
1861 GList *appimage = NULL;
1863 if (mfx->author && mfx->author->data) {
1864 author = (author_x *)mfx->author->data;
1866 auth_name = author->text;
1868 auth_email = author->email;
1870 auth_href = author->href;
1873 /*Insert in the package_cert_info CERT_DB*/
1874 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1875 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1876 if (ret != PMINFO_R_OK) {
1877 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1878 _LOGE("Cert Info DB create handle failed\n");
1881 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1882 if (ret != PMINFO_R_OK) {
1883 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1884 _LOGE("Cert Info DB Insert Failed\n");
1888 /*Insert in the package_info DB*/
1889 snprintf(query, MAX_QUERY_LEN,
1890 "insert into package_info(" \
1891 "package, package_type, package_version, package_api_version, package_tep_name, " \
1892 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1893 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1894 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1895 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1897 "'%s', '%s', '%s', '%s', '%s', " \
1898 "'%s', '%s', '%s', '%s', '%s', " \
1899 "'%s', '%s', '%s', '%s', '%s', " \
1900 "'%s', '%s', '%s', '%s', '%s', " \
1901 "'%s', '%s', '%s', '%s', '%s')", \
1902 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1903 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1904 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1905 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1906 __get_str(mfx->storeclient_id),
1907 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1909 ret = __exec_query(query);
1911 _LOGD("Package Info DB Insert Failed\n");
1915 /*Insert in the package_privilege_info DB*/
1916 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1917 pv = (const char *)tmp->data;
1920 memset(query, '\0', MAX_QUERY_LEN);
1921 snprintf(query, MAX_QUERY_LEN,
1922 "insert into package_privilege_info(package, privilege) " \
1923 "values('%s','%s')",\
1925 ret = __exec_query(query);
1927 _LOGD("Package Privilege Info DB Insert Failed\n");
1932 if (mfx->application != NULL) {
1933 ret = __insert_mainapp_info(mfx);
1938 /*Insert the package locale*/
1939 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1940 /*remove duplicated data in pkglocale*/
1941 __trimfunc(pkglocale);
1943 /*Insert the app locale, icon, image info */
1944 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1945 app = (application_x *)tmp->data;
1948 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1949 appicon = __create_icon_list(appicon, app->icon);
1950 appimage = __create_image_list(appimage, app->image);
1952 /*remove duplicated data in applocale*/
1953 __trimfunc(applocale);
1954 __trimfunc(appicon);
1955 __trimfunc(appimage);
1957 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1959 /*native app locale info*/
1960 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1961 app = (application_x *)tmp->data;
1964 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1965 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1966 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1969 g_list_free(pkglocale);
1971 g_list_free(applocale);
1973 g_list_free(appicon);
1975 g_list_free(appimage);
1978 /*Insert in the package_app_info DB*/
1979 ret = __insert_application_info(mfx);
1982 /*Insert in the package_app_app_control DB*/
1983 ret = __insert_application_appcontrol_info(mfx);
1987 /*Insert in the package_app_app_category DB*/
1988 ret = __insert_application_appcategory_info(mfx);
1992 /*Insert in the package_app_app_metadata DB*/
1993 ret = __insert_application_appmetadata_info(mfx);
1997 /*Insert in the package_app_app_permission DB*/
1998 ret = __insert_application_apppermission_info(mfx);
2002 /*Insert in the package_app_share_allowed DB*/
2003 ret = __insert_application_share_allowed_info(mfx);
2007 /*Insert in the package_app_share_request DB*/
2008 ret = __insert_application_share_request_info(mfx);
2012 /*Insert in the package_app_data_control DB*/
2013 ret = __insert_application_datacontrol_info(mfx);
2017 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2018 ret = __insert_application_legacy_splashscreen_info(mfx);
2022 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2023 ret = __insert_application_metadata_splashscreen_info(mfx);
2027 /*Insert in the package_app_splash_screen DB*/
2028 ret = __insert_application_splashscreen_info(mfx);
2036 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2038 char query[MAX_QUERY_LEN] = { '\0' };
2040 memset(query, '\0', MAX_QUERY_LEN);
2041 snprintf(query, MAX_QUERY_LEN,
2042 "delete from %s where app_id='%s'", db_table, appid);
2043 ret = __exec_query(query);
2045 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2051 static int __delete_subpkg_info_from_db(char *appid)
2055 ret = __delete_appinfo_from_db("package_app_info", appid);
2058 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2061 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2064 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2067 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2070 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2073 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2076 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2079 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2082 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2085 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2088 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2095 static int __delete_subpkg_from_db(manifest_x *mfx)
2097 char query[MAX_QUERY_LEN] = { '\0' };
2098 char *error_message = NULL;
2100 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2102 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2103 _LOGE("Don't execute query = %s error message = %s\n", query,
2105 sqlite3_free(error_message);
2108 sqlite3_free(error_message);
2113 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2115 char query[MAX_QUERY_LEN] = { '\0' };
2119 /*Delete from cert table*/
2120 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2122 _LOGD("Cert Info DB Delete Failed\n");
2126 /*Delete from Package Info DB*/
2127 snprintf(query, MAX_QUERY_LEN,
2128 "delete from package_info where package='%s'", mfx->package);
2129 ret = __exec_query(query);
2131 _LOGD("Package Info DB Delete Failed\n");
2134 memset(query, '\0', MAX_QUERY_LEN);
2136 /*Delete from Package Localized Info*/
2137 snprintf(query, MAX_QUERY_LEN,
2138 "delete from package_localized_info where package='%s'", mfx->package);
2139 ret = __exec_query(query);
2141 _LOGD("Package Localized Info DB Delete Failed\n");
2145 /*Delete from Package Privilege Info*/
2146 snprintf(query, MAX_QUERY_LEN,
2147 "delete from package_privilege_info where package='%s'", mfx->package);
2148 ret = __exec_query(query);
2150 _LOGD("Package Privilege Info DB Delete Failed\n");
2154 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2155 app = (application_x *)tmp->data;
2158 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2161 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2164 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2167 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2170 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2173 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2176 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2179 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2182 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2185 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2188 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2191 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2196 /* if main package has sub pkg, delete sub pkg data*/
2197 __delete_subpkg_from_db(mfx);
2202 static int __disable_app(const char *appid)
2205 char query[MAX_QUERY_LEN] = {'\0'};
2206 sqlite3_snprintf(MAX_QUERY_LEN, query,
2207 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2209 ret = __exec_query(query);
2211 _LOGD("Insert global app disable failed\n");
2216 static int __enable_app(const char *appid)
2219 char query[MAX_QUERY_LEN] = {'\0'};
2220 sqlite3_snprintf(MAX_QUERY_LEN, query,
2221 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2223 ret = __exec_query(query);
2225 _LOGD("Insert global app disable failed\n");
2230 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2233 char query[MAX_QUERY_LEN] = { '\0', };
2235 const char *val = NULL;
2240 sqlite3_snprintf(MAX_QUERY_LEN, query,
2241 "SELECT COUNT(*) FROM "
2242 "package_app_info_for_uid WHERE app_id=%Q "
2243 "AND uid='%d'", appid, (int)uid);
2245 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2246 if (ret != SQLITE_OK) {
2247 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2248 return PMINFO_R_ERROR;
2251 if (sqlite3_step(stmt) != SQLITE_ROW) {
2252 LOGE("failed to step");
2253 sqlite3_finalize(stmt);
2254 return PMINFO_R_ERROR;
2257 val = (const char *)sqlite3_column_text(stmt, 0);
2259 sqlite3_finalize(stmt);
2264 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2267 char query[MAX_QUERY_LEN] = { '\0', };
2269 ret = __check_appinfo_for_uid_table(appid, uid);
2271 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2274 } else if (ret == 0) {
2275 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2276 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2277 "VALUES(%Q, '%d', 'true', "
2278 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2279 appid, (int)uid, appid);
2281 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2282 "package_app_info_for_uid SET is_disabled='true' "
2283 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2286 ret = __exec_query(query);
2288 _LOGD("Add global app disable info failed\n");
2293 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2296 char query[MAX_QUERY_LEN] = {'\0'};
2298 ret = __check_appinfo_for_uid_table(appid, uid);
2300 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2303 } else if (ret > 0) {
2304 sqlite3_snprintf(MAX_QUERY_LEN, query,
2305 "UPDATE package_app_info_for_uid SET "
2306 "is_disabled='false' WHERE app_id=%Q AND "
2307 "uid='%d'", appid, (int)uid);
2310 ret = __exec_query(query);
2312 _LOGD("Remove global app disable info failed\n");
2317 static int __update_global_app_splash_screen_for_user(const char *appid,
2318 uid_t uid, int flag)
2321 char query[MAX_QUERY_LEN] = { '\0', };
2323 ret = __check_appinfo_for_uid_table(appid, uid);
2325 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2328 } else if (ret == 0) {
2329 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2330 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2331 "VALUES(%Q, '%d', %Q)", appid, (int)uid,
2332 flag ? "true" : "false");
2334 sqlite3_snprintf(MAX_QUERY_LEN, query,
2335 "UPDATE package_app_info_for_uid SET "
2336 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2337 "uid='%d'", flag ? "true" : "false", appid, (int)uid);
2340 ret = __exec_query(query);
2342 _LOGD("update global app splash screen info failed\n");
2347 static int __disable_app_splash_screen(const char *appid)
2350 char query[MAX_QUERY_LEN] = {'\0'};
2352 sqlite3_snprintf(MAX_QUERY_LEN, query,
2353 "UPDATE package_app_info set app_splash_screen_display='false' where app_id=%Q",
2355 ret = __exec_query(query);
2357 _LOGD("Failed to update app_palsh_screen_display");
2362 static int __enable_app_splash_screen(const char *appid)
2365 char query[MAX_QUERY_LEN] = {'\0'};
2367 sqlite3_snprintf(MAX_QUERY_LEN, query,
2368 "UPDATE package_app_info set app_splash_screen_display='true' where app_id=%Q",
2370 ret = __exec_query(query);
2372 _LOGD("Failed to update app_splash_screen_display");
2377 static int __update_preload_condition_in_db()
2380 char query[MAX_QUERY_LEN] = {'\0'};
2382 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2384 ret = __exec_query(query);
2386 _LOGD("Package preload_condition update failed\n");
2391 API int pkgmgr_parser_initialize_db(uid_t uid)
2395 char query[MAX_QUERY_LEN];
2396 static const char *columns[] = {
2397 "author_root_cert", "author_im_cert", "author_signer_cert",
2398 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2399 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2403 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2405 _LOGD("package info DB initialization failed\n");
2408 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2410 _LOGD("package localized info DB initialization failed\n");
2413 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2415 _LOGD("package app app privilege DB initialization failed\n");
2418 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2420 _LOGD("package app info DB initialization failed\n");
2423 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2425 _LOGD("package app localized info DB initialization failed\n");
2428 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2430 _LOGD("package app icon localized info DB initialization failed\n");
2433 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2435 _LOGD("package app image info DB initialization failed\n");
2438 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2440 _LOGD("package app app control DB initialization failed\n");
2443 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2445 _LOGD("package app app category DB initialization failed\n");
2448 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2450 _LOGD("package app app category DB initialization failed\n");
2453 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2455 _LOGD("package app app permission DB initialization failed\n");
2458 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2460 _LOGD("package app share allowed DB initialization failed\n");
2463 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2465 _LOGD("package app share request DB initialization failed\n");
2468 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2470 _LOGD("package app data control DB initialization failed\n");
2474 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2476 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2480 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2482 _LOGD("package app splash screen DB initialization failed\n");
2486 /* Trigger package_app_info_for_uid */
2487 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2489 _LOGD("package app info for uid DB initialization failed\n");
2494 /* TODO: refactor this code */
2495 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2497 _LOGD("package cert info DB initialization failed\n");
2500 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2502 _LOGD("package cert index info DB initialization failed\n");
2505 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2507 _LOGD("package cert info DB initialization failed\n");
2510 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2512 _LOGD("package cert index info DB initialization failed\n");
2515 for (i = 0; columns[i] != NULL; i++) {
2516 snprintf(query, sizeof(query),
2517 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2518 columns[i], columns[i], columns[i]);
2519 ret = __initialize_db(pkgmgr_cert_db, query);
2521 _LOGD("package cert index info DB initialization failed\n");
2526 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2527 _LOGD("Failed to change cert db permission\n");
2529 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2530 _LOGD("Failed to change parser db permission\n");
2536 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2539 char pwuid_buf[1024];
2540 char journal_file[BUFSIZE];
2543 struct passwd userinfo, *result = NULL;
2544 files[0] = (char *)db_file;
2545 files[1] = journal_file;
2549 if (db_file == NULL)
2552 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2554 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2555 if (uid == OWNER_ROOT)
2557 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2558 if (ret != 0 || result == NULL) {
2559 _LOGE("FAIL: user %d doesn't exist", uid);
2562 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2564 for (i = 0; files[i]; i++) {
2565 ret = chown(files[i], uid, userinfo.pw_gid);
2567 if (strerror_r(errno, buf, sizeof(buf)))
2568 strncpy(buf, "", BUFSIZE - 1);
2569 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2570 userinfo.pw_gid, buf);
2574 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2575 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2577 ret = chmod(files[i], mode);
2579 if (strerror_r(errno, buf, sizeof(buf)))
2580 strncpy(buf, "", BUFSIZE - 1);
2581 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2584 SET_SMACK_LABEL(files[i]);
2589 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2593 if (getuid() != OWNER_ROOT) {
2594 _LOGE("Only root user is allowed");
2598 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2599 _LOGE("Manifest db for user %d is already exists", uid);
2603 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2604 _LOGE("Cert db for user %d is already exists", uid);
2608 ret = pkgmgr_parser_check_and_create_db(uid);
2611 ret = pkgmgr_parser_initialize_db(uid);
2613 pkgmgr_parser_close_db();
2616 pkgmgr_parser_close_db();
2621 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2625 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2627 _LOGD("Manifest DB creation Failed\n");
2632 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2634 _LOGD("Cert DB creation Failed\n");
2640 void pkgmgr_parser_close_db(void)
2642 sqlite3_close(pkgmgr_parser_db);
2643 sqlite3_close(pkgmgr_cert_db);
2647 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2649 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2651 _LOGD("manifest pointer is NULL\n");
2655 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2657 _LOGD("Failed to open DB\n");
2660 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2663 /*Begin transaction*/
2664 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2665 if (ret != SQLITE_OK) {
2666 _LOGD("Failed to begin transaction\n");
2670 _LOGD("Transaction Begin\n");
2671 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2673 _LOGD("Insert into DB failed. Rollback now\n");
2674 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2677 /*Commit transaction*/
2678 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2679 if (ret != SQLITE_OK) {
2680 _LOGD("Failed to commit transaction. Rollback now\n");
2681 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2685 _LOGD("Transaction Commit and End\n");
2687 pkgmgr_parser_close_db();
2691 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2693 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2695 _LOGD("manifest pointer is NULL\n");
2699 ret = pkgmgr_parser_check_and_create_db(uid);
2701 _LOGD("Failed to open DB\n");
2704 ret = pkgmgr_parser_initialize_db(uid);
2707 /*Begin transaction*/
2708 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2709 if (ret != SQLITE_OK) {
2710 _LOGD("Failed to begin transaction\n");
2714 _LOGD("Transaction Begin\n");
2715 ret = __insert_manifest_info_in_db(mfx, uid);
2717 _LOGD("Insert into DB failed. Rollback now\n");
2718 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2721 /*Commit transaction*/
2722 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2723 if (ret != SQLITE_OK) {
2724 _LOGD("Failed to commit transaction. Rollback now\n");
2725 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2729 _LOGD("Transaction Commit and End\n");
2731 pkgmgr_parser_close_db();
2735 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2738 _LOGD("manifest pointer is NULL\n");
2742 ret = pkgmgr_parser_check_and_create_db(uid);
2744 _LOGD("Failed to open DB\n");
2747 ret = pkgmgr_parser_initialize_db(uid);
2750 /*Preserve guest mode visibility*/
2751 __preserve_guestmode_visibility_value( mfx);
2752 /*Begin transaction*/
2753 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2754 if (ret != SQLITE_OK) {
2755 _LOGD("Failed to begin transaction\n");
2759 _LOGD("Transaction Begin\n");
2760 ret = __delete_manifest_info_from_db(mfx, uid);
2762 _LOGD("Delete from DB failed. Rollback now\n");
2763 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2766 ret = __insert_manifest_info_in_db(mfx, uid);
2768 _LOGD("Insert into DB failed. Rollback now\n");
2769 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2773 /*Commit transaction*/
2774 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2775 if (ret != SQLITE_OK) {
2776 _LOGD("Failed to commit transaction. Rollback now\n");
2777 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2781 _LOGD("Transaction Commit and End\n");
2783 pkgmgr_parser_close_db();
2787 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2789 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2792 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2795 _LOGD("manifest pointer is NULL\n");
2799 ret = pkgmgr_parser_check_and_create_db(uid);
2801 _LOGD("Failed to open DB\n");
2804 /*Begin transaction*/
2805 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2806 if (ret != SQLITE_OK) {
2807 _LOGD("Failed to begin transaction\n");
2811 _LOGD("Transaction Begin\n");
2812 ret = __delete_manifest_info_from_db(mfx, uid);
2814 _LOGD("Delete from DB failed. Rollback now\n");
2815 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2818 /*Commit transaction*/
2819 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2820 if (ret != SQLITE_OK) {
2821 _LOGD("Failed to commit transaction, Rollback now\n");
2822 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2826 _LOGD("Transaction Commit and End\n");
2828 pkgmgr_parser_close_db();
2832 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2834 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2837 API int pkgmgr_parser_update_preload_info_in_db()
2840 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
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 = __update_preload_condition_in_db();
2855 _LOGD("__update_preload_condition_in_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_update_preload_info_in_usr_db(uid_t uid)
2876 ret = pkgmgr_parser_check_and_create_db(uid);
2878 _LOGD("Failed to open DB\n");
2881 /*Begin transaction*/
2882 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2883 if (ret != SQLITE_OK) {
2884 _LOGD("Failed to begin transaction\n");
2888 _LOGD("Transaction Begin\n");
2889 ret = __update_preload_condition_in_db();
2891 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2892 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2895 /*Commit transaction*/
2896 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2897 if (ret != SQLITE_OK) {
2898 _LOGD("Failed to commit transaction, Rollback now\n");
2899 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2903 _LOGD("Transaction Commit and End\n");
2905 pkgmgr_parser_close_db();
2909 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2913 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2915 _LOGD("Failed to open DB\n");
2919 /*Begin transaction*/
2920 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2921 if (ret != SQLITE_OK) {
2922 _LOGD("Failed to begin transaction\n");
2926 _LOGD("Transaction Begin\n");
2928 ret = __disable_global_app_for_user(appid, uid);
2930 ret = __enable_global_app_for_user(appid, uid);
2932 _LOGD("__update_global_app_disable_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();
2951 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2953 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2956 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2960 ret = pkgmgr_parser_check_and_create_db(uid);
2962 _LOGD("Failed to open DB\n");
2966 /*Begin transaction*/
2967 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2968 if (ret != SQLITE_OK) {
2969 _LOGD("Failed to begin transaction\n");
2973 _LOGD("Transaction Begin\n");
2975 ret = __disable_app(appid);
2977 ret = __enable_app(appid);
2979 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2980 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2983 /*Commit transaction*/
2984 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2985 if (ret != SQLITE_OK) {
2986 _LOGD("Failed to commit transaction, Rollback now\n");
2987 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2991 _LOGD("Transaction Commit and End\n");
2993 pkgmgr_parser_close_db();
2998 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3002 if (appid == NULL) {
3003 _LOGD("Invalid parameter");
3007 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3009 _LOGD("Failed to open DB\n");
3013 /* Begin transaction */
3014 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3015 if (ret != SQLITE_OK) {
3016 _LOGD("Failed to begin transaction\n");
3020 _LOGD("Transaction Begin\n");
3022 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3024 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3025 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3028 /* Commit transaction */
3029 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3030 if (ret != SQLITE_OK) {
3031 _LOGD("Failed to commit transaction, Rollback now\n");
3032 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3036 _LOGD("Transaction Commit and End\n");
3038 pkgmgr_parser_close_db();
3042 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3044 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3047 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3051 if (appid == NULL) {
3052 _LOGD("Invalid parameter");
3056 ret = pkgmgr_parser_check_and_create_db(uid);
3058 _LOGD("Failed to open DB");
3062 /* Begin transaction */
3063 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN_EXCLUSIVE", NULL, NULL, NULL);
3064 if (ret != SQLITE_OK) {
3065 _LOGD("Failed to begin transaction");
3069 _LOGD("Transaction Begin");
3072 ret = __enable_app_splash_screen(appid);
3074 ret = __disable_app_splash_screen(appid);
3076 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3077 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3080 /* Commit transaction */
3081 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3082 if (ret != SQLITE_OK) {
3083 _LOGD("Failed to commit transaction, Rollback now");
3084 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3088 _LOGD("Transaction Commit and End");
3091 pkgmgr_parser_close_db();