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_DISABLE_FOR_USER "CREATE TABLE IF NOT EXISTS package_app_disable_for_user " \
328 "(app_id text not null, " \
329 "uid text not null, " \
330 "PRIMARY KEY(app_id, uid))"
332 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
333 "create table if not exists package_app_splash_screen " \
334 "(app_id text not null, " \
335 "src text not null, " \
336 "type text not null, " \
337 "orientation text not null, " \
338 "indicatordisplay text, " \
340 "PRIMARY KEY(app_id, orientation, operation) " \
341 "FOREIGN KEY(app_id) " \
342 "REFERENCES package_app_info(app_id) " \
345 static int __insert_application_info(manifest_x *mfx);
346 static int __insert_application_appcategory_info(manifest_x *mfx);
347 static int __insert_application_appcontrol_info(manifest_x *mfx);
348 static int __insert_application_appmetadata_info(manifest_x *mfx);
349 static int __insert_application_share_allowed_info(manifest_x *mfx);
350 static int __insert_application_share_request_info(manifest_x *mfx);
351 static int __insert_application_datacontrol_info(manifest_x *mfx);
352 static void __insert_application_locale_info(gpointer data, gpointer userdata);
353 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
354 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
355 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
356 static int __delete_subpkg_info_from_db(char *appid);
357 static int __delete_appinfo_from_db(char *db_table, const char *appid);
358 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
359 static int __exec_query(char *query);
360 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
361 char **label, char **license, char **icon, char **description, char **author);
362 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
363 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
364 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
365 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
366 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
367 static int __parserdb_change_perm(const char *db_file, uid_t uid);
369 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
372 __delete_subpkg_info_from_db(coltxt[0]);
377 static const char *__get_str(const char *str)
381 return PKGMGR_PARSER_EMPTY_STR;
387 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
392 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
393 if (ret != SQLITE_OK) {
394 _LOGD("connect db [%s] failed!\n", db_path);
402 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
404 manifest_x *mfx = (manifest_x *)data;
410 if (mfx->application == NULL)
412 app = (application_x *)mfx->application->data;
413 for(i = 0; i < ncols; i++)
415 if (strcmp(colname[i], "app_id") == 0) {
417 appid = strdup(coltxt[i]);
418 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
420 status = strdup(coltxt[i]);
426 _LOGD("app id is NULL\n");
429 /*update guest mode visibility*/
430 for (tmp = mfx->application; tmp; tmp = tmp->next) {
431 app = (application_x *)tmp->data;
434 if (strcmp(app->appid, appid) == 0) {
435 free((void *)app->guestmode_visibility);
436 app->guestmode_visibility = strdup(status);
452 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
454 char *error_message = NULL;
455 char query[MAX_QUERY_LEN] = {'\0'};
456 snprintf(query, MAX_QUERY_LEN - 1, "select app_id, app_guestmodevisibility from package_app_info where package='%s'", mfx->package);
458 sqlite3_exec(pkgmgr_parser_db, query,
459 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
460 _LOGD("Don't execute query = %s error message = %s\n",
461 query, error_message);
462 sqlite3_free(error_message);
467 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
469 char *error_message = NULL;
471 sqlite3_exec(db_handle, db_query,
472 NULL, NULL, &error_message)) {
473 _LOGD("Don't execute query = %s error message = %s\n",
474 db_query, error_message);
475 sqlite3_free(error_message);
478 sqlite3_free(error_message);
482 static int __exec_query(char *query)
484 char *error_message = NULL;
486 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
487 _LOGE("Don't execute query = %s error message = %s\n", query,
489 sqlite3_free(error_message);
492 sqlite3_free(error_message);
496 static int __exec_query_no_msg(char *query)
498 char *error_message = NULL;
500 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
501 sqlite3_free(error_message);
504 sqlite3_free(error_message);
508 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
516 for (tmp = lbls; tmp; tmp = tmp->next) {
517 lbl = (label_x *)tmp->data;
521 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
523 for (tmp = lcns; tmp; tmp = tmp->next) {
524 lcn = (license_x *)tmp->data;
528 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
530 for (tmp = icns; tmp; tmp = tmp->next) {
531 icn = (icon_x *)tmp->data;
535 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
537 for (tmp = dcns; tmp; tmp = tmp->next) {
538 dcn = (description_x *)tmp->data;
542 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
544 for (tmp = aths; tmp; tmp = tmp->next) {
545 ath = (author_x *)tmp->data;
549 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
555 static GList *__create_icon_list(GList *appicon, GList *icns)
560 for (tmp = icns; tmp; tmp = tmp->next) {
561 icn = (icon_x *)tmp->data;
565 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
570 static GList *__create_image_list(GList *appimage, GList *imgs)
575 for (tmp = imgs; tmp; tmp = tmp->next) {
576 img = (image_x *)tmp->data;
580 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
585 static void __trimfunc(GList* trim_list)
587 char *trim_data = NULL;
591 list = g_list_first(trim_list);
594 trim_data = (char *)list->data;
597 if (strcmp(trim_data, prev) == 0) {
598 trim_list = g_list_remove(trim_list, trim_data);
599 list = g_list_first(trim_list);
608 list = g_list_next(list);
612 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
614 if (a == NULL || b == NULL)
616 if (strcmp((char*)a, (char*)b) == 0)
618 if (strcmp((char*)a, (char*)b) < 0)
620 if (strcmp((char*)a, (char*)b) > 0)
625 static int __check_dpi(const char *dpi_char, int dpi_int)
627 if (dpi_char == NULL)
630 if (strcasecmp(dpi_char, LDPI) == 0) {
631 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
635 } else if (strcasecmp(dpi_char, MDPI) == 0) {
636 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
640 } else if (strcasecmp(dpi_char, HDPI) == 0) {
641 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
645 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
646 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
650 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
651 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
659 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
662 char *icon_filename = NULL;
663 char modified_iconpath[BUFSIZE] = { '\0' };
664 char icon_path[BUFSIZE] = { '\0' };
668 if (orig_icon_path == NULL)
671 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
675 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
676 dpi_path[0] = "LDPI";
677 dpi_path[1] = "ldpi";
678 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
679 dpi_path[0] = "MDPI";
680 dpi_path[1] = "mdpi";
681 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
682 dpi_path[0] = "HDPI";
683 dpi_path[1] = "hdpi";
684 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
685 dpi_path[0] = "XHDPI";
686 dpi_path[1] = "xhdpi";
687 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
688 dpi_path[0] = "XXHDPI";
689 dpi_path[1] = "xxhdpi";
691 _LOGE("Unidentified dpi[%d]", dpi);
695 icon_filename = strrchr(orig_icon_path, '/');
696 if (icon_filename == NULL)
699 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
700 for (i = 0; i < 2; i++) {
701 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
702 if (access(modified_iconpath, F_OK) != -1) {
703 // if exists, return modified icon path
704 *new_icon_path = strdup(modified_iconpath);
712 static gint __compare_icon(gconstpointer a, gconstpointer b)
714 icon_x *icon = (icon_x *)a;
716 char *icon_folder_path = NULL;
718 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
721 if (icon->dpi != NULL)
724 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
726 icon->text = icon_folder_path;
732 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
734 icon_x *icon = (icon_x *)a;
735 int dpi = GPOINTER_TO_INT(b);
737 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
740 if (icon->dpi == NULL)
743 if (__check_dpi(icon->dpi, dpi) == 0)
749 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
751 icon_x *icon = (icon_x *)a;
752 char *lang = (char *)b;
753 char *icon_folder_path = NULL;
755 if (icon->dpi != NULL)
758 if (strcasecmp(icon->lang, lang) == 0) {
759 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
760 //icon for no locale. check existance of folder-hierachied default icons
761 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
763 icon->text = icon_folder_path;
772 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
774 icon_x *icon = (icon_x *)a;
775 char *lang = (char *)b;
778 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
782 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
788 static char *__find_icon(GList *icons, const char *lang)
794 // first, find icon whose locale and dpi with given lang and system's dpi has matched
795 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
797 icon = (icon_x *)tmp->data;
798 return (char *)icon->text;
801 // if first has failed, find icon whose locale has matched
802 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
804 icon = (icon_x *)tmp->data;
805 return (char *)icon->text;
808 // if second has failed, find icon whose dpi has matched with system's dpi
809 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
812 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
814 icon = (icon_x *)tmp->data;
815 return (char *)icon->text;
818 // last, find default icon marked as "No Locale"
819 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
821 icon = (icon_x *)tmp->data;
822 return (char *)icon->text;
828 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
829 char **label, char **license, char **icon, char **description, char **author)
836 for (tmp = lbls; tmp; tmp = tmp->next) {
837 lbl = (label_x *)tmp->data;
841 if (strcmp(lbl->lang, (char *)data) == 0) {
842 *label = (char*)lbl->text;
847 for (tmp = lcns; tmp; tmp = tmp->next) {
848 lcn = (license_x *)tmp->data;
852 if (strcmp(lcn->lang, (char *)data) == 0) {
853 *license = (char*)lcn->text;
859 *icon = __find_icon(icns, (char *)data);
861 for (tmp = dcns; tmp; tmp = tmp->next) {
862 dcn = (description_x *)tmp->data;
866 if (strcmp(dcn->lang, (char *)data) == 0) {
867 *description = (char*)dcn->text;
872 for (tmp = aths; tmp; tmp = tmp->next) {
873 ath = (author_x *)tmp->data;
877 if (strcmp(ath->lang, (char *)data) == 0) {
878 *author = (char*)ath->text;
886 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
890 for (tmp = icns; tmp; tmp = tmp->next) {
891 icn = (icon_x *)tmp->data;
895 if (strcmp(icn->section, (char *)data) == 0) {
896 *icon = (char*)icn->text;
897 *resolution = (char*)icn->resolution;
904 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
908 for (tmp = imgs; tmp; tmp = tmp->next) {
909 img = (image_x *)tmp->data;
913 if (strcmp(img->section, (char *)data) == 0) {
914 *lang = (char*)img->lang;
915 *image = (char*)img->text;
922 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
927 char *description = NULL;
928 char *license = NULL;
932 manifest_x *mfx = (manifest_x *)userdata;
933 GList *lbl = mfx->label;
934 GList *lcn = mfx->license;
935 GList *icn = mfx->icon;
936 GList *dcn = mfx->description;
937 GList *ath = mfx->author;
939 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
940 if (!label && !description && !icon && !license && !author)
943 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
944 "package_label, package_icon, package_description, package_license, package_author) values " \
945 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
950 __get_str(description),
954 ret = __exec_query(query);
956 _LOGD("Package Localized Info DB Insert failed\n");
961 static void __insert_application_locale_info(gpointer data, gpointer userdata)
968 application_x *app = (application_x*)userdata;
969 GList *lbl = app->label;
970 GList *icn = app->icon;
972 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
976 query = sqlite3_mprintf("insert into package_app_localized_info(app_id, app_locale, " \
977 "app_label, app_icon) values " \
978 "(%Q, %Q, %Q, %Q)", app->appid, (char*)data,
979 __get_str(label), __get_str(icon));
980 ret = __exec_query(query);
982 _LOGD("Package UiApp Localized Info DB Insert failed\n");
986 /*insert ui app locale info to pkg locale to get mainapp data */
987 if (strcasecmp(app->mainapp, "true")==0) {
988 query = sqlite3_mprintf("insert into package_localized_info(package, package_locale, " \
989 "package_label, package_icon, package_description, package_license, package_author) values " \
990 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
995 PKGMGR_PARSER_EMPTY_STR,
996 PKGMGR_PARSER_EMPTY_STR,
997 PKGMGR_PARSER_EMPTY_STR);
999 ret = __exec_query_no_msg(query);
1000 sqlite3_free(query);
1003 query = sqlite3_mprintf("update package_localized_info set package_icon=%Q "\
1004 "where package=%Q and package_locale=%Q", icon, app->package, (char*)data);
1005 ret = __exec_query_no_msg(query);
1006 sqlite3_free(query);
1011 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1015 char *resolution = NULL;
1016 char query[MAX_QUERY_LEN] = {'\0'};
1018 application_x *app = (application_x*)userdata;
1019 GList *icn = app->icon;
1021 __extract_icon_data(data, icn, &icon, &resolution);
1022 if (!icon && !resolution)
1024 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_icon_section_info(app_id, " \
1025 "app_icon, app_icon_section, app_icon_resolution) values " \
1026 "('%q', '%q', '%q', '%q')", app->appid,
1027 icon, (char*)data, resolution);
1029 ret = __exec_query(query);
1031 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1035 static void __insert_application_image_info(gpointer data, gpointer userdata)
1040 char query[MAX_QUERY_LEN] = {'\0'};
1042 application_x *app = (application_x*)userdata;
1043 GList *image = app->image;
1045 __extract_image_data(data, image, &lang, &img);
1048 sqlite3_snprintf(MAX_QUERY_LEN, query, "insert into package_app_image_info(app_id, app_locale, " \
1049 "app_image_section, app_image) values " \
1050 "('%q', '%q', '%q', '%q')", app->appid, lang, (char*)data, img);
1052 ret = __exec_query(query);
1054 _LOGD("Package UiApp image Info DB Insert failed\n");
1059 static int __insert_mainapp_info(manifest_x *mfx)
1064 char query[MAX_QUERY_LEN] = {'\0'};
1065 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1066 app = (application_x *)tmp->data;
1069 snprintf(query, MAX_QUERY_LEN,
1070 "update package_app_info set app_mainapp='%s' where app_id='%s'", app->mainapp, app->appid);
1072 ret = __exec_query(query);
1074 _LOGD("Package App Info DB Insert Failed\n");
1077 if (strcasecmp(app->mainapp, "True")==0)
1078 mfx->mainapp_id = strdup(app->appid);
1081 if (mfx->mainapp_id == NULL) {
1082 if (mfx->application == NULL)
1084 app = (application_x *)mfx->application->data;
1088 snprintf(query, MAX_QUERY_LEN, "update package_app_info set app_mainapp='true' where app_id='%s'", app->appid);
1090 _LOGD("Not valid appid\n");
1094 ret = __exec_query(query);
1096 _LOGD("Package UiApp Info DB Insert Failed\n");
1100 free((void *)app->mainapp);
1101 app->mainapp= strdup("true");
1102 mfx->mainapp_id = strdup(app->appid);
1105 memset(query, '\0', MAX_QUERY_LEN);
1106 snprintf(query, MAX_QUERY_LEN,
1107 "update package_info set mainapp_id='%s' where package='%s'", mfx->mainapp_id, mfx->package);
1108 ret = __exec_query(query);
1110 _LOGD("Package Info DB update Failed\n");
1117 static int __convert_background_category(GList *category_list)
1120 GList *tmp_list = category_list;
1121 char *category_data = NULL;
1123 if (category_list == NULL)
1126 while (tmp_list != NULL) {
1127 category_data = (char *)tmp_list->data;
1128 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0) {
1129 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1130 } else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0) {
1131 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1132 } else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0) {
1133 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1134 } else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0) {
1135 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1136 } else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0) {
1137 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1138 } else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0) {
1139 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1140 } else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0) {
1141 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1143 _LOGE("Unidentified category [%s]", category_data);
1145 tmp_list = g_list_next(tmp_list);
1151 static const char *__find_effective_appid(GList *metadata_list)
1156 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1157 md = (metadata_x *)tmp_list->data;
1158 if (md == NULL || md->key == NULL)
1161 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1170 /* _PRODUCT_LAUNCHING_ENHANCED_
1171 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1173 static int __insert_application_info(manifest_x *mfx)
1178 int background_value = 0;
1179 char query[MAX_QUERY_LEN] = {'\0'};
1181 const char *effective_appid;
1184 type = strdup(mfx->type);
1186 type = strdup("tpk");
1188 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1189 app = (application_x *)tmp->data;
1193 background_value = __convert_background_category(app->background_category);
1194 if (background_value < 0) {
1195 _LOGE("Failed to retrieve background value[%d]", background_value);
1196 background_value = 0;
1199 effective_appid = __find_effective_appid(app->metadata);
1201 snprintf(query, MAX_QUERY_LEN,
1202 "insert into package_app_info(" \
1203 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1204 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1205 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1206 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1207 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1208 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1209 "app_tep_name, app_background_category, app_package_type, app_root_path, app_api_version, " \
1210 "app_effective_appid, app_splash_screen_display) " \
1212 "'%s', '%s', '%s', '%s', '%s', " \
1213 "'%s', '%s', '%s', '%s', '%s', " \
1214 "'%s', '%s', '%s', '%s', '%s', " \
1215 "'%s', '%s', '%s', '%s', '%s', " \
1216 "'%s', '%s', '%s', '%s', '%s', " \
1217 "'%s', '%s', '%s', '%s', '%s', " \
1218 "'%s', '%d', '%s', '%s', '%s', " \
1220 app->appid, app->component_type, app->exec, app->nodisplay, app->type,
1221 app->onboot, app->multiple, app->autorestart, app->taskmanage, app->enabled,
1222 app->hwacceleration, app->screenreader, app->mainapp, __get_str(app->recentimage), app->launchcondition,
1223 app->indicatordisplay, __get_str(app->portraitimg), __get_str(app->landscapeimg),
1224 app->guestmode_visibility, app->permission_type,
1225 mfx->preload, app->submode, __get_str(app->submode_mainid), mfx->installed_storage, app->process_pool,
1226 app->launch_mode, app->ui_gadget, mfx->support_disable, app->component_type, mfx->package,
1227 __get_str(mfx->tep_name), background_value, type, mfx->root_path, __get_str(mfx->api_version),
1228 __get_str(effective_appid), app->splash_screen_display);
1230 ret = __exec_query(query);
1232 _LOGD("Package UiApp Info DB Insert Failed\n");
1237 memset(query, '\0', MAX_QUERY_LEN);
1246 static int __insert_application_appcategory_info(manifest_x *mfx)
1253 char query[MAX_QUERY_LEN] = {'\0'};
1254 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1255 app = (application_x *)app_tmp->data;
1258 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1259 ct = (const char *)ct_tmp->data;
1262 snprintf(query, MAX_QUERY_LEN,
1263 "insert into package_app_app_category(app_id, category) " \
1264 "values('%s','%s')",\
1266 ret = __exec_query(query);
1268 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1271 memset(query, '\0', MAX_QUERY_LEN);
1277 static int __insert_application_appmetadata_info(manifest_x *mfx)
1284 char query[MAX_QUERY_LEN] = {'\0'};
1285 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1286 app = (application_x *)app_tmp->data;
1289 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1290 md = (metadata_x *)md_tmp->data;
1294 snprintf(query, MAX_QUERY_LEN,
1295 "insert into package_app_app_metadata(app_id, md_key, md_value) " \
1296 "values('%s','%s', '%s')",\
1297 app->appid, md->key, md->value ? md->value : "");
1298 ret = __exec_query(query);
1300 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1304 memset(query, '\0', MAX_QUERY_LEN);
1310 static int __insert_application_apppermission_info(manifest_x *mfx)
1317 char query[MAX_QUERY_LEN] = {'\0'};
1318 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1319 app = (application_x *)app_tmp->data;
1322 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1323 pm = (permission_x *)pm_tmp->data;
1326 snprintf(query, MAX_QUERY_LEN,
1327 "insert into package_app_app_permission(app_id, pm_type, pm_value) " \
1328 "values('%s','%s', '%s')",\
1329 app->appid, pm->type, pm->value);
1330 ret = __exec_query(query);
1332 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1335 memset(query, '\0', MAX_QUERY_LEN);
1341 static int __insert_application_appcontrol_info(manifest_x *mfx)
1345 GList *acontrol_tmp;
1346 appcontrol_x *acontrol;
1348 char query[MAX_QUERY_LEN] = {'\0'};
1349 char buf[BUFSIZE] = {'\0'};
1350 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1351 app = (application_x *)app_tmp->data;
1354 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1355 acontrol = (appcontrol_x *)acontrol_tmp->data;
1356 if (acontrol == NULL)
1358 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1359 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1360 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1361 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1362 snprintf(query, MAX_QUERY_LEN,
1363 "insert into package_app_app_control(app_id, app_control) " \
1364 "values('%s', '%s')",\
1366 ret = __exec_query(query);
1368 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1371 memset(query, '\0', MAX_QUERY_LEN);
1377 static int __insert_application_datacontrol_info(manifest_x *mfx)
1384 char query[MAX_QUERY_LEN] = {'\0'};
1386 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1387 app = (application_x *)app_tmp->data;
1390 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1391 dc = (datacontrol_x *)dc_tmp->data;
1394 snprintf(query, MAX_QUERY_LEN,
1395 "insert into package_app_data_control(app_id, providerid, access, type) " \
1396 "values('%s', '%s', '%s', '%s')",\
1402 ret = __exec_query(query);
1404 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1407 memset(query, '\0', MAX_QUERY_LEN);
1413 static int __insert_application_share_request_info(manifest_x *mfx)
1422 char query[MAX_QUERY_LEN] = {'\0'};
1423 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1424 app = (application_x *)app_tmp->data;
1427 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1428 ds = (datashare_x *)ds_tmp->data;
1431 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1432 rq = (const char *)rq_tmp->data;
1435 snprintf(query, MAX_QUERY_LEN,
1436 "insert into package_app_share_request(app_id, data_share_request) " \
1437 "values('%s', '%s')",\
1439 ret = __exec_query(query);
1441 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1444 memset(query, '\0', MAX_QUERY_LEN);
1451 static int __insert_application_share_allowed_info(manifest_x *mfx)
1462 char query[MAX_QUERY_LEN] = {'\0'};
1463 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1464 app = (application_x *)app_tmp->data;
1467 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1468 ds = (datashare_x *)ds_tmp->data;
1471 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1472 df = (define_x *)df_tmp->data;
1475 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1476 al = (const char *)al_tmp->data;
1479 snprintf(query, MAX_QUERY_LEN,
1480 "insert into package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1481 "values('%s', '%s', '%s')",\
1482 app->appid, df->path, al);
1483 ret = __exec_query(query);
1485 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1488 memset(query, '\0', MAX_QUERY_LEN);
1496 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1498 splashscreen_x *ss = (splashscreen_x *)a;
1499 const char *orientation = (const char *)b;
1502 if (ss->operation || ss->dpi == NULL)
1505 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1509 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1515 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1517 splashscreen_x *ss = (splashscreen_x *)a;
1518 const char *orientation = (const char *)b;
1520 if (ss->operation || ss->dpi)
1523 if (strcasecmp(ss->orientation, orientation) == 0)
1529 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1530 const char *orientation)
1534 tmp = g_list_find_custom(splashscreens, orientation,
1535 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1537 return (splashscreen_x *)tmp->data;
1539 tmp = g_list_find_custom(splashscreens, orientation,
1540 (GCompareFunc)__compare_splashscreen_with_orientation);
1542 return (splashscreen_x *)tmp->data;
1547 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1549 splashscreen_x *ss = (splashscreen_x *)data;
1550 GList **list = (GList **)user_data;
1553 if (ss->operation == NULL || ss->dpi == NULL)
1556 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1560 if (__check_dpi(ss->dpi, dpi) != 0)
1563 *list = g_list_append(*list, ss);
1566 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1568 splashscreen_x *ss = (splashscreen_x *)data;
1569 GList **list = (GList **)user_data;
1570 splashscreen_x *ss_tmp;
1573 if (ss->operation == NULL || ss->dpi)
1576 for (tmp = *list; tmp; tmp = tmp->next) {
1577 ss_tmp = (splashscreen_x *)tmp->data;
1578 if (ss_tmp->operation
1579 && strcmp(ss_tmp->operation, ss->operation) == 0
1580 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1584 *list = g_list_append(*list, ss);
1587 static GList *__find_splashscreens(GList *splashscreens)
1592 g_list_foreach(splashscreens,
1593 __find_appcontrol_splashscreen_with_dpi, &list);
1594 g_list_foreach(splashscreens,
1595 __find_appcontrol_splashscreen, &list);
1597 ss = __find_default_splashscreen(splashscreens, "portrait");
1599 list = g_list_append(list, ss);
1600 ss = __find_default_splashscreen(splashscreens, "landscape");
1602 list = g_list_append(list, ss);
1607 static int __insert_application_splashscreen_info(manifest_x *mfx)
1615 char query[MAX_QUERY_LEN];
1617 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1618 app = (application_x *)app_tmp->data;
1619 if (app == NULL || app->splashscreens == NULL)
1622 ss_tmp = __find_splashscreens(app->splashscreens);
1626 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1627 ss = (splashscreen_x *)tmp->data;
1628 snprintf(query, sizeof(query),
1629 "insert into package_app_splash_screen" \
1630 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1631 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1632 app->appid, ss->src, ss->type, ss->orientation,
1633 ss->indicatordisplay, __get_str(ss->operation));
1634 ret = __exec_query(query);
1636 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1639 memset(query, '\0', MAX_QUERY_LEN);
1641 g_list_free(ss_tmp);
1646 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1651 char query[MAX_QUERY_LEN];
1653 const char *image_type;
1654 const char *indicatordisplay;
1655 const char *orientation;
1656 const char *operation = NULL;
1658 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1659 app = (application_x *)app_tmp->data;
1661 (app->portraitimg == NULL && app->landscapeimg == NULL))
1663 image_type = "img"; /* default */
1664 if (app->effectimage_type) {
1665 tmp = strstr(app->effectimage_type, "edj");
1669 indicatordisplay = "true"; /* default */
1670 if (app->indicatordisplay)
1671 indicatordisplay = app->indicatordisplay;
1672 if (app->portraitimg) {
1673 orientation = "portrait";
1674 snprintf(query, sizeof(query),
1675 "insert into package_app_splash_screen" \
1676 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1677 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1678 app->appid, app->portraitimg, image_type,
1679 orientation, indicatordisplay, __get_str(operation));
1680 ret = __exec_query(query);
1682 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1685 memset(query, '\0', MAX_QUERY_LEN);
1687 if (app->landscapeimg) {
1688 orientation = "landscape";
1689 snprintf(query, sizeof(query),
1690 "insert into package_app_splash_screen" \
1691 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1692 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1693 app->appid, app->landscapeimg, image_type,
1694 orientation, indicatordisplay, __get_str(operation));
1695 ret = __exec_query(query);
1697 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1700 memset(query, '\0', MAX_QUERY_LEN);
1706 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1713 char query[MAX_QUERY_LEN];
1715 char *tmpptr = NULL;
1716 const char *operation;
1717 const char *portraitimg;
1718 const char *landscapeimg;
1719 const char *indicatordisplay;
1720 const char *orientation;
1721 const char *image_type;
1723 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1724 app = (application_x *)app_tmp->data;
1728 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1729 md = (metadata_x *)md_tmp->data;
1730 if (md == NULL || md->key == NULL || md->value == NULL)
1733 if (strcasestr(md->key, "operation_effect=")) {
1734 operation = index(md->key, '=');
1735 if ((operation + 1) != NULL)
1739 } else if (strcasestr(md->key, "launch_effect")) {
1746 landscapeimg = NULL;
1747 indicatordisplay = "true"; /* default */
1748 token = strtok_r(md->value, "|", &tmpptr);
1749 while (token != NULL) {
1750 if (strcasestr(token, "portrait-effectimage=")) {
1751 portraitimg = index(token, '=');
1752 if ((portraitimg + 1) != NULL)
1756 } else if (strcasestr(token, "landscape-effectimage=")) {
1757 landscapeimg = index(token, '=');
1758 if ((landscapeimg + 1) != NULL)
1761 landscapeimg = NULL;
1762 } else if (strcasestr(token, "indicatordisplay=")) {
1763 indicatordisplay = index(token, '=');
1764 if ((indicatordisplay + 1) != NULL)
1767 indicatordisplay = "true";
1770 token = strtok_r(NULL, "|", &tmpptr);
1774 orientation = "portrait";
1776 if (strcasestr(portraitimg, "edj"))
1778 snprintf(query, sizeof(query),
1779 "insert into package_app_splash_screen" \
1780 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1781 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1782 app->appid, portraitimg, image_type,
1783 orientation, indicatordisplay, __get_str(operation));
1784 ret = __exec_query(query);
1786 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1789 memset(query, '\0', MAX_QUERY_LEN);
1792 orientation = "landscape";
1794 if (strcasestr(landscapeimg, "edj"))
1796 snprintf(query, sizeof(query),
1797 "insert into package_app_splash_screen" \
1798 "(app_id, src, type, orientation, indicatordisplay, operation) " \
1799 "values('%s', '%s', '%s', '%s', '%s', '%s')",
1800 app->appid, landscapeimg, image_type,
1801 orientation, indicatordisplay, __get_str(operation));
1802 ret = __exec_query(query);
1804 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1807 memset(query, '\0', MAX_QUERY_LEN);
1815 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1819 const char *pv = NULL;
1820 char query[MAX_QUERY_LEN] = { '\0' };
1823 const char *auth_name = NULL;
1824 const char *auth_email = NULL;
1825 const char *auth_href = NULL;
1827 GList *pkglocale = NULL;
1828 GList *applocale = NULL;
1829 GList *appicon = NULL;
1830 GList *appimage = NULL;
1832 if (mfx->author && mfx->author->data) {
1833 author = (author_x *)mfx->author->data;
1835 auth_name = author->text;
1837 auth_email = author->email;
1839 auth_href = author->href;
1842 /*Insert in the package_cert_info CERT_DB*/
1843 pkgmgrinfo_instcertinfo_h cert_handle = NULL;
1844 ret = pkgmgrinfo_set_cert_value(&cert_handle, PMINFO_SET_AUTHOR_ROOT_CERT, "author root certificate");
1845 if (ret != PMINFO_R_OK) {
1846 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1847 _LOGE("Cert Info DB create handle failed\n");
1850 ret = pkgmgrinfo_save_certinfo(mfx->package, &cert_handle, uid);
1851 if (ret != PMINFO_R_OK) {
1852 pkgmgrinfo_destroy_certinfo_set_handle(cert_handle);
1853 _LOGE("Cert Info DB Insert Failed\n");
1857 /*Insert in the package_info DB*/
1858 snprintf(query, MAX_QUERY_LEN,
1859 "insert into package_info(" \
1860 "package, package_type, package_version, package_api_version, package_tep_name, " \
1861 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1862 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1863 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1864 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1866 "'%s', '%s', '%s', '%s', '%s', " \
1867 "'%s', '%s', '%s', '%s', '%s', " \
1868 "'%s', '%s', '%s', '%s', '%s', " \
1869 "'%s', '%s', '%s', '%s', '%s', " \
1870 "'%s', '%s', '%s', '%s', '%s')", \
1871 mfx->package, mfx->type, mfx->version, __get_str(mfx->api_version), __get_str(mfx->tep_name),
1872 __get_str(mfx->installlocation), __get_str(mfx->package_size), mfx->removable, mfx->preload, mfx->readonly,
1873 mfx->update, mfx->appsetting, mfx->nodisplay_setting, mfx->system, __get_str(auth_name),
1874 __get_str(auth_email), __get_str(auth_href), mfx->installed_time, mfx->installed_storage,
1875 __get_str(mfx->storeclient_id),
1876 mfx->mainapp_id, __get_str(mfx->package_url), mfx->root_path, __get_str(mfx->csc_path), mfx->support_disable);
1878 ret = __exec_query(query);
1880 _LOGD("Package Info DB Insert Failed\n");
1884 /*Insert in the package_privilege_info DB*/
1885 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1886 pv = (const char *)tmp->data;
1889 memset(query, '\0', MAX_QUERY_LEN);
1890 snprintf(query, MAX_QUERY_LEN,
1891 "insert into package_privilege_info(package, privilege) " \
1892 "values('%s','%s')",\
1894 ret = __exec_query(query);
1896 _LOGD("Package Privilege Info DB Insert Failed\n");
1901 if (mfx->application != NULL) {
1902 ret = __insert_mainapp_info(mfx);
1907 /*Insert the package locale*/
1908 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1909 /*remove duplicated data in pkglocale*/
1910 __trimfunc(pkglocale);
1912 /*Insert the app locale, icon, image info */
1913 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1914 app = (application_x *)tmp->data;
1917 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1918 appicon = __create_icon_list(appicon, app->icon);
1919 appimage = __create_image_list(appimage, app->image);
1921 /*remove duplicated data in applocale*/
1922 __trimfunc(applocale);
1923 __trimfunc(appicon);
1924 __trimfunc(appimage);
1926 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1928 /*native app locale info*/
1929 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1930 app = (application_x *)tmp->data;
1933 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1934 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1935 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1938 g_list_free(pkglocale);
1940 g_list_free(applocale);
1942 g_list_free(appicon);
1944 g_list_free(appimage);
1947 /*Insert in the package_app_info DB*/
1948 ret = __insert_application_info(mfx);
1951 /*Insert in the package_app_app_control DB*/
1952 ret = __insert_application_appcontrol_info(mfx);
1956 /*Insert in the package_app_app_category DB*/
1957 ret = __insert_application_appcategory_info(mfx);
1961 /*Insert in the package_app_app_metadata DB*/
1962 ret = __insert_application_appmetadata_info(mfx);
1966 /*Insert in the package_app_app_permission DB*/
1967 ret = __insert_application_apppermission_info(mfx);
1971 /*Insert in the package_app_share_allowed DB*/
1972 ret = __insert_application_share_allowed_info(mfx);
1976 /*Insert in the package_app_share_request DB*/
1977 ret = __insert_application_share_request_info(mfx);
1981 /*Insert in the package_app_data_control DB*/
1982 ret = __insert_application_datacontrol_info(mfx);
1986 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1987 ret = __insert_application_legacy_splashscreen_info(mfx);
1991 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
1992 ret = __insert_application_metadata_splashscreen_info(mfx);
1996 /*Insert in the package_app_splash_screen DB*/
1997 ret = __insert_application_splashscreen_info(mfx);
2005 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2007 char query[MAX_QUERY_LEN] = { '\0' };
2009 memset(query, '\0', MAX_QUERY_LEN);
2010 snprintf(query, MAX_QUERY_LEN,
2011 "delete from %s where app_id='%s'", db_table, appid);
2012 ret = __exec_query(query);
2014 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2020 static int __delete_subpkg_info_from_db(char *appid)
2024 ret = __delete_appinfo_from_db("package_app_info", appid);
2027 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2030 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2033 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2036 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2039 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2042 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2045 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2048 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2051 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2054 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2057 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2064 static int __delete_subpkg_from_db(manifest_x *mfx)
2066 char query[MAX_QUERY_LEN] = { '\0' };
2067 char *error_message = NULL;
2069 snprintf(query, MAX_QUERY_LEN, "select app_id from package_app_info where package='%s'", mfx->package);
2071 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2072 _LOGE("Don't execute query = %s error message = %s\n", query,
2074 sqlite3_free(error_message);
2077 sqlite3_free(error_message);
2082 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2084 char query[MAX_QUERY_LEN] = { '\0' };
2088 /*Delete from cert table*/
2089 ret = pkgmgrinfo_delete_certinfo(mfx->package);
2091 _LOGD("Cert Info DB Delete Failed\n");
2095 /*Delete from Package Info DB*/
2096 snprintf(query, MAX_QUERY_LEN,
2097 "delete from package_info where package='%s'", mfx->package);
2098 ret = __exec_query(query);
2100 _LOGD("Package Info DB Delete Failed\n");
2103 memset(query, '\0', MAX_QUERY_LEN);
2105 /*Delete from Package Localized Info*/
2106 snprintf(query, MAX_QUERY_LEN,
2107 "delete from package_localized_info where package='%s'", mfx->package);
2108 ret = __exec_query(query);
2110 _LOGD("Package Localized Info DB Delete Failed\n");
2114 /*Delete from Package Privilege Info*/
2115 snprintf(query, MAX_QUERY_LEN,
2116 "delete from package_privilege_info where package='%s'", mfx->package);
2117 ret = __exec_query(query);
2119 _LOGD("Package Privilege Info DB Delete Failed\n");
2123 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2124 app = (application_x *)tmp->data;
2127 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2130 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2133 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2136 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2139 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2142 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2145 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2148 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2151 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2154 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2157 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2160 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2165 /* if main package has sub pkg, delete sub pkg data*/
2166 __delete_subpkg_from_db(mfx);
2171 static int __disable_app(const char *appid)
2174 char query[MAX_QUERY_LEN] = {'\0'};
2175 sqlite3_snprintf(MAX_QUERY_LEN, query,
2176 "UPDATE package_app_info set app_disable='true' where app_id=%Q",
2178 ret = __exec_query(query);
2180 _LOGD("Insert global app disable failed\n");
2185 static int __enable_app(const char *appid)
2188 char query[MAX_QUERY_LEN] = {'\0'};
2189 sqlite3_snprintf(MAX_QUERY_LEN, query,
2190 "UPDATE package_app_info set app_disable='false' where app_id=%Q",
2192 ret = __exec_query(query);
2194 _LOGD("Insert global app disable failed\n");
2199 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2202 char query[MAX_QUERY_LEN] = {'\0'};
2204 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO " \
2205 "package_app_disable_for_user(app_id, uid) VALUES(%Q, '%d')",
2207 ret = __exec_query(query);
2209 _LOGD("Insert global app disable failed\n");
2214 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2217 char query[MAX_QUERY_LEN] = {'\0'};
2219 sqlite3_snprintf(MAX_QUERY_LEN, query, "DELETE FROM " \
2220 "package_app_disable_for_user WHERE app_id=%Q AND uid='%d'",
2222 ret = __exec_query(query);
2224 _LOGD("Delete global app disable failed\n");
2229 static int __update_preload_condition_in_db()
2232 char query[MAX_QUERY_LEN] = {'\0'};
2234 snprintf(query, MAX_QUERY_LEN, "update package_info set package_preload='true'");
2236 ret = __exec_query(query);
2238 _LOGD("Package preload_condition update failed\n");
2243 API int pkgmgr_parser_initialize_db(uid_t uid)
2247 char query[MAX_QUERY_LEN];
2248 static const char *columns[] = {
2249 "author_root_cert", "author_im_cert", "author_signer_cert",
2250 "dist_root_cert", "dist_im_cert", "dist_signer_cert",
2251 "dist2_root_cert", "dist2_im_cert", "dist2_signer_cert",
2255 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2257 _LOGD("package info DB initialization failed\n");
2260 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2262 _LOGD("package localized info DB initialization failed\n");
2265 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2267 _LOGD("package app app privilege DB initialization failed\n");
2270 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2272 _LOGD("package app info DB initialization failed\n");
2275 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2277 _LOGD("package app localized info DB initialization failed\n");
2280 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2282 _LOGD("package app icon localized info DB initialization failed\n");
2285 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2287 _LOGD("package app image info DB initialization failed\n");
2290 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2292 _LOGD("package app app control DB initialization failed\n");
2295 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2297 _LOGD("package app app category DB initialization failed\n");
2300 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2302 _LOGD("package app app category DB initialization failed\n");
2305 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2307 _LOGD("package app app permission DB initialization failed\n");
2310 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2312 _LOGD("package app share allowed DB initialization failed\n");
2315 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2317 _LOGD("package app share request DB initialization failed\n");
2320 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2322 _LOGD("package app data control DB initialization failed\n");
2326 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DISABLE_FOR_USER);
2328 _LOGD("package app disable for user DB initialization failed\n");
2332 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2334 _LOGD("package app splash screen DB initialization failed\n");
2339 /* TODO: refactor this code */
2340 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2342 _LOGD("package cert info DB initialization failed\n");
2345 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2347 _LOGD("package cert index info DB initialization failed\n");
2350 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2352 _LOGD("package cert info DB initialization failed\n");
2355 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2357 _LOGD("package cert index info DB initialization failed\n");
2360 for (i = 0; columns[i] != NULL; i++) {
2361 snprintf(query, sizeof(query),
2362 QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO_FORMAT,
2363 columns[i], columns[i], columns[i]);
2364 ret = __initialize_db(pkgmgr_cert_db, query);
2366 _LOGD("package cert index info DB initialization failed\n");
2371 if( 0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER)) {
2372 _LOGD("Failed to change cert db permission\n");
2374 if( 0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid)) {
2375 _LOGD("Failed to change parser db permission\n");
2381 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2384 char pwuid_buf[1024];
2385 char journal_file[BUFSIZE];
2388 struct passwd userinfo, *result = NULL;
2389 files[0] = (char *)db_file;
2390 files[1] = journal_file;
2394 if (db_file == NULL)
2397 if (getuid() != OWNER_ROOT) //At this time we should be root to apply this
2399 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2400 if (uid == OWNER_ROOT)
2402 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2403 if (ret != 0 || result == NULL) {
2404 _LOGE("FAIL: user %d doesn't exist", uid);
2407 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2409 for (i = 0; files[i]; i++) {
2410 ret = chown(files[i], uid, userinfo.pw_gid);
2412 if (strerror_r(errno, buf, sizeof(buf)))
2413 strncpy(buf, "", BUFSIZE - 1);
2414 _LOGD("FAIL : chown %s %d.%d : %s", files[i], uid,
2415 userinfo.pw_gid, buf);
2419 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2420 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2422 ret = chmod(files[i], mode);
2424 if (strerror_r(errno, buf, sizeof(buf)))
2425 strncpy(buf, "", BUFSIZE - 1);
2426 _LOGD("FAIL : chmod %s 0664 : %s", files[i], buf);
2429 SET_SMACK_LABEL(files[i]);
2434 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2438 if (getuid() != OWNER_ROOT) {
2439 _LOGE("Only root user is allowed");
2443 if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
2444 _LOGE("Manifest db for user %d is already exists", uid);
2448 if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
2449 _LOGE("Cert db for user %d is already exists", uid);
2453 ret = pkgmgr_parser_check_and_create_db(uid);
2456 ret = pkgmgr_parser_initialize_db(uid);
2458 pkgmgr_parser_close_db();
2461 pkgmgr_parser_close_db();
2466 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2470 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
2472 _LOGD("Manifest DB creation Failed\n");
2477 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
2479 _LOGD("Cert DB creation Failed\n");
2485 void pkgmgr_parser_close_db(void)
2487 sqlite3_close(pkgmgr_parser_db);
2488 sqlite3_close(pkgmgr_cert_db);
2492 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2494 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2496 _LOGD("manifest pointer is NULL\n");
2500 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2502 _LOGD("Failed to open DB\n");
2505 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2508 /*Begin transaction*/
2509 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2510 if (ret != SQLITE_OK) {
2511 _LOGD("Failed to begin transaction\n");
2515 _LOGD("Transaction Begin\n");
2516 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2518 _LOGD("Insert into DB failed. Rollback now\n");
2519 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2522 /*Commit transaction*/
2523 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2524 if (ret != SQLITE_OK) {
2525 _LOGD("Failed to commit transaction. Rollback now\n");
2526 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2530 _LOGD("Transaction Commit and End\n");
2532 pkgmgr_parser_close_db();
2536 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2538 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2540 _LOGD("manifest pointer is NULL\n");
2544 ret = pkgmgr_parser_check_and_create_db(uid);
2546 _LOGD("Failed to open DB\n");
2549 ret = pkgmgr_parser_initialize_db(uid);
2552 /*Begin transaction*/
2553 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2554 if (ret != SQLITE_OK) {
2555 _LOGD("Failed to begin transaction\n");
2559 _LOGD("Transaction Begin\n");
2560 ret = __insert_manifest_info_in_db(mfx, uid);
2562 _LOGD("Insert into DB failed. Rollback now\n");
2563 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2566 /*Commit transaction*/
2567 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2568 if (ret != SQLITE_OK) {
2569 _LOGD("Failed to commit transaction. Rollback now\n");
2570 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2574 _LOGD("Transaction Commit and End\n");
2576 pkgmgr_parser_close_db();
2580 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2582 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, GLOBAL_USER);
2585 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2587 if (pkgid == NULL || tep_path == NULL) {
2588 _LOGE("invalid parameter");
2595 ret = pkgmgr_parser_check_and_create_db(uid);
2597 _LOGD("Failed to open DB\n");
2600 ret = pkgmgr_parser_initialize_db(uid);
2604 /*Begin transaction*/
2605 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2606 if (ret != SQLITE_OK) {
2607 _LOGD("Failed to begin transaction\n");
2611 _LOGD("Transaction Begin\n");
2614 /* Updating TEP info in "package_info" table */
2615 query = sqlite3_mprintf("UPDATE package_info "\
2616 "SET package_tep_name = %Q "\
2617 "WHERE package = %Q", tep_path, pkgid);
2619 ret = __exec_query(query);
2620 sqlite3_free(query);
2621 if (ret != SQLITE_OK) {
2622 ret = PM_PARSER_R_ERROR;
2623 _LOGE("sqlite exec failed to insert entries into package_info!!");
2627 /* Updating TEP info in "package_app_info" table */
2628 query = sqlite3_mprintf("UPDATE package_app_info "\
2629 "SET app_tep_name = %Q "\
2630 "WHERE package = %Q", tep_path, pkgid);
2632 ret = __exec_query(query);
2633 sqlite3_free(query);
2634 if (ret != SQLITE_OK) {
2635 ret = PM_PARSER_R_ERROR;
2636 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2640 /*Commit transaction*/
2641 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2642 if (ret != SQLITE_OK) {
2643 _LOGE("Failed to commit transaction, Rollback now\n");
2644 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2645 if (ret != SQLITE_OK)
2646 _LOGE("Failed to Rollback\n");
2648 ret = PM_PARSER_R_ERROR;
2651 _LOGD("Transaction Commit and End\n");
2652 ret = PM_PARSER_R_OK;
2655 pkgmgr_parser_close_db();
2660 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2663 _LOGD("manifest pointer is NULL\n");
2667 ret = pkgmgr_parser_check_and_create_db(uid);
2669 _LOGD("Failed to open DB\n");
2672 ret = pkgmgr_parser_initialize_db(uid);
2675 /*Preserve guest mode visibility*/
2676 __preserve_guestmode_visibility_value( mfx);
2677 /*Begin transaction*/
2678 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2679 if (ret != SQLITE_OK) {
2680 _LOGD("Failed to begin transaction\n");
2684 _LOGD("Transaction Begin\n");
2685 ret = __delete_manifest_info_from_db(mfx, uid);
2687 _LOGD("Delete from DB failed. Rollback now\n");
2688 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2691 ret = __insert_manifest_info_in_db(mfx, uid);
2693 _LOGD("Insert into DB failed. Rollback now\n");
2694 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2698 /*Commit transaction*/
2699 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2700 if (ret != SQLITE_OK) {
2701 _LOGD("Failed to commit transaction. Rollback now\n");
2702 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2706 _LOGD("Transaction Commit and End\n");
2708 pkgmgr_parser_close_db();
2712 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2714 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, GLOBAL_USER);
2717 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2720 _LOGD("manifest pointer is NULL\n");
2724 ret = pkgmgr_parser_check_and_create_db(uid);
2726 _LOGD("Failed to open DB\n");
2729 /*Begin transaction*/
2730 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2731 if (ret != SQLITE_OK) {
2732 _LOGD("Failed to begin transaction\n");
2736 _LOGD("Transaction Begin\n");
2737 ret = __delete_manifest_info_from_db(mfx, uid);
2739 _LOGD("Delete from DB failed. Rollback now\n");
2740 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2743 /*Commit transaction*/
2744 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2745 if (ret != SQLITE_OK) {
2746 _LOGD("Failed to commit transaction, Rollback now\n");
2747 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2751 _LOGD("Transaction Commit and End\n");
2753 pkgmgr_parser_close_db();
2757 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2759 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, GLOBAL_USER);
2762 API int pkgmgr_parser_update_preload_info_in_db()
2765 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2767 _LOGD("Failed to open DB\n");
2770 /*Begin transaction*/
2771 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2772 if (ret != SQLITE_OK) {
2773 _LOGD("Failed to begin transaction\n");
2777 _LOGD("Transaction Begin\n");
2778 ret = __update_preload_condition_in_db();
2780 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2781 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2784 /*Commit transaction*/
2785 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2786 if (ret != SQLITE_OK) {
2787 _LOGD("Failed to commit transaction, Rollback now\n");
2788 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2792 _LOGD("Transaction Commit and End\n");
2794 pkgmgr_parser_close_db();
2798 API int pkgmgr_parser_update_preload_info_in_usr_db(uid_t uid)
2801 ret = pkgmgr_parser_check_and_create_db(uid);
2803 _LOGD("Failed to open DB\n");
2806 /*Begin transaction*/
2807 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2808 if (ret != SQLITE_OK) {
2809 _LOGD("Failed to begin transaction\n");
2813 _LOGD("Transaction Begin\n");
2814 ret = __update_preload_condition_in_db();
2816 _LOGD("__update_preload_condition_in_db failed. Rollback now\n");
2817 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2820 /*Commit transaction*/
2821 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2822 if (ret != SQLITE_OK) {
2823 _LOGD("Failed to commit transaction, Rollback now\n");
2824 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2828 _LOGD("Transaction Commit and End\n");
2830 pkgmgr_parser_close_db();
2834 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2838 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2840 _LOGD("Failed to open DB\n");
2844 /*Begin transaction*/
2845 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2846 if (ret != SQLITE_OK) {
2847 _LOGD("Failed to begin transaction\n");
2851 _LOGD("Transaction Begin\n");
2853 ret = __disable_global_app_for_user(appid, uid);
2855 ret = __enable_global_app_for_user(appid, uid);
2857 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2858 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2861 /*Commit transaction*/
2862 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2863 if (ret != SQLITE_OK) {
2864 _LOGD("Failed to commit transaction, Rollback now\n");
2865 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2869 _LOGD("Transaction Commit and End\n");
2871 pkgmgr_parser_close_db();
2876 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2878 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, GLOBAL_USER, is_disable);
2881 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2885 ret = pkgmgr_parser_check_and_create_db(uid);
2887 _LOGD("Failed to open DB\n");
2891 /*Begin transaction*/
2892 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2893 if (ret != SQLITE_OK) {
2894 _LOGD("Failed to begin transaction\n");
2898 _LOGD("Transaction Begin\n");
2900 ret = __disable_app(appid);
2902 ret = __enable_app(appid);
2904 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2905 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2908 /*Commit transaction*/
2909 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2910 if (ret != SQLITE_OK) {
2911 _LOGD("Failed to commit transaction, Rollback now\n");
2912 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2916 _LOGD("Transaction Commit and End\n");
2918 pkgmgr_parser_close_db();