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_disable TEXT NOT NULL DEFAULT 'false', " \
117 "package_disable TEXT NOT NULL DEFAULT 'false')"
119 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
120 "(package TEXT NOT NULL, " \
121 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
122 "package_label TEXT, " \
123 "package_icon TEXT, " \
124 "package_description TEXT, " \
125 "package_license TEXT, " \
126 "package_author TEXT, " \
127 "PRIMARY KEY(package, package_locale), " \
128 "FOREIGN KEY(package) " \
129 "REFERENCES package_info(package) " \
132 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
133 "(package TEXT NOT NULL, " \
134 "privilege TEXT NOT NULL, " \
135 "type TEXT NOT NULL, " \
136 "PRIMARY KEY(package, privilege, type) " \
137 "FOREIGN KEY(package) " \
138 "REFERENCES package_info(package) " \
141 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
142 "(app_id TEXT PRIMARY KEY NOT NULL, " \
143 "app_component TEXT NOT NULL, " \
145 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
147 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
148 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
149 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
150 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
151 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
152 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
153 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
154 "app_mainapp TEXT NOT NULL, " \
155 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
156 "app_launchcondition TEXT, " \
157 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
158 "app_portraitimg TEXT, " \
159 "app_landscapeimg TEXT, " \
160 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
161 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
162 "app_preload TEXT NOT NULL DEFAULT 'false', " \
163 "app_submode TEXT NOT NULL DEFAULT 'false', " \
164 "app_submode_mainid TEXT, " \
165 "app_installed_storage TEXT NOT NULL, " \
166 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
167 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
168 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
169 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
170 "app_disable TEXT NOT NULL DEFAULT 'false', " \
171 "app_package_type TEXT DEFAULT 'tpk', " \
172 "app_package_system TEXT NOT NULL, " \
173 "app_removable TEXT NOT NULL DEFAULT 'false', " \
174 "app_package_installed_time TEXT, " \
175 "component_type TEXT, " \
176 "package TEXT NOT NULL, " \
177 "app_tep_name TEXT, " \
178 "app_zip_mount_file TEXT, " \
179 "app_background_category INTEGER DEFAULT 0, " \
180 "app_root_path TEXT, " \
181 "app_api_version TEXT, " \
182 "app_effective_appid TEXT, " \
183 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
184 "app_external_path TEXT, " \
185 "FOREIGN KEY(package) " \
186 "REFERENCES package_info(package) " \
189 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
190 "(app_id TEXT NOT NULL, " \
191 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
194 "PRIMARY KEY(app_id,app_locale) " \
195 "FOREIGN KEY(app_id) " \
196 "REFERENCES package_app_info(app_id) " \
199 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
200 "(app_id TEXT NOT NULL, " \
202 "app_icon_section TEXT NOT NULL, " \
203 "app_icon_resolution TEXT NOT NULL, " \
204 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
205 "FOREIGN KEY(app_id) " \
206 "REFERENCES package_app_info(app_id) " \
209 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
210 "(app_id TEXT NOT NULL, " \
211 "app_locale TEXT DEFAULT 'No Locale', " \
212 "app_image_section TEXT NOT NULL, " \
214 "PRIMARY KEY(app_id,app_image_section) " \
215 "FOREIGN KEY(app_id) " \
216 "REFERENCES package_app_info(app_id) " \
219 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
220 "(app_id TEXT NOT NULL, " \
221 "app_control TEXT NOT NULL, " \
222 "PRIMARY KEY(app_id,app_control) " \
223 "FOREIGN KEY(app_id) " \
224 "REFERENCES package_app_info(app_id) " \
227 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
228 "(app_id TEXT NOT NULL, " \
229 "category TEXT NOT NULL, " \
230 "PRIMARY KEY(app_id,category) " \
231 "FOREIGN KEY(app_id) " \
232 "REFERENCES package_app_info(app_id) " \
235 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
236 "(app_id TEXT NOT NULL, " \
237 "md_key TEXT NOT NULL, " \
239 "PRIMARY KEY(app_id, md_key, md_value) " \
240 "FOREIGN KEY(app_id) " \
241 "REFERENCES package_app_info(app_id) " \
244 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
245 "(app_id TEXT NOT NULL, " \
246 "pm_type TEXT NOT NULL, " \
247 "pm_value TEXT NOT NULL, " \
248 "PRIMARY KEY(app_id, pm_type, pm_value) " \
249 "FOREIGN KEY(app_id) " \
250 "REFERENCES package_app_info(app_id) " \
253 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
254 "(app_id TEXT NOT NULL, " \
255 "data_share_path TEXT NOT NULL, " \
256 "data_share_allowed TEXT NOT NULL, " \
257 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
258 "FOREIGN KEY(app_id) " \
259 "REFERENCES package_app_info(app_id) " \
262 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
263 "(app_id TEXT NOT NULL, " \
264 "data_share_request TEXT NOT NULL, " \
265 "PRIMARY KEY(app_id,data_share_request) " \
266 "FOREIGN KEY(app_id) " \
267 "REFERENCES package_app_info(app_id) " \
270 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
271 "(app_id TEXT NOT NULL, " \
272 "providerid TEXT NOT NULL, " \
273 "access TEXT NOT NULL, " \
274 "type TEXT NOT NULL, " \
275 "PRIMARY KEY(app_id, providerid, access, type) " \
276 "FOREIGN KEY(app_id) " \
277 "REFERENCES package_app_info(app_id) " \
280 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
281 "(app_id TEXT NOT NULL, " \
282 "uid INTEGER NOT NULL, " \
283 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
284 "is_splash_screen_enabled TEXT NOT NULL, " \
285 "PRIMARY KEY(app_id, uid))"
287 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
288 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
289 "AFTER UPDATE ON package_app_info_for_uid " \
291 " DELETE FROM package_app_info_for_uid WHERE " \
292 " is_splash_screen_enabled=" \
293 " (SELECT package_app_info.app_splash_screen_display FROM " \
294 " package_app_info, package_app_info_for_uid WHERE " \
295 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
298 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
299 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
300 "(app_id TEXT NOT NULL, " \
301 "src TEXT NOT NULL, " \
302 "type TEXT NOT NULL, " \
303 "orientation TEXT NOT NULL, " \
304 "indicatordisplay TEXT, " \
305 "operation TEXT NOT NULL, " \
306 "color_depth TEXT NOT NULL DEFAULT '24', " \
307 "PRIMARY KEY(app_id, orientation, operation) " \
308 "FOREIGN KEY(app_id) " \
309 "REFERENCES package_app_info(app_id) " \
313 /* FIXME: duplicated at pkgmgrinfo_db.c */
314 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
315 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
316 " cert_info TEXT UNIQUE, " \
317 " cert_id INTEGER PRIMARY KEY, " \
318 " cert_ref_count INTEGER NOT NULL)"
320 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
321 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
322 " package TEXT PRIMARY KEY, " \
323 " package_count INTEGER, " \
324 " author_root_cert INTEGER, " \
325 " author_im_cert INTEGER, " \
326 " author_signer_cert INTEGER, " \
327 " dist_root_cert INTEGER, " \
328 " dist_im_cert INTEGER, " \
329 " dist_signer_cert INTEGER, " \
330 " dist2_root_cert INTEGER, " \
331 " dist2_im_cert INTEGER, " \
332 " dist2_signer_cert INTEGER)"
334 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
335 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
336 "AFTER UPDATE ON package_cert_info " \
337 "WHEN (NEW.package_count = 0) " \
339 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
342 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
343 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
344 "AFTER UPDATE ON package_cert_info " \
345 "WHEN (NEW.package_count = OLD.package_count + 1) " \
347 " UPDATE package_cert_index_info SET" \
348 " cert_ref_count = cert_ref_count - 1" \
349 " WHERE cert_id = OLD.author_root_cert" \
350 " OR cert_id = OLD.author_im_cert" \
351 " OR cert_id = OLD.author_signer_cert" \
352 " OR cert_id = OLD.dist_root_cert" \
353 " OR cert_id = OLD.dist_im_cert" \
354 " OR cert_id = OLD.dist_signer_cert" \
355 " OR cert_id = OLD.dist2_root_cert" \
356 " OR cert_id = OLD.dist2_im_cert" \
357 " OR cert_id = OLD.dist2_signer_cert;" \
360 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
361 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
362 "AFTER DELETE ON package_cert_info " \
364 " UPDATE package_cert_index_info SET" \
365 " cert_ref_count = cert_ref_count - 1" \
366 " WHERE cert_id = OLD.author_root_cert" \
367 " OR cert_id = OLD.author_im_cert" \
368 " OR cert_id = OLD.author_signer_cert" \
369 " OR cert_id = OLD.dist_root_cert" \
370 " OR cert_id = OLD.dist_im_cert" \
371 " OR cert_id = OLD.dist_signer_cert" \
372 " OR cert_id = OLD.dist2_root_cert" \
373 " OR cert_id = OLD.dist2_im_cert" \
374 " OR cert_id = OLD.dist2_signer_cert;" \
377 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
378 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
379 "AFTER UPDATE ON package_cert_index_info " \
380 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
381 " WHERE cert_id = OLD.cert_id) = 0) "\
383 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
386 static int __insert_application_info(manifest_x *mfx);
387 static int __insert_application_appcategory_info(manifest_x *mfx);
388 static int __insert_application_appcontrol_info(manifest_x *mfx);
389 static int __insert_application_appmetadata_info(manifest_x *mfx);
390 static int __insert_application_share_allowed_info(manifest_x *mfx);
391 static int __insert_application_share_request_info(manifest_x *mfx);
392 static int __insert_application_datacontrol_info(manifest_x *mfx);
393 static void __insert_application_locale_info(gpointer data, gpointer userdata);
394 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
395 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
396 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
397 static int __delete_subpkg_info_from_db(char *appid);
398 static int __delete_appinfo_from_db(char *db_table, const char *appid);
399 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
400 static int __exec_query(char *query);
401 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
402 char **label, char **license, char **icon, char **description, char **author);
403 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
404 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
405 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
406 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
407 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
408 static int __parserdb_change_perm(const char *db_file, uid_t uid);
410 #define REGULAR_USER 5000
411 static inline uid_t _getuid(void)
413 uid_t uid = getuid();
415 if (uid < REGULAR_USER)
416 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
421 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
424 __delete_subpkg_info_from_db(coltxt[0]);
429 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
434 char *error_message = NULL;
436 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
437 if (ret != SQLITE_OK) {
438 _LOGD("connect db [%s] failed!\n", db_path);
443 /* add user_version for db upgrade*/
444 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
446 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
447 _LOGE("Don't execute query = %s error message = %s\n", query,
450 sqlite3_free(error_message);
456 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
458 manifest_x *mfx = (manifest_x *)data;
464 if (mfx->application == NULL)
466 app = (application_x *)mfx->application->data;
467 for (i = 0; i < ncols; i++) {
468 if (strcmp(colname[i], "app_id") == 0) {
470 appid = strdup(coltxt[i]);
471 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
473 status = strdup(coltxt[i]);
479 _LOGD("app id is NULL\n");
482 /*update guest mode visibility*/
483 for (tmp = mfx->application; tmp; tmp = tmp->next) {
484 app = (application_x *)tmp->data;
487 if (strcmp(app->appid, appid) == 0) {
488 free((void *)app->guestmode_visibility);
489 app->guestmode_visibility = strdup(status);
505 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
507 char *error_message = NULL;
508 char query[MAX_QUERY_LEN] = {'\0'};
509 sqlite3_snprintf(MAX_QUERY_LEN, query,
510 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
511 "WHERE package=%Q", mfx->package);
513 sqlite3_exec(pkgmgr_parser_db, query,
514 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
515 _LOGD("Don't execute query = %s error message = %s\n",
516 query, error_message);
517 sqlite3_free(error_message);
522 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
524 char *error_message = NULL;
526 sqlite3_exec(db_handle, db_query,
527 NULL, NULL, &error_message)) {
528 _LOGD("Don't execute query = %s error message = %s\n",
529 db_query, error_message);
530 sqlite3_free(error_message);
533 sqlite3_free(error_message);
537 static int __exec_query(char *query)
539 char *error_message = NULL;
541 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
542 _LOGE("Don't execute query = %s error message = %s\n", query,
544 sqlite3_free(error_message);
547 sqlite3_free(error_message);
551 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
559 for (tmp = lbls; tmp; tmp = tmp->next) {
560 lbl = (label_x *)tmp->data;
564 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
566 for (tmp = lcns; tmp; tmp = tmp->next) {
567 lcn = (license_x *)tmp->data;
571 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
573 for (tmp = icns; tmp; tmp = tmp->next) {
574 icn = (icon_x *)tmp->data;
578 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
580 for (tmp = dcns; tmp; tmp = tmp->next) {
581 dcn = (description_x *)tmp->data;
585 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
587 for (tmp = aths; tmp; tmp = tmp->next) {
588 ath = (author_x *)tmp->data;
592 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
598 static GList *__create_icon_list(GList *appicon, GList *icns)
603 for (tmp = icns; tmp; tmp = tmp->next) {
604 icn = (icon_x *)tmp->data;
608 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
613 static GList *__create_image_list(GList *appimage, GList *imgs)
618 for (tmp = imgs; tmp; tmp = tmp->next) {
619 img = (image_x *)tmp->data;
623 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
628 static void __trimfunc(GList *trim_list)
630 char *trim_data = NULL;
634 list = g_list_first(trim_list);
637 trim_data = (char *)list->data;
640 if (strcmp(trim_data, prev) == 0) {
641 trim_list = g_list_remove(trim_list, trim_data);
642 list = g_list_first(trim_list);
651 list = g_list_next(list);
655 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
657 if (a == NULL || b == NULL)
659 if (strcmp((char *)a, (char *)b) == 0)
661 if (strcmp((char *)a, (char *)b) < 0)
663 if (strcmp((char *)a, (char *)b) > 0)
668 static int __check_dpi(const char *dpi_char, int dpi_int)
670 if (dpi_char == NULL)
673 if (strcasecmp(dpi_char, LDPI) == 0) {
674 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
678 } else if (strcasecmp(dpi_char, MDPI) == 0) {
679 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
683 } else if (strcasecmp(dpi_char, HDPI) == 0) {
684 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
688 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
689 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
693 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
694 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
702 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
705 char *icon_filename = NULL;
706 char modified_iconpath[BUFSIZE] = { '\0' };
707 char icon_path[BUFSIZE] = { '\0' };
711 if (orig_icon_path == NULL)
714 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
718 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
719 dpi_path[0] = "LDPI";
720 dpi_path[1] = "ldpi";
721 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
722 dpi_path[0] = "MDPI";
723 dpi_path[1] = "mdpi";
724 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
725 dpi_path[0] = "HDPI";
726 dpi_path[1] = "hdpi";
727 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
728 dpi_path[0] = "XHDPI";
729 dpi_path[1] = "xhdpi";
730 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
731 dpi_path[0] = "XXHDPI";
732 dpi_path[1] = "xxhdpi";
734 _LOGE("Unidentified dpi[%d]", dpi);
738 icon_filename = strrchr(orig_icon_path, '/');
739 if (icon_filename == NULL)
742 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
743 for (i = 0; i < 2; i++) {
744 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
745 if (access(modified_iconpath, F_OK) != -1) {
746 /* if exists, return modified icon path */
747 *new_icon_path = strdup(modified_iconpath);
755 static gint __compare_icon(gconstpointer a, gconstpointer b)
757 icon_x *icon = (icon_x *)a;
759 char *icon_folder_path = NULL;
761 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
764 if (icon->dpi != NULL)
767 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
769 icon->text = icon_folder_path;
775 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
777 icon_x *icon = (icon_x *)a;
778 int dpi = GPOINTER_TO_INT(b);
780 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
783 if (icon->dpi == NULL)
786 if (__check_dpi(icon->dpi, dpi) == 0)
792 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
794 icon_x *icon = (icon_x *)a;
795 char *lang = (char *)b;
796 char *icon_folder_path = NULL;
798 if (icon->dpi != NULL)
801 if (strcasecmp(icon->lang, lang) == 0) {
802 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
803 /* icon for no locale. check existance of folder-hierachied default icons */
804 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
806 icon->text = icon_folder_path;
815 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
817 icon_x *icon = (icon_x *)a;
818 char *lang = (char *)b;
821 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
825 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
831 static char *__find_icon(GList *icons, const char *lang)
838 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
839 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
841 icon = (icon_x *)tmp->data;
842 return (char *)icon->text;
845 /* if first has failed, find icon whose locale has matched */
846 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
848 icon = (icon_x *)tmp->data;
849 return (char *)icon->text;
852 /* if second has failed, find icon whose dpi has matched with system's dpi */
853 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
854 if (ret == SYSTEM_INFO_ERROR_NONE) {
855 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
857 icon = (icon_x *)tmp->data;
858 return (char *)icon->text;
862 /* last, find default icon marked as "No Locale" */
863 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
865 icon = (icon_x *)tmp->data;
866 return (char *)icon->text;
872 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
873 char **label, char **license, char **icon, char **description, char **author)
880 for (tmp = lbls; tmp; tmp = tmp->next) {
881 lbl = (label_x *)tmp->data;
885 if (strcmp(lbl->lang, (char *)data) == 0) {
886 *label = (char *)lbl->text;
891 for (tmp = lcns; tmp; tmp = tmp->next) {
892 lcn = (license_x *)tmp->data;
896 if (strcmp(lcn->lang, (char *)data) == 0) {
897 *license = (char *)lcn->text;
903 *icon = __find_icon(icns, (char *)data);
905 for (tmp = dcns; tmp; tmp = tmp->next) {
906 dcn = (description_x *)tmp->data;
910 if (strcmp(dcn->lang, (char *)data) == 0) {
911 *description = (char *)dcn->text;
916 for (tmp = aths; tmp; tmp = tmp->next) {
917 ath = (author_x *)tmp->data;
921 if (strcmp(ath->lang, (char *)data) == 0) {
922 *author = (char *)ath->text;
930 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
934 for (tmp = icns; tmp; tmp = tmp->next) {
935 icn = (icon_x *)tmp->data;
939 if (strcmp(icn->section, (char *)data) == 0) {
940 *icon = (char *)icn->text;
941 *resolution = (char *)icn->resolution;
948 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
952 for (tmp = imgs; tmp; tmp = tmp->next) {
953 img = (image_x *)tmp->data;
957 if (strcmp(img->section, (char *)data) == 0) {
958 *lang = (char *)img->lang;
959 *image = (char *)img->text;
966 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
971 char *description = NULL;
972 char *license = NULL;
976 manifest_x *mfx = (manifest_x *)userdata;
977 GList *lbl = mfx->label;
978 GList *lcn = mfx->license;
979 GList *icn = mfx->icon;
980 GList *dcn = mfx->description;
981 GList *ath = mfx->author;
983 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
984 if (!label && !description && !icon && !license && !author)
987 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
988 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
989 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
998 ret = __exec_query(query);
1000 _LOGD("Package Localized Info DB Insert failed\n");
1002 sqlite3_free(query);
1005 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1011 char *locale = (char *)data;
1013 application_x *app = (application_x *)userdata;
1014 GList *lbl = app->label;
1015 GList *icn = app->icon;
1017 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1018 if (!label && !icon)
1021 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1022 "app_label, app_icon) VALUES" \
1023 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1025 ret = __exec_query(query);
1027 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1029 sqlite3_free(query);
1031 /*insert ui app locale info to pkg locale to get mainapp data */
1032 if (strcasecmp(app->mainapp, "true") == 0) {
1033 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1034 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1036 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1037 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1038 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1039 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1040 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1041 app->package, locale,
1042 app->package, locale, label,
1043 app->package, locale, icon,
1044 app->package, locale,
1045 app->package, locale,
1046 app->package, locale);
1048 ret = __exec_query(query);
1050 _LOGE("Package Localized Info DB Insert failed");
1051 sqlite3_free(query);
1055 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1059 char *resolution = NULL;
1060 char query[MAX_QUERY_LEN] = {'\0'};
1062 application_x *app = (application_x *)userdata;
1063 GList *icn = app->icon;
1065 __extract_icon_data(data, icn, &icon, &resolution);
1066 if (!icon && !resolution)
1068 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1069 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1070 "(%Q, %Q, %Q, %Q)", app->appid,
1071 icon, (char *)data, resolution);
1073 ret = __exec_query(query);
1075 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1079 static void __insert_application_image_info(gpointer data, gpointer userdata)
1084 char query[MAX_QUERY_LEN] = {'\0'};
1086 application_x *app = (application_x *)userdata;
1087 GList *image = app->image;
1089 __extract_image_data(data, image, &lang, &img);
1092 sqlite3_snprintf(MAX_QUERY_LEN, query,
1093 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1094 "app_image_section, app_image) VALUES" \
1095 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1097 ret = __exec_query(query);
1099 _LOGD("Package UiApp image Info DB Insert failed\n");
1104 static int __insert_mainapp_info(manifest_x *mfx)
1109 char query[MAX_QUERY_LEN] = {'\0'};
1110 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1111 app = (application_x *)tmp->data;
1115 sqlite3_snprintf(MAX_QUERY_LEN, query,
1116 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1117 app->mainapp, app->appid);
1118 ret = __exec_query(query);
1120 _LOGD("Package App Info DB Insert Failed\n");
1123 if (strcasecmp(app->mainapp, "True") == 0)
1124 mfx->mainapp_id = strdup(app->appid);
1127 if (mfx->mainapp_id == NULL) {
1128 if (mfx->application == NULL)
1130 app = (application_x *)mfx->application->data;
1134 sqlite3_snprintf(MAX_QUERY_LEN, query,
1135 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1138 _LOGD("Not valid appid\n");
1142 ret = __exec_query(query);
1144 _LOGD("Package UiApp Info DB Insert Failed\n");
1148 free((void *)app->mainapp);
1149 app->mainapp = strdup("true");
1150 mfx->mainapp_id = strdup(app->appid);
1153 memset(query, '\0', MAX_QUERY_LEN);
1154 sqlite3_snprintf(MAX_QUERY_LEN, query,
1155 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1156 ret = __exec_query(query);
1158 _LOGD("Package Info DB update Failed\n");
1165 static int __convert_background_category(GList *category_list)
1168 GList *tmp_list = category_list;
1169 char *category_data = NULL;
1171 if (category_list == NULL)
1174 while (tmp_list != NULL) {
1175 category_data = (char *)tmp_list->data;
1176 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1177 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1178 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1179 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1180 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1181 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1182 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1183 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1184 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1185 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1186 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1187 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1188 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1189 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1191 _LOGE("Unidentified category [%s]", category_data);
1192 tmp_list = g_list_next(tmp_list);
1198 static const char *__find_effective_appid(GList *metadata_list)
1203 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1204 md = (metadata_x *)tmp_list->data;
1205 if (md == NULL || md->key == NULL)
1208 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1217 static char *__get_bool(char *value, bool is_true)
1219 if (value != NULL) {
1220 if (!strcmp(value, ""))
1221 return (is_true) ? "true" : "false";
1225 return (is_true) ? "true" : "false";
1228 /* _PRODUCT_LAUNCHING_ENHANCED_
1229 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1231 static int __insert_application_info(manifest_x *mfx)
1236 int background_value = 0;
1237 char query[MAX_QUERY_LEN] = {'\0'};
1239 const char *effective_appid;
1242 type = strdup(mfx->type);
1244 type = strdup("tpk");
1246 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1247 app = (application_x *)tmp->data;
1251 background_value = __convert_background_category(app->background_category);
1252 if (background_value < 0) {
1253 _LOGE("Failed to retrieve background value[%d]", background_value);
1254 background_value = 0;
1257 effective_appid = __find_effective_appid(app->metadata);
1259 sqlite3_snprintf(MAX_QUERY_LEN, query,
1260 "INSERT INTO package_app_info(" \
1261 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1262 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1263 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1264 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1265 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1266 "app_launch_mode, app_ui_gadget, app_support_disable, component_type, package, " \
1267 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1268 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1269 "app_package_installed_time) " \
1271 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1272 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1273 "%Q, %Q, %Q, %Q, %Q, " \
1274 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1275 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1276 "COALESCE(%Q, 'caller'), LOWER(%Q), LOWER(%Q), %Q, %Q, " \
1277 "%Q, %Q, %d, %Q, %Q, " \
1278 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1280 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1281 __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),
1282 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1283 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1284 __get_bool(app->guestmode_visibility, true), app->permission_type,
1285 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1286 app->launch_mode, __get_bool(app->ui_gadget, false), __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1287 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1288 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true), mfx->installed_time);
1290 ret = __exec_query(query);
1292 _LOGD("Package UiApp Info DB Insert Failed\n");
1297 memset(query, '\0', MAX_QUERY_LEN);
1306 static int __insert_application_appcategory_info(manifest_x *mfx)
1313 char query[MAX_QUERY_LEN] = {'\0'};
1314 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1315 app = (application_x *)app_tmp->data;
1318 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1319 ct = (const char *)ct_tmp->data;
1322 sqlite3_snprintf(MAX_QUERY_LEN, query,
1323 "INSERT INTO package_app_app_category(app_id, category) " \
1326 ret = __exec_query(query);
1328 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1331 memset(query, '\0', MAX_QUERY_LEN);
1337 static int __insert_application_appmetadata_info(manifest_x *mfx)
1344 char query[MAX_QUERY_LEN] = {'\0'};
1345 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1346 app = (application_x *)app_tmp->data;
1349 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1350 md = (metadata_x *)md_tmp->data;
1354 sqlite3_snprintf(MAX_QUERY_LEN, query,
1355 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1356 "VALUES(%Q, %Q, %Q)",\
1357 app->appid, md->key, md->value ? md->value : NULL);
1358 ret = __exec_query(query);
1360 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1364 memset(query, '\0', MAX_QUERY_LEN);
1370 static int __insert_application_apppermission_info(manifest_x *mfx)
1377 char query[MAX_QUERY_LEN] = {'\0'};
1378 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1379 app = (application_x *)app_tmp->data;
1382 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1383 pm = (permission_x *)pm_tmp->data;
1386 sqlite3_snprintf(MAX_QUERY_LEN, query,
1387 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1388 "VALUES(%Q, %Q, %Q)",\
1389 app->appid, pm->type, pm->value);
1390 ret = __exec_query(query);
1392 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1395 memset(query, '\0', MAX_QUERY_LEN);
1401 static int __insert_application_appcontrol_info(manifest_x *mfx)
1405 GList *acontrol_tmp;
1406 appcontrol_x *acontrol;
1408 char query[MAX_QUERY_LEN] = {'\0'};
1409 char buf[BUFSIZE] = {'\0'};
1410 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1411 app = (application_x *)app_tmp->data;
1414 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1415 acontrol = (appcontrol_x *)acontrol_tmp->data;
1416 if (acontrol == NULL)
1418 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1419 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1420 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1421 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1422 sqlite3_snprintf(MAX_QUERY_LEN, query,
1423 "INSERT INTO package_app_app_control(app_id, app_control) " \
1426 ret = __exec_query(query);
1428 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1431 memset(query, '\0', MAX_QUERY_LEN);
1437 static int __insert_application_datacontrol_info(manifest_x *mfx)
1444 char query[MAX_QUERY_LEN] = {'\0'};
1446 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1447 app = (application_x *)app_tmp->data;
1450 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1451 dc = (datacontrol_x *)dc_tmp->data;
1454 sqlite3_snprintf(MAX_QUERY_LEN, query,
1455 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1456 "VALUES(%Q, %Q, %Q, %Q)",\
1462 ret = __exec_query(query);
1464 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1467 memset(query, '\0', MAX_QUERY_LEN);
1473 static int __insert_application_share_request_info(manifest_x *mfx)
1482 char query[MAX_QUERY_LEN] = {'\0'};
1483 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1484 app = (application_x *)app_tmp->data;
1487 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1488 ds = (datashare_x *)ds_tmp->data;
1491 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1492 rq = (const char *)rq_tmp->data;
1495 sqlite3_snprintf(MAX_QUERY_LEN, query,
1496 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1499 ret = __exec_query(query);
1501 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1504 memset(query, '\0', MAX_QUERY_LEN);
1511 static int __insert_application_share_allowed_info(manifest_x *mfx)
1522 char query[MAX_QUERY_LEN] = {'\0'};
1523 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1524 app = (application_x *)app_tmp->data;
1527 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1528 ds = (datashare_x *)ds_tmp->data;
1531 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1532 df = (define_x *)df_tmp->data;
1535 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1536 al = (const char *)al_tmp->data;
1539 sqlite3_snprintf(MAX_QUERY_LEN, query,
1540 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1541 "VALUES(%Q, %Q, %Q)",\
1542 app->appid, df->path, al);
1543 ret = __exec_query(query);
1545 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1548 memset(query, '\0', MAX_QUERY_LEN);
1556 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1558 splashscreen_x *ss = (splashscreen_x *)a;
1559 const char *orientation = (const char *)b;
1562 if (ss->operation || ss->dpi == NULL)
1565 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1569 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1575 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1577 splashscreen_x *ss = (splashscreen_x *)a;
1578 const char *orientation = (const char *)b;
1580 if (ss->operation || ss->dpi)
1583 if (strcasecmp(ss->orientation, orientation) == 0)
1589 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1590 const char *orientation)
1594 tmp = g_list_find_custom(splashscreens, orientation,
1595 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1597 return (splashscreen_x *)tmp->data;
1599 tmp = g_list_find_custom(splashscreens, orientation,
1600 (GCompareFunc)__compare_splashscreen_with_orientation);
1602 return (splashscreen_x *)tmp->data;
1607 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1609 splashscreen_x *ss = (splashscreen_x *)data;
1610 GList **list = (GList **)user_data;
1613 if (ss->operation == NULL || ss->dpi == NULL)
1616 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1620 if (__check_dpi(ss->dpi, dpi) != 0)
1623 *list = g_list_append(*list, ss);
1626 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1628 splashscreen_x *ss = (splashscreen_x *)data;
1629 GList **list = (GList **)user_data;
1630 splashscreen_x *ss_tmp;
1633 if (ss->operation == NULL || ss->dpi)
1636 for (tmp = *list; tmp; tmp = tmp->next) {
1637 ss_tmp = (splashscreen_x *)tmp->data;
1638 if (ss_tmp->operation
1639 && strcmp(ss_tmp->operation, ss->operation) == 0
1640 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1644 *list = g_list_append(*list, ss);
1647 static GList *__find_splashscreens(GList *splashscreens)
1652 g_list_foreach(splashscreens,
1653 __find_appcontrol_splashscreen_with_dpi, &list);
1654 g_list_foreach(splashscreens,
1655 __find_appcontrol_splashscreen, &list);
1657 ss = __find_default_splashscreen(splashscreens, "portrait");
1659 list = g_list_append(list, ss);
1660 ss = __find_default_splashscreen(splashscreens, "landscape");
1662 list = g_list_append(list, ss);
1667 static int __insert_application_splashscreen_info(manifest_x *mfx)
1675 char query[MAX_QUERY_LEN] = {'\0'};
1677 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1678 app = (application_x *)app_tmp->data;
1679 if (app == NULL || app->splashscreens == NULL)
1682 ss_tmp = __find_splashscreens(app->splashscreens);
1686 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1687 ss = (splashscreen_x *)tmp->data;
1688 sqlite3_snprintf(MAX_QUERY_LEN, query,
1689 "INSERT INTO package_app_splash_screen" \
1690 "(app_id, src, type, orientation, indicatordisplay, " \
1691 "operation, color_depth) " \
1692 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1693 app->appid, ss->src, ss->type, ss->orientation,
1694 ss->indicatordisplay, ss->operation,
1697 ret = __exec_query(query);
1699 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1702 memset(query, '\0', MAX_QUERY_LEN);
1704 g_list_free(ss_tmp);
1709 static int __insert_application_legacy_splashscreen_info(manifest_x *mfx)
1714 char query[MAX_QUERY_LEN] = {'\0'};
1716 const char *image_type;
1717 const char *indicatordisplay;
1718 const char *orientation;
1719 const char *operation = "launch-effect";
1720 const char *color_depth = "24"; /* default */
1722 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1723 app = (application_x *)app_tmp->data;
1725 (app->portraitimg == NULL && app->landscapeimg == NULL))
1727 image_type = "img"; /* default */
1728 if (app->effectimage_type) {
1729 tmp = strstr(app->effectimage_type, "edj");
1733 indicatordisplay = "true"; /* default */
1734 if (app->indicatordisplay)
1735 indicatordisplay = app->indicatordisplay;
1736 if (app->portraitimg) {
1737 orientation = "portrait";
1738 sqlite3_snprintf(MAX_QUERY_LEN, query,
1739 "INSERT INTO package_app_splash_screen" \
1740 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1741 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1742 app->appid, app->portraitimg, image_type,
1743 orientation, indicatordisplay, operation,
1745 ret = __exec_query(query);
1747 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1750 memset(query, '\0', MAX_QUERY_LEN);
1752 if (app->landscapeimg) {
1753 orientation = "landscape";
1754 sqlite3_snprintf(MAX_QUERY_LEN, query,
1755 "INSERT INTO package_app_splash_screen" \
1756 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1757 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1758 app->appid, app->landscapeimg, image_type,
1759 orientation, indicatordisplay, operation,
1761 ret = __exec_query(query);
1763 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1766 memset(query, '\0', MAX_QUERY_LEN);
1772 static int __insert_application_metadata_splashscreen_info(manifest_x *mfx)
1779 char query[MAX_QUERY_LEN] = {'\0'};
1781 char *tmpptr = NULL;
1782 const char *operation;
1783 const char *portraitimg;
1784 const char *landscapeimg;
1785 const char *indicatordisplay;
1786 const char *orientation;
1787 const char *image_type;
1788 const char *color_depth = "24"; /* default */
1790 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1791 app = (application_x *)app_tmp->data;
1795 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1796 md = (metadata_x *)md_tmp->data;
1797 if (md == NULL || md->key == NULL || md->value == NULL)
1800 if (strcasestr(md->key, "operation_effect=")) {
1801 operation = index(md->key, '=');
1802 if (operation && operation[1] != '\0')
1805 operation = "launch-effect";
1806 } else if (strcasestr(md->key, "launch_effect")) {
1807 operation = "launch-effect";
1813 landscapeimg = NULL;
1814 indicatordisplay = "true"; /* default */
1815 token = strtok_r(md->value, "|", &tmpptr);
1816 while (token != NULL) {
1817 if (strcasestr(token, "portrait-effectimage=")) {
1818 portraitimg = index(token, '=');
1819 if (portraitimg && portraitimg[1] != '\0')
1823 } else if (strcasestr(token, "landscape-effectimage=")) {
1824 landscapeimg = index(token, '=');
1825 if (landscapeimg && landscapeimg[1] != '\0')
1828 landscapeimg = NULL;
1829 } else if (strcasestr(token, "indicatordisplay=")) {
1830 indicatordisplay = index(token, '=');
1831 if (indicatordisplay && indicatordisplay[1] != '\0')
1834 indicatordisplay = "true";
1837 token = strtok_r(NULL, "|", &tmpptr);
1841 orientation = "portrait";
1843 if (strcasestr(portraitimg, "edj"))
1845 sqlite3_snprintf(MAX_QUERY_LEN, query,
1846 "INSERT INTO package_app_splash_screen" \
1847 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1848 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1849 app->appid, portraitimg, image_type,
1850 orientation, indicatordisplay, operation,
1852 ret = __exec_query(query);
1854 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1857 memset(query, '\0', MAX_QUERY_LEN);
1860 orientation = "landscape";
1862 if (strcasestr(landscapeimg, "edj"))
1864 sqlite3_snprintf(MAX_QUERY_LEN, query,
1865 "INSERT INTO package_app_splash_screen" \
1866 "(app_id, src, type, orientation, indicatordisplay, operation, color_depth) " \
1867 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1868 app->appid, landscapeimg, image_type,
1869 orientation, indicatordisplay, operation,
1871 ret = __exec_query(query);
1873 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1876 memset(query, '\0', MAX_QUERY_LEN);
1884 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1888 privilege_x *pv = NULL;
1889 char query[MAX_QUERY_LEN] = { '\0' };
1892 const char *auth_name = NULL;
1893 const char *auth_email = NULL;
1894 const char *auth_href = NULL;
1896 GList *pkglocale = NULL;
1897 GList *applocale = NULL;
1898 GList *appicon = NULL;
1899 GList *appimage = NULL;
1901 if (mfx->author && mfx->author->data) {
1902 author = (author_x *)mfx->author->data;
1904 auth_name = author->text;
1906 auth_email = author->email;
1908 auth_href = author->href;
1911 /*Insert in the package_info DB*/
1912 sqlite3_snprintf(MAX_QUERY_LEN, query,
1913 "INSERT INTO package_info(" \
1914 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1915 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1916 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1917 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1918 "mainapp_id, package_url, root_path, csc_path, package_support_disable) " \
1920 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1921 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1922 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1923 "%Q, %Q, %Q, %Q, %Q, " \
1924 "%Q, %Q, %Q, %Q, LOWER(%Q))",
1925 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1926 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1927 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1928 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1929 mfx->storeclient_id,
1930 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, __get_bool(mfx->support_disable, false));
1932 ret = __exec_query(query);
1934 _LOGD("Package Info DB Insert Failed\n");
1938 /*Insert in the package_privilege_info DB*/
1939 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1940 pv = (privilege_x *)tmp->data;
1943 memset(query, '\0', MAX_QUERY_LEN);
1944 sqlite3_snprintf(MAX_QUERY_LEN, query,
1945 "INSERT INTO package_privilege_info(package, privilege, type) " \
1946 "VALUES(%Q, %Q, %Q)",\
1947 mfx->package, pv->value, pv->type);
1948 ret = __exec_query(query);
1950 _LOGD("Package Privilege Info DB Insert Failed\n");
1955 if (mfx->application != NULL) {
1956 ret = __insert_mainapp_info(mfx);
1961 /*Insert the package locale*/
1962 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1963 /*remove duplicated data in pkglocale*/
1964 __trimfunc(pkglocale);
1966 /*Insert the app locale, icon, image info */
1967 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1968 app = (application_x *)tmp->data;
1971 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1972 appicon = __create_icon_list(appicon, app->icon);
1973 appimage = __create_image_list(appimage, app->image);
1975 /*remove duplicated data in applocale*/
1976 __trimfunc(applocale);
1977 __trimfunc(appicon);
1978 __trimfunc(appimage);
1980 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1982 /*native app locale info*/
1983 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1984 app = (application_x *)tmp->data;
1987 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1988 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1989 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1992 g_list_free(pkglocale);
1994 g_list_free(applocale);
1996 g_list_free(appicon);
1998 g_list_free(appimage);
2001 /*Insert in the package_app_info DB*/
2002 ret = __insert_application_info(mfx);
2005 /*Insert in the package_app_app_control DB*/
2006 ret = __insert_application_appcontrol_info(mfx);
2010 /*Insert in the package_app_app_category DB*/
2011 ret = __insert_application_appcategory_info(mfx);
2015 /*Insert in the package_app_app_metadata DB*/
2016 ret = __insert_application_appmetadata_info(mfx);
2020 /*Insert in the package_app_app_permission DB*/
2021 ret = __insert_application_apppermission_info(mfx);
2025 /*Insert in the package_app_share_allowed DB*/
2026 ret = __insert_application_share_allowed_info(mfx);
2030 /*Insert in the package_app_share_request DB*/
2031 ret = __insert_application_share_request_info(mfx);
2035 /*Insert in the package_app_data_control DB*/
2036 ret = __insert_application_datacontrol_info(mfx);
2040 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2041 ret = __insert_application_legacy_splashscreen_info(mfx);
2045 /*Insert in the package_app_splash_screen DB (backward compatibility)*/
2046 ret = __insert_application_metadata_splashscreen_info(mfx);
2050 /*Insert in the package_app_splash_screen DB*/
2051 ret = __insert_application_splashscreen_info(mfx);
2059 static int __delete_appinfo_from_db(char *db_table, const char *appid)
2061 char query[MAX_QUERY_LEN] = { '\0' };
2064 sqlite3_snprintf(MAX_QUERY_LEN, query,
2065 "DELETE FROM %q where app_id=%Q", db_table, appid);
2066 ret = __exec_query(query);
2068 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
2074 static int __delete_subpkg_info_from_db(char *appid)
2078 ret = __delete_appinfo_from_db("package_app_info", appid);
2081 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
2084 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
2087 ret = __delete_appinfo_from_db("package_app_image_info", appid);
2090 ret = __delete_appinfo_from_db("package_app_app_control", appid);
2093 ret = __delete_appinfo_from_db("package_app_app_category", appid);
2096 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
2099 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
2102 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
2105 ret = __delete_appinfo_from_db("package_app_share_request", appid);
2108 ret = __delete_appinfo_from_db("package_app_data_control", appid);
2111 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
2118 static int __delete_subpkg_from_db(manifest_x *mfx)
2120 char query[MAX_QUERY_LEN] = { '\0' };
2121 char *error_message = NULL;
2123 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
2125 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
2126 _LOGE("Don't execute query = %s error message = %s\n", query,
2128 sqlite3_free(error_message);
2131 sqlite3_free(error_message);
2136 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
2138 char query[MAX_QUERY_LEN] = { '\0' };
2143 /*Delete from Package Info DB*/
2144 sqlite3_snprintf(MAX_QUERY_LEN, query,
2145 "DELETE FROM package_info WHERE package=%Q", mfx->package);
2146 ret = __exec_query(query);
2148 _LOGD("Package Info DB Delete Failed\n");
2151 memset(query, '\0', MAX_QUERY_LEN);
2153 /*Delete from Package Localized Info*/
2154 sqlite3_snprintf(MAX_QUERY_LEN, query,
2155 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
2156 ret = __exec_query(query);
2158 _LOGD("Package Localized Info DB Delete Failed\n");
2162 /*Delete from Package Privilege Info*/
2163 sqlite3_snprintf(MAX_QUERY_LEN, query,
2164 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2165 ret = __exec_query(query);
2167 _LOGD("Package Privilege Info DB Delete Failed\n");
2171 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2172 app = (application_x *)tmp->data;
2175 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2178 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2181 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2184 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2187 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2190 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2193 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2196 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2199 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2202 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2205 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2208 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2213 /* if main package has sub pkg, delete sub pkg data*/
2214 __delete_subpkg_from_db(mfx);
2219 static int __disable_app(const char *appid)
2222 char query[MAX_QUERY_LEN] = {'\0'};
2223 sqlite3_snprintf(MAX_QUERY_LEN, query,
2224 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2226 ret = __exec_query(query);
2228 _LOGD("Insert global app disable failed\n");
2233 static int __enable_app(const char *appid)
2236 char query[MAX_QUERY_LEN] = {'\0'};
2237 sqlite3_snprintf(MAX_QUERY_LEN, query,
2238 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2240 ret = __exec_query(query);
2242 _LOGD("Insert global app disable failed\n");
2247 static int __disable_pkg(const char *pkgid)
2250 char query[MAX_QUERY_LEN] = {'\0'};
2251 sqlite3_snprintf(MAX_QUERY_LEN, query,
2252 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2254 ret = __exec_query(query);
2256 _LOGD("Update pkg disable info has failed\n");
2261 static int __enable_pkg(const char *pkgid)
2264 char query[MAX_QUERY_LEN] = {'\0'};
2265 sqlite3_snprintf(MAX_QUERY_LEN, query,
2266 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2268 ret = __exec_query(query);
2270 _LOGD("Update pkg disable info has failed\n");
2275 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2278 char query[MAX_QUERY_LEN] = { '\0', };
2280 const char *val = NULL;
2285 sqlite3_snprintf(MAX_QUERY_LEN, query,
2286 "SELECT COUNT(*) FROM "
2287 "package_app_info_for_uid WHERE app_id=%Q "
2288 "AND uid=%d", appid, (int)uid);
2290 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2291 if (ret != SQLITE_OK) {
2292 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2293 return PMINFO_R_ERROR;
2296 if (sqlite3_step(stmt) != SQLITE_ROW) {
2297 LOGE("failed to step");
2298 sqlite3_finalize(stmt);
2299 return PMINFO_R_ERROR;
2302 val = (const char *)sqlite3_column_text(stmt, 0);
2304 sqlite3_finalize(stmt);
2309 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2312 char query[MAX_QUERY_LEN] = { '\0', };
2314 ret = __check_appinfo_for_uid_table(appid, uid);
2316 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2319 } else if (ret == 0) {
2320 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2321 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2322 "VALUES(%Q, %d, 'true', "
2323 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2324 appid, (int)uid, appid);
2326 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2327 "package_app_info_for_uid SET is_disabled='true' "
2328 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2331 ret = __exec_query(query);
2333 _LOGD("Add global app disable info failed\n");
2338 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2341 char query[MAX_QUERY_LEN] = {'\0'};
2343 ret = __check_appinfo_for_uid_table(appid, uid);
2345 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2348 } else if (ret > 0) {
2349 sqlite3_snprintf(MAX_QUERY_LEN, query,
2350 "UPDATE package_app_info_for_uid SET "
2351 "is_disabled='false' WHERE app_id=%Q AND "
2352 "uid=%d", appid, (int)uid);
2355 ret = __exec_query(query);
2357 _LOGD("Remove global app disable info failed\n");
2362 static int __update_global_app_splash_screen_for_user(const char *appid,
2363 uid_t uid, int flag)
2366 char query[MAX_QUERY_LEN] = { '\0', };
2368 ret = __check_appinfo_for_uid_table(appid, uid);
2370 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2373 } else if (ret == 0) {
2374 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2375 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2376 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2377 flag ? "true" : "false");
2379 sqlite3_snprintf(MAX_QUERY_LEN, query,
2380 "UPDATE package_app_info_for_uid SET "
2381 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2382 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2385 ret = __exec_query(query);
2387 _LOGD("update global app splash screen info failed\n");
2392 static int __disable_app_splash_screen(const char *appid)
2395 char query[MAX_QUERY_LEN] = {'\0'};
2397 sqlite3_snprintf(MAX_QUERY_LEN, query,
2398 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2400 ret = __exec_query(query);
2402 _LOGD("Failed to update app_palsh_screen_display");
2407 static int __enable_app_splash_screen(const char *appid)
2410 char query[MAX_QUERY_LEN] = {'\0'};
2412 sqlite3_snprintf(MAX_QUERY_LEN, query,
2413 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2415 ret = __exec_query(query);
2417 _LOGD("Failed to update app_splash_screen_display");
2422 API int pkgmgr_parser_initialize_db(uid_t uid)
2428 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2430 _LOGD("package info DB initialization failed\n");
2433 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2435 _LOGD("package localized info DB initialization failed\n");
2438 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2440 _LOGD("package app app privilege DB initialization failed\n");
2443 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2445 _LOGD("package app info DB initialization failed\n");
2448 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2450 _LOGD("package app localized info DB initialization failed\n");
2453 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2455 _LOGD("package app icon localized info DB initialization failed\n");
2458 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2460 _LOGD("package app image info DB initialization failed\n");
2463 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2465 _LOGD("package app app control DB initialization failed\n");
2468 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2470 _LOGD("package app app category DB initialization failed\n");
2473 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2475 _LOGD("package app app category DB initialization failed\n");
2478 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2480 _LOGD("package app app permission DB initialization failed\n");
2483 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2485 _LOGD("package app share allowed DB initialization failed\n");
2488 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2490 _LOGD("package app share request DB initialization failed\n");
2493 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2495 _LOGD("package app data control DB initialization failed\n");
2499 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2501 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2505 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2507 _LOGD("package app splash screen DB initialization failed\n");
2511 /* Trigger package_app_info_for_uid */
2512 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2514 _LOGD("package app info for uid DB initialization failed\n");
2519 /* TODO: refactor this code */
2520 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2522 _LOGD("package cert info DB initialization failed\n");
2525 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2527 _LOGD("package cert index info DB initialization failed\n");
2530 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2532 _LOGD("package cert info DB initialization failed\n");
2535 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2537 _LOGD("package cert info DB initialization failed\n");
2540 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2542 _LOGD("package cert info DB initialization failed\n");
2545 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2547 _LOGD("package cert index info DB initialization failed\n");
2551 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2552 if (db_path == NULL) {
2553 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2555 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2557 _LOGD("Failed to change cert db permission");
2561 db_path = getUserPkgParserDBPathUID(uid);
2562 if (db_path == NULL) {
2563 _LOGD("Failed to get user pkg parser db path - %d", uid);
2565 ret = __parserdb_change_perm(db_path, uid);
2567 _LOGD("Failed to change parser db permission\n");
2574 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2577 char pwuid_buf[1024];
2578 char journal_file[BUFSIZE];
2583 struct passwd userinfo, *result = NULL;
2584 files[0] = (char *)db_file;
2585 files[1] = journal_file;
2589 if (db_file == NULL)
2592 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2594 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2595 if (uid == OWNER_ROOT)
2597 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2598 if (ret != 0 || result == NULL) {
2599 _LOGE("FAIL: user %d doesn't exist", uid);
2602 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2604 for (i = 0; files[i]; i++) {
2605 fd = open(files[i], O_RDONLY);
2607 if (strerror_r(errno, buf, sizeof(buf)))
2608 strncpy(buf, "", BUFSIZE - 1);
2609 _LOGD("FAIL : open %s : %s", files[i], buf);
2612 ret = fstat(fd, &sb);
2614 if (strerror_r(errno, buf, sizeof(buf)))
2615 strncpy(buf, "", BUFSIZE - 1);
2616 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2620 if (S_ISLNK(sb.st_mode)) {
2621 _LOGE("FAIL : %s is symlink!", files[i]);
2625 ret = fchown(fd, uid, userinfo.pw_gid);
2627 if (strerror_r(errno, buf, sizeof(buf)))
2628 strncpy(buf, "", BUFSIZE - 1);
2629 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2630 userinfo.pw_gid, buf);
2635 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2636 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2638 ret = fchmod(fd, mode);
2640 if (strerror_r(errno, buf, sizeof(buf)))
2641 strncpy(buf, "", BUFSIZE - 1);
2642 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2647 SET_SMACK_LABEL(files[i]);
2652 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2657 if (getuid() != OWNER_ROOT) {
2658 _LOGE("Only root user is allowed");
2662 db_path = getUserPkgParserDBPathUID(uid);
2663 if (db_path == NULL) {
2664 _LOGE("Failed to get pkg parser db path - %d", uid);
2668 if (access(db_path, F_OK) != -1) {
2669 _LOGE("Manifest db for user %d is already exists", uid);
2675 db_path = getUserPkgCertDBPathUID(uid);
2676 if (db_path == NULL) {
2677 _LOGE("Failed to get pkg cert db path - %d", uid);
2681 if (access(db_path, F_OK) != -1) {
2682 _LOGE("Cert db for user %d is already exists", uid);
2688 ret = pkgmgr_parser_check_and_create_db(uid);
2691 ret = pkgmgr_parser_initialize_db(uid);
2693 pkgmgr_parser_close_db();
2696 pkgmgr_parser_close_db();
2701 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2706 db_path = getUserPkgParserDBPathUID(uid);
2707 if (db_path == NULL) {
2708 _LOGD("Failed to get pkg parser db path - %d", uid);
2713 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2715 _LOGD("Manifest DB creation Failed\n");
2721 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2722 if (db_path == NULL) {
2723 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2728 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2730 _LOGD("Cert DB creation Failed\n");
2740 void pkgmgr_parser_close_db(void)
2742 sqlite3_close(pkgmgr_parser_db);
2743 sqlite3_close(pkgmgr_cert_db);
2747 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2749 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2751 _LOGD("manifest pointer is NULL\n");
2755 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2757 _LOGD("Failed to open DB\n");
2760 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2763 /*Begin transaction*/
2764 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2765 if (ret != SQLITE_OK) {
2766 _LOGD("Failed to begin transaction\n");
2770 _LOGD("Transaction Begin\n");
2771 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2773 _LOGD("Insert into DB failed. Rollback now\n");
2774 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2777 /*Commit transaction*/
2778 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2779 if (ret != SQLITE_OK) {
2780 _LOGD("Failed to commit transaction. Rollback now\n");
2781 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2785 _LOGD("Transaction Commit and End\n");
2787 pkgmgr_parser_close_db();
2791 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2793 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2795 _LOGD("manifest pointer is NULL\n");
2799 ret = pkgmgr_parser_check_and_create_db(uid);
2801 _LOGD("Failed to open DB\n");
2804 ret = pkgmgr_parser_initialize_db(uid);
2807 /*Begin transaction*/
2808 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2809 if (ret != SQLITE_OK) {
2810 _LOGD("Failed to begin transaction\n");
2814 _LOGD("Transaction Begin\n");
2815 ret = __insert_manifest_info_in_db(mfx, uid);
2817 _LOGD("Insert into DB failed. Rollback now\n");
2818 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2821 /*Commit transaction*/
2822 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2823 if (ret != SQLITE_OK) {
2824 _LOGD("Failed to commit transaction. Rollback now\n");
2825 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2829 _LOGD("Transaction Commit and End\n");
2831 pkgmgr_parser_close_db();
2835 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2837 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2840 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2842 if (pkgid == NULL || tep_path == NULL) {
2843 _LOGE("invalid parameter");
2850 ret = pkgmgr_parser_check_and_create_db(uid);
2852 _LOGD("Failed to open DB\n");
2855 ret = pkgmgr_parser_initialize_db(uid);
2859 /*Begin transaction*/
2860 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2861 if (ret != SQLITE_OK) {
2862 _LOGD("Failed to begin transaction\n");
2866 _LOGD("Transaction Begin\n");
2869 /* Updating TEP info in "package_info" table */
2870 query = sqlite3_mprintf("UPDATE package_info "\
2871 "SET package_tep_name = %Q "\
2872 "WHERE package = %Q", tep_path, pkgid);
2874 ret = __exec_query(query);
2875 sqlite3_free(query);
2876 if (ret != SQLITE_OK) {
2877 ret = PM_PARSER_R_ERROR;
2878 _LOGE("sqlite exec failed to insert entries into package_info!!");
2882 /* Updating TEP info in "package_app_info" table */
2883 query = sqlite3_mprintf("UPDATE package_app_info "\
2884 "SET app_tep_name = %Q "\
2885 "WHERE package = %Q", tep_path, pkgid);
2887 ret = __exec_query(query);
2888 sqlite3_free(query);
2889 if (ret != SQLITE_OK) {
2890 ret = PM_PARSER_R_ERROR;
2891 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2895 /*Commit transaction*/
2896 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2897 if (ret != SQLITE_OK) {
2898 _LOGE("Failed to commit transaction, Rollback now\n");
2899 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2900 if (ret != SQLITE_OK)
2901 _LOGE("Failed to Rollback\n");
2903 ret = PM_PARSER_R_ERROR;
2906 _LOGD("Transaction Commit and End\n");
2907 ret = PM_PARSER_R_OK;
2910 pkgmgr_parser_close_db();
2915 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2918 _LOGD("manifest pointer is NULL\n");
2922 ret = pkgmgr_parser_check_and_create_db(uid);
2924 _LOGD("Failed to open DB\n");
2927 ret = pkgmgr_parser_initialize_db(uid);
2930 /*Preserve guest mode visibility*/
2931 __preserve_guestmode_visibility_value(mfx);
2932 /*Begin transaction*/
2933 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2934 if (ret != SQLITE_OK) {
2935 _LOGD("Failed to begin transaction\n");
2939 _LOGD("Transaction Begin\n");
2940 ret = __delete_manifest_info_from_db(mfx, uid);
2942 _LOGD("Delete from DB failed. Rollback now\n");
2943 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2946 ret = __insert_manifest_info_in_db(mfx, uid);
2948 _LOGD("Insert into DB failed. Rollback now\n");
2949 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2953 /*Commit transaction*/
2954 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2955 if (ret != SQLITE_OK) {
2956 _LOGD("Failed to commit transaction. Rollback now\n");
2957 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2961 _LOGD("Transaction Commit and End\n");
2963 pkgmgr_parser_close_db();
2967 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2969 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2972 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2975 _LOGD("manifest pointer is NULL\n");
2979 ret = pkgmgr_parser_check_and_create_db(uid);
2981 _LOGD("Failed to open DB\n");
2984 /*Begin transaction*/
2985 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2986 if (ret != SQLITE_OK) {
2987 _LOGD("Failed to begin transaction\n");
2991 _LOGD("Transaction Begin\n");
2992 ret = __delete_manifest_info_from_db(mfx, uid);
2994 _LOGD("Delete from DB failed. Rollback now\n");
2995 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2998 /*Commit transaction*/
2999 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3000 if (ret != SQLITE_OK) {
3001 _LOGD("Failed to commit transaction, Rollback now\n");
3002 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3006 _LOGD("Transaction Commit and End\n");
3008 pkgmgr_parser_close_db();
3012 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
3014 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
3017 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
3021 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3023 _LOGD("Failed to open DB\n");
3027 /*Begin transaction*/
3028 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3029 if (ret != SQLITE_OK) {
3030 _LOGD("Failed to begin transaction\n");
3034 _LOGD("Transaction Begin\n");
3036 ret = __disable_global_app_for_user(appid, uid);
3038 ret = __enable_global_app_for_user(appid, uid);
3040 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
3041 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3044 /*Commit transaction*/
3045 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3046 if (ret != SQLITE_OK) {
3047 _LOGD("Failed to commit transaction, Rollback now\n");
3048 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3052 _LOGD("Transaction Commit and End\n");
3054 pkgmgr_parser_close_db();
3059 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
3061 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
3064 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
3068 ret = pkgmgr_parser_check_and_create_db(uid);
3070 _LOGD("Failed to open DB\n");
3074 /*Begin transaction*/
3075 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3076 if (ret != SQLITE_OK) {
3077 _LOGD("Failed to begin transaction\n");
3082 _LOGD("Transaction Begin\n");
3084 ret = __disable_pkg(pkgid);
3086 ret = __enable_pkg(pkgid);
3089 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
3090 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3094 /*Commit transaction*/
3095 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3096 if (ret != SQLITE_OK) {
3097 _LOGD("Failed to commit transaction, Rollback now\n");
3098 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3102 _LOGD("Transaction Commit and End\n");
3105 pkgmgr_parser_close_db();
3109 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
3111 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
3114 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
3118 ret = pkgmgr_parser_check_and_create_db(uid);
3120 _LOGD("Failed to open DB\n");
3124 /*Begin transaction*/
3125 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3126 if (ret != SQLITE_OK) {
3127 _LOGD("Failed to begin transaction\n");
3131 _LOGD("Transaction Begin\n");
3133 ret = __disable_app(appid);
3135 ret = __enable_app(appid);
3137 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
3138 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3141 /*Commit transaction*/
3142 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3143 if (ret != SQLITE_OK) {
3144 _LOGD("Failed to commit transaction, Rollback now\n");
3145 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3149 _LOGD("Transaction Commit and End\n");
3151 pkgmgr_parser_close_db();
3156 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3160 if (appid == NULL) {
3161 _LOGD("Invalid parameter");
3165 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3167 _LOGD("Failed to open DB\n");
3171 /* Begin transaction */
3172 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3173 if (ret != SQLITE_OK) {
3174 _LOGD("Failed to begin transaction\n");
3178 _LOGD("Transaction Begin\n");
3180 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3182 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3183 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3186 /* Commit transaction */
3187 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3188 if (ret != SQLITE_OK) {
3189 _LOGD("Failed to commit transaction, Rollback now\n");
3190 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3194 _LOGD("Transaction Commit and End\n");
3196 pkgmgr_parser_close_db();
3200 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3202 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3205 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3209 if (appid == NULL) {
3210 _LOGD("Invalid parameter");
3214 ret = pkgmgr_parser_check_and_create_db(uid);
3216 _LOGD("Failed to open DB");
3220 /* Begin transaction */
3221 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3222 if (ret != SQLITE_OK) {
3223 _LOGD("Failed to begin transaction");
3227 _LOGD("Transaction Begin");
3230 ret = __enable_app_splash_screen(appid);
3232 ret = __disable_app_splash_screen(appid);
3234 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3235 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3238 /* Commit transaction */
3239 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3240 if (ret != SQLITE_OK) {
3241 _LOGD("Failed to commit transaction, Rollback now");
3242 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3246 _LOGD("Transaction Commit and End");
3249 pkgmgr_parser_close_db();
3253 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3256 char query[MAX_QUERY_LEN] = {'\0'};
3258 if (appid == NULL || label == NULL) {
3259 _LOGE("Invalid parameter");
3263 ret = pkgmgr_parser_check_and_create_db(uid);
3265 _LOGD("Failed to open DB");
3269 /*Begin transaction*/
3270 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3271 if (ret != SQLITE_OK) {
3272 _LOGD("Failed to begin transaction\n");
3277 sqlite3_snprintf(MAX_QUERY_LEN, query,
3278 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3279 "app_id=%Q AND app_label IS NOT NULL",
3281 ret = __exec_query(query);
3283 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3287 /* Commit transaction */
3288 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3289 if (ret != SQLITE_OK) {
3290 _LOGD("Failed to commit transaction, Rollback now");
3291 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3295 _LOGD("Transaction Commit and End");
3298 pkgmgr_parser_close_db();
3302 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3304 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);