4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <sys/types.h>
28 #include <sys/smack.h>
37 #include <system_info.h>
39 /* For multi-user support */
40 #include <tzplatform_config.h>
42 #include "pkgmgr-info.h"
43 #include "pkgmgrinfo_basic.h"
44 #include "pkgmgrinfo_debug.h"
45 #include "pkgmgr_parser_internal.h"
46 #include "pkgmgr_parser_db.h"
51 #define LOG_TAG "PKGMGR_PARSER"
53 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
54 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
55 #define MAX_QUERY_LEN 4096
63 #define XXHDPI "xxhdpi"
73 #define XXHDPI_MIN 481
74 #define XXHDPI_MAX 600
76 #define DB_LABEL "User::Home"
77 #define SET_SMACK_LABEL(x) \
79 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
80 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
82 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
85 sqlite3 *pkgmgr_parser_db;
86 sqlite3 *pkgmgr_cert_db;
89 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
90 "(package TEXT PRIMARY KEY NOT NULL, " \
91 "package_type TEXT DEFAULT 'tpk', " \
92 "package_version TEXT, " \
93 "package_api_version TEXT, " \
94 "package_tep_name TEXT, " \
95 "package_zip_mount_file TEXT, " \
96 "install_location TEXT NOT NULL , " \
97 "package_size TEXT, " \
98 "package_removable TEXT NOT NULL DEFAULT 'true', " \
99 "package_preload TEXT NOT NULL DEFAULT 'false', " \
100 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
101 "package_update TEXT NOT NULL DEFAULT 'false', " \
102 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
103 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
104 "package_system TEXT NOT NULL DEFAULT 'false', " \
105 "author_name TEXT, " \
106 "author_email TEXT, " \
107 "author_href TEXT," \
108 "installed_time TEXT, " \
109 "installed_storage TEXT, " \
110 "storeclient_id TEXT, " \
111 "mainapp_id TEXT, " \
112 "package_url TEXT, " \
114 "external_path TEXT, " \
116 "package_support_mode TEXT, " \
117 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
118 "package_disable TEXT NOT NULL DEFAULT 'false')"
120 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
121 "(package TEXT NOT NULL, " \
122 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
123 "package_label TEXT, " \
124 "package_icon TEXT, " \
125 "package_description TEXT, " \
126 "package_license TEXT, " \
127 "package_author TEXT, " \
128 "PRIMARY KEY(package, package_locale), " \
129 "FOREIGN KEY(package) " \
130 "REFERENCES package_info(package) " \
133 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
134 "(package TEXT NOT NULL, " \
135 "privilege TEXT NOT NULL, " \
136 "type TEXT NOT NULL, " \
137 "PRIMARY KEY(package, privilege, type) " \
138 "FOREIGN KEY(package) " \
139 "REFERENCES package_info(package) " \
142 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
143 "(app_id TEXT PRIMARY KEY NOT NULL, " \
144 "app_component TEXT NOT NULL, " \
146 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
148 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
149 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
150 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
151 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
152 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
153 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
154 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
155 "app_mainapp TEXT NOT NULL, " \
156 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
157 "app_launchcondition TEXT, " \
158 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
159 "app_portraitimg TEXT, " \
160 "app_landscapeimg TEXT, " \
161 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
162 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
163 "app_preload TEXT NOT NULL DEFAULT 'false', " \
164 "app_submode TEXT NOT NULL DEFAULT 'false', " \
165 "app_submode_mainid TEXT, " \
166 "app_installed_storage TEXT NOT NULL, " \
167 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
168 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
169 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
170 "app_support_mode TEXT, " \
171 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
172 "app_disable TEXT NOT NULL DEFAULT 'false', " \
173 "app_package_type TEXT DEFAULT 'tpk', " \
174 "app_package_system TEXT NOT NULL, " \
175 "app_removable TEXT NOT NULL DEFAULT 'false', " \
176 "app_package_installed_time TEXT, " \
177 "component_type TEXT, " \
178 "package TEXT NOT NULL, " \
179 "app_tep_name TEXT, " \
180 "app_zip_mount_file TEXT, " \
181 "app_background_category INTEGER DEFAULT 0, " \
182 "app_root_path TEXT, " \
183 "app_api_version TEXT, " \
184 "app_effective_appid TEXT, " \
185 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
186 "app_external_path TEXT, " \
187 "FOREIGN KEY(package) " \
188 "REFERENCES package_info(package) " \
191 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
192 "(app_id TEXT NOT NULL, " \
193 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
196 "PRIMARY KEY(app_id,app_locale) " \
197 "FOREIGN KEY(app_id) " \
198 "REFERENCES package_app_info(app_id) " \
201 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
202 "(app_id TEXT NOT NULL, " \
204 "app_icon_section TEXT NOT NULL, " \
205 "app_icon_resolution TEXT NOT NULL, " \
206 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
207 "FOREIGN KEY(app_id) " \
208 "REFERENCES package_app_info(app_id) " \
211 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
212 "(app_id TEXT NOT NULL, " \
213 "app_locale TEXT DEFAULT 'No Locale', " \
214 "app_image_section TEXT NOT NULL, " \
216 "PRIMARY KEY(app_id,app_image_section) " \
217 "FOREIGN KEY(app_id) " \
218 "REFERENCES package_app_info(app_id) " \
221 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
222 "(app_id TEXT NOT NULL, " \
223 "app_control TEXT NOT NULL, " \
224 "PRIMARY KEY(app_id,app_control) " \
225 "FOREIGN KEY(app_id) " \
226 "REFERENCES package_app_info(app_id) " \
229 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
230 "(app_id TEXT NOT NULL, " \
231 "category TEXT NOT NULL, " \
232 "PRIMARY KEY(app_id,category) " \
233 "FOREIGN KEY(app_id) " \
234 "REFERENCES package_app_info(app_id) " \
237 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
238 "(app_id TEXT NOT NULL, " \
239 "md_key TEXT NOT NULL, " \
241 "PRIMARY KEY(app_id, md_key, md_value) " \
242 "FOREIGN KEY(app_id) " \
243 "REFERENCES package_app_info(app_id) " \
246 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
247 "(app_id TEXT NOT NULL, " \
248 "pm_type TEXT NOT NULL, " \
249 "pm_value TEXT NOT NULL, " \
250 "PRIMARY KEY(app_id, pm_type, pm_value) " \
251 "FOREIGN KEY(app_id) " \
252 "REFERENCES package_app_info(app_id) " \
255 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
256 "(app_id TEXT NOT NULL, " \
257 "data_share_path TEXT NOT NULL, " \
258 "data_share_allowed TEXT NOT NULL, " \
259 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
260 "FOREIGN KEY(app_id) " \
261 "REFERENCES package_app_info(app_id) " \
264 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
265 "(app_id TEXT NOT NULL, " \
266 "data_share_request TEXT NOT NULL, " \
267 "PRIMARY KEY(app_id,data_share_request) " \
268 "FOREIGN KEY(app_id) " \
269 "REFERENCES package_app_info(app_id) " \
272 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
273 "(app_id TEXT NOT NULL, " \
274 "providerid TEXT NOT NULL, " \
275 "access TEXT NOT NULL, " \
276 "type TEXT NOT NULL, " \
277 "PRIMARY KEY(app_id, providerid, access, type) " \
278 "FOREIGN KEY(app_id) " \
279 "REFERENCES package_app_info(app_id) " \
282 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
283 "(app_id TEXT NOT NULL, " \
284 "uid INTEGER NOT NULL, " \
285 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
286 "is_splash_screen_enabled TEXT NOT NULL, " \
287 "PRIMARY KEY(app_id, uid))"
289 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
290 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
291 "AFTER UPDATE ON package_app_info_for_uid " \
293 " DELETE FROM package_app_info_for_uid WHERE " \
294 " is_splash_screen_enabled=" \
295 " (SELECT package_app_info.app_splash_screen_display FROM " \
296 " package_app_info, package_app_info_for_uid WHERE " \
297 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
300 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
301 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
302 "(app_id TEXT NOT NULL, " \
303 "src TEXT NOT NULL, " \
304 "type TEXT NOT NULL, " \
305 "orientation TEXT NOT NULL, " \
306 "indicatordisplay TEXT, " \
307 "operation TEXT NOT NULL, " \
308 "color_depth TEXT NOT NULL DEFAULT '24', " \
309 "PRIMARY KEY(app_id, orientation, operation) " \
310 "FOREIGN KEY(app_id) " \
311 "REFERENCES package_app_info(app_id) " \
315 /* FIXME: duplicated at pkgmgrinfo_db.c */
316 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
317 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
318 " cert_info TEXT UNIQUE, " \
319 " cert_id INTEGER PRIMARY KEY, " \
320 " cert_ref_count INTEGER NOT NULL)"
322 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
323 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
324 " package TEXT PRIMARY KEY, " \
325 " package_count INTEGER, " \
326 " author_root_cert INTEGER, " \
327 " author_im_cert INTEGER, " \
328 " author_signer_cert INTEGER, " \
329 " dist_root_cert INTEGER, " \
330 " dist_im_cert INTEGER, " \
331 " dist_signer_cert INTEGER, " \
332 " dist2_root_cert INTEGER, " \
333 " dist2_im_cert INTEGER, " \
334 " dist2_signer_cert INTEGER)"
336 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
337 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
338 "AFTER UPDATE ON package_cert_info " \
339 "WHEN (NEW.package_count = 0) " \
341 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
344 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
345 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
346 "AFTER UPDATE ON package_cert_info " \
347 "WHEN (NEW.package_count = OLD.package_count + 1) " \
349 " UPDATE package_cert_index_info SET" \
350 " cert_ref_count = cert_ref_count - 1" \
351 " WHERE cert_id = OLD.author_root_cert" \
352 " OR cert_id = OLD.author_im_cert" \
353 " OR cert_id = OLD.author_signer_cert" \
354 " OR cert_id = OLD.dist_root_cert" \
355 " OR cert_id = OLD.dist_im_cert" \
356 " OR cert_id = OLD.dist_signer_cert" \
357 " OR cert_id = OLD.dist2_root_cert" \
358 " OR cert_id = OLD.dist2_im_cert" \
359 " OR cert_id = OLD.dist2_signer_cert;" \
362 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
363 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
364 "AFTER DELETE ON package_cert_info " \
366 " UPDATE package_cert_index_info SET" \
367 " cert_ref_count = cert_ref_count - 1" \
368 " WHERE cert_id = OLD.author_root_cert" \
369 " OR cert_id = OLD.author_im_cert" \
370 " OR cert_id = OLD.author_signer_cert" \
371 " OR cert_id = OLD.dist_root_cert" \
372 " OR cert_id = OLD.dist_im_cert" \
373 " OR cert_id = OLD.dist_signer_cert" \
374 " OR cert_id = OLD.dist2_root_cert" \
375 " OR cert_id = OLD.dist2_im_cert" \
376 " OR cert_id = OLD.dist2_signer_cert;" \
379 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
380 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
381 "AFTER UPDATE ON package_cert_index_info " \
382 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
383 " WHERE cert_id = OLD.cert_id) = 0) "\
385 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
388 static int __insert_application_info(manifest_x *mfx);
389 static int __insert_application_appcategory_info(manifest_x *mfx);
390 static int __insert_application_appcontrol_info(manifest_x *mfx);
391 static int __insert_application_appmetadata_info(manifest_x *mfx);
392 static int __insert_application_share_allowed_info(manifest_x *mfx);
393 static int __insert_application_share_request_info(manifest_x *mfx);
394 static int __insert_application_datacontrol_info(manifest_x *mfx);
395 static void __insert_application_locale_info(gpointer data, gpointer userdata);
396 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
397 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
398 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
399 static int __delete_subpkg_info_from_db(char *appid);
400 static int __delete_appinfo_from_db(char *db_table, const char *appid);
401 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
402 static int __exec_query(char *query);
403 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
404 char **label, char **license, char **icon, char **description, char **author);
405 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
406 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
407 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
408 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
409 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
410 static int __parserdb_change_perm(const char *db_file, uid_t uid);
412 #define REGULAR_USER 5000
413 static inline uid_t _getuid(void)
415 uid_t uid = getuid();
417 if (uid < REGULAR_USER)
418 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
423 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
426 __delete_subpkg_info_from_db(coltxt[0]);
431 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
436 char *error_message = NULL;
438 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
439 if (ret != SQLITE_OK) {
440 _LOGD("connect db [%s] failed!\n", db_path);
445 /* add user_version for db upgrade*/
446 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
448 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
449 _LOGE("Don't execute query = %s error message = %s\n", query,
452 sqlite3_free(error_message);
458 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
460 manifest_x *mfx = (manifest_x *)data;
466 if (mfx->application == NULL)
468 app = (application_x *)mfx->application->data;
469 for (i = 0; i < ncols; i++) {
470 if (strcmp(colname[i], "app_id") == 0) {
472 appid = strdup(coltxt[i]);
473 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
475 status = strdup(coltxt[i]);
481 _LOGD("app id is NULL\n");
484 /*update guest mode visibility*/
485 for (tmp = mfx->application; tmp; tmp = tmp->next) {
486 app = (application_x *)tmp->data;
489 if (strcmp(app->appid, appid) == 0) {
490 free((void *)app->guestmode_visibility);
491 app->guestmode_visibility = strdup(status);
507 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
509 char *error_message = NULL;
510 char query[MAX_QUERY_LEN] = {'\0'};
511 sqlite3_snprintf(MAX_QUERY_LEN, query,
512 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
513 "WHERE package=%Q", mfx->package);
515 sqlite3_exec(pkgmgr_parser_db, query,
516 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
517 _LOGD("Don't execute query = %s error message = %s\n",
518 query, error_message);
519 sqlite3_free(error_message);
524 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
526 char *error_message = NULL;
528 sqlite3_exec(db_handle, db_query,
529 NULL, NULL, &error_message)) {
530 _LOGD("Don't execute query = %s error message = %s\n",
531 db_query, error_message);
532 sqlite3_free(error_message);
535 sqlite3_free(error_message);
539 static int __exec_query(char *query)
541 char *error_message = NULL;
543 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
544 _LOGE("Don't execute query = %s error message = %s\n", query,
546 sqlite3_free(error_message);
549 sqlite3_free(error_message);
553 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
561 for (tmp = lbls; tmp; tmp = tmp->next) {
562 lbl = (label_x *)tmp->data;
566 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
568 for (tmp = lcns; tmp; tmp = tmp->next) {
569 lcn = (license_x *)tmp->data;
573 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
575 for (tmp = icns; tmp; tmp = tmp->next) {
576 icn = (icon_x *)tmp->data;
580 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
582 for (tmp = dcns; tmp; tmp = tmp->next) {
583 dcn = (description_x *)tmp->data;
587 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
589 for (tmp = aths; tmp; tmp = tmp->next) {
590 ath = (author_x *)tmp->data;
594 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
600 static GList *__create_icon_list(GList *appicon, GList *icns)
605 for (tmp = icns; tmp; tmp = tmp->next) {
606 icn = (icon_x *)tmp->data;
610 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
615 static GList *__create_image_list(GList *appimage, GList *imgs)
620 for (tmp = imgs; tmp; tmp = tmp->next) {
621 img = (image_x *)tmp->data;
625 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
630 static void __trimfunc(GList *trim_list)
632 char *trim_data = NULL;
636 list = g_list_first(trim_list);
639 trim_data = (char *)list->data;
642 if (strcmp(trim_data, prev) == 0) {
643 trim_list = g_list_remove(trim_list, trim_data);
644 list = g_list_first(trim_list);
653 list = g_list_next(list);
657 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
659 if (a == NULL || b == NULL)
661 if (strcmp((char *)a, (char *)b) == 0)
663 if (strcmp((char *)a, (char *)b) < 0)
665 if (strcmp((char *)a, (char *)b) > 0)
670 static int __check_dpi(const char *dpi_char, int dpi_int)
672 if (dpi_char == NULL)
675 if (strcasecmp(dpi_char, LDPI) == 0) {
676 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
680 } else if (strcasecmp(dpi_char, MDPI) == 0) {
681 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
685 } else if (strcasecmp(dpi_char, HDPI) == 0) {
686 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
690 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
691 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
695 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
696 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
704 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
707 char *icon_filename = NULL;
708 char modified_iconpath[BUFSIZE] = { '\0' };
709 char icon_path[BUFSIZE] = { '\0' };
713 if (orig_icon_path == NULL)
716 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
720 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
721 dpi_path[0] = "LDPI";
722 dpi_path[1] = "ldpi";
723 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
724 dpi_path[0] = "MDPI";
725 dpi_path[1] = "mdpi";
726 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
727 dpi_path[0] = "HDPI";
728 dpi_path[1] = "hdpi";
729 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
730 dpi_path[0] = "XHDPI";
731 dpi_path[1] = "xhdpi";
732 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
733 dpi_path[0] = "XXHDPI";
734 dpi_path[1] = "xxhdpi";
736 _LOGE("Unidentified dpi[%d]", dpi);
740 icon_filename = strrchr(orig_icon_path, '/');
741 if (icon_filename == NULL)
744 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
745 for (i = 0; i < 2; i++) {
746 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
747 if (access(modified_iconpath, F_OK) != -1) {
748 /* if exists, return modified icon path */
749 *new_icon_path = strdup(modified_iconpath);
757 static gint __compare_icon(gconstpointer a, gconstpointer b)
759 icon_x *icon = (icon_x *)a;
761 char *icon_folder_path = NULL;
763 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
766 if (icon->dpi != NULL)
769 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
771 icon->text = icon_folder_path;
777 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
779 icon_x *icon = (icon_x *)a;
780 int dpi = GPOINTER_TO_INT(b);
782 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
785 if (icon->dpi == NULL)
788 if (__check_dpi(icon->dpi, dpi) == 0)
794 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
796 icon_x *icon = (icon_x *)a;
797 char *lang = (char *)b;
798 char *icon_folder_path = NULL;
800 if (icon->dpi != NULL)
803 if (strcasecmp(icon->lang, lang) == 0) {
804 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
805 /* icon for no locale. check existance of folder-hierachied default icons */
806 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
808 icon->text = icon_folder_path;
817 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
819 icon_x *icon = (icon_x *)a;
820 char *lang = (char *)b;
823 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
827 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
833 static char *__find_icon(GList *icons, const char *lang)
840 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
841 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
843 icon = (icon_x *)tmp->data;
844 return (char *)icon->text;
847 /* if first has failed, find icon whose locale has matched */
848 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
850 icon = (icon_x *)tmp->data;
851 return (char *)icon->text;
854 /* if second has failed, find icon whose dpi has matched with system's dpi */
855 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
856 if (ret == SYSTEM_INFO_ERROR_NONE) {
857 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
859 icon = (icon_x *)tmp->data;
860 return (char *)icon->text;
864 /* last, find default icon marked as "No Locale" */
865 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
867 icon = (icon_x *)tmp->data;
868 return (char *)icon->text;
874 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
875 char **label, char **license, char **icon, char **description, char **author)
882 for (tmp = lbls; tmp; tmp = tmp->next) {
883 lbl = (label_x *)tmp->data;
887 if (strcmp(lbl->lang, (char *)data) == 0) {
888 *label = (char *)lbl->text;
893 for (tmp = lcns; tmp; tmp = tmp->next) {
894 lcn = (license_x *)tmp->data;
898 if (strcmp(lcn->lang, (char *)data) == 0) {
899 *license = (char *)lcn->text;
905 *icon = __find_icon(icns, (char *)data);
907 for (tmp = dcns; tmp; tmp = tmp->next) {
908 dcn = (description_x *)tmp->data;
912 if (strcmp(dcn->lang, (char *)data) == 0) {
913 *description = (char *)dcn->text;
918 for (tmp = aths; tmp; tmp = tmp->next) {
919 ath = (author_x *)tmp->data;
923 if (strcmp(ath->lang, (char *)data) == 0) {
924 *author = (char *)ath->text;
932 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
936 for (tmp = icns; tmp; tmp = tmp->next) {
937 icn = (icon_x *)tmp->data;
941 if (strcmp(icn->section, (char *)data) == 0) {
942 *icon = (char *)icn->text;
943 *resolution = (char *)icn->resolution;
950 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
954 for (tmp = imgs; tmp; tmp = tmp->next) {
955 img = (image_x *)tmp->data;
959 if (strcmp(img->section, (char *)data) == 0) {
960 *lang = (char *)img->lang;
961 *image = (char *)img->text;
968 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
973 char *description = NULL;
974 char *license = NULL;
978 manifest_x *mfx = (manifest_x *)userdata;
979 GList *lbl = mfx->label;
980 GList *lcn = mfx->license;
981 GList *icn = mfx->icon;
982 GList *dcn = mfx->description;
983 GList *ath = mfx->author;
985 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
986 if (!label && !description && !icon && !license && !author)
989 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
990 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
991 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1000 ret = __exec_query(query);
1002 _LOGD("Package Localized Info DB Insert failed\n");
1004 sqlite3_free(query);
1007 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1013 char *locale = (char *)data;
1015 application_x *app = (application_x *)userdata;
1016 GList *lbl = app->label;
1017 GList *icn = app->icon;
1019 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1020 if (!label && !icon)
1023 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1024 "app_label, app_icon) VALUES" \
1025 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1027 ret = __exec_query(query);
1029 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1031 sqlite3_free(query);
1033 /*insert ui app locale info to pkg locale to get mainapp data */
1034 if (strcasecmp(app->mainapp, "true") == 0) {
1035 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1036 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1038 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1039 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1040 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1041 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1042 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1043 app->package, locale,
1044 app->package, locale, label,
1045 app->package, locale, icon,
1046 app->package, locale,
1047 app->package, locale,
1048 app->package, locale);
1050 ret = __exec_query(query);
1052 _LOGE("Package Localized Info DB Insert failed");
1053 sqlite3_free(query);
1057 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1061 char *resolution = NULL;
1062 char query[MAX_QUERY_LEN] = {'\0'};
1064 application_x *app = (application_x *)userdata;
1065 GList *icn = app->icon;
1067 __extract_icon_data(data, icn, &icon, &resolution);
1068 if (!icon && !resolution)
1070 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1071 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1072 "(%Q, %Q, %Q, %Q)", app->appid,
1073 icon, (char *)data, resolution);
1075 ret = __exec_query(query);
1077 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1081 static void __insert_application_image_info(gpointer data, gpointer userdata)
1086 char query[MAX_QUERY_LEN] = {'\0'};
1088 application_x *app = (application_x *)userdata;
1089 GList *image = app->image;
1091 __extract_image_data(data, image, &lang, &img);
1094 sqlite3_snprintf(MAX_QUERY_LEN, query,
1095 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1096 "app_image_section, app_image) VALUES" \
1097 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1099 ret = __exec_query(query);
1101 _LOGD("Package UiApp image Info DB Insert failed\n");
1106 static int __insert_mainapp_info(manifest_x *mfx)
1111 char query[MAX_QUERY_LEN] = {'\0'};
1112 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1113 app = (application_x *)tmp->data;
1117 sqlite3_snprintf(MAX_QUERY_LEN, query,
1118 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1119 app->mainapp, app->appid);
1120 ret = __exec_query(query);
1122 _LOGD("Package App Info DB Insert Failed\n");
1125 if (strcasecmp(app->mainapp, "True") == 0)
1126 mfx->mainapp_id = strdup(app->appid);
1129 if (mfx->mainapp_id == NULL) {
1130 if (mfx->application == NULL)
1132 app = (application_x *)mfx->application->data;
1136 sqlite3_snprintf(MAX_QUERY_LEN, query,
1137 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1140 _LOGD("Not valid appid\n");
1144 ret = __exec_query(query);
1146 _LOGD("Package UiApp Info DB Insert Failed\n");
1150 free((void *)app->mainapp);
1151 app->mainapp = strdup("true");
1152 mfx->mainapp_id = strdup(app->appid);
1155 memset(query, '\0', MAX_QUERY_LEN);
1156 sqlite3_snprintf(MAX_QUERY_LEN, query,
1157 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1158 ret = __exec_query(query);
1160 _LOGD("Package Info DB update Failed\n");
1167 static int __convert_background_category(GList *category_list)
1170 GList *tmp_list = category_list;
1171 char *category_data = NULL;
1173 if (category_list == NULL)
1176 while (tmp_list != NULL) {
1177 category_data = (char *)tmp_list->data;
1178 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1179 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1180 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1181 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1182 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1183 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1184 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1185 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1186 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1187 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1188 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1189 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1190 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1191 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1193 _LOGE("Unidentified category [%s]", category_data);
1194 tmp_list = g_list_next(tmp_list);
1200 static const char *__find_effective_appid(GList *metadata_list)
1205 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1206 md = (metadata_x *)tmp_list->data;
1207 if (md == NULL || md->key == NULL)
1210 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1219 static char *__get_bool(char *value, bool is_true)
1221 if (value != NULL) {
1222 if (!strcmp(value, ""))
1223 return (is_true) ? "true" : "false";
1227 return (is_true) ? "true" : "false";
1230 /* _PRODUCT_LAUNCHING_ENHANCED_
1231 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1233 static int __insert_application_info(manifest_x *mfx)
1238 int background_value = 0;
1239 char query[MAX_QUERY_LEN] = {'\0'};
1241 const char *effective_appid;
1244 type = strdup(mfx->type);
1246 type = strdup("tpk");
1248 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1249 app = (application_x *)tmp->data;
1253 background_value = __convert_background_category(app->background_category);
1254 if (background_value < 0) {
1255 _LOGE("Failed to retrieve background value[%d]", background_value);
1256 background_value = 0;
1259 effective_appid = __find_effective_appid(app->metadata);
1261 sqlite3_snprintf(MAX_QUERY_LEN, query,
1262 "INSERT INTO package_app_info(" \
1263 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1264 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1265 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1266 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1267 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1268 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1269 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1270 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1271 "app_package_installed_time, app_support_mode) " \
1273 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1274 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1275 "%Q, %Q, %Q, %Q, %Q, " \
1276 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1277 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1278 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1279 "%Q, %Q, %d, %Q, %Q, " \
1280 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1282 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1283 __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),
1284 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1285 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1286 __get_bool(app->guestmode_visibility, true), app->permission_type,
1287 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1288 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1289 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1290 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true), mfx->installed_time, mfx->support_mode);
1292 ret = __exec_query(query);
1294 _LOGD("Package UiApp Info DB Insert Failed\n");
1299 memset(query, '\0', MAX_QUERY_LEN);
1308 static int __insert_application_appcategory_info(manifest_x *mfx)
1315 char query[MAX_QUERY_LEN] = {'\0'};
1316 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1317 app = (application_x *)app_tmp->data;
1320 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1321 ct = (const char *)ct_tmp->data;
1324 sqlite3_snprintf(MAX_QUERY_LEN, query,
1325 "INSERT INTO package_app_app_category(app_id, category) " \
1328 ret = __exec_query(query);
1330 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1333 memset(query, '\0', MAX_QUERY_LEN);
1339 static int __insert_application_appmetadata_info(manifest_x *mfx)
1346 char query[MAX_QUERY_LEN] = {'\0'};
1347 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1348 app = (application_x *)app_tmp->data;
1351 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1352 md = (metadata_x *)md_tmp->data;
1356 sqlite3_snprintf(MAX_QUERY_LEN, query,
1357 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1358 "VALUES(%Q, %Q, %Q)",\
1359 app->appid, md->key, md->value ? md->value : NULL);
1360 ret = __exec_query(query);
1362 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1366 memset(query, '\0', MAX_QUERY_LEN);
1372 static int __insert_application_apppermission_info(manifest_x *mfx)
1379 char query[MAX_QUERY_LEN] = {'\0'};
1380 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1381 app = (application_x *)app_tmp->data;
1384 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1385 pm = (permission_x *)pm_tmp->data;
1388 sqlite3_snprintf(MAX_QUERY_LEN, query,
1389 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1390 "VALUES(%Q, %Q, %Q)",\
1391 app->appid, pm->type, pm->value);
1392 ret = __exec_query(query);
1394 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1397 memset(query, '\0', MAX_QUERY_LEN);
1403 static int __insert_application_appcontrol_info(manifest_x *mfx)
1407 GList *acontrol_tmp;
1408 appcontrol_x *acontrol;
1410 char query[MAX_QUERY_LEN] = {'\0'};
1411 char buf[BUFSIZE] = {'\0'};
1412 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1413 app = (application_x *)app_tmp->data;
1416 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1417 acontrol = (appcontrol_x *)acontrol_tmp->data;
1418 if (acontrol == NULL)
1420 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1421 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1422 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1423 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1424 sqlite3_snprintf(MAX_QUERY_LEN, query,
1425 "INSERT INTO package_app_app_control(app_id, app_control) " \
1428 ret = __exec_query(query);
1430 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1433 memset(query, '\0', MAX_QUERY_LEN);
1439 static int __insert_application_datacontrol_info(manifest_x *mfx)
1446 char query[MAX_QUERY_LEN] = {'\0'};
1448 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1449 app = (application_x *)app_tmp->data;
1452 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1453 dc = (datacontrol_x *)dc_tmp->data;
1456 sqlite3_snprintf(MAX_QUERY_LEN, query,
1457 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1458 "VALUES(%Q, %Q, %Q, %Q)",\
1464 ret = __exec_query(query);
1466 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1469 memset(query, '\0', MAX_QUERY_LEN);
1475 static int __insert_application_share_request_info(manifest_x *mfx)
1484 char query[MAX_QUERY_LEN] = {'\0'};
1485 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1486 app = (application_x *)app_tmp->data;
1489 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1490 ds = (datashare_x *)ds_tmp->data;
1493 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1494 rq = (const char *)rq_tmp->data;
1497 sqlite3_snprintf(MAX_QUERY_LEN, query,
1498 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1501 ret = __exec_query(query);
1503 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1506 memset(query, '\0', MAX_QUERY_LEN);
1513 static int __insert_application_share_allowed_info(manifest_x *mfx)
1524 char query[MAX_QUERY_LEN] = {'\0'};
1525 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1526 app = (application_x *)app_tmp->data;
1529 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1530 ds = (datashare_x *)ds_tmp->data;
1533 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1534 df = (define_x *)df_tmp->data;
1537 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1538 al = (const char *)al_tmp->data;
1541 sqlite3_snprintf(MAX_QUERY_LEN, query,
1542 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1543 "VALUES(%Q, %Q, %Q)",\
1544 app->appid, df->path, al);
1545 ret = __exec_query(query);
1547 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1550 memset(query, '\0', MAX_QUERY_LEN);
1558 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1560 splashscreen_x *ss = (splashscreen_x *)a;
1561 const char *orientation = (const char *)b;
1564 if (ss->operation || ss->dpi == NULL)
1567 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1571 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1577 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1579 splashscreen_x *ss = (splashscreen_x *)a;
1580 const char *orientation = (const char *)b;
1582 if (ss->operation || ss->dpi)
1585 if (strcasecmp(ss->orientation, orientation) == 0)
1591 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1592 const char *orientation)
1596 tmp = g_list_find_custom(splashscreens, orientation,
1597 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1599 return (splashscreen_x *)tmp->data;
1601 tmp = g_list_find_custom(splashscreens, orientation,
1602 (GCompareFunc)__compare_splashscreen_with_orientation);
1604 return (splashscreen_x *)tmp->data;
1609 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1611 splashscreen_x *ss = (splashscreen_x *)data;
1612 GList **list = (GList **)user_data;
1615 if (ss->operation == NULL || ss->dpi == NULL)
1618 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1622 if (__check_dpi(ss->dpi, dpi) != 0)
1625 *list = g_list_append(*list, ss);
1628 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1630 splashscreen_x *ss = (splashscreen_x *)data;
1631 GList **list = (GList **)user_data;
1632 splashscreen_x *ss_tmp;
1635 if (ss->operation == NULL || ss->dpi)
1638 for (tmp = *list; tmp; tmp = tmp->next) {
1639 ss_tmp = (splashscreen_x *)tmp->data;
1640 if (ss_tmp->operation
1641 && strcmp(ss_tmp->operation, ss->operation) == 0
1642 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1646 *list = g_list_append(*list, ss);
1649 static GList *__find_splashscreens(GList *splashscreens)
1654 g_list_foreach(splashscreens,
1655 __find_appcontrol_splashscreen_with_dpi, &list);
1656 g_list_foreach(splashscreens,
1657 __find_appcontrol_splashscreen, &list);
1659 ss = __find_default_splashscreen(splashscreens, "portrait");
1661 list = g_list_append(list, ss);
1662 ss = __find_default_splashscreen(splashscreens, "landscape");
1664 list = g_list_append(list, ss);
1669 static int __insert_application_splashscreen_info(manifest_x *mfx)
1677 char query[MAX_QUERY_LEN] = {'\0'};
1679 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1680 app = (application_x *)app_tmp->data;
1681 if (app == NULL || app->splashscreens == NULL)
1684 ss_tmp = __find_splashscreens(app->splashscreens);
1688 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1689 ss = (splashscreen_x *)tmp->data;
1690 sqlite3_snprintf(MAX_QUERY_LEN, query,
1691 "INSERT INTO package_app_splash_screen" \
1692 "(app_id, src, type, orientation, indicatordisplay, " \
1693 "operation, color_depth) " \
1694 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1695 app->appid, ss->src, ss->type, ss->orientation,
1696 ss->indicatordisplay, ss->operation,
1699 ret = __exec_query(query);
1701 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1704 memset(query, '\0', MAX_QUERY_LEN);
1706 g_list_free(ss_tmp);
1711 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1716 char query[MAX_QUERY_LEN] = {'\0'};
1718 const char *image_type;
1719 const char *indicatordisplay;
1720 const char *orientation;
1721 const char *operation = "launch-effect";
1722 const char *color_depth = "24"; /* default */
1724 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1725 app = (application_x *)app_tmp->data;
1727 (app->portraitimg == NULL && app->landscapeimg == NULL))
1729 image_type = "img"; /* default */
1730 if (app->effectimage_type) {
1731 tmp = strstr(app->effectimage_type, "edj");
1735 indicatordisplay = "true"; /* default */
1736 if (app->indicatordisplay)
1737 indicatordisplay = app->indicatordisplay;
1738 if (app->portraitimg) {
1739 orientation = "portrait";
1740 sqlite3_snprintf(MAX_QUERY_LEN, query,
1741 "INSERT INTO package_app_splash_screen" \
1742 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1743 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1744 app->appid, app->portraitimg, image_type,
1745 orientation, indicatordisplay, operation,
1747 ret = __exec_query(query);
1749 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1752 memset(query, '\0', MAX_QUERY_LEN);
1754 if (app->landscapeimg) {
1755 orientation = "landscape";
1756 sqlite3_snprintf(MAX_QUERY_LEN, query,
1757 "INSERT INTO package_app_splash_screen" \
1758 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1759 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1760 app->appid, app->landscapeimg, image_type,
1761 orientation, indicatordisplay, operation,
1763 ret = __exec_query(query);
1765 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1768 memset(query, '\0', MAX_QUERY_LEN);
1774 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1781 char query[MAX_QUERY_LEN] = {'\0'};
1783 char *tmpptr = NULL;
1784 const char *operation;
1785 const char *portraitimg;
1786 const char *landscapeimg;
1787 const char *indicatordisplay;
1788 const char *orientation;
1789 const char *image_type;
1790 const char *color_depth = "24"; /* default */
1792 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1793 app = (application_x *)app_tmp->data;
1797 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1798 md = (metadata_x *)md_tmp->data;
1799 if (md == NULL || md->key == NULL || md->value == NULL)
1802 if (strcasestr(md->key, "operation_effect=")) {
1803 operation = index(md->key, '=');
1804 if (operation && operation[1] != '\0')
1807 operation = "launch-effect";
1808 } else if (strcasestr(md->key, "launch_effect")) {
1809 operation = "launch-effect";
1815 landscapeimg = NULL;
1816 indicatordisplay = "true"; /* default */
1817 token = strtok_r(md->value, "|", &tmpptr);
1818 while (token != NULL) {
1819 if (strcasestr(token, "portrait-effectimage=")) {
1820 portraitimg = index(token, '=');
1821 if (portraitimg && portraitimg[1] != '\0')
1825 } else if (strcasestr(token, "landscape-effectimage=")) {
1826 landscapeimg = index(token, '=');
1827 if (landscapeimg && landscapeimg[1] != '\0')
1830 landscapeimg = NULL;
1831 } else if (strcasestr(token, "indicatordisplay=")) {
1832 indicatordisplay = index(token, '=');
1833 if (indicatordisplay && indicatordisplay[1] != '\0')
1836 indicatordisplay = "true";
1839 token = strtok_r(NULL, "|", &tmpptr);
1843 orientation = "portrait";
1845 if (strcasestr(portraitimg, "edj"))
1847 sqlite3_snprintf(MAX_QUERY_LEN, query,
1848 "INSERT INTO package_app_splash_screen" \
1849 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1850 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1851 app->appid, portraitimg, image_type,
1852 orientation, indicatordisplay, operation,
1854 ret = __exec_query(query);
1856 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1859 memset(query, '\0', MAX_QUERY_LEN);
1862 orientation = "landscape";
1864 if (strcasestr(landscapeimg, "edj"))
1866 sqlite3_snprintf(MAX_QUERY_LEN, query,
1867 "INSERT INTO package_app_splash_screen" \
1868 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1869 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1870 app->appid, landscapeimg, image_type,
1871 orientation, indicatordisplay, operation,
1873 ret = __exec_query(query);
1875 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1878 memset(query, '\0', MAX_QUERY_LEN);
1886 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1890 privilege_x *pv = NULL;
1891 char query[MAX_QUERY_LEN] = { '\0' };
1894 const char *auth_name = NULL;
1895 const char *auth_email = NULL;
1896 const char *auth_href = NULL;
1898 GList *pkglocale = NULL;
1899 GList *applocale = NULL;
1900 GList *appicon = NULL;
1901 GList *appimage = NULL;
1903 int temp_pkg_mode = 0;
1904 int temp_app_mode = 0;
1905 char pkg_mode[10] = {'\0'};
1906 application_x *up_support_mode = NULL;
1907 GList *list_up = NULL;
1909 if (mfx->author && mfx->author->data) {
1910 author = (author_x *)mfx->author->data;
1912 auth_name = author->text;
1914 auth_email = author->email;
1916 auth_href = author->href;
1919 if (mfx->support_mode)
1920 temp_pkg_mode = atoi(mfx->support_mode);
1922 list_up = mfx->application;
1923 while (list_up != NULL) {
1924 up_support_mode = (application_x *)list_up->data;
1925 if (up_support_mode->support_mode) {
1926 temp_app_mode = atoi(up_support_mode->support_mode);
1927 temp_pkg_mode |= temp_app_mode;
1929 list_up = list_up->next;
1931 sprintf(pkg_mode, "%d", temp_pkg_mode);
1933 if(mfx->support_mode)
1934 free((void *)mfx->support_mode);
1935 mfx->support_mode = strdup(pkg_mode);
1937 /*Insert in the package_info DB*/
1938 sqlite3_snprintf(MAX_QUERY_LEN, query,
1939 "INSERT INTO package_info(" \
1940 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1941 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1942 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1943 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1944 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable, package_support_mode) " \
1946 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1947 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1948 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1949 "%Q, %Q, %Q, %Q, %Q, " \
1950 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q), %Q)",
1951 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1952 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1953 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1954 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1955 mfx->storeclient_id,
1956 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false), mfx->support_mode);
1958 ret = __exec_query(query);
1960 _LOGD("Package Info DB Insert Failed\n");
1964 /*Insert in the package_privilege_info DB*/
1965 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1966 pv = (privilege_x *)tmp->data;
1969 memset(query, '\0', MAX_QUERY_LEN);
1970 sqlite3_snprintf(MAX_QUERY_LEN, query,
1971 "INSERT INTO package_privilege_info(package, privilege, type) " \
1972 "VALUES(%Q, %Q, %Q)",\
1973 mfx->package, pv->value, pv->type);
1974 ret = __exec_query(query);
1976 _LOGD("Package Privilege Info DB Insert Failed\n");
1981 if (mfx->application != NULL) {
1982 ret = __insert_mainapp_info(mfx);
1987 /*Insert the package locale*/
1988 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1989 /*remove duplicated data in pkglocale*/
1990 __trimfunc(pkglocale);
1992 /*Insert the app locale, icon, image info */
1993 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1994 app = (application_x *)tmp->data;
1997 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1998 appicon = __create_icon_list(appicon, app->icon);
1999 appimage = __create_image_list(appimage, app->image);
2001 /*remove duplicated data in applocale*/
2002 __trimfunc(applocale);
2003 __trimfunc(appicon);
2004 __trimfunc(appimage);
2006 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
2008 /*native app locale info*/
2009 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2010 app = (application_x *)tmp->data;
2013 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
2014 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
2015 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
2018 g_list_free(pkglocale);
2020 g_list_free(applocale);
2022 g_list_free(appicon);
2024 g_list_free(appimage);
2027 /*Insert in the package_app_info DB*/
2028 ret = __insert_application_info(mfx);
2031 /*Insert in the package_app_app_control DB*/
2032 ret = __insert_application_appcontrol_info(mfx);
2036 /*Insert in the package_app_app_category DB*/
2037 ret = __insert_application_appcategory_info(mfx);
2041 /*Insert in the package_app_app_metadata DB*/
2042 ret = __insert_application_appmetadata_info(mfx);
2046 /*Insert in the package_app_app_permission DB*/
2047 ret = __insert_application_apppermission_info(mfx);
2051 /*Insert in the package_app_share_allowed DB*/
2052 ret = __insert_application_share_allowed_info(mfx);
2056 /*Insert in the package_app_share_request DB*/
2057 ret = __insert_application_share_request_info(mfx);
2061 /*Insert in the package_app_data_control DB*/
2062 ret = __insert_application_datacontrol_info(mfx);
2066 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2067 ret = __insert_application_legacy_splashscreen_info(mfx);
2071 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2072 ret = __insert_application_metadata_splashscreen_info(mfx);
2076 /*Insert in the package_app_splash_screen DB*/
2077 ret = __insert_application_splashscreen_info(mfx);
2085 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2087 char query[MAX_QUERY_LEN] = { '\0' };
2090 sqlite3_snprintf(MAX_QUERY_LEN, query,
2091 "DELETE FROM %q where app_id=%Q", db_table, appid);
2092 ret = __exec_query(query);
2094 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2100 static int __delete_subpkg_info_from_db(char *appid)
2104 ret = __delete_appinfo_from_db("package_app_info", appid);
2107 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2110 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2113 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2116 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2119 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2122 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2125 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2128 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2131 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2134 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2137 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2144 static int __delete_subpkg_from_db(manifest_x *mfx)
2146 char query[MAX_QUERY_LEN] = { '\0' };
2147 char *error_message = NULL;
2149 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2151 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2152 _LOGE("Don't execute query = %s error message = %s\n", query,
2154 sqlite3_free(error_message);
2157 sqlite3_free(error_message);
2162 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2164 char query[MAX_QUERY_LEN] = { '\0' };
2169 /*Delete from Package Info DB*/
2170 sqlite3_snprintf(MAX_QUERY_LEN, query,
2171 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2172 ret = __exec_query(query);
2174 _LOGD("Package Info DB Delete Failed\n");
2177 memset(query, '\0', MAX_QUERY_LEN);
2179 /*Delete from Package Localized Info*/
2180 sqlite3_snprintf(MAX_QUERY_LEN, query,
2181 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2182 ret = __exec_query(query);
2184 _LOGD("Package Localized Info DB Delete Failed\n");
2188 /*Delete from Package Privilege Info*/
2189 sqlite3_snprintf(MAX_QUERY_LEN, query,
2190 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2191 ret = __exec_query(query);
2193 _LOGD("Package Privilege Info DB Delete Failed\n");
2197 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2198 app = (application_x *)tmp->data;
2201 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2204 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2207 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2210 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2213 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2216 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2219 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2222 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2225 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2228 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2231 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2234 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2239 /* if main package has sub pkg, delete sub pkg data*/
2240 __delete_subpkg_from_db(mfx);
2245 static int __disable_app(const char *appid)
2248 char query[MAX_QUERY_LEN] = {'\0'};
2249 sqlite3_snprintf(MAX_QUERY_LEN, query,
2250 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2252 ret = __exec_query(query);
2254 _LOGD("Insert global app disable failed\n");
2259 static int __enable_app(const char *appid)
2262 char query[MAX_QUERY_LEN] = {'\0'};
2263 sqlite3_snprintf(MAX_QUERY_LEN, query,
2264 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2266 ret = __exec_query(query);
2268 _LOGD("Insert global app disable failed\n");
2273 static int __disable_pkg(const char *pkgid)
2276 char query[MAX_QUERY_LEN] = {'\0'};
2277 sqlite3_snprintf(MAX_QUERY_LEN, query,
2278 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2280 ret = __exec_query(query);
2282 _LOGD("Update pkg disable info has failed\n");
2287 static int __enable_pkg(const char *pkgid)
2290 char query[MAX_QUERY_LEN] = {'\0'};
2291 sqlite3_snprintf(MAX_QUERY_LEN, query,
2292 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2294 ret = __exec_query(query);
2296 _LOGD("Update pkg disable info has failed\n");
2301 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2304 char query[MAX_QUERY_LEN] = { '\0', };
2306 const char *val = NULL;
2311 sqlite3_snprintf(MAX_QUERY_LEN, query,
2312 "SELECT COUNT(*) FROM "
2313 "package_app_info_for_uid WHERE app_id=%Q "
2314 "AND uid=%d", appid, (int)uid);
2316 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2317 if (ret != SQLITE_OK) {
2318 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2319 return PMINFO_R_ERROR;
2322 if (sqlite3_step(stmt) != SQLITE_ROW) {
2323 LOGE("failed to step");
2324 sqlite3_finalize(stmt);
2325 return PMINFO_R_ERROR;
2328 val = (const char *)sqlite3_column_text(stmt, 0);
2330 sqlite3_finalize(stmt);
2335 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2338 char query[MAX_QUERY_LEN] = { '\0', };
2340 ret = __check_appinfo_for_uid_table(appid, uid);
2342 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2345 } else if (ret == 0) {
2346 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2347 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2348 "VALUES(%Q, %d, 'true', "
2349 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2350 appid, (int)uid, appid);
2352 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2353 "package_app_info_for_uid SET is_disabled='true' "
2354 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2357 ret = __exec_query(query);
2359 _LOGD("Add global app disable info failed\n");
2364 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2367 char query[MAX_QUERY_LEN] = {'\0'};
2369 ret = __check_appinfo_for_uid_table(appid, uid);
2371 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2374 } else if (ret > 0) {
2375 sqlite3_snprintf(MAX_QUERY_LEN, query,
2376 "UPDATE package_app_info_for_uid SET "
2377 "is_disabled='false' WHERE app_id=%Q AND "
2378 "uid=%d", appid, (int)uid);
2381 ret = __exec_query(query);
2383 _LOGD("Remove global app disable info failed\n");
2388 static int __update_global_app_splash_screen_for_user(const char *appid,
2389 uid_t uid, int flag)
2392 char query[MAX_QUERY_LEN] = { '\0', };
2394 ret = __check_appinfo_for_uid_table(appid, uid);
2396 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2399 } else if (ret == 0) {
2400 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2401 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2402 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2403 flag ? "true" : "false");
2405 sqlite3_snprintf(MAX_QUERY_LEN, query,
2406 "UPDATE package_app_info_for_uid SET "
2407 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2408 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2411 ret = __exec_query(query);
2413 _LOGD("update global app splash screen info failed\n");
2418 static int __disable_app_splash_screen(const char *appid)
2421 char query[MAX_QUERY_LEN] = {'\0'};
2423 sqlite3_snprintf(MAX_QUERY_LEN, query,
2424 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2426 ret = __exec_query(query);
2428 _LOGD("Failed to update app_palsh_screen_display");
2433 static int __enable_app_splash_screen(const char *appid)
2436 char query[MAX_QUERY_LEN] = {'\0'};
2438 sqlite3_snprintf(MAX_QUERY_LEN, query,
2439 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2441 ret = __exec_query(query);
2443 _LOGD("Failed to update app_splash_screen_display");
2448 API int pkgmgr_parser_initialize_db(uid_t uid)
2454 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2456 _LOGD("package info DB initialization failed\n");
2459 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2461 _LOGD("package localized info DB initialization failed\n");
2464 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2466 _LOGD("package app app privilege DB initialization failed\n");
2469 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2471 _LOGD("package app info DB initialization failed\n");
2474 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2476 _LOGD("package app localized info DB initialization failed\n");
2479 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2481 _LOGD("package app icon localized info DB initialization failed\n");
2484 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2486 _LOGD("package app image info DB initialization failed\n");
2489 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2491 _LOGD("package app app control DB initialization failed\n");
2494 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2496 _LOGD("package app app category DB initialization failed\n");
2499 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2501 _LOGD("package app app category DB initialization failed\n");
2504 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2506 _LOGD("package app app permission DB initialization failed\n");
2509 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2511 _LOGD("package app share allowed DB initialization failed\n");
2514 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2516 _LOGD("package app share request DB initialization failed\n");
2519 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2521 _LOGD("package app data control DB initialization failed\n");
2525 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2527 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2531 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2533 _LOGD("package app splash screen DB initialization failed\n");
2537 /* Trigger package_app_info_for_uid */
2538 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2540 _LOGD("package app info for uid DB initialization failed\n");
2545 /* TODO: refactor this code */
2546 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2548 _LOGD("package cert info DB initialization failed\n");
2551 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2553 _LOGD("package cert index info DB initialization failed\n");
2556 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2558 _LOGD("package cert info DB initialization failed\n");
2561 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2563 _LOGD("package cert info DB initialization failed\n");
2566 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2568 _LOGD("package cert info DB initialization failed\n");
2571 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2573 _LOGD("package cert index info DB initialization failed\n");
2577 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2578 if (db_path == NULL) {
2579 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2581 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2583 _LOGD("Failed to change cert db permission");
2587 db_path = getUserPkgParserDBPathUID(uid);
2588 if (db_path == NULL) {
2589 _LOGD("Failed to get user pkg parser db path - %d", uid);
2591 ret = __parserdb_change_perm(db_path, uid);
2593 _LOGD("Failed to change parser db permission\n");
2600 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2603 char pwuid_buf[1024];
2604 char journal_file[BUFSIZE];
2609 struct passwd userinfo, *result = NULL;
2610 files[0] = (char *)db_file;
2611 files[1] = journal_file;
2615 if (db_file == NULL)
2618 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2620 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2621 if (uid == OWNER_ROOT)
2623 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2624 if (ret != 0 || result == NULL) {
2625 _LOGE("FAIL: user %d doesn't exist", uid);
2628 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2630 for (i = 0; files[i]; i++) {
2631 fd = open(files[i], O_RDONLY);
2633 if (strerror_r(errno, buf, sizeof(buf)))
2634 strncpy(buf, "", BUFSIZE - 1);
2635 _LOGD("FAIL : open %s : %s", files[i], buf);
2638 ret = fstat(fd, &sb);
2640 if (strerror_r(errno, buf, sizeof(buf)))
2641 strncpy(buf, "", BUFSIZE - 1);
2642 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2646 if (S_ISLNK(sb.st_mode)) {
2647 _LOGE("FAIL : %s is symlink!", files[i]);
2651 ret = fchown(fd, uid, userinfo.pw_gid);
2653 if (strerror_r(errno, buf, sizeof(buf)))
2654 strncpy(buf, "", BUFSIZE - 1);
2655 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2656 userinfo.pw_gid, buf);
2661 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2662 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2664 ret = fchmod(fd, mode);
2666 if (strerror_r(errno, buf, sizeof(buf)))
2667 strncpy(buf, "", BUFSIZE - 1);
2668 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2673 SET_SMACK_LABEL(files[i]);
2678 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2683 if (getuid() != OWNER_ROOT) {
2684 _LOGE("Only root user is allowed");
2688 db_path = getUserPkgParserDBPathUID(uid);
2689 if (db_path == NULL) {
2690 _LOGE("Failed to get pkg parser db path - %d", uid);
2694 if (access(db_path, F_OK) != -1) {
2695 _LOGE("Manifest db for user %d is already exists", uid);
2701 db_path = getUserPkgCertDBPathUID(uid);
2702 if (db_path == NULL) {
2703 _LOGE("Failed to get pkg cert db path - %d", uid);
2707 if (access(db_path, F_OK) != -1) {
2708 _LOGE("Cert db for user %d is already exists", uid);
2714 ret = pkgmgr_parser_check_and_create_db(uid);
2717 ret = pkgmgr_parser_initialize_db(uid);
2719 pkgmgr_parser_close_db();
2722 pkgmgr_parser_close_db();
2727 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2732 db_path = getUserPkgParserDBPathUID(uid);
2733 if (db_path == NULL) {
2734 _LOGD("Failed to get pkg parser db path - %d", uid);
2739 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2741 _LOGD("Manifest DB creation Failed\n");
2747 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2748 if (db_path == NULL) {
2749 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2754 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2756 _LOGD("Cert DB creation Failed\n");
2766 void pkgmgr_parser_close_db(void)
2768 sqlite3_close(pkgmgr_parser_db);
2769 sqlite3_close(pkgmgr_cert_db);
2773 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2775 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2777 _LOGD("manifest pointer is NULL\n");
2781 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2783 _LOGD("Failed to open DB\n");
2786 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2789 /*Begin transaction*/
2790 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2791 if (ret != SQLITE_OK) {
2792 _LOGD("Failed to begin transaction\n");
2796 _LOGD("Transaction Begin\n");
2797 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2799 _LOGD("Insert into DB failed. Rollback now\n");
2800 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2803 /*Commit transaction*/
2804 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2805 if (ret != SQLITE_OK) {
2806 _LOGD("Failed to commit transaction. Rollback now\n");
2807 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2811 _LOGD("Transaction Commit and End\n");
2813 pkgmgr_parser_close_db();
2817 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2819 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2821 _LOGD("manifest pointer is NULL\n");
2825 ret = pkgmgr_parser_check_and_create_db(uid);
2827 _LOGD("Failed to open DB\n");
2830 ret = pkgmgr_parser_initialize_db(uid);
2833 /*Begin transaction*/
2834 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2835 if (ret != SQLITE_OK) {
2836 _LOGD("Failed to begin transaction\n");
2840 _LOGD("Transaction Begin\n");
2841 ret = __insert_manifest_info_in_db(mfx, uid);
2843 _LOGD("Insert into DB failed. Rollback now\n");
2844 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2847 /*Commit transaction*/
2848 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2849 if (ret != SQLITE_OK) {
2850 _LOGD("Failed to commit transaction. Rollback now\n");
2851 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2855 _LOGD("Transaction Commit and End\n");
2857 pkgmgr_parser_close_db();
2861 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2863 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2866 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2868 if (pkgid == NULL || tep_path == NULL) {
2869 _LOGE("invalid parameter");
2876 ret = pkgmgr_parser_check_and_create_db(uid);
2878 _LOGD("Failed to open DB\n");
2881 ret = pkgmgr_parser_initialize_db(uid);
2885 /*Begin transaction*/
2886 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2887 if (ret != SQLITE_OK) {
2888 _LOGD("Failed to begin transaction\n");
2892 _LOGD("Transaction Begin\n");
2895 /* Updating TEP info in "package_info" table */
2896 query = sqlite3_mprintf("UPDATE package_info "\
2897 "SET package_tep_name = %Q "\
2898 "WHERE package = %Q", tep_path, pkgid);
2900 ret = __exec_query(query);
2901 sqlite3_free(query);
2902 if (ret != SQLITE_OK) {
2903 ret = PM_PARSER_R_ERROR;
2904 _LOGE("sqlite exec failed to insert entries into package_info!!");
2908 /* Updating TEP info in "package_app_info" table */
2909 query = sqlite3_mprintf("UPDATE package_app_info "\
2910 "SET app_tep_name = %Q "\
2911 "WHERE package = %Q", tep_path, pkgid);
2913 ret = __exec_query(query);
2914 sqlite3_free(query);
2915 if (ret != SQLITE_OK) {
2916 ret = PM_PARSER_R_ERROR;
2917 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2921 /*Commit transaction*/
2922 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2923 if (ret != SQLITE_OK) {
2924 _LOGE("Failed to commit transaction, Rollback now\n");
2925 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2926 if (ret != SQLITE_OK)
2927 _LOGE("Failed to Rollback\n");
2929 ret = PM_PARSER_R_ERROR;
2932 _LOGD("Transaction Commit and End\n");
2933 ret = PM_PARSER_R_OK;
2936 pkgmgr_parser_close_db();
2941 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2944 _LOGD("manifest pointer is NULL\n");
2948 ret = pkgmgr_parser_check_and_create_db(uid);
2950 _LOGD("Failed to open DB\n");
2953 ret = pkgmgr_parser_initialize_db(uid);
2956 /*Preserve guest mode visibility*/
2957 __preserve_guestmode_visibility_value(mfx);
2958 /*Begin transaction*/
2959 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2960 if (ret != SQLITE_OK) {
2961 _LOGD("Failed to begin transaction\n");
2965 _LOGD("Transaction Begin\n");
2966 ret = __delete_manifest_info_from_db(mfx, uid);
2968 _LOGD("Delete from DB failed. Rollback now\n");
2969 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2972 ret = __insert_manifest_info_in_db(mfx, uid);
2974 _LOGD("Insert into DB failed. Rollback now\n");
2975 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2979 /*Commit transaction*/
2980 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2981 if (ret != SQLITE_OK) {
2982 _LOGD("Failed to commit transaction. Rollback now\n");
2983 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2987 _LOGD("Transaction Commit and End\n");
2989 pkgmgr_parser_close_db();
2993 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2995 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2998 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
3001 _LOGD("manifest pointer is NULL\n");
3005 ret = pkgmgr_parser_check_and_create_db(uid);
3007 _LOGD("Failed to open DB\n");
3010 /*Begin transaction*/
3011 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3012 if (ret != SQLITE_OK) {
3013 _LOGD("Failed to begin transaction\n");
3017 _LOGD("Transaction Begin\n");
3018 ret = __delete_manifest_info_from_db(mfx, uid);
3020 _LOGD("Delete from DB failed. Rollback now\n");
3021 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3024 /*Commit transaction*/
3025 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3026 if (ret != SQLITE_OK) {
3027 _LOGD("Failed to commit transaction, Rollback now\n");
3028 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3032 _LOGD("Transaction Commit and End\n");
3034 pkgmgr_parser_close_db();
3038 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
3040 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
3043 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
3047 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3049 _LOGD("Failed to open DB\n");
3053 /*Begin transaction*/
3054 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3055 if (ret != SQLITE_OK) {
3056 _LOGD("Failed to begin transaction\n");
3060 _LOGD("Transaction Begin\n");
3062 ret = __disable_global_app_for_user(appid, uid);
3064 ret = __enable_global_app_for_user(appid, uid);
3066 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
3067 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3070 /*Commit transaction*/
3071 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3072 if (ret != SQLITE_OK) {
3073 _LOGD("Failed to commit transaction, Rollback now\n");
3074 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3078 _LOGD("Transaction Commit and End\n");
3080 pkgmgr_parser_close_db();
3085 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3087 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3090 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3094 ret = pkgmgr_parser_check_and_create_db(uid);
3096 _LOGD("Failed to open DB\n");
3100 /*Begin transaction*/
3101 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3102 if (ret != SQLITE_OK) {
3103 _LOGD("Failed to begin transaction\n");
3108 _LOGD("Transaction Begin\n");
3110 ret = __disable_pkg(pkgid);
3112 ret = __enable_pkg(pkgid);
3115 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3116 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3120 /*Commit transaction*/
3121 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3122 if (ret != SQLITE_OK) {
3123 _LOGD("Failed to commit transaction, Rollback now\n");
3124 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3128 _LOGD("Transaction Commit and End\n");
3131 pkgmgr_parser_close_db();
3135 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3137 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3140 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3144 ret = pkgmgr_parser_check_and_create_db(uid);
3146 _LOGD("Failed to open DB\n");
3150 /*Begin transaction*/
3151 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3152 if (ret != SQLITE_OK) {
3153 _LOGD("Failed to begin transaction\n");
3157 _LOGD("Transaction Begin\n");
3159 ret = __disable_app(appid);
3161 ret = __enable_app(appid);
3163 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3164 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3167 /*Commit transaction*/
3168 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3169 if (ret != SQLITE_OK) {
3170 _LOGD("Failed to commit transaction, Rollback now\n");
3171 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3175 _LOGD("Transaction Commit and End\n");
3177 pkgmgr_parser_close_db();
3182 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3186 if (appid == NULL) {
3187 _LOGD("Invalid parameter");
3191 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3193 _LOGD("Failed to open DB\n");
3197 /* Begin transaction */
3198 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3199 if (ret != SQLITE_OK) {
3200 _LOGD("Failed to begin transaction\n");
3204 _LOGD("Transaction Begin\n");
3206 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3208 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3209 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3212 /* Commit transaction */
3213 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3214 if (ret != SQLITE_OK) {
3215 _LOGD("Failed to commit transaction, Rollback now\n");
3216 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3220 _LOGD("Transaction Commit and End\n");
3222 pkgmgr_parser_close_db();
3226 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3228 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3231 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3235 if (appid == NULL) {
3236 _LOGD("Invalid parameter");
3240 ret = pkgmgr_parser_check_and_create_db(uid);
3242 _LOGD("Failed to open DB");
3246 /* Begin transaction */
3247 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3248 if (ret != SQLITE_OK) {
3249 _LOGD("Failed to begin transaction");
3253 _LOGD("Transaction Begin");
3256 ret = __enable_app_splash_screen(appid);
3258 ret = __disable_app_splash_screen(appid);
3260 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3261 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3264 /* Commit transaction */
3265 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3266 if (ret != SQLITE_OK) {
3267 _LOGD("Failed to commit transaction, Rollback now");
3268 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3272 _LOGD("Transaction Commit and End");
3275 pkgmgr_parser_close_db();
3279 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3282 char query[MAX_QUERY_LEN] = {'\0'};
3284 if (appid == NULL || label == NULL) {
3285 _LOGE("Invalid parameter");
3289 ret = pkgmgr_parser_check_and_create_db(uid);
3291 _LOGD("Failed to open DB");
3295 /*Begin transaction*/
3296 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3297 if (ret != SQLITE_OK) {
3298 _LOGD("Failed to begin transaction\n");
3303 sqlite3_snprintf(MAX_QUERY_LEN, query,
3304 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3305 "app_id=%Q AND app_label IS NOT NULL",
3307 ret = __exec_query(query);
3309 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3313 /* Commit transaction */
3314 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3315 if (ret != SQLITE_OK) {
3316 _LOGD("Failed to commit transaction, Rollback now");
3317 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3321 _LOGD("Transaction Commit and End");
3324 pkgmgr_parser_close_db();
3328 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3330 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);