4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <sys/types.h>
28 #include <sys/smack.h>
37 #include <system_info.h>
39 /* For multi-user support */
40 #include <tzplatform_config.h>
42 #include "pkgmgr-info.h"
43 #include "pkgmgrinfo_basic.h"
44 #include "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
46 #include "pkgmgr_parser_debug.h"
48 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
49 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
50 #define MAX_QUERY_LEN 4096
53 #define MAX_INTEGER_LENGTH 10
59 #define XXHDPI "xxhdpi"
69 #define XXHDPI_MIN 481
70 #define XXHDPI_MAX 600
72 #define DB_LABEL "User::Home"
73 #define SET_SMACK_LABEL(x) \
75 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
76 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
78 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
81 sqlite3 *pkgmgr_parser_db;
82 sqlite3 *pkgmgr_cert_db;
85 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
86 "(package TEXT PRIMARY KEY NOT NULL, " \
87 "package_type TEXT DEFAULT 'tpk', " \
88 "package_version TEXT, " \
89 "package_api_version TEXT, " \
90 "package_tep_name TEXT, " \
91 "package_zip_mount_file TEXT, " \
92 "install_location TEXT NOT NULL , " \
93 "package_size TEXT, " \
94 "package_removable TEXT NOT NULL DEFAULT 'true', " \
95 "package_preload TEXT NOT NULL DEFAULT 'false', " \
96 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
97 "package_update TEXT NOT NULL DEFAULT 'false', " \
98 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
99 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
100 "package_system TEXT NOT NULL DEFAULT 'false', " \
101 "author_name TEXT, " \
102 "author_email TEXT, " \
103 "author_href TEXT," \
104 "installed_time TEXT, " \
105 "installed_storage TEXT, " \
106 "storeclient_id TEXT, " \
107 "mainapp_id TEXT, " \
108 "package_url TEXT, " \
110 "external_path TEXT, " \
112 "package_support_mode TEXT, " \
113 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
114 "package_disable TEXT NOT NULL 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 NOT NULL DEFAULT 'No Locale', " \
119 "package_label TEXT, " \
120 "package_icon TEXT, " \
121 "package_description TEXT, " \
122 "package_license TEXT, " \
123 "package_author 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 "type TEXT NOT NULL, " \
133 "PRIMARY KEY(package, privilege, type) " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
139 "(app_id TEXT PRIMARY KEY NOT NULL, " \
140 "app_component TEXT NOT NULL, " \
142 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
144 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
145 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
146 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
147 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
148 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
149 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
150 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
151 "app_mainapp TEXT NOT NULL, " \
152 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
153 "app_launchcondition TEXT, " \
154 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
155 "app_portraitimg TEXT, " \
156 "app_landscapeimg TEXT, " \
157 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
158 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
159 "app_preload TEXT NOT NULL DEFAULT 'false', " \
160 "app_submode TEXT NOT NULL DEFAULT 'false', " \
161 "app_submode_mainid TEXT, " \
162 "app_installed_storage TEXT NOT NULL, " \
163 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
164 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
165 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
166 "app_support_mode TEXT, " \
167 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_disable TEXT NOT NULL DEFAULT 'false', " \
169 "app_package_type TEXT DEFAULT 'tpk', " \
170 "app_package_system TEXT NOT NULL, " \
171 "app_removable TEXT NOT NULL DEFAULT 'false', " \
172 "app_package_installed_time TEXT, " \
173 "component_type TEXT, " \
174 "package TEXT NOT NULL, " \
175 "app_tep_name TEXT, " \
176 "app_zip_mount_file TEXT, " \
177 "app_background_category INTEGER DEFAULT 0, " \
178 "app_root_path TEXT, " \
179 "app_api_version TEXT, " \
180 "app_effective_appid TEXT, " \
181 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
182 "app_external_path TEXT, " \
183 "FOREIGN KEY(package) " \
184 "REFERENCES package_info(package) " \
187 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
188 "(app_id TEXT NOT NULL, " \
189 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
192 "PRIMARY KEY(app_id,app_locale) " \
193 "FOREIGN KEY(app_id) " \
194 "REFERENCES package_app_info(app_id) " \
197 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
198 "(app_id TEXT NOT NULL, " \
200 "app_icon_section TEXT NOT NULL, " \
201 "app_icon_resolution TEXT NOT NULL, " \
202 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
203 "FOREIGN KEY(app_id) " \
204 "REFERENCES package_app_info(app_id) " \
207 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
208 "(app_id TEXT NOT NULL, " \
209 "app_locale TEXT DEFAULT 'No Locale', " \
210 "app_image_section TEXT NOT NULL, " \
212 "PRIMARY KEY(app_id,app_image_section) " \
213 "FOREIGN KEY(app_id) " \
214 "REFERENCES package_app_info(app_id) " \
217 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
218 "(app_id TEXT NOT NULL, " \
219 "app_control TEXT NOT NULL, " \
220 "PRIMARY KEY(app_id,app_control) " \
221 "FOREIGN KEY(app_id) " \
222 "REFERENCES package_app_info(app_id) " \
225 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
226 "(app_id TEXT NOT NULL, " \
227 "category TEXT NOT NULL, " \
228 "PRIMARY KEY(app_id,category) " \
229 "FOREIGN KEY(app_id) " \
230 "REFERENCES package_app_info(app_id) " \
233 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
234 "(app_id TEXT NOT NULL, " \
235 "md_key TEXT NOT NULL, " \
237 "PRIMARY KEY(app_id, md_key, md_value) " \
238 "FOREIGN KEY(app_id) " \
239 "REFERENCES package_app_info(app_id) " \
242 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
243 "(app_id TEXT NOT NULL, " \
244 "pm_type TEXT NOT NULL, " \
245 "pm_value TEXT NOT NULL, " \
246 "PRIMARY KEY(app_id, pm_type, pm_value) " \
247 "FOREIGN KEY(app_id) " \
248 "REFERENCES package_app_info(app_id) " \
251 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
252 "(app_id TEXT NOT NULL, " \
253 "data_share_path TEXT NOT NULL, " \
254 "data_share_allowed TEXT NOT NULL, " \
255 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
256 "FOREIGN KEY(app_id) " \
257 "REFERENCES package_app_info(app_id) " \
260 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
261 "(app_id TEXT NOT NULL, " \
262 "data_share_request TEXT NOT NULL, " \
263 "PRIMARY KEY(app_id,data_share_request) " \
264 "FOREIGN KEY(app_id) " \
265 "REFERENCES package_app_info(app_id) " \
268 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
269 "(app_id TEXT NOT NULL, " \
270 "providerid TEXT NOT NULL, " \
271 "access TEXT NOT NULL, " \
272 "type TEXT NOT NULL, " \
273 "PRIMARY KEY(app_id, providerid, access, type) " \
274 "FOREIGN KEY(app_id) " \
275 "REFERENCES package_app_info(app_id) " \
278 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
279 "(app_id TEXT NOT NULL, " \
280 "uid INTEGER NOT NULL, " \
281 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
282 "is_splash_screen_enabled TEXT NOT NULL, " \
283 "PRIMARY KEY(app_id, uid))"
285 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
286 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
287 "AFTER UPDATE ON package_app_info_for_uid " \
289 " DELETE FROM package_app_info_for_uid WHERE " \
290 " is_splash_screen_enabled=" \
291 " (SELECT package_app_info.app_splash_screen_display FROM " \
292 " package_app_info, package_app_info_for_uid WHERE " \
293 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
296 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
297 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
298 "(app_id TEXT NOT NULL, " \
299 "src TEXT NOT NULL, " \
300 "type TEXT NOT NULL, " \
301 "orientation TEXT NOT NULL, " \
302 "indicatordisplay TEXT, " \
303 "operation TEXT NOT NULL, " \
304 "color_depth TEXT NOT NULL DEFAULT '24', " \
305 "PRIMARY KEY(app_id, orientation, operation) " \
306 "FOREIGN KEY(app_id) " \
307 "REFERENCES package_app_info(app_id) " \
311 /* FIXME: duplicated at pkgmgrinfo_db.c */
312 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
313 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
314 " cert_info TEXT UNIQUE, " \
315 " cert_id INTEGER PRIMARY KEY, " \
316 " cert_ref_count INTEGER NOT NULL)"
318 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
319 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
320 " package TEXT PRIMARY KEY, " \
321 " package_count INTEGER, " \
322 " author_root_cert INTEGER, " \
323 " author_im_cert INTEGER, " \
324 " author_signer_cert INTEGER, " \
325 " dist_root_cert INTEGER, " \
326 " dist_im_cert INTEGER, " \
327 " dist_signer_cert INTEGER, " \
328 " dist2_root_cert INTEGER, " \
329 " dist2_im_cert INTEGER, " \
330 " dist2_signer_cert INTEGER)"
332 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
333 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
334 "AFTER UPDATE ON package_cert_info " \
335 "WHEN (NEW.package_count = 0) " \
337 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
340 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
341 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
342 "AFTER UPDATE ON package_cert_info " \
343 "WHEN (NEW.package_count = OLD.package_count + 1) " \
345 " UPDATE package_cert_index_info SET" \
346 " cert_ref_count = cert_ref_count - 1" \
347 " WHERE cert_id = OLD.author_root_cert" \
348 " OR cert_id = OLD.author_im_cert" \
349 " OR cert_id = OLD.author_signer_cert" \
350 " OR cert_id = OLD.dist_root_cert" \
351 " OR cert_id = OLD.dist_im_cert" \
352 " OR cert_id = OLD.dist_signer_cert" \
353 " OR cert_id = OLD.dist2_root_cert" \
354 " OR cert_id = OLD.dist2_im_cert" \
355 " OR cert_id = OLD.dist2_signer_cert;" \
358 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
359 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
360 "AFTER DELETE ON package_cert_info " \
362 " UPDATE package_cert_index_info SET" \
363 " cert_ref_count = cert_ref_count - 1" \
364 " WHERE cert_id = OLD.author_root_cert" \
365 " OR cert_id = OLD.author_im_cert" \
366 " OR cert_id = OLD.author_signer_cert" \
367 " OR cert_id = OLD.dist_root_cert" \
368 " OR cert_id = OLD.dist_im_cert" \
369 " OR cert_id = OLD.dist_signer_cert" \
370 " OR cert_id = OLD.dist2_root_cert" \
371 " OR cert_id = OLD.dist2_im_cert" \
372 " OR cert_id = OLD.dist2_signer_cert;" \
375 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
376 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
377 "AFTER UPDATE ON package_cert_index_info " \
378 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
379 " WHERE cert_id = OLD.cert_id) = 0) "\
381 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
384 static int __insert_application_info(manifest_x *mfx);
385 static int __insert_application_appcategory_info(manifest_x *mfx);
386 static int __insert_application_appcontrol_info(manifest_x *mfx);
387 static int __insert_application_appmetadata_info(manifest_x *mfx);
388 static int __insert_application_share_allowed_info(manifest_x *mfx);
389 static int __insert_application_share_request_info(manifest_x *mfx);
390 static int __insert_application_datacontrol_info(manifest_x *mfx);
391 static void __insert_application_locale_info(gpointer data, gpointer userdata);
392 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
393 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
394 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
395 static int __delete_subpkg_info_from_db(char *appid);
396 static int __delete_appinfo_from_db(char *db_table, const char *appid);
397 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
398 static int __exec_query(char *query);
399 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
400 char **label, char **license, char **icon, char **description, char **author);
401 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
402 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
403 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
404 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
405 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
406 static int __parserdb_change_perm(const char *db_file, uid_t uid);
408 #define REGULAR_USER 5000
409 static inline uid_t _getuid(void)
411 uid_t uid = getuid();
413 if (uid < REGULAR_USER)
414 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
419 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
422 __delete_subpkg_info_from_db(coltxt[0]);
427 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
432 char *error_message = NULL;
434 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
435 if (ret != SQLITE_OK) {
436 _LOGD("connect db [%s] failed!\n", db_path);
441 /* add user_version for db upgrade*/
442 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
444 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
445 _LOGE("Don't execute query = %s error message = %s\n", query,
448 sqlite3_free(error_message);
454 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
456 manifest_x *mfx = (manifest_x *)data;
462 if (mfx->application == NULL)
464 app = (application_x *)mfx->application->data;
465 for (i = 0; i < ncols; i++) {
466 if (strcmp(colname[i], "app_id") == 0) {
468 appid = strdup(coltxt[i]);
469 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
471 status = strdup(coltxt[i]);
477 _LOGD("app id is NULL\n");
480 /*update guest mode visibility*/
481 for (tmp = mfx->application; tmp; tmp = tmp->next) {
482 app = (application_x *)tmp->data;
485 if (strcmp(app->appid, appid) == 0) {
486 free((void *)app->guestmode_visibility);
487 app->guestmode_visibility = strdup(status);
503 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
505 char *error_message = NULL;
506 char query[MAX_QUERY_LEN] = {'\0'};
507 sqlite3_snprintf(MAX_QUERY_LEN, query,
508 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
509 "WHERE package=%Q", mfx->package);
511 sqlite3_exec(pkgmgr_parser_db, query,
512 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
513 _LOGD("Don't execute query = %s error message = %s\n",
514 query, error_message);
515 sqlite3_free(error_message);
520 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
522 char *error_message = NULL;
524 sqlite3_exec(db_handle, db_query,
525 NULL, NULL, &error_message)) {
526 _LOGD("Don't execute query = %s error message = %s\n",
527 db_query, error_message);
528 sqlite3_free(error_message);
531 sqlite3_free(error_message);
535 static int __exec_query(char *query)
537 char *error_message = NULL;
539 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
540 _LOGE("Don't execute query = %s error message = %s\n", query,
542 sqlite3_free(error_message);
545 sqlite3_free(error_message);
549 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
557 for (tmp = lbls; tmp; tmp = tmp->next) {
558 lbl = (label_x *)tmp->data;
562 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
564 for (tmp = lcns; tmp; tmp = tmp->next) {
565 lcn = (license_x *)tmp->data;
569 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
571 for (tmp = icns; tmp; tmp = tmp->next) {
572 icn = (icon_x *)tmp->data;
576 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
578 for (tmp = dcns; tmp; tmp = tmp->next) {
579 dcn = (description_x *)tmp->data;
583 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
585 for (tmp = aths; tmp; tmp = tmp->next) {
586 ath = (author_x *)tmp->data;
590 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
596 static GList *__create_icon_list(GList *appicon, GList *icns)
601 for (tmp = icns; tmp; tmp = tmp->next) {
602 icn = (icon_x *)tmp->data;
606 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
611 static GList *__create_image_list(GList *appimage, GList *imgs)
616 for (tmp = imgs; tmp; tmp = tmp->next) {
617 img = (image_x *)tmp->data;
621 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
626 static void __trimfunc(GList *trim_list)
628 char *trim_data = NULL;
632 list = g_list_first(trim_list);
635 trim_data = (char *)list->data;
638 if (strcmp(trim_data, prev) == 0) {
639 trim_list = g_list_remove(trim_list, trim_data);
640 list = g_list_first(trim_list);
649 list = g_list_next(list);
653 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
655 if (a == NULL || b == NULL)
657 if (strcmp((char *)a, (char *)b) == 0)
659 if (strcmp((char *)a, (char *)b) < 0)
661 if (strcmp((char *)a, (char *)b) > 0)
666 static int __check_dpi(const char *dpi_char, int dpi_int)
668 if (dpi_char == NULL)
671 if (strcasecmp(dpi_char, LDPI) == 0) {
672 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
676 } else if (strcasecmp(dpi_char, MDPI) == 0) {
677 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
681 } else if (strcasecmp(dpi_char, HDPI) == 0) {
682 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
686 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
687 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
691 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
692 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
700 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
703 char *icon_filename = NULL;
704 char modified_iconpath[BUFSIZE] = { '\0' };
705 char icon_path[BUFSIZE] = { '\0' };
709 if (orig_icon_path == NULL)
712 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
716 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
717 dpi_path[0] = "LDPI";
718 dpi_path[1] = "ldpi";
719 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
720 dpi_path[0] = "MDPI";
721 dpi_path[1] = "mdpi";
722 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
723 dpi_path[0] = "HDPI";
724 dpi_path[1] = "hdpi";
725 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
726 dpi_path[0] = "XHDPI";
727 dpi_path[1] = "xhdpi";
728 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
729 dpi_path[0] = "XXHDPI";
730 dpi_path[1] = "xxhdpi";
732 _LOGE("Unidentified dpi[%d]", dpi);
736 icon_filename = strrchr(orig_icon_path, '/');
737 if (icon_filename == NULL)
740 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
741 for (i = 0; i < 2; i++) {
742 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
743 if (access(modified_iconpath, F_OK) != -1) {
744 /* if exists, return modified icon path */
745 *new_icon_path = strdup(modified_iconpath);
753 static gint __compare_icon(gconstpointer a, gconstpointer b)
755 icon_x *icon = (icon_x *)a;
757 char *icon_folder_path = NULL;
759 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
762 if (icon->dpi != NULL)
765 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
767 icon->text = icon_folder_path;
773 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
775 icon_x *icon = (icon_x *)a;
776 int dpi = GPOINTER_TO_INT(b);
778 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
781 if (icon->dpi == NULL)
784 if (__check_dpi(icon->dpi, dpi) == 0)
790 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
792 icon_x *icon = (icon_x *)a;
793 char *lang = (char *)b;
794 char *icon_folder_path = NULL;
796 if (icon->dpi != NULL)
799 if (strcasecmp(icon->lang, lang) == 0) {
800 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
801 /* icon for no locale. check existance of folder-hierachied default icons */
802 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
804 icon->text = icon_folder_path;
813 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
815 icon_x *icon = (icon_x *)a;
816 char *lang = (char *)b;
819 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
823 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
829 static char *__find_icon(GList *icons, const char *lang)
836 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
837 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
839 icon = (icon_x *)tmp->data;
840 return (char *)icon->text;
843 /* if first has failed, find icon whose locale has matched */
844 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
846 icon = (icon_x *)tmp->data;
847 return (char *)icon->text;
850 /* if second has failed, find icon whose dpi has matched with system's dpi */
851 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
852 if (ret == SYSTEM_INFO_ERROR_NONE) {
853 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
855 icon = (icon_x *)tmp->data;
856 return (char *)icon->text;
860 /* last, find default icon marked as "No Locale" */
861 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
863 icon = (icon_x *)tmp->data;
864 return (char *)icon->text;
870 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
871 char **label, char **license, char **icon, char **description, char **author)
878 for (tmp = lbls; tmp; tmp = tmp->next) {
879 lbl = (label_x *)tmp->data;
883 if (strcmp(lbl->lang, (char *)data) == 0) {
884 *label = (char *)lbl->text;
889 for (tmp = lcns; tmp; tmp = tmp->next) {
890 lcn = (license_x *)tmp->data;
894 if (strcmp(lcn->lang, (char *)data) == 0) {
895 *license = (char *)lcn->text;
901 *icon = __find_icon(icns, (char *)data);
903 for (tmp = dcns; tmp; tmp = tmp->next) {
904 dcn = (description_x *)tmp->data;
908 if (strcmp(dcn->lang, (char *)data) == 0) {
909 *description = (char *)dcn->text;
914 for (tmp = aths; tmp; tmp = tmp->next) {
915 ath = (author_x *)tmp->data;
919 if (strcmp(ath->lang, (char *)data) == 0) {
920 *author = (char *)ath->text;
928 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
932 for (tmp = icns; tmp; tmp = tmp->next) {
933 icn = (icon_x *)tmp->data;
937 if (strcmp(icn->section, (char *)data) == 0) {
938 *icon = (char *)icn->text;
939 *resolution = (char *)icn->resolution;
946 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
950 for (tmp = imgs; tmp; tmp = tmp->next) {
951 img = (image_x *)tmp->data;
955 if (strcmp(img->section, (char *)data) == 0) {
956 *lang = (char *)img->lang;
957 *image = (char *)img->text;
964 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
969 char *description = NULL;
970 char *license = NULL;
974 manifest_x *mfx = (manifest_x *)userdata;
975 GList *lbl = mfx->label;
976 GList *lcn = mfx->license;
977 GList *icn = mfx->icon;
978 GList *dcn = mfx->description;
979 GList *ath = mfx->author;
981 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
982 if (!label && !description && !icon && !license && !author)
985 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
986 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
987 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
996 ret = __exec_query(query);
998 _LOGD("Package Localized Info DB Insert failed\n");
1000 sqlite3_free(query);
1003 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1009 char *locale = (char *)data;
1011 application_x *app = (application_x *)userdata;
1012 GList *lbl = app->label;
1013 GList *icn = app->icon;
1015 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1016 if (!label && !icon)
1019 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1020 "app_label, app_icon) VALUES" \
1021 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1023 ret = __exec_query(query);
1025 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1027 sqlite3_free(query);
1029 /*insert ui app locale info to pkg locale to get mainapp data */
1030 if (strcasecmp(app->mainapp, "true") == 0) {
1031 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1032 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1034 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1035 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1036 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1037 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1038 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1039 app->package, locale,
1040 app->package, locale, label,
1041 app->package, locale, icon,
1042 app->package, locale,
1043 app->package, locale,
1044 app->package, locale);
1046 ret = __exec_query(query);
1048 _LOGE("Package Localized Info DB Insert failed");
1049 sqlite3_free(query);
1053 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1057 char *resolution = NULL;
1058 char query[MAX_QUERY_LEN] = {'\0'};
1060 application_x *app = (application_x *)userdata;
1061 GList *icn = app->icon;
1063 __extract_icon_data(data, icn, &icon, &resolution);
1064 if (!icon && !resolution)
1066 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1067 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1068 "(%Q, %Q, %Q, %Q)", app->appid,
1069 icon, (char *)data, resolution);
1071 ret = __exec_query(query);
1073 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1077 static void __insert_application_image_info(gpointer data, gpointer userdata)
1082 char query[MAX_QUERY_LEN] = {'\0'};
1084 application_x *app = (application_x *)userdata;
1085 GList *image = app->image;
1087 __extract_image_data(data, image, &lang, &img);
1090 sqlite3_snprintf(MAX_QUERY_LEN, query,
1091 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1092 "app_image_section, app_image) VALUES" \
1093 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1095 ret = __exec_query(query);
1097 _LOGD("Package UiApp image Info DB Insert failed\n");
1102 static int __insert_mainapp_info(manifest_x *mfx)
1107 char query[MAX_QUERY_LEN] = {'\0'};
1108 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1109 app = (application_x *)tmp->data;
1113 sqlite3_snprintf(MAX_QUERY_LEN, query,
1114 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1115 app->mainapp, app->appid);
1116 ret = __exec_query(query);
1118 _LOGD("Package App Info DB Insert Failed\n");
1121 if (strcasecmp(app->mainapp, "True") == 0)
1122 mfx->mainapp_id = strdup(app->appid);
1125 if (mfx->mainapp_id == NULL) {
1126 if (mfx->application == NULL)
1128 app = (application_x *)mfx->application->data;
1132 sqlite3_snprintf(MAX_QUERY_LEN, query,
1133 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1136 _LOGD("Not valid appid\n");
1140 ret = __exec_query(query);
1142 _LOGD("Package UiApp Info DB Insert Failed\n");
1146 free((void *)app->mainapp);
1147 app->mainapp = strdup("true");
1148 mfx->mainapp_id = strdup(app->appid);
1151 memset(query, '\0', MAX_QUERY_LEN);
1152 sqlite3_snprintf(MAX_QUERY_LEN, query,
1153 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1154 ret = __exec_query(query);
1156 _LOGD("Package Info DB update Failed\n");
1163 static int __convert_background_category(GList *category_list)
1166 GList *tmp_list = category_list;
1167 char *category_data = NULL;
1169 if (category_list == NULL)
1172 while (tmp_list != NULL) {
1173 category_data = (char *)tmp_list->data;
1174 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1175 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1176 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1177 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1178 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1179 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1180 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1181 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1182 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1183 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1184 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1185 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1186 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1187 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1189 _LOGE("Unidentified category [%s]", category_data);
1190 tmp_list = g_list_next(tmp_list);
1196 static const char *__find_effective_appid(GList *metadata_list)
1201 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1202 md = (metadata_x *)tmp_list->data;
1203 if (md == NULL || md->key == NULL)
1206 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1215 static char *__get_bool(char *value, bool is_true)
1217 if (value != NULL) {
1218 if (!strcmp(value, ""))
1219 return (is_true) ? "true" : "false";
1223 return (is_true) ? "true" : "false";
1226 /* _PRODUCT_LAUNCHING_ENHANCED_
1227 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1229 static int __insert_application_info(manifest_x *mfx)
1234 int background_value = 0;
1235 char query[MAX_QUERY_LEN] = {'\0'};
1237 const char *effective_appid;
1240 type = strdup(mfx->type);
1242 type = strdup("tpk");
1244 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1245 app = (application_x *)tmp->data;
1249 background_value = __convert_background_category(app->background_category);
1250 if (background_value < 0) {
1251 _LOGE("Failed to retrieve background value[%d]", background_value);
1252 background_value = 0;
1255 effective_appid = __find_effective_appid(app->metadata);
1257 sqlite3_snprintf(MAX_QUERY_LEN, query,
1258 "INSERT INTO package_app_info(" \
1259 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1260 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1261 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1262 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1263 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1264 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1265 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1266 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1267 "app_package_installed_time) " \
1269 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1270 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1271 "%Q, %Q, %Q, %Q, %Q, " \
1272 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1273 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1274 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1275 "%Q, %Q, %d, %Q, %Q, " \
1276 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1278 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1279 __get_bool(app->onboot, false), __get_bool(app->multiple, false), __get_bool(app->autorestart, false), __get_bool(app->taskmanage, false), __get_bool(app->enabled, true),
1280 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1281 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1282 __get_bool(app->guestmode_visibility, true), app->permission_type,
1283 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1284 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1285 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1286 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true), mfx->installed_time);
1288 ret = __exec_query(query);
1290 _LOGD("Package UiApp Info DB Insert Failed\n");
1295 memset(query, '\0', MAX_QUERY_LEN);
1304 static int __insert_application_appcategory_info(manifest_x *mfx)
1311 char query[MAX_QUERY_LEN] = {'\0'};
1312 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1313 app = (application_x *)app_tmp->data;
1316 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1317 ct = (const char *)ct_tmp->data;
1320 sqlite3_snprintf(MAX_QUERY_LEN, query,
1321 "INSERT INTO package_app_app_category(app_id, category) " \
1324 ret = __exec_query(query);
1326 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1329 memset(query, '\0', MAX_QUERY_LEN);
1335 static int __insert_application_appmetadata_info(manifest_x *mfx)
1342 char query[MAX_QUERY_LEN] = {'\0'};
1343 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1344 app = (application_x *)app_tmp->data;
1347 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1348 md = (metadata_x *)md_tmp->data;
1352 sqlite3_snprintf(MAX_QUERY_LEN, query,
1353 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1354 "VALUES(%Q, %Q, %Q)",\
1355 app->appid, md->key, md->value ? md->value : NULL);
1356 ret = __exec_query(query);
1358 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1362 memset(query, '\0', MAX_QUERY_LEN);
1368 static int __insert_application_apppermission_info(manifest_x *mfx)
1375 char query[MAX_QUERY_LEN] = {'\0'};
1376 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1377 app = (application_x *)app_tmp->data;
1380 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1381 pm = (permission_x *)pm_tmp->data;
1384 sqlite3_snprintf(MAX_QUERY_LEN, query,
1385 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1386 "VALUES(%Q, %Q, %Q)",\
1387 app->appid, pm->type, pm->value);
1388 ret = __exec_query(query);
1390 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1393 memset(query, '\0', MAX_QUERY_LEN);
1399 static int __insert_application_appcontrol_info(manifest_x *mfx)
1403 GList *acontrol_tmp;
1404 appcontrol_x *acontrol;
1406 char query[MAX_QUERY_LEN] = {'\0'};
1407 char buf[BUFSIZE] = {'\0'};
1408 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1409 app = (application_x *)app_tmp->data;
1412 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1413 acontrol = (appcontrol_x *)acontrol_tmp->data;
1414 if (acontrol == NULL)
1416 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1417 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1418 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1419 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1420 sqlite3_snprintf(MAX_QUERY_LEN, query,
1421 "INSERT INTO package_app_app_control(app_id, app_control) " \
1424 ret = __exec_query(query);
1426 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1429 memset(query, '\0', MAX_QUERY_LEN);
1435 static int __insert_application_datacontrol_info(manifest_x *mfx)
1442 char query[MAX_QUERY_LEN] = {'\0'};
1444 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1445 app = (application_x *)app_tmp->data;
1448 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1449 dc = (datacontrol_x *)dc_tmp->data;
1452 sqlite3_snprintf(MAX_QUERY_LEN, query,
1453 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1454 "VALUES(%Q, %Q, %Q, %Q)",\
1460 ret = __exec_query(query);
1462 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1465 memset(query, '\0', MAX_QUERY_LEN);
1471 static int __insert_application_share_request_info(manifest_x *mfx)
1480 char query[MAX_QUERY_LEN] = {'\0'};
1481 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1482 app = (application_x *)app_tmp->data;
1485 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1486 ds = (datashare_x *)ds_tmp->data;
1489 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1490 rq = (const char *)rq_tmp->data;
1493 sqlite3_snprintf(MAX_QUERY_LEN, query,
1494 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1497 ret = __exec_query(query);
1499 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1502 memset(query, '\0', MAX_QUERY_LEN);
1509 static int __insert_application_share_allowed_info(manifest_x *mfx)
1520 char query[MAX_QUERY_LEN] = {'\0'};
1521 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1522 app = (application_x *)app_tmp->data;
1525 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1526 ds = (datashare_x *)ds_tmp->data;
1529 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1530 df = (define_x *)df_tmp->data;
1533 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1534 al = (const char *)al_tmp->data;
1537 sqlite3_snprintf(MAX_QUERY_LEN, query,
1538 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1539 "VALUES(%Q, %Q, %Q)",\
1540 app->appid, df->path, al);
1541 ret = __exec_query(query);
1543 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1546 memset(query, '\0', MAX_QUERY_LEN);
1554 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1556 splashscreen_x *ss = (splashscreen_x *)a;
1557 const char *orientation = (const char *)b;
1560 if (ss->operation || ss->dpi == NULL)
1563 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1567 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1573 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1575 splashscreen_x *ss = (splashscreen_x *)a;
1576 const char *orientation = (const char *)b;
1578 if (ss->operation || ss->dpi)
1581 if (strcasecmp(ss->orientation, orientation) == 0)
1587 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1588 const char *orientation)
1592 tmp = g_list_find_custom(splashscreens, orientation,
1593 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1595 return (splashscreen_x *)tmp->data;
1597 tmp = g_list_find_custom(splashscreens, orientation,
1598 (GCompareFunc)__compare_splashscreen_with_orientation);
1600 return (splashscreen_x *)tmp->data;
1605 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1607 splashscreen_x *ss = (splashscreen_x *)data;
1608 GList **list = (GList **)user_data;
1611 if (ss->operation == NULL || ss->dpi == NULL)
1614 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1618 if (__check_dpi(ss->dpi, dpi) != 0)
1621 *list = g_list_append(*list, ss);
1624 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1626 splashscreen_x *ss = (splashscreen_x *)data;
1627 GList **list = (GList **)user_data;
1628 splashscreen_x *ss_tmp;
1631 if (ss->operation == NULL || ss->dpi)
1634 for (tmp = *list; tmp; tmp = tmp->next) {
1635 ss_tmp = (splashscreen_x *)tmp->data;
1636 if (ss_tmp->operation
1637 && strcmp(ss_tmp->operation, ss->operation) == 0
1638 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1642 *list = g_list_append(*list, ss);
1645 static GList *__find_splashscreens(GList *splashscreens)
1650 g_list_foreach(splashscreens,
1651 __find_appcontrol_splashscreen_with_dpi, &list);
1652 g_list_foreach(splashscreens,
1653 __find_appcontrol_splashscreen, &list);
1655 ss = __find_default_splashscreen(splashscreens, "portrait");
1657 list = g_list_append(list, ss);
1658 ss = __find_default_splashscreen(splashscreens, "landscape");
1660 list = g_list_append(list, ss);
1665 static int __insert_application_splashscreen_info(manifest_x *mfx)
1673 char query[MAX_QUERY_LEN] = {'\0'};
1675 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1676 app = (application_x *)app_tmp->data;
1677 if (app == NULL || app->splashscreens == NULL)
1680 ss_tmp = __find_splashscreens(app->splashscreens);
1684 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1685 ss = (splashscreen_x *)tmp->data;
1686 sqlite3_snprintf(MAX_QUERY_LEN, query,
1687 "INSERT INTO package_app_splash_screen" \
1688 "(app_id, src, type, orientation, indicatordisplay, " \
1689 "operation, color_depth) " \
1690 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1691 app->appid, ss->src, ss->type, ss->orientation,
1692 ss->indicatordisplay, ss->operation,
1695 ret = __exec_query(query);
1697 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1700 memset(query, '\0', MAX_QUERY_LEN);
1702 g_list_free(ss_tmp);
1707 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1712 char query[MAX_QUERY_LEN] = {'\0'};
1714 const char *image_type;
1715 const char *indicatordisplay;
1716 const char *orientation;
1717 const char *operation = "launch-effect";
1718 const char *color_depth = "24"; /* default */
1720 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1721 app = (application_x *)app_tmp->data;
1723 (app->portraitimg == NULL && app->landscapeimg == NULL))
1725 image_type = "img"; /* default */
1726 if (app->effectimage_type) {
1727 tmp = strstr(app->effectimage_type, "edj");
1731 indicatordisplay = "true"; /* default */
1732 if (app->indicatordisplay)
1733 indicatordisplay = app->indicatordisplay;
1734 if (app->portraitimg) {
1735 orientation = "portrait";
1736 sqlite3_snprintf(MAX_QUERY_LEN, query,
1737 "INSERT INTO package_app_splash_screen" \
1738 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1739 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1740 app->appid, app->portraitimg, image_type,
1741 orientation, indicatordisplay, operation,
1743 ret = __exec_query(query);
1745 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1748 memset(query, '\0', MAX_QUERY_LEN);
1750 if (app->landscapeimg) {
1751 orientation = "landscape";
1752 sqlite3_snprintf(MAX_QUERY_LEN, query,
1753 "INSERT INTO package_app_splash_screen" \
1754 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1755 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1756 app->appid, app->landscapeimg, image_type,
1757 orientation, indicatordisplay, operation,
1759 ret = __exec_query(query);
1761 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1764 memset(query, '\0', MAX_QUERY_LEN);
1770 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1777 char query[MAX_QUERY_LEN] = {'\0'};
1779 char *tmpptr = NULL;
1780 const char *operation;
1781 const char *portraitimg;
1782 const char *landscapeimg;
1783 const char *indicatordisplay;
1784 const char *orientation;
1785 const char *image_type;
1786 const char *color_depth = "24"; /* default */
1788 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1789 app = (application_x *)app_tmp->data;
1793 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1794 md = (metadata_x *)md_tmp->data;
1795 if (md == NULL || md->key == NULL || md->value == NULL)
1798 if (strcasestr(md->key, "operation_effect=")) {
1799 operation = index(md->key, '=');
1800 if (operation && operation[1] != '\0')
1803 operation = "launch-effect";
1804 } else if (strcasestr(md->key, "launch_effect")) {
1805 operation = "launch-effect";
1811 landscapeimg = NULL;
1812 indicatordisplay = "true"; /* default */
1813 token = strtok_r(md->value, "|", &tmpptr);
1814 while (token != NULL) {
1815 if (strcasestr(token, "portrait-effectimage=")) {
1816 portraitimg = index(token, '=');
1817 if (portraitimg && portraitimg[1] != '\0')
1821 } else if (strcasestr(token, "landscape-effectimage=")) {
1822 landscapeimg = index(token, '=');
1823 if (landscapeimg && landscapeimg[1] != '\0')
1826 landscapeimg = NULL;
1827 } else if (strcasestr(token, "indicatordisplay=")) {
1828 indicatordisplay = index(token, '=');
1829 if (indicatordisplay && indicatordisplay[1] != '\0')
1832 indicatordisplay = "true";
1835 token = strtok_r(NULL, "|", &tmpptr);
1839 orientation = "portrait";
1841 if (strcasestr(portraitimg, "edj"))
1843 sqlite3_snprintf(MAX_QUERY_LEN, query,
1844 "INSERT INTO package_app_splash_screen" \
1845 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1846 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1847 app->appid, portraitimg, image_type,
1848 orientation, indicatordisplay, operation,
1850 ret = __exec_query(query);
1852 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1855 memset(query, '\0', MAX_QUERY_LEN);
1858 orientation = "landscape";
1860 if (strcasestr(landscapeimg, "edj"))
1862 sqlite3_snprintf(MAX_QUERY_LEN, query,
1863 "INSERT INTO package_app_splash_screen" \
1864 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1865 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1866 app->appid, landscapeimg, image_type,
1867 orientation, indicatordisplay, operation,
1869 ret = __exec_query(query);
1871 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1874 memset(query, '\0', MAX_QUERY_LEN);
1882 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1886 privilege_x *pv = NULL;
1887 char query[MAX_QUERY_LEN] = { '\0' };
1890 const char *auth_name = NULL;
1891 const char *auth_email = NULL;
1892 const char *auth_href = NULL;
1894 GList *pkglocale = NULL;
1895 GList *applocale = NULL;
1896 GList *appicon = NULL;
1897 GList *appimage = NULL;
1899 int temp_pkg_mode = 0;
1900 int temp_app_mode = 0;
1901 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1902 application_x *up_support_mode = NULL;
1903 GList *list_up = NULL;
1905 if (mfx->author && mfx->author->data) {
1906 author = (author_x *)mfx->author->data;
1908 auth_name = author->text;
1910 auth_email = author->email;
1912 auth_href = author->href;
1915 if (mfx->support_mode)
1916 temp_pkg_mode = atoi(mfx->support_mode);
1918 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1919 list_up = mfx->application;
1920 while (list_up != NULL) {
1921 up_support_mode = (application_x *)list_up->data;
1922 if (up_support_mode->support_mode) {
1923 temp_app_mode = atoi(up_support_mode->support_mode);
1924 temp_pkg_mode |= temp_app_mode;
1926 list_up = list_up->next;
1928 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1930 if (mfx->support_mode)
1931 free((void *)mfx->support_mode);
1932 mfx->support_mode = strdup(pkg_mode);
1934 /*Insert in the package_info DB*/
1935 sqlite3_snprintf(MAX_QUERY_LEN, query,
1936 "INSERT INTO package_info(" \
1937 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1938 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1939 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1940 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1941 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1943 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1944 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1945 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1946 "%Q, %Q, %Q, %Q, %Q, " \
1947 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1948 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1949 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1950 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1951 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1952 mfx->storeclient_id,
1953 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1955 ret = __exec_query(query);
1957 _LOGD("Package Info DB Insert Failed\n");
1961 /*Insert in the package_privilege_info DB*/
1962 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1963 pv = (privilege_x *)tmp->data;
1966 memset(query, '\0', MAX_QUERY_LEN);
1967 sqlite3_snprintf(MAX_QUERY_LEN, query,
1968 "INSERT INTO package_privilege_info(package, privilege, type) " \
1969 "VALUES(%Q, %Q, %Q)",\
1970 mfx->package, pv->value, pv->type);
1971 ret = __exec_query(query);
1973 _LOGD("Package Privilege Info DB Insert Failed\n");
1978 if (mfx->application != NULL) {
1979 ret = __insert_mainapp_info(mfx);
1984 /*Insert the package locale*/
1985 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1986 /*remove duplicated data in pkglocale*/
1987 __trimfunc(pkglocale);
1989 /*Insert the app locale, icon, image info */
1990 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1991 app = (application_x *)tmp->data;
1994 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1995 appicon = __create_icon_list(appicon, app->icon);
1996 appimage = __create_image_list(appimage, app->image);
1998 /*remove duplicated data in applocale*/
1999 __trimfunc(applocale);
2000 __trimfunc(appicon);
2001 __trimfunc(appimage);
2003 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
2005 /*native app locale info*/
2006 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2007 app = (application_x *)tmp->data;
2010 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
2011 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
2012 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
2015 g_list_free(pkglocale);
2017 g_list_free(applocale);
2019 g_list_free(appicon);
2021 g_list_free(appimage);
2024 /*Insert in the package_app_info DB*/
2025 ret = __insert_application_info(mfx);
2028 /*Insert in the package_app_app_control DB*/
2029 ret = __insert_application_appcontrol_info(mfx);
2033 /*Insert in the package_app_app_category DB*/
2034 ret = __insert_application_appcategory_info(mfx);
2038 /*Insert in the package_app_app_metadata DB*/
2039 ret = __insert_application_appmetadata_info(mfx);
2043 /*Insert in the package_app_app_permission DB*/
2044 ret = __insert_application_apppermission_info(mfx);
2048 /*Insert in the package_app_share_allowed DB*/
2049 ret = __insert_application_share_allowed_info(mfx);
2053 /*Insert in the package_app_share_request DB*/
2054 ret = __insert_application_share_request_info(mfx);
2058 /*Insert in the package_app_data_control DB*/
2059 ret = __insert_application_datacontrol_info(mfx);
2063 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2064 ret = __insert_application_legacy_splashscreen_info(mfx);
2068 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2069 ret = __insert_application_metadata_splashscreen_info(mfx);
2073 /*Insert in the package_app_splash_screen DB*/
2074 ret = __insert_application_splashscreen_info(mfx);
2082 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2084 char query[MAX_QUERY_LEN] = { '\0' };
2087 sqlite3_snprintf(MAX_QUERY_LEN, query,
2088 "DELETE FROM %q where app_id=%Q", db_table, appid);
2089 ret = __exec_query(query);
2091 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2097 static int __delete_subpkg_info_from_db(char *appid)
2101 ret = __delete_appinfo_from_db("package_app_info", appid);
2104 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2107 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2110 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2113 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2116 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2119 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2122 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2125 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2128 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2131 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2134 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2141 static int __delete_subpkg_from_db(manifest_x *mfx)
2143 char query[MAX_QUERY_LEN] = { '\0' };
2144 char *error_message = NULL;
2146 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2148 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2149 _LOGE("Don't execute query = %s error message = %s\n", query,
2151 sqlite3_free(error_message);
2154 sqlite3_free(error_message);
2159 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2161 char query[MAX_QUERY_LEN] = { '\0' };
2166 /*Delete from Package Info DB*/
2167 sqlite3_snprintf(MAX_QUERY_LEN, query,
2168 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2169 ret = __exec_query(query);
2171 _LOGD("Package Info DB Delete Failed\n");
2174 memset(query, '\0', MAX_QUERY_LEN);
2176 /*Delete from Package Localized Info*/
2177 sqlite3_snprintf(MAX_QUERY_LEN, query,
2178 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2179 ret = __exec_query(query);
2181 _LOGD("Package Localized Info DB Delete Failed\n");
2185 /*Delete from Package Privilege Info*/
2186 sqlite3_snprintf(MAX_QUERY_LEN, query,
2187 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2188 ret = __exec_query(query);
2190 _LOGD("Package Privilege Info DB Delete Failed\n");
2194 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2195 app = (application_x *)tmp->data;
2198 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2201 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2204 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2207 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2210 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2213 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2216 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2219 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2222 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2225 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2228 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2231 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2236 /* if main package has sub pkg, delete sub pkg data*/
2237 __delete_subpkg_from_db(mfx);
2242 static int __disable_app(const char *appid)
2245 char query[MAX_QUERY_LEN] = {'\0'};
2246 sqlite3_snprintf(MAX_QUERY_LEN, query,
2247 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2249 ret = __exec_query(query);
2251 _LOGD("Insert global app disable failed\n");
2256 static int __enable_app(const char *appid)
2259 char query[MAX_QUERY_LEN] = {'\0'};
2260 sqlite3_snprintf(MAX_QUERY_LEN, query,
2261 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2263 ret = __exec_query(query);
2265 _LOGD("Insert global app disable failed\n");
2270 static int __disable_pkg(const char *pkgid)
2273 char query[MAX_QUERY_LEN] = {'\0'};
2274 sqlite3_snprintf(MAX_QUERY_LEN, query,
2275 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2277 ret = __exec_query(query);
2279 _LOGD("Update pkg disable info has failed\n");
2284 static int __enable_pkg(const char *pkgid)
2287 char query[MAX_QUERY_LEN] = {'\0'};
2288 sqlite3_snprintf(MAX_QUERY_LEN, query,
2289 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2291 ret = __exec_query(query);
2293 _LOGD("Update pkg disable info has failed\n");
2298 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2301 char query[MAX_QUERY_LEN] = { '\0', };
2303 const char *val = NULL;
2308 sqlite3_snprintf(MAX_QUERY_LEN, query,
2309 "SELECT COUNT(*) FROM "
2310 "package_app_info_for_uid WHERE app_id=%Q "
2311 "AND uid=%d", appid, (int)uid);
2313 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2314 if (ret != SQLITE_OK) {
2315 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2316 return PMINFO_R_ERROR;
2319 if (sqlite3_step(stmt) != SQLITE_ROW) {
2320 LOGE("failed to step");
2321 sqlite3_finalize(stmt);
2322 return PMINFO_R_ERROR;
2325 val = (const char *)sqlite3_column_text(stmt, 0);
2327 sqlite3_finalize(stmt);
2332 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2335 char query[MAX_QUERY_LEN] = { '\0', };
2337 ret = __check_appinfo_for_uid_table(appid, uid);
2339 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2342 } else if (ret == 0) {
2343 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2344 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2345 "VALUES(%Q, %d, 'true', "
2346 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2347 appid, (int)uid, appid);
2349 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2350 "package_app_info_for_uid SET is_disabled='true' "
2351 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2354 ret = __exec_query(query);
2356 _LOGD("Add global app disable info failed\n");
2361 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2364 char query[MAX_QUERY_LEN] = {'\0'};
2366 ret = __check_appinfo_for_uid_table(appid, uid);
2368 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2371 } else if (ret > 0) {
2372 sqlite3_snprintf(MAX_QUERY_LEN, query,
2373 "UPDATE package_app_info_for_uid SET "
2374 "is_disabled='false' WHERE app_id=%Q AND "
2375 "uid=%d", appid, (int)uid);
2378 ret = __exec_query(query);
2380 _LOGD("Remove global app disable info failed\n");
2385 static int __update_global_app_splash_screen_for_user(const char *appid,
2386 uid_t uid, int flag)
2389 char query[MAX_QUERY_LEN] = { '\0', };
2391 ret = __check_appinfo_for_uid_table(appid, uid);
2393 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2396 } else if (ret == 0) {
2397 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2398 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2399 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2400 flag ? "true" : "false");
2402 sqlite3_snprintf(MAX_QUERY_LEN, query,
2403 "UPDATE package_app_info_for_uid SET "
2404 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2405 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2408 ret = __exec_query(query);
2410 _LOGD("update global app splash screen info failed\n");
2415 static int __disable_app_splash_screen(const char *appid)
2418 char query[MAX_QUERY_LEN] = {'\0'};
2420 sqlite3_snprintf(MAX_QUERY_LEN, query,
2421 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2423 ret = __exec_query(query);
2425 _LOGD("Failed to update app_palsh_screen_display");
2430 static int __enable_app_splash_screen(const char *appid)
2433 char query[MAX_QUERY_LEN] = {'\0'};
2435 sqlite3_snprintf(MAX_QUERY_LEN, query,
2436 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2438 ret = __exec_query(query);
2440 _LOGD("Failed to update app_splash_screen_display");
2445 API int pkgmgr_parser_initialize_db(uid_t uid)
2451 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2453 _LOGD("package info DB initialization failed\n");
2456 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2458 _LOGD("package localized info DB initialization failed\n");
2461 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2463 _LOGD("package app app privilege DB initialization failed\n");
2466 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2468 _LOGD("package app info DB initialization failed\n");
2471 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2473 _LOGD("package app localized info DB initialization failed\n");
2476 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2478 _LOGD("package app icon localized info DB initialization failed\n");
2481 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2483 _LOGD("package app image info DB initialization failed\n");
2486 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2488 _LOGD("package app app control DB initialization failed\n");
2491 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2493 _LOGD("package app app category DB initialization failed\n");
2496 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2498 _LOGD("package app app category DB initialization failed\n");
2501 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2503 _LOGD("package app app permission DB initialization failed\n");
2506 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2508 _LOGD("package app share allowed DB initialization failed\n");
2511 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2513 _LOGD("package app share request DB initialization failed\n");
2516 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2518 _LOGD("package app data control DB initialization failed\n");
2522 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2524 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2528 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2530 _LOGD("package app splash screen DB initialization failed\n");
2534 /* Trigger package_app_info_for_uid */
2535 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2537 _LOGD("package app info for uid DB initialization failed\n");
2542 /* TODO: refactor this code */
2543 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2545 _LOGD("package cert info DB initialization failed\n");
2548 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2550 _LOGD("package cert index info DB initialization failed\n");
2553 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2555 _LOGD("package cert info DB initialization failed\n");
2558 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2560 _LOGD("package cert info DB initialization failed\n");
2563 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2565 _LOGD("package cert info DB initialization failed\n");
2568 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2570 _LOGD("package cert index info DB initialization failed\n");
2574 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2575 if (db_path == NULL) {
2576 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2578 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2580 _LOGD("Failed to change cert db permission");
2584 db_path = getUserPkgParserDBPathUID(uid);
2585 if (db_path == NULL) {
2586 _LOGD("Failed to get user pkg parser db path - %d", uid);
2588 ret = __parserdb_change_perm(db_path, uid);
2590 _LOGD("Failed to change parser db permission\n");
2597 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2600 char pwuid_buf[1024];
2601 char journal_file[BUFSIZE];
2606 struct passwd userinfo, *result = NULL;
2607 files[0] = (char *)db_file;
2608 files[1] = journal_file;
2612 if (db_file == NULL)
2615 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2617 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2618 if (uid == OWNER_ROOT)
2620 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2621 if (ret != 0 || result == NULL) {
2622 _LOGE("FAIL: user %d doesn't exist", uid);
2625 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2627 for (i = 0; files[i]; i++) {
2628 fd = open(files[i], O_RDONLY);
2630 if (strerror_r(errno, buf, sizeof(buf)))
2631 strncpy(buf, "", BUFSIZE - 1);
2632 _LOGD("FAIL : open %s : %s", files[i], buf);
2635 ret = fstat(fd, &sb);
2637 if (strerror_r(errno, buf, sizeof(buf)))
2638 strncpy(buf, "", BUFSIZE - 1);
2639 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2643 if (S_ISLNK(sb.st_mode)) {
2644 _LOGE("FAIL : %s is symlink!", files[i]);
2648 ret = fchown(fd, uid, userinfo.pw_gid);
2650 if (strerror_r(errno, buf, sizeof(buf)))
2651 strncpy(buf, "", BUFSIZE - 1);
2652 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2653 userinfo.pw_gid, buf);
2658 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2659 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2661 ret = fchmod(fd, mode);
2663 if (strerror_r(errno, buf, sizeof(buf)))
2664 strncpy(buf, "", BUFSIZE - 1);
2665 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2670 SET_SMACK_LABEL(files[i]);
2675 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2680 if (getuid() != OWNER_ROOT) {
2681 _LOGE("Only root user is allowed");
2685 db_path = getUserPkgParserDBPathUID(uid);
2686 if (db_path == NULL) {
2687 _LOGE("Failed to get pkg parser db path - %d", uid);
2691 if (access(db_path, F_OK) != -1) {
2692 _LOGE("Manifest db for user %d is already exists", uid);
2698 db_path = getUserPkgCertDBPathUID(uid);
2699 if (db_path == NULL) {
2700 _LOGE("Failed to get pkg cert db path - %d", uid);
2704 if (access(db_path, F_OK) != -1) {
2705 _LOGE("Cert db for user %d is already exists", uid);
2711 ret = pkgmgr_parser_check_and_create_db(uid);
2714 ret = pkgmgr_parser_initialize_db(uid);
2716 pkgmgr_parser_close_db();
2719 pkgmgr_parser_close_db();
2724 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2729 db_path = getUserPkgParserDBPathUID(uid);
2730 if (db_path == NULL) {
2731 _LOGD("Failed to get pkg parser db path - %d", uid);
2736 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2738 _LOGD("Manifest DB creation Failed\n");
2744 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2745 if (db_path == NULL) {
2746 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2751 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2753 _LOGD("Cert DB creation Failed\n");
2763 void pkgmgr_parser_close_db(void)
2765 sqlite3_close(pkgmgr_parser_db);
2766 sqlite3_close(pkgmgr_cert_db);
2770 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2772 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2774 _LOGD("manifest pointer is NULL\n");
2778 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2780 _LOGD("Failed to open DB\n");
2783 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2786 /*Begin transaction*/
2787 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2788 if (ret != SQLITE_OK) {
2789 _LOGD("Failed to begin transaction\n");
2793 _LOGD("Transaction Begin\n");
2794 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2796 _LOGD("Insert into DB failed. Rollback now\n");
2797 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2800 /*Commit transaction*/
2801 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2802 if (ret != SQLITE_OK) {
2803 _LOGD("Failed to commit transaction. Rollback now\n");
2804 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2808 _LOGD("Transaction Commit and End\n");
2810 pkgmgr_parser_close_db();
2814 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2816 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2818 _LOGD("manifest pointer is NULL\n");
2822 ret = pkgmgr_parser_check_and_create_db(uid);
2824 _LOGD("Failed to open DB\n");
2827 ret = pkgmgr_parser_initialize_db(uid);
2830 /*Begin transaction*/
2831 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2832 if (ret != SQLITE_OK) {
2833 _LOGD("Failed to begin transaction\n");
2837 _LOGD("Transaction Begin\n");
2838 ret = __insert_manifest_info_in_db(mfx, uid);
2840 _LOGD("Insert into DB failed. Rollback now\n");
2841 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2844 /*Commit transaction*/
2845 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2846 if (ret != SQLITE_OK) {
2847 _LOGD("Failed to commit transaction. Rollback now\n");
2848 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2852 _LOGD("Transaction Commit and End\n");
2854 pkgmgr_parser_close_db();
2858 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2860 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2863 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2865 if (pkgid == NULL || tep_path == NULL) {
2866 _LOGE("invalid parameter");
2873 ret = pkgmgr_parser_check_and_create_db(uid);
2875 _LOGD("Failed to open DB\n");
2878 ret = pkgmgr_parser_initialize_db(uid);
2882 /*Begin transaction*/
2883 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2884 if (ret != SQLITE_OK) {
2885 _LOGD("Failed to begin transaction\n");
2889 _LOGD("Transaction Begin\n");
2892 /* Updating TEP info in "package_info" table */
2893 query = sqlite3_mprintf("UPDATE package_info "\
2894 "SET package_tep_name = %Q "\
2895 "WHERE package = %Q", tep_path, pkgid);
2897 ret = __exec_query(query);
2898 sqlite3_free(query);
2899 if (ret != SQLITE_OK) {
2900 ret = PM_PARSER_R_ERROR;
2901 _LOGE("sqlite exec failed to insert entries into package_info!!");
2905 /* Updating TEP info in "package_app_info" table */
2906 query = sqlite3_mprintf("UPDATE package_app_info "\
2907 "SET app_tep_name = %Q "\
2908 "WHERE package = %Q", tep_path, pkgid);
2910 ret = __exec_query(query);
2911 sqlite3_free(query);
2912 if (ret != SQLITE_OK) {
2913 ret = PM_PARSER_R_ERROR;
2914 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2918 /*Commit transaction*/
2919 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2920 if (ret != SQLITE_OK) {
2921 _LOGE("Failed to commit transaction, Rollback now\n");
2922 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2923 if (ret != SQLITE_OK)
2924 _LOGE("Failed to Rollback\n");
2926 ret = PM_PARSER_R_ERROR;
2929 _LOGD("Transaction Commit and End\n");
2930 ret = PM_PARSER_R_OK;
2933 pkgmgr_parser_close_db();
2938 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2941 _LOGD("manifest pointer is NULL\n");
2945 ret = pkgmgr_parser_check_and_create_db(uid);
2947 _LOGD("Failed to open DB\n");
2950 ret = pkgmgr_parser_initialize_db(uid);
2953 /*Preserve guest mode visibility*/
2954 __preserve_guestmode_visibility_value(mfx);
2955 /*Begin transaction*/
2956 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2957 if (ret != SQLITE_OK) {
2958 _LOGD("Failed to begin transaction\n");
2962 _LOGD("Transaction Begin\n");
2963 ret = __delete_manifest_info_from_db(mfx, uid);
2965 _LOGD("Delete from DB failed. Rollback now\n");
2966 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2969 ret = __insert_manifest_info_in_db(mfx, uid);
2971 _LOGD("Insert into DB failed. Rollback now\n");
2972 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2976 /*Commit transaction*/
2977 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2978 if (ret != SQLITE_OK) {
2979 _LOGD("Failed to commit transaction. Rollback now\n");
2980 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2984 _LOGD("Transaction Commit and End\n");
2986 pkgmgr_parser_close_db();
2990 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2992 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2995 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2998 _LOGD("manifest pointer is NULL\n");
3002 ret = pkgmgr_parser_check_and_create_db(uid);
3004 _LOGD("Failed to open DB\n");
3007 /*Begin transaction*/
3008 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3009 if (ret != SQLITE_OK) {
3010 _LOGD("Failed to begin transaction\n");
3014 _LOGD("Transaction Begin\n");
3015 ret = __delete_manifest_info_from_db(mfx, uid);
3017 _LOGD("Delete from DB failed. Rollback now\n");
3018 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3021 /*Commit transaction*/
3022 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3023 if (ret != SQLITE_OK) {
3024 _LOGD("Failed to commit transaction, Rollback now\n");
3025 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3029 _LOGD("Transaction Commit and End\n");
3031 pkgmgr_parser_close_db();
3035 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
3037 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
3040 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
3044 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3046 _LOGD("Failed to open DB\n");
3050 /*Begin transaction*/
3051 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3052 if (ret != SQLITE_OK) {
3053 _LOGD("Failed to begin transaction\n");
3057 _LOGD("Transaction Begin\n");
3059 ret = __disable_global_app_for_user(appid, uid);
3061 ret = __enable_global_app_for_user(appid, uid);
3063 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
3064 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3067 /*Commit transaction*/
3068 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3069 if (ret != SQLITE_OK) {
3070 _LOGD("Failed to commit transaction, Rollback now\n");
3071 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3075 _LOGD("Transaction Commit and End\n");
3077 pkgmgr_parser_close_db();
3082 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3084 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3087 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3091 ret = pkgmgr_parser_check_and_create_db(uid);
3093 _LOGD("Failed to open DB\n");
3097 /*Begin transaction*/
3098 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3099 if (ret != SQLITE_OK) {
3100 _LOGD("Failed to begin transaction\n");
3105 _LOGD("Transaction Begin\n");
3107 ret = __disable_pkg(pkgid);
3109 ret = __enable_pkg(pkgid);
3112 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3113 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3117 /*Commit transaction*/
3118 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3119 if (ret != SQLITE_OK) {
3120 _LOGD("Failed to commit transaction, Rollback now\n");
3121 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3125 _LOGD("Transaction Commit and End\n");
3128 pkgmgr_parser_close_db();
3132 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3134 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3137 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3141 ret = pkgmgr_parser_check_and_create_db(uid);
3143 _LOGD("Failed to open DB\n");
3147 /*Begin transaction*/
3148 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3149 if (ret != SQLITE_OK) {
3150 _LOGD("Failed to begin transaction\n");
3154 _LOGD("Transaction Begin\n");
3156 ret = __disable_app(appid);
3158 ret = __enable_app(appid);
3160 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3161 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3164 /*Commit transaction*/
3165 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3166 if (ret != SQLITE_OK) {
3167 _LOGD("Failed to commit transaction, Rollback now\n");
3168 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3172 _LOGD("Transaction Commit and End\n");
3174 pkgmgr_parser_close_db();
3179 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3183 if (appid == NULL) {
3184 _LOGD("Invalid parameter");
3188 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3190 _LOGD("Failed to open DB\n");
3194 /* Begin transaction */
3195 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3196 if (ret != SQLITE_OK) {
3197 _LOGD("Failed to begin transaction\n");
3201 _LOGD("Transaction Begin\n");
3203 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3205 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3206 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3209 /* Commit transaction */
3210 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3211 if (ret != SQLITE_OK) {
3212 _LOGD("Failed to commit transaction, Rollback now\n");
3213 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3217 _LOGD("Transaction Commit and End\n");
3219 pkgmgr_parser_close_db();
3223 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3225 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3228 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3232 if (appid == NULL) {
3233 _LOGD("Invalid parameter");
3237 ret = pkgmgr_parser_check_and_create_db(uid);
3239 _LOGD("Failed to open DB");
3243 /* Begin transaction */
3244 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3245 if (ret != SQLITE_OK) {
3246 _LOGD("Failed to begin transaction");
3250 _LOGD("Transaction Begin");
3253 ret = __enable_app_splash_screen(appid);
3255 ret = __disable_app_splash_screen(appid);
3257 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3258 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3261 /* Commit transaction */
3262 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3263 if (ret != SQLITE_OK) {
3264 _LOGD("Failed to commit transaction, Rollback now");
3265 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3269 _LOGD("Transaction Commit and End");
3272 pkgmgr_parser_close_db();
3276 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3279 char query[MAX_QUERY_LEN] = {'\0'};
3281 if (appid == NULL || label == NULL) {
3282 _LOGE("Invalid parameter");
3286 ret = pkgmgr_parser_check_and_create_db(uid);
3288 _LOGD("Failed to open DB");
3292 /*Begin transaction*/
3293 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3294 if (ret != SQLITE_OK) {
3295 _LOGD("Failed to begin transaction\n");
3300 sqlite3_snprintf(MAX_QUERY_LEN, query,
3301 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3302 "app_id=%Q AND app_label IS NOT NULL",
3304 ret = __exec_query(query);
3306 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3310 /* Commit transaction */
3311 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3312 if (ret != SQLITE_OK) {
3313 _LOGD("Failed to commit transaction, Rollback now");
3314 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3318 _LOGD("Transaction Commit and End");
3321 pkgmgr_parser_close_db();
3325 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3327 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);