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_disabled TEXT NOT NULL DEFAULT 'false', " \
332 "PRIMARY KEY(app_id, uid))"
334 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
335 "create table if not exists package_app_splash_screen " \
336 "(app_id text not null, " \
337 "src text not null, " \
338 "type text not null, " \
339 "orientation text not null, " \
340 "indicatordisplay text, " \
342 "PRIMARY KEY(app_id, orientation, operation) " \
343 "FOREIGN KEY(app_id) " \
344 "REFERENCES package_app_info(app_id) " \
347 static int __insert_application_info(manifest_x *mfx);
348 static int __insert_application_appcategory_info(manifest_x *mfx);
349 static int __insert_application_appcontrol_info(manifest_x *mfx);
350 static int __insert_application_appmetadata_info(manifest_x *mfx);
351 static int __insert_application_share_allowed_info(manifest_x *mfx);
352 static int __insert_application_share_request_info(manifest_x *mfx);
353 static int __insert_application_datacontrol_info(manifest_x *mfx);
354 static void __insert_application_locale_info(gpointer data, gpointer userdata);
355 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
356 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
357 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
358 static int __delete_subpkg_info_from_db(char *appid);
359 static int __delete_appinfo_from_db(char *db_table, const char *appid);
360 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
361 static int __exec_query(char *query);
362 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
363 char **label, char **license, char **icon, char **description, char **author);
364 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
365 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
366 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
367 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
368 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
369 static int __parserdb_change_perm(const char *db_file, uid_t uid);
371 #define REGULAR_USER 5000
372 static inline uid_t _getuid(void)
374 uid_t uid = getuid();
376 if (uid < REGULAR_USER)
377 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
382 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
385 __delete_subpkg_info_from_db(coltxt[0]);
390 static const char *__get_str(const char *str)
394 return PKGMGR_PARSER_EMPTY_STR;
400 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
405 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
406 if (ret != SQLITE_OK) {
407 _LOGD("connect db [%s] failed!\n", db_path);
415 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
417 manifest_x *mfx = (manifest_x *)data;
423 if (mfx->application == NULL)
425 app = (application_x *)mfx->application->data;
426 for(i = 0; i < ncols; i++)
428 if (strcmp(colname[i], "app_id") == 0) {
430 appid = strdup(coltxt[i]);
431 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
433 status = strdup(coltxt[i]);
439 _LOGD("app id is NULL\n");
442 /*update guest mode visibility*/
443 for (tmp = mfx->application; tmp; tmp = tmp->next) {
444 app = (application_x *)tmp->data;
447 if (strcmp(app->appid, appid) == 0) {
448 free((void *)app->guestmode_visibility);
449 app->guestmode_visibility = strdup(status);
465 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
467 char *error_message = NULL;
468 char query[MAX_QUERY_LEN] = {'\0'};
469 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
471 sqlite3_exec(pkgmgr_parser_db, query,
472 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
473 _LOGD("Don't execute query = %s error message = %s\n",
474 query, error_message);
475 sqlite3_free(error_message);
480 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
482 char *error_message = NULL;
484 sqlite3_exec(db_handle, db_query,
485 NULL, NULL, &error_message)) {
486 _LOGD("Don't execute query = %s error message = %s\n",
487 db_query, error_message);
488 sqlite3_free(error_message);
491 sqlite3_free(error_message);
495 static int __exec_query(char *query)
497 char *error_message = NULL;
499 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
500 _LOGE("Don't execute query = %s error message = %s\n", query,
502 sqlite3_free(error_message);
505 sqlite3_free(error_message);
509 static int __exec_query_no_msg(char *query)
511 char *error_message = NULL;
513 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
514 sqlite3_free(error_message);
517 sqlite3_free(error_message);
521 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
529 for (tmp = lbls; tmp; tmp = tmp->next) {
530 lbl = (label_x *)tmp->data;
534 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
536 for (tmp = lcns; tmp; tmp = tmp->next) {
537 lcn = (license_x *)tmp->data;
541 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
543 for (tmp = icns; tmp; tmp = tmp->next) {
544 icn = (icon_x *)tmp->data;
548 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
550 for (tmp = dcns; tmp; tmp = tmp->next) {
551 dcn = (description_x *)tmp->data;
555 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
557 for (tmp = aths; tmp; tmp = tmp->next) {
558 ath = (author_x *)tmp->data;
562 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
568 static GList *__create_icon_list(GList *appicon, GList *icns)
573 for (tmp = icns; tmp; tmp = tmp->next) {
574 icn = (icon_x *)tmp->data;
578 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
583 static GList *__create_image_list(GList *appimage, GList *imgs)
588 for (tmp = imgs; tmp; tmp = tmp->next) {
589 img = (image_x *)tmp->data;
593 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
598 static void __trimfunc(GList* trim_list)
600 char *trim_data = NULL;
604 list = g_list_first(trim_list);
607 trim_data = (char *)list->data;
610 if (strcmp(trim_data, prev) == 0) {
611 trim_list = g_list_remove(trim_list, trim_data);
612 list = g_list_first(trim_list);
621 list = g_list_next(list);
625 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
627 if (a == NULL || b == NULL)
629 if (strcmp((char*)a, (char*)b) == 0)
631 if (strcmp((char*)a, (char*)b) < 0)
633 if (strcmp((char*)a, (char*)b) > 0)
638 static int __check_dpi(const char *dpi_char, int dpi_int)
640 if (dpi_char == NULL)
643 if (strcasecmp(dpi_char, LDPI) == 0) {
644 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
648 } else if (strcasecmp(dpi_char, MDPI) == 0) {
649 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
653 } else if (strcasecmp(dpi_char, HDPI) == 0) {
654 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
658 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
659 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
663 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
664 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
672 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
675 char *icon_filename = NULL;
676 char modified_iconpath[BUFSIZE] = { '\0' };
677 char icon_path[BUFSIZE] = { '\0' };
681 if (orig_icon_path == NULL)
684 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
688 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
689 dpi_path[0] = "LDPI";
690 dpi_path[1] = "ldpi";
691 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
692 dpi_path[0] = "MDPI";
693 dpi_path[1] = "mdpi";
694 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
695 dpi_path[0] = "HDPI";
696 dpi_path[1] = "hdpi";
697 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
698 dpi_path[0] = "XHDPI";
699 dpi_path[1] = "xhdpi";
700 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
701 dpi_path[0] = "XXHDPI";
702 dpi_path[1] = "xxhdpi";
704 _LOGE("Unidentified dpi[%d]", dpi);
708 icon_filename = strrchr(orig_icon_path, '/');
709 if (icon_filename == NULL)
712 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
713 for (i = 0; i < 2; i++) {
714 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
715 if (access(modified_iconpath, F_OK) != -1) {
716 // if exists, return modified icon path
717 *new_icon_path = strdup(modified_iconpath);
725 static gint __compare_icon(gconstpointer a, gconstpointer b)
727 icon_x *icon = (icon_x *)a;
729 char *icon_folder_path = NULL;
731 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
734 if (icon->dpi != NULL)
737 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
739 icon->text = icon_folder_path;
745 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
747 icon_x *icon = (icon_x *)a;
748 int dpi = GPOINTER_TO_INT(b);
750 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
753 if (icon->dpi == NULL)
756 if (__check_dpi(icon->dpi, dpi) == 0)
762 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
764 icon_x *icon = (icon_x *)a;
765 char *lang = (char *)b;
766 char *icon_folder_path = NULL;
768 if (icon->dpi != NULL)
771 if (strcasecmp(icon->lang, lang) == 0) {
772 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
773 //icon for no locale. check existance of folder-hierachied default icons
774 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
776 icon->text = icon_folder_path;
785 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
787 icon_x *icon = (icon_x *)a;
788 char *lang = (char *)b;
791 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
795 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
801 static char *__find_icon(GList *icons, const char *lang)
807 // first, find icon whose locale and dpi with given lang and system's dpi has matched
808 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
810 icon = (icon_x *)tmp->data;
811 return (char *)icon->text;
814 // if first has failed, find icon whose locale has matched
815 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
817 icon = (icon_x *)tmp->data;
818 return (char *)icon->text;
821 // if second has failed, find icon whose dpi has matched with system's dpi
822 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
825 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
827 icon = (icon_x *)tmp->data;
828 return (char *)icon->text;
831 // last, find default icon marked as "No Locale"
832 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
834 icon = (icon_x *)tmp->data;
835 return (char *)icon->text;
841 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
842 char **label, char **license, char **icon, char **description, char **author)
849 for (tmp = lbls; tmp; tmp = tmp->next) {
850 lbl = (label_x *)tmp->data;
854 if (strcmp(lbl->lang, (char *)data) == 0) {
855 *label = (char*)lbl->text;
860 for (tmp = lcns; tmp; tmp = tmp->next) {
861 lcn = (license_x *)tmp->data;
865 if (strcmp(lcn->lang, (char *)data) == 0) {
866 *license = (char*)lcn->text;
872 *icon = __find_icon(icns, (char *)data);
874 for (tmp = dcns; tmp; tmp = tmp->next) {
875 dcn = (description_x *)tmp->data;
879 if (strcmp(dcn->lang, (char *)data) == 0) {
880 *description = (char*)dcn->text;
885 for (tmp = aths; tmp; tmp = tmp->next) {
886 ath = (author_x *)tmp->data;
890 if (strcmp(ath->lang, (char *)data) == 0) {
891 *author = (char*)ath->text;
899 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
903 for (tmp = icns; tmp; tmp = tmp->next) {
904 icn = (icon_x *)tmp->data;
908 if (strcmp(icn->section, (char *)data) == 0) {
909 *icon = (char*)icn->text;
910 *resolution = (char*)icn->resolution;
917 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
921 for (tmp = imgs; tmp; tmp = tmp->next) {
922 img = (image_x *)tmp->data;
926 if (strcmp(img->section, (char *)data) == 0) {
927 *lang = (char*)img->lang;
928 *image = (char*)img->text;
935 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
940 char *description = NULL;
941 char *license = NULL;
945 manifest_x *mfx = (manifest_x *)userdata;
946 GList *lbl = mfx->label;
947 GList *lcn = mfx->license;
948 GList *icn = mfx->icon;
949 GList *dcn = mfx->description;
950 GList *ath = mfx->author;
952 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
953 if (!label && !description && !icon && !license && !author)
956 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
957 "package_label, package_icon, package_description, package_license, package_author) values " \
958 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
963 __get_str(description),
967 ret = __exec_query(query);
969 _LOGD("Package Localized Info DB Insert failed\n");
974 static void __insert_application_locale_info(gpointer data, gpointer userdata)
981 application_x *app = (application_x*)userdata;
982 GList *lbl = app->label;
983 GList *icn = app->icon;
985 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
989 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
990 "app_label, app_icon) values " \
991 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
992 __get_str(label), __get_str(icon));
993 ret = __exec_query(query);
995 _LOGD("Package UiApp Localized Info DB Insert failed\n");
999 /*insert ui app locale info to pkg locale to get mainapp data */
1000 if (strcasecmp(app->mainapp, "true")==0) {
1001 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
1002 "package_label, package_icon, package_description, package_license, package_author) values " \
1003 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1008 PKGMGR_PARSER_EMPTY_STR,
1009 PKGMGR_PARSER_EMPTY_STR,
1010 PKGMGR_PARSER_EMPTY_STR);
1012 ret = __exec_query_no_msg(query);
1013 sqlite3_free(query);
1016 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1017 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1018 ret = __exec_query_no_msg(query);
1019 sqlite3_free(query);
1024 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1028 char *resolution = NULL;
1029 char query[MAX_QUERY_LEN] = {'\0'};
1031 application_x *app = (application_x*)userdata;
1032 GList *icn = app->icon;
1034 __extract_icon_data(data, icn, &icon, &resolution);
1035 if (!icon && !resolution)
1037 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1038 "app_icon, app_icon_section, app_icon_resolution) values " \
1039 "('%q', '%q', '%q', '%q')", app->appid,
1040 icon, (char*)data, resolution);
1042 ret = __exec_query(query);
1044 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1048 static void __insert_application_image_info(gpointer data, gpointer userdata)
1053 char query[MAX_QUERY_LEN] = {'\0'};
1055 application_x *app = (application_x*)userdata;
1056 GList *image = app->image;
1058 __extract_image_data(data, image, &lang, &img);
1061 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1062 "app_image_section, app_image) values " \
1063 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1065 ret = __exec_query(query);
1067 _LOGD("Package UiApp image Info DB Insert failed\n");
1072 static int __insert_mainapp_info(manifest_x *mfx)
1077 char query[MAX_QUERY_LEN] = {'\0'};
1078 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1079 app = (application_x *)tmp->data;
1082 snprintf(query, MAX_QUERY_LEN,
1083 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1085 ret = __exec_query(query);
1087 _LOGD("Package App Info DB Insert Failed\n");
1090 if (strcasecmp(app->mainapp, "True")==0)
1091 mfx->mainapp_id = strdup(app->appid);
1094 if (mfx->mainapp_id == NULL) {
1095 if (mfx->application == NULL)
1097 app = (application_x *)mfx->application->data;
1101 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1103 _LOGD("Not valid appid\n");
1107 ret = __exec_query(query);
1109 _LOGD("Package UiApp Info DB Insert Failed\n");
1113 free((void *)app->mainapp);
1114 app->mainapp= strdup("true");
1115 mfx->mainapp_id = strdup(app->appid);
1118 memset(query, '\0', MAX_QUERY_LEN);
1119 snprintf(query, MAX_QUERY_LEN,
1120 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1121 ret = __exec_query(query);
1123 _LOGD("Package Info DB update Failed\n");
1130 static int __convert_background_category(GList *category_list)
1133 GList *tmp_list = category_list;
1134 char *category_data = NULL;
1136 if (category_list == NULL)
1139 while (tmp_list != NULL) {
1140 category_data = (char *)tmp_list->data;
1141 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1142 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1143 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1144 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1145 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1146 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1147 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1148 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1149 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1150 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1151 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1152 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1153 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1154 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1156 _LOGE("Unidentified category [%s]", category_data);
1158 tmp_list = g_list_next(tmp_list);
1164 static const char *__find_effective_appid(GList *metadata_list)
1169 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1170 md = (metadata_x *)tmp_list->data;
1171 if (md == NULL || md->key == NULL)
1174 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1183 /* _PRODUCT_LAUNCHING_ENHANCED_
1184 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1186 static int __insert_application_info(manifest_x *mfx)
1191 int background_value = 0;
1192 char query[MAX_QUERY_LEN] = {'\0'};
1194 const char *effective_appid;
1197 type = strdup(mfx->type);
1199 type = strdup("tpk");
1201 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1202 app = (application_x *)tmp->data;
1206 background_value = __convert_background_category(app->background_category);
1207 if (background_value < 0) {
1208 _LOGE("Failed to retrieve background value[%d]", background_value);
1209 background_value = 0;
1212 effective_appid = __find_effective_appid(app->metadata);
1214 snprintf(query, MAX_QUERY_LEN,
1215 "insert into package_app_info(" \
1216 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1217 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1218 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1219 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1220 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1221 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1222 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1223 "app_effective_appid, app_splash_screen_display) " \
1225 "'%s', '%s', '%s', '%s', '%s', " \
1226 "'%s', '%s', '%s', '%s', '%s', " \
1227 "'%s', '%s', '%s', '%s', '%s', " \
1228 "'%s', '%s', '%s', '%s', '%s', " \
1229 "'%s', '%s', '%s', '%s', '%s', " \
1230 "'%s', '%s', '%s', '%s', '%s', " \
1231 "'%s', '%d', '%s', '%s', '%s', " \
1233 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1234 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1235 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1236 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1237 app->guestmode_visibility, app->permission_type,
1238 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1239 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1240 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1241 __get_str(effective_appid), app->splash_screen_display);
1243 ret = __exec_query(query);
1245 _LOGD("Package UiApp Info DB Insert Failed\n");
1250 memset(query, '\0', MAX_QUERY_LEN);
1259 static int __insert_application_appcategory_info(manifest_x *mfx)
1266 char query[MAX_QUERY_LEN] = {'\0'};
1267 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1268 app = (application_x *)app_tmp->data;
1271 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1272 ct = (const char *)ct_tmp->data;
1275 snprintf(query, MAX_QUERY_LEN,
1276 "insert into package_app_app_category(app_id, category) " \
1277 "values('%s','%s')",\
1279 ret = __exec_query(query);
1281 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1284 memset(query, '\0', MAX_QUERY_LEN);
1290 static int __insert_application_appmetadata_info(manifest_x *mfx)
1297 char query[MAX_QUERY_LEN] = {'\0'};
1298 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1299 app = (application_x *)app_tmp->data;
1302 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1303 md = (metadata_x *)md_tmp->data;
1307 snprintf(query, MAX_QUERY_LEN,
1308 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1309 "values('%s','%s', '%s')",\
1310 app->appid, md->key, md->value ? md->value : "");
1311 ret = __exec_query(query);
1313 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1317 memset(query, '\0', MAX_QUERY_LEN);
1323 static int __insert_application_apppermission_info(manifest_x *mfx)
1330 char query[MAX_QUERY_LEN] = {'\0'};
1331 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1332 app = (application_x *)app_tmp->data;
1335 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1336 pm = (permission_x *)pm_tmp->data;
1339 snprintf(query, MAX_QUERY_LEN,
1340 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1341 "values('%s','%s', '%s')",\
1342 app->appid, pm->type, pm->value);
1343 ret = __exec_query(query);
1345 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1348 memset(query, '\0', MAX_QUERY_LEN);
1354 static int __insert_application_appcontrol_info(manifest_x *mfx)
1358 GList *acontrol_tmp;
1359 appcontrol_x *acontrol;
1361 char query[MAX_QUERY_LEN] = {'\0'};
1362 char buf[BUFSIZE] = {'\0'};
1363 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1364 app = (application_x *)app_tmp->data;
1367 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1368 acontrol = (appcontrol_x *)acontrol_tmp->data;
1369 if (acontrol == NULL)
1371 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1372 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1373 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1374 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1375 snprintf(query, MAX_QUERY_LEN,
1376 "insert into package_app_app_control(app_id, app_control) " \
1377 "values('%s', '%s')",\
1379 ret = __exec_query(query);
1381 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1384 memset(query, '\0', MAX_QUERY_LEN);
1390 static int __insert_application_datacontrol_info(manifest_x *mfx)
1397 char query[MAX_QUERY_LEN] = {'\0'};
1399 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1400 app = (application_x *)app_tmp->data;
1403 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1404 dc = (datacontrol_x *)dc_tmp->data;
1407 snprintf(query, MAX_QUERY_LEN,
1408 "insert into package_app_data_control(app_id, providerid, access, type) " \
1409 "values('%s', '%s', '%s', '%s')",\
1415 ret = __exec_query(query);
1417 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1420 memset(query, '\0', MAX_QUERY_LEN);
1426 static int __insert_application_share_request_info(manifest_x *mfx)
1435 char query[MAX_QUERY_LEN] = {'\0'};
1436 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1437 app = (application_x *)app_tmp->data;
1440 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1441 ds = (datashare_x *)ds_tmp->data;
1444 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1445 rq = (const char *)rq_tmp->data;
1448 snprintf(query, MAX_QUERY_LEN,
1449 "insert into package_app_share_request(app_id, data_share_request) " \
1450 "values('%s', '%s')",\
1452 ret = __exec_query(query);
1454 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1457 memset(query, '\0', MAX_QUERY_LEN);
1464 static int __insert_application_share_allowed_info(manifest_x *mfx)
1475 char query[MAX_QUERY_LEN] = {'\0'};
1476 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1477 app = (application_x *)app_tmp->data;
1480 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1481 ds = (datashare_x *)ds_tmp->data;
1484 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1485 df = (define_x *)df_tmp->data;
1488 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1489 al = (const char *)al_tmp->data;
1492 snprintf(query, MAX_QUERY_LEN,
1493 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1494 "values('%s', '%s', '%s')",\
1495 app->appid, df->path, al);
1496 ret = __exec_query(query);
1498 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1501 memset(query, '\0', MAX_QUERY_LEN);
1509 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1511 splashscreen_x *ss = (splashscreen_x *)a;
1512 const char *orientation = (const char *)b;
1515 if (ss->operation || ss->dpi == NULL)
1518 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1522 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1528 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1530 splashscreen_x *ss = (splashscreen_x *)a;
1531 const char *orientation = (const char *)b;
1533 if (ss->operation || ss->dpi)
1536 if (strcasecmp(ss->orientation, orientation) == 0)
1542 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1543 const char *orientation)
1547 tmp = g_list_find_custom(splashscreens, orientation,
1548 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1550 return (splashscreen_x *)tmp->data;
1552 tmp = g_list_find_custom(splashscreens, orientation,
1553 (GCompareFunc)__compare_splashscreen_with_orientation);
1555 return (splashscreen_x *)tmp->data;
1560 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1562 splashscreen_x *ss = (splashscreen_x *)data;
1563 GList **list = (GList **)user_data;
1566 if (ss->operation == NULL || ss->dpi == NULL)
1569 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1573 if (__check_dpi(ss->dpi, dpi) != 0)
1576 *list = g_list_append(*list, ss);
1579 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1581 splashscreen_x *ss = (splashscreen_x *)data;
1582 GList **list = (GList **)user_data;
1583 splashscreen_x *ss_tmp;
1586 if (ss->operation == NULL || ss->dpi)
1589 for (tmp = *list; tmp; tmp = tmp->next) {
1590 ss_tmp = (splashscreen_x *)tmp->data;
1591 if (ss_tmp->operation
1592 && strcmp(ss_tmp->operation, ss->operation) == 0
1593 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1597 *list = g_list_append(*list, ss);
1600 static GList *__find_splashscreens(GList *splashscreens)
1605 g_list_foreach(splashscreens,
1606 __find_appcontrol_splashscreen_with_dpi, &list);
1607 g_list_foreach(splashscreens,
1608 __find_appcontrol_splashscreen, &list);
1610 ss = __find_default_splashscreen(splashscreens, "portrait");
1612 list = g_list_append(list, ss);
1613 ss = __find_default_splashscreen(splashscreens, "landscape");
1615 list = g_list_append(list, ss);
1620 static int __insert_application_splashscreen_info(manifest_x *mfx)
1628 char query[MAX_QUERY_LEN];
1630 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1631 app = (application_x *)app_tmp->data;
1632 if (app == NULL || app->splashscreens == NULL)
1635 ss_tmp = __find_splashscreens(app->splashscreens);
1639 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1640 ss = (splashscreen_x *)tmp->data;
1641 snprintf(query, sizeof(query),
1642 "insert into package_app_splash_screen" \
1643 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1644 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1645 app->appid, ss->src, ss->type, ss->orientation,
1646 ss->indicatordisplay, __get_str(ss->operation));
1647 ret = __exec_query(query);
1649 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1652 memset(query, '\0', MAX_QUERY_LEN);
1654 g_list_free(ss_tmp);
1659 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1664 char query[MAX_QUERY_LEN];
1666 const char *image_type;
1667 const char *indicatordisplay;
1668 const char *orientation;
1669 const char *operation = NULL;
1671 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1672 app = (application_x *)app_tmp->data;
1674 (app->portraitimg == NULL && app->landscapeimg == NULL))
1676 image_type = "img"; /* default */
1677 if (app->effectimage_type) {
1678 tmp = strstr(app->effectimage_type, "edj");
1682 indicatordisplay = "true"; /* default */
1683 if (app->indicatordisplay)
1684 indicatordisplay = app->indicatordisplay;
1685 if (app->portraitimg) {
1686 orientation = "portrait";
1687 snprintf(query, sizeof(query),
1688 "insert into package_app_splash_screen" \
1689 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1690 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1691 app->appid, app->portraitimg, image_type,
1692 orientation, indicatordisplay, __get_str(operation));
1693 ret = __exec_query(query);
1695 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1698 memset(query, '\0', MAX_QUERY_LEN);
1700 if (app->landscapeimg) {
1701 orientation = "landscape";
1702 snprintf(query, sizeof(query),
1703 "insert into package_app_splash_screen" \
1704 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1705 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1706 app->appid, app->landscapeimg, image_type,
1707 orientation, indicatordisplay, __get_str(operation));
1708 ret = __exec_query(query);
1710 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1713 memset(query, '\0', MAX_QUERY_LEN);
1719 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1726 char query[MAX_QUERY_LEN];
1728 char *tmpptr = NULL;
1729 const char *operation;
1730 const char *portraitimg;
1731 const char *landscapeimg;
1732 const char *indicatordisplay;
1733 const char *orientation;
1734 const char *image_type;
1736 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1737 app = (application_x *)app_tmp->data;
1741 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1742 md = (metadata_x *)md_tmp->data;
1743 if (md == NULL || md->key == NULL || md->value == NULL)
1746 if (strcasestr(md->key, "operation_effect=")) {
1747 operation = index(md->key, '=');
1748 if ((operation + 1) != NULL)
1752 } else if (strcasestr(md->key, "launch_effect")) {
1759 landscapeimg = NULL;
1760 indicatordisplay = "true"; /* default */
1761 token = strtok_r(md->value, "|", &tmpptr);
1762 while (token != NULL) {
1763 if (strcasestr(token, "portrait-effectimage=")) {
1764 portraitimg = index(token, '=');
1765 if ((portraitimg + 1) != NULL)
1769 } else if (strcasestr(token, "landscape-effectimage=")) {
1770 landscapeimg = index(token, '=');
1771 if ((landscapeimg + 1) != NULL)
1774 landscapeimg = NULL;
1775 } else if (strcasestr(token, "indicatordisplay=")) {
1776 indicatordisplay = index(token, '=');
1777 if ((indicatordisplay + 1) != NULL)
1780 indicatordisplay = "true";
1783 token = strtok_r(NULL, "|", &tmpptr);
1787 orientation = "portrait";
1789 if (strcasestr(portraitimg, "edj"))
1791 snprintf(query, sizeof(query),
1792 "insert into package_app_splash_screen" \
1793 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1794 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1795 app->appid, portraitimg, image_type,
1796 orientation, indicatordisplay, __get_str(operation));
1797 ret = __exec_query(query);
1799 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1802 memset(query, '\0', MAX_QUERY_LEN);
1805 orientation = "landscape";
1807 if (strcasestr(landscapeimg, "edj"))
1809 snprintf(query, sizeof(query),
1810 "insert into package_app_splash_screen" \
1811 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1812 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1813 app->appid, landscapeimg, image_type,
1814 orientation, indicatordisplay, __get_str(operation));
1815 ret = __exec_query(query);
1817 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1820 memset(query, '\0', MAX_QUERY_LEN);
1828 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1832 const char *pv = NULL;
1833 char query[MAX_QUERY_LEN] = { '\0' };
1836 const char *auth_name = NULL;
1837 const char *auth_email = NULL;
1838 const char *auth_href = NULL;
1840 GList *pkglocale = NULL;
1841 GList *applocale = NULL;
1842 GList *appicon = NULL;
1843 GList *appimage = NULL;
1845 if (mfx->author && mfx->author->data) {
1846 author = (author_x *)mfx->author->data;
1848 auth_name = author->text;
1850 auth_email = author->email;
1852 auth_href = author->href;
1855 /*Insert in the package_cert_info CERT_DB*/
1856 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1857 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1858 if (ret != PMINFO_R_OK) {
1859 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1860 _LOGE("Cert Info DB create handle failed\n");
1863 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1864 if (ret != PMINFO_R_OK) {
1865 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1866 _LOGE("Cert Info DB Insert Failed\n");
1870 /*Insert in the package_info DB*/
1871 snprintf(query, MAX_QUERY_LEN,
1872 "insert into package_info(" \
1873 "package, package_type, package_version, package_api_version, package_tep_name, " \
1874 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1875 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1876 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1877 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1879 "'%s', '%s', '%s', '%s', '%s', " \
1880 "'%s', '%s', '%s', '%s', '%s', " \
1881 "'%s', '%s', '%s', '%s', '%s', " \
1882 "'%s', '%s', '%s', '%s', '%s', " \
1883 "'%s', '%s', '%s', '%s', '%s')", \
1884 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1885 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1886 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1887 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1888 __get_str(mfx->storeclient_id),
1889 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1891 ret = __exec_query(query);
1893 _LOGD("Package Info DB Insert Failed\n");
1897 /*Insert in the package_privilege_info DB*/
1898 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1899 pv = (const char *)tmp->data;
1902 memset(query, '\0', MAX_QUERY_LEN);
1903 snprintf(query, MAX_QUERY_LEN,
1904 "insert into package_privilege_info(package, privilege) " \
1905 "values('%s','%s')",\
1907 ret = __exec_query(query);
1909 _LOGD("Package Privilege Info DB Insert Failed\n");
1914 if (mfx->application != NULL) {
1915 ret = __insert_mainapp_info(mfx);
1920 /*Insert the package locale*/
1921 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1922 /*remove duplicated data in pkglocale*/
1923 __trimfunc(pkglocale);
1925 /*Insert the app locale, icon, image info */
1926 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1927 app = (application_x *)tmp->data;
1930 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1931 appicon = __create_icon_list(appicon, app->icon);
1932 appimage = __create_image_list(appimage, app->image);
1934 /*remove duplicated data in applocale*/
1935 __trimfunc(applocale);
1936 __trimfunc(appicon);
1937 __trimfunc(appimage);
1939 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1941 /*native app locale info*/
1942 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1943 app = (application_x *)tmp->data;
1946 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1947 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1948 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1951 g_list_free(pkglocale);
1953 g_list_free(applocale);
1955 g_list_free(appicon);
1957 g_list_free(appimage);
1960 /*Insert in the package_app_info DB*/
1961 ret = __insert_application_info(mfx);
1964 /*Insert in the package_app_app_control DB*/
1965 ret = __insert_application_appcontrol_info(mfx);
1969 /*Insert in the package_app_app_category DB*/
1970 ret = __insert_application_appcategory_info(mfx);
1974 /*Insert in the package_app_app_metadata DB*/
1975 ret = __insert_application_appmetadata_info(mfx);
1979 /*Insert in the package_app_app_permission DB*/
1980 ret = __insert_application_apppermission_info(mfx);
1984 /*Insert in the package_app_share_allowed DB*/
1985 ret = __insert_application_share_allowed_info(mfx);
1989 /*Insert in the package_app_share_request DB*/
1990 ret = __insert_application_share_request_info(mfx);
1994 /*Insert in the package_app_data_control DB*/
1995 ret = __insert_application_datacontrol_info(mfx);
1999 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2000 ret = __insert_application_legacy_splashscreen_info(mfx);
2004 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2005 ret = __insert_application_metadata_splashscreen_info(mfx);
2009 /*Insert in the package_app_splash_screen DB*/
2010 ret = __insert_application_splashscreen_info(mfx);
2018 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2020 char query[MAX_QUERY_LEN] = { '\0' };
2022 memset(query, '\0', MAX_QUERY_LEN);
2023 snprintf(query, MAX_QUERY_LEN,
2024 "delete from %s where app_id='%s'", db_table, appid);
2025 ret = __exec_query(query);
2027 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2033 static int __delete_subpkg_info_from_db(char *appid)
2037 ret = __delete_appinfo_from_db("package_app_info", appid);
2040 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2043 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2046 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2049 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2052 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2055 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2058 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2061 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2064 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2067 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2070 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2077 static int __delete_subpkg_from_db(manifest_x *mfx)
2079 char query[MAX_QUERY_LEN] = { '\0' };
2080 char *error_message = NULL;
2082 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2084 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2085 _LOGE("Don't execute query = %s error message = %s\n", query,
2087 sqlite3_free(error_message);
2090 sqlite3_free(error_message);
2095 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2097 char query[MAX_QUERY_LEN] = { '\0' };
2101 /*Delete from cert table*/
2102 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2104 _LOGD("Cert Info DB Delete Failed\n");
2108 /*Delete from Package Info DB*/
2109 snprintf(query, MAX_QUERY_LEN,
2110 "delete from package_info where package='%s'", mfx->package);
2111 ret = __exec_query(query);
2113 _LOGD("Package Info DB Delete Failed\n");
2116 memset(query, '\0', MAX_QUERY_LEN);
2118 /*Delete from Package Localized Info*/
2119 snprintf(query, MAX_QUERY_LEN,
2120 "delete from package_localized_info where package='%s'", mfx->package);
2121 ret = __exec_query(query);
2123 _LOGD("Package Localized Info DB Delete Failed\n");
2127 /*Delete from Package Privilege Info*/
2128 snprintf(query, MAX_QUERY_LEN,
2129 "delete from package_privilege_info where package='%s'", mfx->package);
2130 ret = __exec_query(query);
2132 _LOGD("Package Privilege Info DB Delete Failed\n");
2136 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2137 app = (application_x *)tmp->data;
2140 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2143 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2146 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2149 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2152 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2155 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2158 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2161 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2164 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2167 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2170 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2173 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2178 /* if main package has sub pkg, delete sub pkg data*/
2179 __delete_subpkg_from_db(mfx);
2184 static int __disable_app(const char *appid)
2187 char query[MAX_QUERY_LEN] = {'\0'};
2188 sqlite3_snprintf(MAX_QUERY_LEN, query,
2189 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2191 ret = __exec_query(query);
2193 _LOGD("Insert global app disable failed\n");
2198 static int __enable_app(const char *appid)
2201 char query[MAX_QUERY_LEN] = {'\0'};
2202 sqlite3_snprintf(MAX_QUERY_LEN, query,
2203 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2205 ret = __exec_query(query);
2207 _LOGD("Insert global app disable failed\n");
2212 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid,
2213 const char *except_col_name)
2216 char query[MAX_QUERY_LEN] = { '\0', };
2223 if (except_col_name == NULL) {
2224 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT COUNT(*) FROM " \
2225 "package_app_info_for_uid WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2226 } else if (strcmp(except_col_name, "is_disabled") == 0) {
2227 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT COUNT(*) FROM " \
2228 "package_app_info_for_uid WHERE app_id=%Q AND uid='%d' " \
2229 "AND is_splash_screen_disabled='false'", appid, (int)uid);
2230 } else if (strcmp(except_col_name, "is_splash_screen_disabled") == 0) {
2231 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT COUNT(*) FROM " \
2232 "package_app_info_for_uid WHERE app_id=%Q AND uid='%d' " \
2233 "AND is_disabled='false'", appid, (int)uid);
2236 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2237 if (ret != SQLITE_OK) {
2238 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2239 return PMINFO_R_ERROR;
2242 if (sqlite3_step(stmt) != SQLITE_ROW) {
2243 LOGE("failed to step");
2244 sqlite3_finalize(stmt);
2245 return PMINFO_R_ERROR;
2248 val = (const char *)sqlite3_column_text(stmt, 0);
2250 sqlite3_finalize(stmt);
2254 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2257 char query[MAX_QUERY_LEN] = { '\0', };
2259 ret = __check_appinfo_for_uid_table(appid, uid, NULL);
2262 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2265 } else if (ret == 0) {
2266 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2267 "package_app_info_for_uid(app_id, uid, is_disabled) " \
2268 "VALUES(%Q, '%d', 'true')", appid, (int)uid);
2270 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
2271 "package_app_info_for_uid SET is_disabled='true' " \
2272 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2275 ret = __exec_query(query);
2277 _LOGD("Add global app disable info failed\n");
2282 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2285 char query[MAX_QUERY_LEN] = {'\0'};
2287 ret = __check_appinfo_for_uid_table(appid, uid, "is_disabled");
2289 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2292 } else if (ret == 0) {
2293 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
2294 "package_app_info_for_uid SET is_disabled='false' " \
2295 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2297 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2298 "package_app_info_for_uid WHERE app_id=%Q AND uid='%d'",
2302 ret = __exec_query(query);
2304 _LOGD("Remove global app disable info failed\n");
2309 static int __disable_global_app_splash_screen_for_user(const char *appid, uid_t uid)
2312 char query[MAX_QUERY_LEN] = { '\0', };
2314 ret = __check_appinfo_for_uid_table(appid, uid, NULL);
2317 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2320 } else if (ret == 0) {
2321 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2322 "package_app_info_for_uid(app_id, uid, is_splash_screen_disabled) " \
2323 "VALUES(%Q, '%d', 'true')", appid, (int)uid);
2325 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
2326 "package_app_info_for_uid SET is_splash_screen_disabled='true' " \
2327 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2330 ret = __exec_query(query);
2332 _LOGD("Add global app splash screen info failed\n");
2337 static int __enable_global_app_splash_screen_for_user(const char *appid, uid_t uid)
2340 char query[MAX_QUERY_LEN] = {'\0'};
2342 ret = __check_appinfo_for_uid_table(appid, uid, "is_splash_screen_disabled");
2344 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2347 } else if (ret == 0) {
2348 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE " \
2349 "package_app_info_for_uid SET is_splash_screen_disabled='false' " \
2350 "WHERE app_id=%Q AND uid='%d'", appid, (int)uid);
2352 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2353 "package_app_info_for_uid WHERE app_id=%Q AND uid='%d'",
2357 ret = __exec_query(query);
2359 _LOGD("Remove global app splash screen info failed\n");
2364 static int __update_preload_condition_in_db()
2367 char query[MAX_QUERY_LEN] = {'\0'};
2369 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2371 ret = __exec_query(query);
2373 _LOGD("Package preload_condition update failed\n");
2378 API int pkgmgr_parser_initialize_db(uid_t uid)
2382 char query[MAX_QUERY_LEN];
2383 static const char *columns[] = {
2384 "author_root_cert", "author_im_cert", "author_signer_cert",
2385 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2386 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2390 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2392 _LOGD("package info DB initialization failed\n");
2395 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2397 _LOGD("package localized info DB initialization failed\n");
2400 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2402 _LOGD("package app app privilege DB initialization failed\n");
2405 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2407 _LOGD("package app info DB initialization failed\n");
2410 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2412 _LOGD("package app localized info DB initialization failed\n");
2415 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2417 _LOGD("package app icon localized info DB initialization failed\n");
2420 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2422 _LOGD("package app image info DB initialization failed\n");
2425 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2427 _LOGD("package app app control DB initialization failed\n");
2430 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2432 _LOGD("package app app category DB initialization failed\n");
2435 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2437 _LOGD("package app app category DB initialization failed\n");
2440 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2442 _LOGD("package app app permission DB initialization failed\n");
2445 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2447 _LOGD("package app share allowed DB initialization failed\n");
2450 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2452 _LOGD("package app share request DB initialization failed\n");
2455 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2457 _LOGD("package app data control DB initialization failed\n");
2461 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2463 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2467 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2469 _LOGD("package app splash screen DB initialization failed\n");
2474 /* TODO: refactor this code */
2475 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2477 _LOGD("package cert info DB initialization failed\n");
2480 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2482 _LOGD("package cert index info DB initialization failed\n");
2485 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2487 _LOGD("package cert info DB initialization failed\n");
2490 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2492 _LOGD("package cert index info DB initialization failed\n");
2495 for (i = 0; columns[i] != NULL; i++) {
2496 snprintf(query, sizeof(query),
2497 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2498 columns[i], columns[i], columns[i]);
2499 ret = __initialize_db(pkgmgr_cert_db, query);
2501 _LOGD("package cert index info DB initialization failed\n");
2506 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2507 _LOGD("Failed to change cert db permission\n");
2509 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2510 _LOGD("Failed to change parser db permission\n");
2516 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2519 char pwuid_buf[1024];
2520 char journal_file[BUFSIZE];
2523 struct passwd userinfo, *result = NULL;
2524 files[0] = (char *)db_file;
2525 files[1] = journal_file;
2529 if (db_file == NULL)
2532 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2534 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2535 if (uid == OWNER_ROOT)
2537 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2538 if (ret != 0 || result == NULL) {
2539 _LOGE("FAIL: user %d doesn't exist", uid);
2542 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2544 for (i = 0; files[i]; i++) {
2545 ret = chown(files[i], uid, userinfo.pw_gid);
2547 if (strerror_r(errno, buf, sizeof(buf)))
2548 strncpy(buf, "", BUFSIZE - 1);
2549 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2550 userinfo.pw_gid, buf);
2554 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2555 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2557 ret = chmod(files[i], mode);
2559 if (strerror_r(errno, buf, sizeof(buf)))
2560 strncpy(buf, "", BUFSIZE - 1);
2561 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2564 SET_SMACK_LABEL(files[i]);
2569 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2573 if (getuid() != OWNER_ROOT) {
2574 _LOGE("Only root user is allowed");
2578 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2579 _LOGE("Manifest db for user %d is already exists", uid);
2583 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2584 _LOGE("Cert db for user %d is already exists", uid);
2588 ret = pkgmgr_parser_check_and_create_db(uid);
2591 ret = pkgmgr_parser_initialize_db(uid);
2593 pkgmgr_parser_close_db();
2596 pkgmgr_parser_close_db();
2601 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2605 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2607 _LOGD("Manifest DB creation Failed\n");
2612 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2614 _LOGD("Cert DB creation Failed\n");
2620 void pkgmgr_parser_close_db(void)
2622 sqlite3_close(pkgmgr_parser_db);
2623 sqlite3_close(pkgmgr_cert_db);
2627 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2629 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2631 _LOGD("manifest pointer is NULL\n");
2635 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2637 _LOGD("Failed to open DB\n");
2640 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2643 /*Begin transaction*/
2644 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2645 if (ret != SQLITE_OK) {
2646 _LOGD("Failed to begin transaction\n");
2650 _LOGD("Transaction Begin\n");
2651 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2653 _LOGD("Insert into DB failed. Rollback now\n");
2654 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2657 /*Commit transaction*/
2658 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2659 if (ret != SQLITE_OK) {
2660 _LOGD("Failed to commit transaction. Rollback now\n");
2661 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2665 _LOGD("Transaction Commit and End\n");
2667 pkgmgr_parser_close_db();
2671 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2673 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2675 _LOGD("manifest pointer is NULL\n");
2679 ret = pkgmgr_parser_check_and_create_db(uid);
2681 _LOGD("Failed to open DB\n");
2684 ret = pkgmgr_parser_initialize_db(uid);
2687 /*Begin transaction*/
2688 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2689 if (ret != SQLITE_OK) {
2690 _LOGD("Failed to begin transaction\n");
2694 _LOGD("Transaction Begin\n");
2695 ret = __insert_manifest_info_in_db(mfx, uid);
2697 _LOGD("Insert into DB failed. Rollback now\n");
2698 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2701 /*Commit transaction*/
2702 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2703 if (ret != SQLITE_OK) {
2704 _LOGD("Failed to commit transaction. Rollback now\n");
2705 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2709 _LOGD("Transaction Commit and End\n");
2711 pkgmgr_parser_close_db();
2715 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2717 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2720 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2722 if (pkgid == NULL || tep_path == NULL) {
2723 _LOGE("invalid parameter");
2730 ret = pkgmgr_parser_check_and_create_db(uid);
2732 _LOGD("Failed to open DB\n");
2735 ret = pkgmgr_parser_initialize_db(uid);
2739 /*Begin transaction*/
2740 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2741 if (ret != SQLITE_OK) {
2742 _LOGD("Failed to begin transaction\n");
2746 _LOGD("Transaction Begin\n");
2749 /* Updating TEP info in "package_info" table */
2750 query = sqlite3_mprintf("UPDATE package_info "\
2751 "SET package_tep_name = %Q "\
2752 "WHERE package = %Q", tep_path, pkgid);
2754 ret = __exec_query(query);
2755 sqlite3_free(query);
2756 if (ret != SQLITE_OK) {
2757 ret = PM_PARSER_R_ERROR;
2758 _LOGE("sqlite exec failed to insert entries into package_info!!");
2762 /* Updating TEP info in "package_app_info" table */
2763 query = sqlite3_mprintf("UPDATE package_app_info "\
2764 "SET app_tep_name = %Q "\
2765 "WHERE package = %Q", tep_path, pkgid);
2767 ret = __exec_query(query);
2768 sqlite3_free(query);
2769 if (ret != SQLITE_OK) {
2770 ret = PM_PARSER_R_ERROR;
2771 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2775 /*Commit transaction*/
2776 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2777 if (ret != SQLITE_OK) {
2778 _LOGE("Failed to commit transaction, Rollback now\n");
2779 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2780 if (ret != SQLITE_OK)
2781 _LOGE("Failed to Rollback\n");
2783 ret = PM_PARSER_R_ERROR;
2786 _LOGD("Transaction Commit and End\n");
2787 ret = PM_PARSER_R_OK;
2790 pkgmgr_parser_close_db();
2795 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2798 _LOGD("manifest pointer is NULL\n");
2802 ret = pkgmgr_parser_check_and_create_db(uid);
2804 _LOGD("Failed to open DB\n");
2807 ret = pkgmgr_parser_initialize_db(uid);
2810 /*Preserve guest mode visibility*/
2811 __preserve_guestmode_visibility_value( mfx);
2812 /*Begin transaction*/
2813 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2814 if (ret != SQLITE_OK) {
2815 _LOGD("Failed to begin transaction\n");
2819 _LOGD("Transaction Begin\n");
2820 ret = __delete_manifest_info_from_db(mfx, uid);
2822 _LOGD("Delete from DB failed. Rollback now\n");
2823 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2826 ret = __insert_manifest_info_in_db(mfx, uid);
2828 _LOGD("Insert into DB failed. Rollback now\n");
2829 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2833 /*Commit transaction*/
2834 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2835 if (ret != SQLITE_OK) {
2836 _LOGD("Failed to commit transaction. Rollback now\n");
2837 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2841 _LOGD("Transaction Commit and End\n");
2843 pkgmgr_parser_close_db();
2847 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2849 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2852 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2855 _LOGD("manifest pointer is NULL\n");
2859 ret = pkgmgr_parser_check_and_create_db(uid);
2861 _LOGD("Failed to open DB\n");
2864 /*Begin transaction*/
2865 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2866 if (ret != SQLITE_OK) {
2867 _LOGD("Failed to begin transaction\n");
2871 _LOGD("Transaction Begin\n");
2872 ret = __delete_manifest_info_from_db(mfx, uid);
2874 _LOGD("Delete from DB failed. Rollback now\n");
2875 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2878 /*Commit transaction*/
2879 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2880 if (ret != SQLITE_OK) {
2881 _LOGD("Failed to commit transaction, Rollback now\n");
2882 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2886 _LOGD("Transaction Commit and End\n");
2888 pkgmgr_parser_close_db();
2892 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2894 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2897 API int pkgmgr_parser_update_preload_info_in_db()
2900 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2902 _LOGD("Failed to open DB\n");
2905 /*Begin transaction*/
2906 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2907 if (ret != SQLITE_OK) {
2908 _LOGD("Failed to begin transaction\n");
2912 _LOGD("Transaction Begin\n");
2913 ret = __update_preload_condition_in_db();
2915 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2916 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2919 /*Commit transaction*/
2920 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2921 if (ret != SQLITE_OK) {
2922 _LOGD("Failed to commit transaction, Rollback now\n");
2923 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2927 _LOGD("Transaction Commit and End\n");
2929 pkgmgr_parser_close_db();
2933 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2936 ret = pkgmgr_parser_check_and_create_db(uid);
2938 _LOGD("Failed to open DB\n");
2941 /*Begin transaction*/
2942 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2943 if (ret != SQLITE_OK) {
2944 _LOGD("Failed to begin transaction\n");
2948 _LOGD("Transaction Begin\n");
2949 ret = __update_preload_condition_in_db();
2951 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2952 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2955 /*Commit transaction*/
2956 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2957 if (ret != SQLITE_OK) {
2958 _LOGD("Failed to commit transaction, Rollback now\n");
2959 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2963 _LOGD("Transaction Commit and End\n");
2965 pkgmgr_parser_close_db();
2969 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2973 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2975 _LOGD("Failed to open DB\n");
2979 /*Begin transaction*/
2980 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2981 if (ret != SQLITE_OK) {
2982 _LOGD("Failed to begin transaction\n");
2986 _LOGD("Transaction Begin\n");
2988 ret = __disable_global_app_for_user(appid, uid);
2990 ret = __enable_global_app_for_user(appid, uid);
2992 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2993 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2996 /*Commit transaction*/
2997 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2998 if (ret != SQLITE_OK) {
2999 _LOGD("Failed to commit transaction, Rollback now\n");
3000 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3004 _LOGD("Transaction Commit and End\n");
3006 pkgmgr_parser_close_db();
3011 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3013 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3016 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3020 ret = pkgmgr_parser_check_and_create_db(uid);
3022 _LOGD("Failed to open DB\n");
3026 /*Begin transaction*/
3027 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3028 if (ret != SQLITE_OK) {
3029 _LOGD("Failed to begin transaction\n");
3033 _LOGD("Transaction Begin\n");
3035 ret = __disable_app(appid);
3037 ret = __enable_app(appid);
3039 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3040 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3043 /*Commit transaction*/
3044 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3045 if (ret != SQLITE_OK) {
3046 _LOGD("Failed to commit transaction, Rollback now\n");
3047 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3051 _LOGD("Transaction Commit and End\n");
3053 pkgmgr_parser_close_db();
3058 API int pkgmgr_parser_update_global_app_splash_screen_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3062 ret = pkgmgr_parser_check_and_create_db(uid);
3064 _LOGD("Failed to open DB\n");
3068 /*Begin transaction*/
3069 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3070 if (ret != SQLITE_OK) {
3071 _LOGD("Failed to begin transaction\n");
3075 _LOGD("Transaction Begin\n");
3077 ret = __disable_global_app_splash_screen_for_user(appid, uid);
3079 ret = __enable_global_app_splash_screen_for_user(appid, uid);
3081 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3082 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3085 /*Commit transaction*/
3086 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3087 if (ret != SQLITE_OK) {
3088 _LOGD("Failed to commit transaction, Rollback now\n");
3089 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3093 _LOGD("Transaction Commit and End\n");
3095 pkgmgr_parser_close_db();