4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7 * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
27 #include <sys/types.h>
28 #include <sys/smack.h>
37 #include <system_info.h>
39 /* For multi-user support */
40 #include <tzplatform_config.h>
42 #include "pkgmgr-info.h"
43 #include "pkgmgrinfo_basic.h"
44 #include "pkgmgr_parser_internal.h"
45 #include "pkgmgr_parser_db.h"
46 #include "pkgmgr_parser_debug.h"
48 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
49 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
50 #define MAX_QUERY_LEN 4096
53 #define MAX_INTEGER_LENGTH 10
59 #define XXHDPI "xxhdpi"
69 #define XXHDPI_MIN 481
70 #define XXHDPI_MAX 600
72 #define DB_LABEL "User::Home"
73 #define SET_SMACK_LABEL(x) \
75 if (smack_setlabel((x), DB_LABEL, SMACK_LABEL_ACCESS)) \
76 _LOGE("failed chsmack -a %s %s", DB_LABEL, x); \
78 _LOGD("chsmack -a %s %s", DB_LABEL, x); \
81 sqlite3 *pkgmgr_parser_db;
82 sqlite3 *pkgmgr_cert_db;
85 #define QUERY_CREATE_TABLE_PACKAGE_INFO "CREATE TABLE IF NOT EXISTS package_info " \
86 "(package TEXT PRIMARY KEY NOT NULL, " \
87 "package_type TEXT DEFAULT 'tpk', " \
88 "package_version TEXT, " \
89 "package_api_version TEXT, " \
90 "package_tep_name TEXT, " \
91 "package_zip_mount_file TEXT, " \
92 "install_location TEXT NOT NULL , " \
93 "package_size TEXT, " \
94 "package_removable TEXT NOT NULL DEFAULT 'true', " \
95 "package_preload TEXT NOT NULL DEFAULT 'false', " \
96 "package_readonly TEXT NOT NULL DEFAULT 'false', " \
97 "package_update TEXT NOT NULL DEFAULT 'false', " \
98 "package_appsetting TEXT NOT NULL DEFAULT 'false', " \
99 "package_nodisplay TEXT NOT NULL DEFAULT 'false', " \
100 "package_system TEXT NOT NULL DEFAULT 'false', " \
101 "author_name TEXT, " \
102 "author_email TEXT, " \
103 "author_href TEXT," \
104 "installed_time TEXT, " \
105 "installed_storage TEXT, " \
106 "storeclient_id TEXT, " \
107 "mainapp_id TEXT, " \
108 "package_url TEXT, " \
110 "external_path TEXT, " \
112 "package_support_mode TEXT, " \
113 "package_support_disable TEXT NOT NULL DEFAULT 'false', " \
114 "package_disable TEXT NOT NULL DEFAULT 'false')"
116 #define QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_localized_info " \
117 "(package TEXT NOT NULL, " \
118 "package_locale TEXT NOT NULL DEFAULT 'No Locale', " \
119 "package_label TEXT, " \
120 "package_icon TEXT, " \
121 "package_description TEXT, " \
122 "package_license TEXT, " \
123 "package_author TEXT, " \
124 "PRIMARY KEY(package, package_locale), " \
125 "FOREIGN KEY(package) " \
126 "REFERENCES package_info(package) " \
129 #define QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO "CREATE TABLE IF NOT EXISTS package_privilege_info " \
130 "(package TEXT NOT NULL, " \
131 "privilege TEXT NOT NULL, " \
132 "type TEXT NOT NULL, " \
133 "PRIMARY KEY(package, privilege, type) " \
134 "FOREIGN KEY(package) " \
135 "REFERENCES package_info(package) " \
138 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO "CREATE TABLE IF NOT EXISTS package_app_info " \
139 "(app_id TEXT PRIMARY KEY NOT NULL, " \
140 "app_component TEXT NOT NULL, " \
142 "app_nodisplay TEXT NOT NULL DEFAULT 'false', " \
144 "app_onboot TEXT NOT NULL DEFAULT 'false', " \
145 "app_multiple TEXT NOT NULL DEFAULT 'false', " \
146 "app_autorestart TEXT NOT NULL DEFAULT 'false', " \
147 "app_taskmanage TEXT NOT NULL DEFAULT 'false', " \
148 "app_enabled TEXT NOT NULL DEFAULT 'true', " \
149 "app_hwacceleration TEXT NOT NULL DEFAULT 'use-system-setting', " \
150 "app_screenreader TEXT NOT NULL DEFAULT 'use-system-setting', " \
151 "app_mainapp TEXT NOT NULL, " \
152 "app_recentimage TEXT NOT NULL DEFAULT 'false', " \
153 "app_launchcondition TEXT, " \
154 "app_indicatordisplay TEXT NOT NULL DEFAULT 'true', " \
155 "app_portraitimg TEXT, " \
156 "app_landscapeimg TEXT, " \
157 "app_guestmodevisibility TEXT NOT NULL DEFAULT 'true', " \
158 "app_permissiontype TEXT NOT NULL DEFAULT 'normal', " \
159 "app_preload TEXT NOT NULL DEFAULT 'false', " \
160 "app_submode TEXT NOT NULL DEFAULT 'false', " \
161 "app_submode_mainid TEXT, " \
162 "app_installed_storage TEXT NOT NULL, " \
163 "app_process_pool TEXT NOT NULL DEFAULT 'false', " \
164 "app_launch_mode TEXT NOT NULL DEFAULT 'caller', " \
165 "app_ui_gadget TEXT NOT NULL DEFAULT 'false', " \
166 "app_support_mode TEXT, " \
167 "app_support_disable TEXT NOT NULL DEFAULT 'false', " \
168 "app_disable TEXT NOT NULL DEFAULT 'false', " \
169 "app_package_type TEXT DEFAULT 'tpk', " \
170 "app_package_system TEXT NOT NULL, " \
171 "app_removable TEXT NOT NULL DEFAULT 'false', " \
172 "app_package_installed_time TEXT, " \
173 "app_support_ambient TEXT NOT NULL DEFAULT 'false', " \
174 "component_type TEXT, " \
175 "package TEXT NOT NULL, " \
176 "app_tep_name TEXT, " \
177 "app_zip_mount_file TEXT, " \
178 "app_background_category INTEGER DEFAULT 0, " \
179 "app_root_path TEXT, " \
180 "app_api_version TEXT, " \
181 "app_effective_appid TEXT, " \
182 "app_splash_screen_display TEXT NOT NULL DEFAULT 'true', " \
183 "app_external_path TEXT, " \
184 "FOREIGN KEY(package) " \
185 "REFERENCES package_info(package) " \
188 #define QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO "CREATE TABLE IF NOT EXISTS package_app_localized_info " \
189 "(app_id TEXT NOT NULL, " \
190 "app_locale TEXT NOT NULL DEFAULT 'No Locale', " \
193 "PRIMARY KEY(app_id,app_locale) " \
194 "FOREIGN KEY(app_id) " \
195 "REFERENCES package_app_info(app_id) " \
198 #define QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO "CREATE TABLE IF NOT EXISTS package_app_icon_section_info " \
199 "(app_id TEXT NOT NULL, " \
201 "app_icon_section TEXT NOT NULL, " \
202 "app_icon_resolution TEXT NOT NULL, " \
203 "PRIMARY KEY(app_id,app_icon_section,app_icon_resolution) " \
204 "FOREIGN KEY(app_id) " \
205 "REFERENCES package_app_info(app_id) " \
208 #define QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO "CREATE TABLE IF NOT EXISTS package_app_image_info " \
209 "(app_id TEXT NOT NULL, " \
210 "app_locale TEXT DEFAULT 'No Locale', " \
211 "app_image_section TEXT NOT NULL, " \
213 "PRIMARY KEY(app_id,app_image_section) " \
214 "FOREIGN KEY(app_id) " \
215 "REFERENCES package_app_info(app_id) " \
218 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL "CREATE TABLE IF NOT EXISTS package_app_app_control " \
219 "(app_id TEXT NOT NULL, " \
220 "app_control TEXT NOT NULL, " \
221 "PRIMARY KEY(app_id,app_control) " \
222 "FOREIGN KEY(app_id) " \
223 "REFERENCES package_app_info(app_id) " \
226 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY "CREATE TABLE IF NOT EXISTS package_app_app_category " \
227 "(app_id TEXT NOT NULL, " \
228 "category TEXT NOT NULL, " \
229 "PRIMARY KEY(app_id,category) " \
230 "FOREIGN KEY(app_id) " \
231 "REFERENCES package_app_info(app_id) " \
234 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA "CREATE TABLE IF NOT EXISTS package_app_app_metadata " \
235 "(app_id TEXT NOT NULL, " \
236 "md_key TEXT NOT NULL, " \
238 "PRIMARY KEY(app_id, md_key, md_value) " \
239 "FOREIGN KEY(app_id) " \
240 "REFERENCES package_app_info(app_id) " \
243 #define QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION "CREATE TABLE IF NOT EXISTS package_app_app_permission " \
244 "(app_id TEXT NOT NULL, " \
245 "pm_type TEXT NOT NULL, " \
246 "pm_value TEXT NOT NULL, " \
247 "PRIMARY KEY(app_id, pm_type, pm_value) " \
248 "FOREIGN KEY(app_id) " \
249 "REFERENCES package_app_info(app_id) " \
252 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED "CREATE TABLE IF NOT EXISTS package_app_share_allowed " \
253 "(app_id TEXT NOT NULL, " \
254 "data_share_path TEXT NOT NULL, " \
255 "data_share_allowed TEXT NOT NULL, " \
256 "PRIMARY KEY(app_id,data_share_path,data_share_allowed) " \
257 "FOREIGN KEY(app_id) " \
258 "REFERENCES package_app_info(app_id) " \
261 #define QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST "CREATE TABLE IF NOT EXISTS package_app_share_request " \
262 "(app_id TEXT NOT NULL, " \
263 "data_share_request TEXT NOT NULL, " \
264 "PRIMARY KEY(app_id,data_share_request) " \
265 "FOREIGN KEY(app_id) " \
266 "REFERENCES package_app_info(app_id) " \
269 #define QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL "CREATE TABLE IF NOT EXISTS package_app_data_control " \
270 "(app_id TEXT NOT NULL, " \
271 "providerid TEXT NOT NULL, " \
272 "access TEXT NOT NULL, " \
273 "type TEXT NOT NULL, " \
274 "PRIMARY KEY(app_id, providerid, access, type) " \
275 "FOREIGN KEY(app_id) " \
276 "REFERENCES package_app_info(app_id) " \
279 #define QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID "CREATE TABLE IF NOT EXISTS package_app_info_for_uid " \
280 "(app_id TEXT NOT NULL, " \
281 "uid INTEGER NOT NULL, " \
282 "is_disabled TEXT NOT NULL DEFAULT 'false', " \
283 "is_splash_screen_enabled TEXT NOT NULL, " \
284 "PRIMARY KEY(app_id, uid))"
286 #define QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID \
287 "CREATE TRIGGER IF NOT EXISTS update_package_appinfo_for_uid "\
288 "AFTER UPDATE ON package_app_info_for_uid " \
290 " DELETE FROM package_app_info_for_uid WHERE " \
291 " is_splash_screen_enabled=" \
292 " (SELECT package_app_info.app_splash_screen_display FROM " \
293 " package_app_info, package_app_info_for_uid WHERE " \
294 " package_app_info.app_id=OLD.app_id) AND is_disabled='false';" \
297 #define QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN \
298 "CREATE TABLE IF NOT EXISTS package_app_splash_screen " \
299 "(app_id TEXT NOT NULL, " \
300 "src TEXT NOT NULL, " \
301 "type TEXT NOT NULL, " \
302 "orientation TEXT NOT NULL, " \
303 "indicatordisplay TEXT, " \
304 "operation TEXT NOT NULL, " \
305 "color_depth TEXT NOT NULL DEFAULT '24', " \
306 "PRIMARY KEY(app_id, orientation, operation) " \
307 "FOREIGN KEY(app_id) " \
308 "REFERENCES package_app_info(app_id) " \
312 /* FIXME: duplicated at pkgmgrinfo_db.c */
313 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO \
314 "CREATE TABLE IF NOT EXISTS package_cert_index_info( " \
315 " cert_info TEXT UNIQUE, " \
316 " cert_id INTEGER PRIMARY KEY, " \
317 " cert_ref_count INTEGER NOT NULL)"
319 #define QUERY_CREATE_TABLE_PACKAGE_CERT_INFO \
320 "CREATE TABLE IF NOT EXISTS package_cert_info( " \
321 " package TEXT PRIMARY KEY, " \
322 " package_count INTEGER, " \
323 " author_root_cert INTEGER, " \
324 " author_im_cert INTEGER, " \
325 " author_signer_cert INTEGER, " \
326 " dist_root_cert INTEGER, " \
327 " dist_im_cert INTEGER, " \
328 " dist_signer_cert INTEGER, " \
329 " dist2_root_cert INTEGER, " \
330 " dist2_im_cert INTEGER, " \
331 " dist2_signer_cert INTEGER)"
333 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO \
334 "CREATE TRIGGER IF NOT EXISTS update_cert_info " \
335 "AFTER UPDATE ON package_cert_info " \
336 "WHEN (NEW.package_count = 0) " \
338 " DELETE FROM package_cert_info WHERE package=OLD.package;" \
341 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2 \
342 "CREATE TRIGGER IF NOT EXISTS update_cert_info2 " \
343 "AFTER UPDATE ON package_cert_info " \
344 "WHEN (NEW.package_count = OLD.package_count + 1) " \
346 " UPDATE package_cert_index_info SET" \
347 " cert_ref_count = cert_ref_count - 1" \
348 " WHERE cert_id = OLD.author_root_cert" \
349 " OR cert_id = OLD.author_im_cert" \
350 " OR cert_id = OLD.author_signer_cert" \
351 " OR cert_id = OLD.dist_root_cert" \
352 " OR cert_id = OLD.dist_im_cert" \
353 " OR cert_id = OLD.dist_signer_cert" \
354 " OR cert_id = OLD.dist2_root_cert" \
355 " OR cert_id = OLD.dist2_im_cert" \
356 " OR cert_id = OLD.dist2_signer_cert;" \
359 #define QUERY_CREATE_TRIGGER_DELETE_CERT_INFO \
360 "CREATE TRIGGER IF NOT EXISTS delete_cert_info " \
361 "AFTER DELETE ON package_cert_info " \
363 " UPDATE package_cert_index_info SET" \
364 " cert_ref_count = cert_ref_count - 1" \
365 " WHERE cert_id = OLD.author_root_cert" \
366 " OR cert_id = OLD.author_im_cert" \
367 " OR cert_id = OLD.author_signer_cert" \
368 " OR cert_id = OLD.dist_root_cert" \
369 " OR cert_id = OLD.dist_im_cert" \
370 " OR cert_id = OLD.dist_signer_cert" \
371 " OR cert_id = OLD.dist2_root_cert" \
372 " OR cert_id = OLD.dist2_im_cert" \
373 " OR cert_id = OLD.dist2_signer_cert;" \
376 #define QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO \
377 "CREATE TRIGGER IF NOT EXISTS update_cert_index_info " \
378 "AFTER UPDATE ON package_cert_index_info " \
379 "WHEN ((SELECT cert_ref_count FROM package_cert_index_info " \
380 " WHERE cert_id = OLD.cert_id) = 0) "\
382 " DELETE FROM package_cert_index_info WHERE cert_id = OLD.cert_id;" \
385 static int __insert_application_info(manifest_x *mfx);
386 static int __insert_application_appcategory_info(manifest_x *mfx);
387 static int __insert_application_appcontrol_info(manifest_x *mfx);
388 static int __insert_application_appmetadata_info(manifest_x *mfx);
389 static int __insert_application_share_allowed_info(manifest_x *mfx);
390 static int __insert_application_share_request_info(manifest_x *mfx);
391 static int __insert_application_datacontrol_info(manifest_x *mfx);
392 static void __insert_application_locale_info(gpointer data, gpointer userdata);
393 static void __insert_pkglocale_info(gpointer data, gpointer userdata);
394 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid);
395 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid);
396 static int __delete_subpkg_info_from_db(char *appid);
397 static int __delete_appinfo_from_db(char *db_table, const char *appid);
398 static int __initialize_db(sqlite3 *db_handle, const char *db_query);
399 static int __exec_query(char *query);
400 static void __extract_data(gpointer data, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath,
401 char **label, char **license, char **icon, char **description, char **author);
402 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata);
403 static GList *__create_locale_list(GList *locale, GList *lbl, GList *lcn, GList *icn, GList *dcn, GList *ath);
404 static void __preserve_guestmode_visibility_value(manifest_x *mfx);
405 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname);
406 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path);
407 static int __parserdb_change_perm(const char *db_file, uid_t uid);
409 #define REGULAR_USER 5000
410 static inline uid_t _getuid(void)
412 uid_t uid = getuid();
414 if (uid < REGULAR_USER)
415 return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
420 static int __delete_subpkg_list_cb(void *data, int ncols, char **coltxt, char **colname)
423 __delete_subpkg_info_from_db(coltxt[0]);
428 static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
433 char *error_message = NULL;
435 ret = db_util_open(db_path, &handle, DB_UTIL_REGISTER_HOOK_METHOD);
436 if (ret != SQLITE_OK) {
437 _LOGD("connect db [%s] failed!\n", db_path);
442 /* add user_version for db upgrade*/
443 query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
445 sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
446 _LOGE("Don't execute query = %s error message = %s\n", query,
449 sqlite3_free(error_message);
455 static int __guestmode_visibility_cb(void *data, int ncols, char **coltxt, char **colname)
457 manifest_x *mfx = (manifest_x *)data;
463 if (mfx->application == NULL)
465 app = (application_x *)mfx->application->data;
466 for (i = 0; i < ncols; i++) {
467 if (strcmp(colname[i], "app_id") == 0) {
469 appid = strdup(coltxt[i]);
470 } else if (strcmp(colname[i], "app_guestmodevisibility") == 0) {
472 status = strdup(coltxt[i]);
478 _LOGD("app id is NULL\n");
481 /*update guest mode visibility*/
482 for (tmp = mfx->application; tmp; tmp = tmp->next) {
483 app = (application_x *)tmp->data;
486 if (strcmp(app->appid, appid) == 0) {
487 free((void *)app->guestmode_visibility);
488 app->guestmode_visibility = strdup(status);
504 static void __preserve_guestmode_visibility_value(manifest_x *mfx)
506 char *error_message = NULL;
507 char query[MAX_QUERY_LEN] = {'\0'};
508 sqlite3_snprintf(MAX_QUERY_LEN, query,
509 "SELECT app_id, app_guestmodevisibility FROM package_app_info " \
510 "WHERE package=%Q", mfx->package);
512 sqlite3_exec(pkgmgr_parser_db, query,
513 __guestmode_visibility_cb, (void *)mfx, &error_message)) {
514 _LOGD("Don't execute query = %s error message = %s\n",
515 query, error_message);
516 sqlite3_free(error_message);
521 static int __initialize_db(sqlite3 *db_handle, const char *db_query)
523 char *error_message = NULL;
525 sqlite3_exec(db_handle, db_query,
526 NULL, NULL, &error_message)) {
527 _LOGD("Don't execute query = %s error message = %s\n",
528 db_query, error_message);
529 sqlite3_free(error_message);
532 sqlite3_free(error_message);
536 static int __exec_query(char *query)
538 char *error_message = NULL;
540 sqlite3_exec(pkgmgr_parser_db, query, NULL, NULL, &error_message)) {
541 _LOGE("Don't execute query = %s error message = %s\n", query,
543 sqlite3_free(error_message);
546 sqlite3_free(error_message);
550 static GList *__create_locale_list(GList *locale, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths)
558 for (tmp = lbls; tmp; tmp = tmp->next) {
559 lbl = (label_x *)tmp->data;
563 locale = g_list_insert_sorted_with_data(locale, (gpointer)lbl->lang, __comparefunc, NULL);
565 for (tmp = lcns; tmp; tmp = tmp->next) {
566 lcn = (license_x *)tmp->data;
570 locale = g_list_insert_sorted_with_data(locale, (gpointer)lcn->lang, __comparefunc, NULL);
572 for (tmp = icns; tmp; tmp = tmp->next) {
573 icn = (icon_x *)tmp->data;
577 locale = g_list_insert_sorted_with_data(locale, (gpointer)icn->lang, __comparefunc, NULL);
579 for (tmp = dcns; tmp; tmp = tmp->next) {
580 dcn = (description_x *)tmp->data;
584 locale = g_list_insert_sorted_with_data(locale, (gpointer)dcn->lang, __comparefunc, NULL);
586 for (tmp = aths; tmp; tmp = tmp->next) {
587 ath = (author_x *)tmp->data;
591 locale = g_list_insert_sorted_with_data(locale, (gpointer)ath->lang, __comparefunc, NULL);
597 static GList *__create_icon_list(GList *appicon, GList *icns)
602 for (tmp = icns; tmp; tmp = tmp->next) {
603 icn = (icon_x *)tmp->data;
607 appicon = g_list_insert_sorted_with_data(appicon, (gpointer)icn->section, __comparefunc, NULL);
612 static GList *__create_image_list(GList *appimage, GList *imgs)
617 for (tmp = imgs; tmp; tmp = tmp->next) {
618 img = (image_x *)tmp->data;
622 appimage = g_list_insert_sorted_with_data(appimage, (gpointer)img->section, __comparefunc, NULL);
627 static void __trimfunc(GList *trim_list)
629 char *trim_data = NULL;
633 list = g_list_first(trim_list);
636 trim_data = (char *)list->data;
639 if (strcmp(trim_data, prev) == 0) {
640 trim_list = g_list_remove(trim_list, trim_data);
641 list = g_list_first(trim_list);
650 list = g_list_next(list);
654 static gint __comparefunc(gconstpointer a, gconstpointer b, gpointer userdata)
656 if (a == NULL || b == NULL)
658 if (strcmp((char *)a, (char *)b) == 0)
660 if (strcmp((char *)a, (char *)b) < 0)
662 if (strcmp((char *)a, (char *)b) > 0)
667 static int __check_dpi(const char *dpi_char, int dpi_int)
669 if (dpi_char == NULL)
672 if (strcasecmp(dpi_char, LDPI) == 0) {
673 if (dpi_int >= LDPI_MIN && dpi_int <= LDPI_MAX)
677 } else if (strcasecmp(dpi_char, MDPI) == 0) {
678 if (dpi_int >= MDPI_MIN && dpi_int <= MDPI_MAX)
682 } else if (strcasecmp(dpi_char, HDPI) == 0) {
683 if (dpi_int >= HDPI_MIN && dpi_int <= HDPI_MAX)
687 } else if (strcasecmp(dpi_char, XHDPI) == 0) {
688 if (dpi_int >= XHDPI_MIN && dpi_int <= XHDPI_MAX)
692 } else if (strcasecmp(dpi_char, XXHDPI) == 0) {
693 if (dpi_int >= XXHDPI_MIN && dpi_int <= XXHDPI_MAX)
701 static gint __check_icon_folder(const char *orig_icon_path, char **new_icon_path)
704 char *icon_filename = NULL;
705 char modified_iconpath[BUFSIZE] = { '\0' };
706 char icon_path[BUFSIZE] = { '\0' };
710 if (orig_icon_path == NULL)
713 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
717 if (dpi >= LDPI_MIN && dpi <= LDPI_MAX) {
718 dpi_path[0] = "LDPI";
719 dpi_path[1] = "ldpi";
720 } else if (dpi >= MDPI_MIN && dpi <= MDPI_MAX) {
721 dpi_path[0] = "MDPI";
722 dpi_path[1] = "mdpi";
723 } else if (dpi >= HDPI_MIN && dpi <= HDPI_MAX) {
724 dpi_path[0] = "HDPI";
725 dpi_path[1] = "hdpi";
726 } else if (dpi >= XHDPI_MIN && dpi <= XHDPI_MAX) {
727 dpi_path[0] = "XHDPI";
728 dpi_path[1] = "xhdpi";
729 } else if (dpi >= XXHDPI_MIN && dpi <= XXHDPI_MAX) {
730 dpi_path[0] = "XXHDPI";
731 dpi_path[1] = "xxhdpi";
733 _LOGE("Unidentified dpi[%d]", dpi);
737 icon_filename = strrchr(orig_icon_path, '/');
738 if (icon_filename == NULL)
741 snprintf(icon_path, strlen(orig_icon_path) - (strlen(icon_filename) - 1), "%s", orig_icon_path);
742 for (i = 0; i < 2; i++) {
743 snprintf(modified_iconpath, BUFSIZE - 1, "%s/%s%s", icon_path, dpi_path[i], icon_filename);
744 if (access(modified_iconpath, F_OK) != -1) {
745 /* if exists, return modified icon path */
746 *new_icon_path = strdup(modified_iconpath);
754 static gint __compare_icon(gconstpointer a, gconstpointer b)
756 icon_x *icon = (icon_x *)a;
758 char *icon_folder_path = NULL;
760 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
763 if (icon->dpi != NULL)
766 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
768 icon->text = icon_folder_path;
774 static gint __compare_icon_with_dpi(gconstpointer a, gconstpointer b)
776 icon_x *icon = (icon_x *)a;
777 int dpi = GPOINTER_TO_INT(b);
779 if (icon->lang != NULL && strcasecmp(icon->lang, DEFAULT_LOCALE) != 0)
782 if (icon->dpi == NULL)
785 if (__check_dpi(icon->dpi, dpi) == 0)
791 static gint __compare_icon_with_lang(gconstpointer a, gconstpointer b)
793 icon_x *icon = (icon_x *)a;
794 char *lang = (char *)b;
795 char *icon_folder_path = NULL;
797 if (icon->dpi != NULL)
800 if (strcasecmp(icon->lang, lang) == 0) {
801 if (strcasecmp(icon->lang, DEFAULT_LOCALE) == 0) {
802 /* icon for no locale. check existance of folder-hierachied default icons */
803 if (__check_icon_folder(icon->text, &icon_folder_path) == 0) {
805 icon->text = icon_folder_path;
814 static gint __compare_icon_with_lang_dpi(gconstpointer a, gconstpointer b)
816 icon_x *icon = (icon_x *)a;
817 char *lang = (char *)b;
820 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
824 if (strcasecmp(icon->lang, lang) == 0 && __check_dpi(icon->dpi, dpi) == 0)
830 static char *__find_icon(GList *icons, const char *lang)
837 /* first, find icon whose locale and dpi with given lang and system's dpi has matched */
838 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang_dpi);
840 icon = (icon_x *)tmp->data;
841 return (char *)icon->text;
844 /* if first has failed, find icon whose locale has matched */
845 tmp = g_list_find_custom(icons, lang, (GCompareFunc)__compare_icon_with_lang);
847 icon = (icon_x *)tmp->data;
848 return (char *)icon->text;
851 /* if second has failed, find icon whose dpi has matched with system's dpi */
852 ret = system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
853 if (ret == SYSTEM_INFO_ERROR_NONE) {
854 tmp = g_list_find_custom(icons, GINT_TO_POINTER(dpi), (GCompareFunc)__compare_icon_with_dpi);
856 icon = (icon_x *)tmp->data;
857 return (char *)icon->text;
861 /* last, find default icon marked as "No Locale" */
862 tmp = g_list_find_custom(icons, NULL, (GCompareFunc)__compare_icon);
864 icon = (icon_x *)tmp->data;
865 return (char *)icon->text;
871 static void __extract_data(gpointer data, GList *lbls, GList *lcns, GList *icns, GList *dcns, GList *aths,
872 char **label, char **license, char **icon, char **description, char **author)
879 for (tmp = lbls; tmp; tmp = tmp->next) {
880 lbl = (label_x *)tmp->data;
884 if (strcmp(lbl->lang, (char *)data) == 0) {
885 *label = (char *)lbl->text;
890 for (tmp = lcns; tmp; tmp = tmp->next) {
891 lcn = (license_x *)tmp->data;
895 if (strcmp(lcn->lang, (char *)data) == 0) {
896 *license = (char *)lcn->text;
902 *icon = __find_icon(icns, (char *)data);
904 for (tmp = dcns; tmp; tmp = tmp->next) {
905 dcn = (description_x *)tmp->data;
909 if (strcmp(dcn->lang, (char *)data) == 0) {
910 *description = (char *)dcn->text;
915 for (tmp = aths; tmp; tmp = tmp->next) {
916 ath = (author_x *)tmp->data;
920 if (strcmp(ath->lang, (char *)data) == 0) {
921 *author = (char *)ath->text;
929 static void __extract_icon_data(gpointer data, GList *icns, char **icon, char **resolution)
933 for (tmp = icns; tmp; tmp = tmp->next) {
934 icn = (icon_x *)tmp->data;
938 if (strcmp(icn->section, (char *)data) == 0) {
939 *icon = (char *)icn->text;
940 *resolution = (char *)icn->resolution;
947 static void __extract_image_data(gpointer data, GList *imgs, char **lang, char **image)
951 for (tmp = imgs; tmp; tmp = tmp->next) {
952 img = (image_x *)tmp->data;
956 if (strcmp(img->section, (char *)data) == 0) {
957 *lang = (char *)img->lang;
958 *image = (char *)img->text;
965 static void __insert_pkglocale_info(gpointer data, gpointer userdata)
970 char *description = NULL;
971 char *license = NULL;
975 manifest_x *mfx = (manifest_x *)userdata;
976 GList *lbl = mfx->label;
977 GList *lcn = mfx->license;
978 GList *icn = mfx->icon;
979 GList *dcn = mfx->description;
980 GList *ath = mfx->author;
982 __extract_data(data, lbl, lcn, icn, dcn, ath, &label, &license, &icon, &description, &author);
983 if (!label && !description && !icon && !license && !author)
986 query = sqlite3_mprintf("INSERT INTO package_localized_info(package, package_locale, " \
987 "package_label, package_icon, package_description, package_license, package_author) VALUES" \
988 "(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
997 ret = __exec_query(query);
999 _LOGD("Package Localized Info DB Insert failed\n");
1001 sqlite3_free(query);
1004 static void __insert_application_locale_info(gpointer data, gpointer userdata)
1010 char *locale = (char *)data;
1012 application_x *app = (application_x *)userdata;
1013 GList *lbl = app->label;
1014 GList *icn = app->icon;
1016 __extract_data(data, lbl, NULL, icn, NULL, NULL, &label, NULL, &icon, NULL, NULL);
1017 if (!label && !icon)
1020 query = sqlite3_mprintf("INSERT INTO package_app_localized_info(app_id, app_locale, " \
1021 "app_label, app_icon) VALUES" \
1022 "(%Q, %Q, %Q, %Q)", app->appid, (char *)data,
1024 ret = __exec_query(query);
1026 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1028 sqlite3_free(query);
1030 /*insert ui app locale info to pkg locale to get mainapp data */
1031 if (strcasecmp(app->mainapp, "true") == 0) {
1032 query = sqlite3_mprintf("INSERT OR REPLACE INTO package_localized_info(package, package_locale, "
1033 "package_label, package_icon, package_description, package_license, package_author) VALUES"
1035 "COALESCE((SELECT package_label FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1036 "COALESCE((SELECT package_icon FROM package_localized_info WHERE package=%Q AND package_locale=%Q), %Q), "
1037 "(SELECT package_description FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1038 "(SELECT package_license FROM package_localized_info WHERE package=%Q AND package_locale=%Q), "
1039 "(SELECT package_author FROM package_localized_info WHERE package=%Q AND package_locale=%Q))",
1040 app->package, locale,
1041 app->package, locale, label,
1042 app->package, locale, icon,
1043 app->package, locale,
1044 app->package, locale,
1045 app->package, locale);
1047 ret = __exec_query(query);
1049 _LOGE("Package Localized Info DB Insert failed");
1050 sqlite3_free(query);
1054 static void __insert_application_icon_section_info(gpointer data, gpointer userdata)
1058 char *resolution = NULL;
1059 char query[MAX_QUERY_LEN] = {'\0'};
1061 application_x *app = (application_x *)userdata;
1062 GList *icn = app->icon;
1064 __extract_icon_data(data, icn, &icon, &resolution);
1065 if (!icon && !resolution)
1067 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO package_app_icon_section_info(app_id, " \
1068 "app_icon, app_icon_section, app_icon_resolution) VALUES " \
1069 "(%Q, %Q, %Q, %Q)", app->appid,
1070 icon, (char *)data, resolution);
1072 ret = __exec_query(query);
1074 _LOGD("Package UiApp Localized Info DB Insert failed\n");
1078 static void __insert_application_image_info(gpointer data, gpointer userdata)
1083 char query[MAX_QUERY_LEN] = {'\0'};
1085 application_x *app = (application_x *)userdata;
1086 GList *image = app->image;
1088 __extract_image_data(data, image, &lang, &img);
1091 sqlite3_snprintf(MAX_QUERY_LEN, query,
1092 "INSERT INTO package_app_image_info(app_id, app_locale, " \
1093 "app_image_section, app_image) VALUES" \
1094 "(%Q, %Q, %Q, %Q)", app->appid, lang, (char *)data, img);
1096 ret = __exec_query(query);
1098 _LOGD("Package UiApp image Info DB Insert failed\n");
1103 static int __insert_mainapp_info(manifest_x *mfx)
1108 char query[MAX_QUERY_LEN] = {'\0'};
1109 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1110 app = (application_x *)tmp->data;
1114 sqlite3_snprintf(MAX_QUERY_LEN, query,
1115 "UPDATE package_app_info SET app_mainapp=%Q WHERE app_id=%Q",
1116 app->mainapp, app->appid);
1117 ret = __exec_query(query);
1119 _LOGD("Package App Info DB Insert Failed\n");
1122 if (strcasecmp(app->mainapp, "True") == 0)
1123 mfx->mainapp_id = strdup(app->appid);
1126 if (mfx->mainapp_id == NULL) {
1127 if (mfx->application == NULL)
1129 app = (application_x *)mfx->application->data;
1133 sqlite3_snprintf(MAX_QUERY_LEN, query,
1134 "UPDATE package_app_info SET app_mainapp='true' WHERE app_id=%Q",
1137 _LOGD("Not valid appid\n");
1141 ret = __exec_query(query);
1143 _LOGD("Package UiApp Info DB Insert Failed\n");
1147 free((void *)app->mainapp);
1148 app->mainapp = strdup("true");
1149 mfx->mainapp_id = strdup(app->appid);
1152 memset(query, '\0', MAX_QUERY_LEN);
1153 sqlite3_snprintf(MAX_QUERY_LEN, query,
1154 "UPDATE package_info SET mainapp_id=%Q WHERE package=%Q", mfx->mainapp_id, mfx->package);
1155 ret = __exec_query(query);
1157 _LOGD("Package Info DB update Failed\n");
1164 static int __convert_background_category(GList *category_list)
1167 GList *tmp_list = category_list;
1168 char *category_data = NULL;
1170 if (category_list == NULL)
1173 while (tmp_list != NULL) {
1174 category_data = (char *)tmp_list->data;
1175 if (strcmp(category_data, APP_BG_CATEGORY_MEDIA_STR) == 0)
1176 ret = ret | APP_BG_CATEGORY_MEDIA_VAL;
1177 else if (strcmp(category_data, APP_BG_CATEGORY_DOWNLOAD_STR) == 0)
1178 ret = ret | APP_BG_CATEGORY_DOWNLOAD_VAL;
1179 else if (strcmp(category_data, APP_BG_CATEGORY_BGNETWORK_STR) == 0)
1180 ret = ret | APP_BG_CATEGORY_BGNETWORK_VAL;
1181 else if (strcmp(category_data, APP_BG_CATEGORY_LOCATION_STR) == 0)
1182 ret = ret | APP_BG_CATEGORY_LOCATION_VAL;
1183 else if (strcmp(category_data, APP_BG_CATEGORY_SENSOR_STR) == 0)
1184 ret = ret | APP_BG_CATEGORY_SENSOR_VAL;
1185 else if (strcmp(category_data, APP_BG_CATEGORY_IOTCOMM_STR) == 0)
1186 ret = ret | APP_BG_CATEGORY_IOTCOMM_VAL;
1187 else if (strcmp(category_data, APP_BG_CATEGORY_SYSTEM) == 0)
1188 ret = ret | APP_BG_CATEGORY_SYSTEM_VAL;
1190 _LOGE("Unidentified category [%s]", category_data);
1191 tmp_list = g_list_next(tmp_list);
1197 static const char *__find_effective_appid(GList *metadata_list)
1202 for (tmp_list = metadata_list; tmp_list; tmp_list = tmp_list->next) {
1203 md = (metadata_x *)tmp_list->data;
1204 if (md == NULL || md->key == NULL)
1207 if (strcmp(md->key, "http://tizen.org/metadata/effective-appid") == 0) {
1216 static char *__get_bool(char *value, bool is_true)
1218 if (value != NULL) {
1219 if (!strcmp(value, ""))
1220 return (is_true) ? "true" : "false";
1224 return (is_true) ? "true" : "false";
1227 /* _PRODUCT_LAUNCHING_ENHANCED_
1228 * app->indicatordisplay, app->portraitimg, app->landscapeimg, app->guestmode_appstatus
1230 static int __insert_application_info(manifest_x *mfx)
1235 int background_value = 0;
1236 char query[MAX_QUERY_LEN] = {'\0'};
1238 const char *effective_appid;
1241 type = strdup(mfx->type);
1243 type = strdup("tpk");
1245 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1246 app = (application_x *)tmp->data;
1250 background_value = __convert_background_category(app->background_category);
1251 if (background_value < 0) {
1252 _LOGE("Failed to retrieve background value[%d]", background_value);
1253 background_value = 0;
1256 effective_appid = __find_effective_appid(app->metadata);
1258 sqlite3_snprintf(MAX_QUERY_LEN, query,
1259 "INSERT INTO package_app_info(" \
1260 "app_id, app_component, app_exec, app_nodisplay, app_type, " \
1261 "app_onboot, app_multiple, app_autorestart, app_taskmanage, app_enabled, " \
1262 "app_hwacceleration, app_screenreader, app_mainapp, app_recentimage, app_launchcondition, " \
1263 "app_indicatordisplay, app_portraitimg, app_landscapeimg, app_guestmodevisibility, app_permissiontype, " \
1264 "app_preload, app_submode, app_submode_mainid, app_installed_storage, app_process_pool, " \
1265 "app_launch_mode, app_ui_gadget, app_support_mode, app_support_disable, component_type, package, " \
1266 "app_tep_name, app_zip_mount_file, app_background_category, app_package_type, app_root_path, " \
1267 "app_api_version, app_effective_appid, app_splash_screen_display, app_package_system, app_removable, " \
1268 "app_package_installed_time, app_support_ambient) " \
1270 "%Q, %Q, %Q, LOWER(%Q), %Q, " \
1271 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1272 "%Q, %Q, %Q, %Q, %Q, " \
1273 "LOWER(%Q), %Q, %Q, LOWER(%Q), %Q, " \
1274 "LOWER(%Q), LOWER(%Q), %Q, %Q, LOWER(%Q), " \
1275 "COALESCE(%Q, 'caller'), LOWER(%Q), %Q, LOWER(%Q), %Q, %Q, " \
1276 "%Q, %Q, %d, %Q, %Q, " \
1277 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1279 app->appid, app->component_type, app->exec, __get_bool(app->nodisplay, false), app->type,
1280 __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),
1281 app->hwacceleration, app->screenreader, app->mainapp, app->recentimage, app->launchcondition,
1282 __get_bool(app->indicatordisplay, true), app->portraitimg, app->landscapeimg,
1283 __get_bool(app->guestmode_visibility, true), app->permission_type,
1284 __get_bool(mfx->preload, false), __get_bool(app->submode, false), app->submode_mainid, mfx->installed_storage, __get_bool(app->process_pool, false),
1285 app->launch_mode, __get_bool(app->ui_gadget, false), mfx->support_mode, __get_bool(mfx->support_disable, false), app->component_type, mfx->package,
1286 mfx->tep_name, mfx->zip_mount_file, background_value, type, mfx->root_path, mfx->api_version,
1287 effective_appid, __get_bool(app->splash_screen_display, false), __get_bool(mfx->system, false), __get_bool(mfx->removable, true), mfx->installed_time, __get_bool(app->support_ambient, false));
1289 ret = __exec_query(query);
1291 _LOGD("Package UiApp Info DB Insert Failed\n");
1296 memset(query, '\0', MAX_QUERY_LEN);
1305 static int __insert_application_appcategory_info(manifest_x *mfx)
1312 char query[MAX_QUERY_LEN] = {'\0'};
1313 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1314 app = (application_x *)app_tmp->data;
1317 for (ct_tmp = app->category; ct_tmp; ct_tmp = ct_tmp->next) {
1318 ct = (const char *)ct_tmp->data;
1321 sqlite3_snprintf(MAX_QUERY_LEN, query,
1322 "INSERT INTO package_app_app_category(app_id, category) " \
1325 ret = __exec_query(query);
1327 _LOGD("Package UiApp Category Info DB Insert Failed\n");
1330 memset(query, '\0', MAX_QUERY_LEN);
1336 static int __insert_application_appmetadata_info(manifest_x *mfx)
1343 char query[MAX_QUERY_LEN] = {'\0'};
1344 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1345 app = (application_x *)app_tmp->data;
1348 for (md_tmp = app->metadata; md_tmp; md_tmp = md_tmp->next) {
1349 md = (metadata_x *)md_tmp->data;
1353 sqlite3_snprintf(MAX_QUERY_LEN, query,
1354 "INSERT INTO package_app_app_metadata(app_id, md_key, md_value) " \
1355 "VALUES(%Q, %Q, %Q)",\
1356 app->appid, md->key, md->value ? md->value : NULL);
1357 ret = __exec_query(query);
1359 _LOGD("Package UiApp Metadata Info DB Insert Failed\n");
1363 memset(query, '\0', MAX_QUERY_LEN);
1369 static int __insert_application_apppermission_info(manifest_x *mfx)
1376 char query[MAX_QUERY_LEN] = {'\0'};
1377 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1378 app = (application_x *)app_tmp->data;
1381 for (pm_tmp = app->permission; pm_tmp; pm_tmp = pm_tmp->next) {
1382 pm = (permission_x *)pm_tmp->data;
1385 sqlite3_snprintf(MAX_QUERY_LEN, query,
1386 "INSERT INTO package_app_app_permission(app_id, pm_type, pm_value) " \
1387 "VALUES(%Q, %Q, %Q)",\
1388 app->appid, pm->type, pm->value);
1389 ret = __exec_query(query);
1391 _LOGD("Package UiApp permission Info DB Insert Failed\n");
1394 memset(query, '\0', MAX_QUERY_LEN);
1400 static int __insert_application_appcontrol_info(manifest_x *mfx)
1404 GList *acontrol_tmp;
1405 appcontrol_x *acontrol;
1407 char query[MAX_QUERY_LEN] = {'\0'};
1408 char buf[BUFSIZE] = {'\0'};
1409 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1410 app = (application_x *)app_tmp->data;
1413 for (acontrol_tmp = app->appcontrol; acontrol_tmp; acontrol_tmp = acontrol_tmp->next) {
1414 acontrol = (appcontrol_x *)acontrol_tmp->data;
1415 if (acontrol == NULL)
1417 snprintf(buf, BUFSIZE, "%s|%s|%s",\
1418 acontrol->operation ? (strlen(acontrol->operation) > 0 ? acontrol->operation : "NULL") : "NULL",
1419 acontrol->uri ? (strlen(acontrol->uri) > 0 ? acontrol->uri : "NULL") : "NULL",
1420 acontrol->mime ? (strlen(acontrol->mime) > 0 ? acontrol->mime : "NULL") : "NULL");
1421 sqlite3_snprintf(MAX_QUERY_LEN, query,
1422 "INSERT INTO package_app_app_control(app_id, app_control) " \
1425 ret = __exec_query(query);
1427 _LOGD("Package UiApp AppSvc DB Insert Failed\n");
1430 memset(query, '\0', MAX_QUERY_LEN);
1436 static int __insert_application_datacontrol_info(manifest_x *mfx)
1443 char query[MAX_QUERY_LEN] = {'\0'};
1445 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1446 app = (application_x *)app_tmp->data;
1449 for (dc_tmp = app->datacontrol; dc_tmp; dc_tmp = dc_tmp->next) {
1450 dc = (datacontrol_x *)dc_tmp->data;
1453 sqlite3_snprintf(MAX_QUERY_LEN, query,
1454 "INSERT INTO package_app_data_control(app_id, providerid, access, type) " \
1455 "VALUES(%Q, %Q, %Q, %Q)",\
1461 ret = __exec_query(query);
1463 _LOGD("Package UiApp Data Control DB Insert Failed\n");
1466 memset(query, '\0', MAX_QUERY_LEN);
1472 static int __insert_application_share_request_info(manifest_x *mfx)
1481 char query[MAX_QUERY_LEN] = {'\0'};
1482 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1483 app = (application_x *)app_tmp->data;
1486 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1487 ds = (datashare_x *)ds_tmp->data;
1490 for (rq_tmp = ds->request; rq_tmp; rq_tmp = rq_tmp->next) {
1491 rq = (const char *)rq_tmp->data;
1494 sqlite3_snprintf(MAX_QUERY_LEN, query,
1495 "INSERT INTO package_app_share_request(app_id, data_share_request) " \
1498 ret = __exec_query(query);
1500 _LOGD("Package UiApp Share Request DB Insert Failed\n");
1503 memset(query, '\0', MAX_QUERY_LEN);
1510 static int __insert_application_share_allowed_info(manifest_x *mfx)
1521 char query[MAX_QUERY_LEN] = {'\0'};
1522 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1523 app = (application_x *)app_tmp->data;
1526 for (ds_tmp = app->datashare; ds_tmp; ds_tmp = ds_tmp->next) {
1527 ds = (datashare_x *)ds_tmp->data;
1530 for (df_tmp = ds->define; df_tmp; df_tmp = df_tmp->next) {
1531 df = (define_x *)df_tmp->data;
1534 for (al_tmp = df->allowed; al_tmp; al_tmp = al_tmp->next) {
1535 al = (const char *)al_tmp->data;
1538 sqlite3_snprintf(MAX_QUERY_LEN, query,
1539 "INSERT INTO package_app_share_allowed(app_id, data_share_path, data_share_allowed) " \
1540 "VALUES(%Q, %Q, %Q)",\
1541 app->appid, df->path, al);
1542 ret = __exec_query(query);
1544 _LOGD("Package UiApp Share Allowed DB Insert Failed\n");
1547 memset(query, '\0', MAX_QUERY_LEN);
1555 static gint __compare_splashscreen_with_orientation_dpi(gconstpointer a, gconstpointer b)
1557 splashscreen_x *ss = (splashscreen_x *)a;
1558 const char *orientation = (const char *)b;
1561 if (ss->operation || ss->dpi == NULL)
1564 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1568 if (strcasecmp(ss->orientation, orientation) == 0 && __check_dpi(ss->dpi, dpi) == 0)
1574 static gint __compare_splashscreen_with_orientation(gconstpointer a, gconstpointer b)
1576 splashscreen_x *ss = (splashscreen_x *)a;
1577 const char *orientation = (const char *)b;
1579 if (ss->operation || ss->dpi)
1582 if (strcasecmp(ss->orientation, orientation) == 0)
1588 static splashscreen_x *__find_default_splashscreen(GList *splashscreens,
1589 const char *orientation)
1593 tmp = g_list_find_custom(splashscreens, orientation,
1594 (GCompareFunc)__compare_splashscreen_with_orientation_dpi);
1596 return (splashscreen_x *)tmp->data;
1598 tmp = g_list_find_custom(splashscreens, orientation,
1599 (GCompareFunc)__compare_splashscreen_with_orientation);
1601 return (splashscreen_x *)tmp->data;
1606 static void __find_appcontrol_splashscreen_with_dpi(gpointer data, gpointer user_data)
1608 splashscreen_x *ss = (splashscreen_x *)data;
1609 GList **list = (GList **)user_data;
1612 if (ss->operation == NULL || ss->dpi == NULL)
1615 system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
1619 if (__check_dpi(ss->dpi, dpi) != 0)
1622 *list = g_list_append(*list, ss);
1625 static void __find_appcontrol_splashscreen(gpointer data, gpointer user_data)
1627 splashscreen_x *ss = (splashscreen_x *)data;
1628 GList **list = (GList **)user_data;
1629 splashscreen_x *ss_tmp;
1632 if (ss->operation == NULL || ss->dpi)
1635 for (tmp = *list; tmp; tmp = tmp->next) {
1636 ss_tmp = (splashscreen_x *)tmp->data;
1637 if (ss_tmp->operation
1638 && strcmp(ss_tmp->operation, ss->operation) == 0
1639 && strcmp(ss_tmp->orientation, ss->orientation) == 0)
1643 *list = g_list_append(*list, ss);
1646 static GList *__find_splashscreens(GList *splashscreens)
1651 g_list_foreach(splashscreens,
1652 __find_appcontrol_splashscreen_with_dpi, &list);
1653 g_list_foreach(splashscreens,
1654 __find_appcontrol_splashscreen, &list);
1656 ss = __find_default_splashscreen(splashscreens, "portrait");
1658 list = g_list_append(list, ss);
1659 ss = __find_default_splashscreen(splashscreens, "landscape");
1661 list = g_list_append(list, ss);
1666 static int __insert_application_splashscreen_info(manifest_x *mfx)
1674 char query[MAX_QUERY_LEN] = {'\0'};
1676 for (app_tmp = mfx->application; app_tmp; app_tmp = app_tmp->next) {
1677 app = (application_x *)app_tmp->data;
1678 if (app == NULL || app->splashscreens == NULL)
1681 ss_tmp = __find_splashscreens(app->splashscreens);
1685 for (tmp = ss_tmp; tmp; tmp = tmp->next) {
1686 ss = (splashscreen_x *)tmp->data;
1687 sqlite3_snprintf(MAX_QUERY_LEN, query,
1688 "INSERT INTO package_app_splash_screen" \
1689 "(app_id, src, type, orientation, indicatordisplay, " \
1690 "operation, color_depth) " \
1691 "VALUES(%Q, %Q, %Q, %Q, %Q, %Q, %Q)",
1692 app->appid, ss->src, ss->type, ss->orientation,
1693 ss->indicatordisplay, ss->operation,
1696 ret = __exec_query(query);
1698 _LOGD("Package UiApp Splash Screen DB Insert Failed");
1701 memset(query, '\0', MAX_QUERY_LEN);
1703 g_list_free(ss_tmp);
1708 static int __insert_manifest_info_in_db(manifest_x *mfx, uid_t uid)
1712 privilege_x *pv = NULL;
1713 char query[MAX_QUERY_LEN] = { '\0' };
1716 const char *auth_name = NULL;
1717 const char *auth_email = NULL;
1718 const char *auth_href = NULL;
1720 GList *pkglocale = NULL;
1721 GList *applocale = NULL;
1722 GList *appicon = NULL;
1723 GList *appimage = NULL;
1725 int temp_pkg_mode = 0;
1726 int temp_app_mode = 0;
1727 char pkg_mode[MAX_INTEGER_LENGTH] = {'\0'};
1728 application_x *up_support_mode = NULL;
1729 GList *list_up = NULL;
1731 if (mfx->author && mfx->author->data) {
1732 author = (author_x *)mfx->author->data;
1734 auth_name = author->text;
1736 auth_email = author->email;
1738 auth_href = author->href;
1741 if (mfx->support_mode)
1742 temp_pkg_mode = atoi(mfx->support_mode);
1744 /* FIXME : OR-ing should be fixed to not to store whole support mode */
1745 list_up = mfx->application;
1746 while (list_up != NULL) {
1747 up_support_mode = (application_x *)list_up->data;
1748 if (up_support_mode->support_mode) {
1749 temp_app_mode = atoi(up_support_mode->support_mode);
1750 temp_pkg_mode |= temp_app_mode;
1752 list_up = list_up->next;
1754 snprintf(pkg_mode, MAX_INTEGER_LENGTH, "%d", temp_pkg_mode);
1756 if (mfx->support_mode)
1757 free((void *)mfx->support_mode);
1758 mfx->support_mode = strdup(pkg_mode);
1760 /*Insert in the package_info DB*/
1761 sqlite3_snprintf(MAX_QUERY_LEN, query,
1762 "INSERT INTO package_info(" \
1763 "package, package_type, package_version, package_api_version, package_tep_name, package_zip_mount_file, " \
1764 "install_location, package_size, package_removable, package_preload, package_readonly, " \
1765 "package_update, package_appsetting, package_nodisplay, package_system, author_name, " \
1766 "author_email, author_href, installed_time, installed_storage, storeclient_id, " \
1767 "mainapp_id, package_url, root_path, csc_path, package_support_mode, package_support_disable) " \
1769 "%Q, %Q, %Q, %Q, %Q, %Q, " \
1770 "%Q, %Q, LOWER(%Q), LOWER(%Q), LOWER(%Q), " \
1771 "LOWER(%Q), LOWER(%Q), LOWER(%Q), LOWER(%Q), %Q, " \
1772 "%Q, %Q, %Q, %Q, %Q, " \
1773 "%Q, %Q, %Q, %Q, %Q, LOWER(%Q))",
1774 mfx->package, mfx->type, mfx->version, mfx->api_version, mfx->tep_name, mfx->zip_mount_file,
1775 mfx->installlocation, mfx->package_size, __get_bool(mfx->removable, true), __get_bool(mfx->preload, false), __get_bool(mfx->readonly, false),
1776 __get_bool(mfx->update, false), __get_bool(mfx->appsetting, false), __get_bool(mfx->nodisplay_setting, false), __get_bool(mfx->system, false), auth_name,
1777 auth_email, auth_href, mfx->installed_time, mfx->installed_storage,
1778 mfx->storeclient_id,
1779 mfx->mainapp_id, mfx->package_url, mfx->root_path, mfx->csc_path, mfx->support_mode, __get_bool(mfx->support_disable, false));
1781 ret = __exec_query(query);
1783 _LOGD("Package Info DB Insert Failed\n");
1787 /*Insert in the package_privilege_info DB*/
1788 for (tmp = mfx->privileges; tmp; tmp = tmp->next) {
1789 pv = (privilege_x *)tmp->data;
1792 memset(query, '\0', MAX_QUERY_LEN);
1793 sqlite3_snprintf(MAX_QUERY_LEN, query,
1794 "INSERT INTO package_privilege_info(package, privilege, type) " \
1795 "VALUES(%Q, %Q, %Q)",\
1796 mfx->package, pv->value, pv->type);
1797 ret = __exec_query(query);
1799 _LOGD("Package Privilege Info DB Insert Failed\n");
1804 if (mfx->application != NULL) {
1805 ret = __insert_mainapp_info(mfx);
1810 /*Insert the package locale*/
1811 pkglocale = __create_locale_list(pkglocale, mfx->label, mfx->license, mfx->icon, mfx->description, mfx->author);
1812 /*remove duplicated data in pkglocale*/
1813 __trimfunc(pkglocale);
1815 /*Insert the app locale, icon, image info */
1816 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1817 app = (application_x *)tmp->data;
1820 applocale = __create_locale_list(applocale, app->label, NULL, app->icon, NULL, NULL);
1821 appicon = __create_icon_list(appicon, app->icon);
1822 appimage = __create_image_list(appimage, app->image);
1824 /*remove duplicated data in applocale*/
1825 __trimfunc(applocale);
1826 __trimfunc(appicon);
1827 __trimfunc(appimage);
1829 g_list_foreach(pkglocale, __insert_pkglocale_info, (gpointer)mfx);
1831 /*native app locale info*/
1832 for (tmp = mfx->application; tmp; tmp = tmp->next) {
1833 app = (application_x *)tmp->data;
1836 g_list_foreach(applocale, __insert_application_locale_info, (gpointer)app);
1837 g_list_foreach(appicon, __insert_application_icon_section_info, (gpointer)app);
1838 g_list_foreach(appimage, __insert_application_image_info, (gpointer)app);
1841 g_list_free(pkglocale);
1843 g_list_free(applocale);
1845 g_list_free(appicon);
1847 g_list_free(appimage);
1850 /*Insert in the package_app_info DB*/
1851 ret = __insert_application_info(mfx);
1854 /*Insert in the package_app_app_control DB*/
1855 ret = __insert_application_appcontrol_info(mfx);
1859 /*Insert in the package_app_app_category DB*/
1860 ret = __insert_application_appcategory_info(mfx);
1864 /*Insert in the package_app_app_metadata DB*/
1865 ret = __insert_application_appmetadata_info(mfx);
1869 /*Insert in the package_app_app_permission DB*/
1870 ret = __insert_application_apppermission_info(mfx);
1874 /*Insert in the package_app_share_allowed DB*/
1875 ret = __insert_application_share_allowed_info(mfx);
1879 /*Insert in the package_app_share_request DB*/
1880 ret = __insert_application_share_request_info(mfx);
1884 /*Insert in the package_app_data_control DB*/
1885 ret = __insert_application_datacontrol_info(mfx);
1889 /*Insert in the package_app_splash_screen DB*/
1890 ret = __insert_application_splashscreen_info(mfx);
1898 static int __delete_appinfo_from_db(char *db_table, const char *appid)
1900 char query[MAX_QUERY_LEN] = { '\0' };
1903 sqlite3_snprintf(MAX_QUERY_LEN, query,
1904 "DELETE FROM %q where app_id=%Q", db_table, appid);
1905 ret = __exec_query(query);
1907 _LOGD("DB Deletion from table (%s) Failed\n", db_table);
1913 static int __delete_subpkg_info_from_db(char *appid)
1917 ret = __delete_appinfo_from_db("package_app_info", appid);
1920 ret = __delete_appinfo_from_db("package_app_localized_info", appid);
1923 ret = __delete_appinfo_from_db("package_app_icon_section_info", appid);
1926 ret = __delete_appinfo_from_db("package_app_image_info", appid);
1929 ret = __delete_appinfo_from_db("package_app_app_control", appid);
1932 ret = __delete_appinfo_from_db("package_app_app_category", appid);
1935 ret = __delete_appinfo_from_db("package_app_app_metadata", appid);
1938 ret = __delete_appinfo_from_db("package_app_app_permission", appid);
1941 ret = __delete_appinfo_from_db("package_app_share_allowed", appid);
1944 ret = __delete_appinfo_from_db("package_app_share_request", appid);
1947 ret = __delete_appinfo_from_db("package_app_data_control", appid);
1950 ret = __delete_appinfo_from_db("package_app_splash_screen", appid);
1957 static int __delete_subpkg_from_db(manifest_x *mfx)
1959 char query[MAX_QUERY_LEN] = { '\0' };
1960 char *error_message = NULL;
1962 sqlite3_snprintf(MAX_QUERY_LEN, query, "SELECT app_id FROM package_app_info WHERE package=%Q", mfx->package);
1964 sqlite3_exec(pkgmgr_parser_db, query, __delete_subpkg_list_cb, NULL, &error_message)) {
1965 _LOGE("Don't execute query = %s error message = %s\n", query,
1967 sqlite3_free(error_message);
1970 sqlite3_free(error_message);
1975 static int __delete_manifest_info_from_db(manifest_x *mfx, uid_t uid)
1977 char query[MAX_QUERY_LEN] = { '\0' };
1982 /*Delete from Package Info DB*/
1983 sqlite3_snprintf(MAX_QUERY_LEN, query,
1984 "DELETE FROM package_info WHERE package=%Q", mfx->package);
1985 ret = __exec_query(query);
1987 _LOGD("Package Info DB Delete Failed\n");
1990 memset(query, '\0', MAX_QUERY_LEN);
1992 /*Delete from Package Localized Info*/
1993 sqlite3_snprintf(MAX_QUERY_LEN, query,
1994 "DELETE FROM package_localized_info WHERE package=%Q", mfx->package);
1995 ret = __exec_query(query);
1997 _LOGD("Package Localized Info DB Delete Failed\n");
2001 /*Delete from Package Privilege Info*/
2002 sqlite3_snprintf(MAX_QUERY_LEN, query,
2003 "DELETE FROM package_privilege_info WHERE package=%Q", mfx->package);
2004 ret = __exec_query(query);
2006 _LOGD("Package Privilege Info DB Delete Failed\n");
2010 for (tmp = mfx->application; tmp; tmp = tmp->next) {
2011 app = (application_x *)tmp->data;
2014 ret = __delete_appinfo_from_db("package_app_info", app->appid);
2017 ret = __delete_appinfo_from_db("package_app_localized_info", app->appid);
2020 ret = __delete_appinfo_from_db("package_app_icon_section_info", app->appid);
2023 ret = __delete_appinfo_from_db("package_app_image_info", app->appid);
2026 ret = __delete_appinfo_from_db("package_app_app_control", app->appid);
2029 ret = __delete_appinfo_from_db("package_app_app_category", app->appid);
2032 ret = __delete_appinfo_from_db("package_app_app_metadata", app->appid);
2035 ret = __delete_appinfo_from_db("package_app_app_permission", app->appid);
2038 ret = __delete_appinfo_from_db("package_app_share_allowed", app->appid);
2041 ret = __delete_appinfo_from_db("package_app_share_request", app->appid);
2044 ret = __delete_appinfo_from_db("package_app_data_control", app->appid);
2047 ret = __delete_appinfo_from_db("package_app_splash_screen", app->appid);
2052 /* if main package has sub pkg, delete sub pkg data*/
2053 __delete_subpkg_from_db(mfx);
2058 static int __disable_app(const char *appid)
2061 char query[MAX_QUERY_LEN] = {'\0'};
2062 sqlite3_snprintf(MAX_QUERY_LEN, query,
2063 "UPDATE package_app_info SET app_disable='true' WHERE app_id=%Q",
2065 ret = __exec_query(query);
2067 _LOGD("Insert global app disable failed\n");
2072 static int __enable_app(const char *appid)
2075 char query[MAX_QUERY_LEN] = {'\0'};
2076 sqlite3_snprintf(MAX_QUERY_LEN, query,
2077 "UPDATE package_app_info SET app_disable='false' WHERE app_id=%Q",
2079 ret = __exec_query(query);
2081 _LOGD("Insert global app disable failed\n");
2086 static int __disable_pkg(const char *pkgid)
2089 char query[MAX_QUERY_LEN] = {'\0'};
2090 sqlite3_snprintf(MAX_QUERY_LEN, query,
2091 "UPDATE package_info SET package_disable='true' WHERE package=%Q",
2093 ret = __exec_query(query);
2095 _LOGD("Update pkg disable info has failed\n");
2100 static int __enable_pkg(const char *pkgid)
2103 char query[MAX_QUERY_LEN] = {'\0'};
2104 sqlite3_snprintf(MAX_QUERY_LEN, query,
2105 "UPDATE package_info SET package_disable='false' WHERE package=%Q",
2107 ret = __exec_query(query);
2109 _LOGD("Update pkg disable info has failed\n");
2114 static int __check_appinfo_for_uid_table(const char *appid, uid_t uid)
2117 char query[MAX_QUERY_LEN] = { '\0', };
2119 const char *val = NULL;
2124 sqlite3_snprintf(MAX_QUERY_LEN, query,
2125 "SELECT COUNT(*) FROM "
2126 "package_app_info_for_uid WHERE app_id=%Q "
2127 "AND uid=%d", appid, (int)uid);
2129 ret = sqlite3_prepare_v2(pkgmgr_parser_db, query, strlen(query), &stmt, NULL);
2130 if (ret != SQLITE_OK) {
2131 LOGE("prepare failed: %s", sqlite3_errmsg(pkgmgr_parser_db));
2132 return PMINFO_R_ERROR;
2135 if (sqlite3_step(stmt) != SQLITE_ROW) {
2136 LOGE("failed to step");
2137 sqlite3_finalize(stmt);
2138 return PMINFO_R_ERROR;
2141 val = (const char *)sqlite3_column_text(stmt, 0);
2143 sqlite3_finalize(stmt);
2148 static int __disable_global_app_for_user(const char *appid, uid_t uid)
2151 char query[MAX_QUERY_LEN] = { '\0', };
2153 ret = __check_appinfo_for_uid_table(appid, uid);
2155 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2158 } else if (ret == 0) {
2159 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2160 "package_app_info_for_uid(app_id, uid, is_disabled, is_splash_screen_enabled) "
2161 "VALUES(%Q, %d, 'true', "
2162 "(SELECT app_splash_screen_display FROM package_app_info WHERE appid='%Q'))",
2163 appid, (int)uid, appid);
2165 sqlite3_snprintf(MAX_QUERY_LEN, query, "UPDATE "
2166 "package_app_info_for_uid SET is_disabled='true' "
2167 "WHERE app_id=%Q AND uid=%d", appid, (int)uid);
2170 ret = __exec_query(query);
2172 _LOGD("Add global app disable info failed\n");
2177 static int __enable_global_app_for_user(const char *appid, uid_t uid)
2180 char query[MAX_QUERY_LEN] = {'\0'};
2182 ret = __check_appinfo_for_uid_table(appid, uid);
2184 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2187 } else if (ret > 0) {
2188 sqlite3_snprintf(MAX_QUERY_LEN, query,
2189 "UPDATE package_app_info_for_uid SET "
2190 "is_disabled='false' WHERE app_id=%Q AND "
2191 "uid=%d", appid, (int)uid);
2194 ret = __exec_query(query);
2196 _LOGD("Remove global app disable info failed\n");
2201 static int __update_global_app_splash_screen_for_user(const char *appid,
2202 uid_t uid, int flag)
2205 char query[MAX_QUERY_LEN] = { '\0', };
2207 ret = __check_appinfo_for_uid_table(appid, uid);
2209 _LOGE("Failed to check package_app_info_for_uid with appid[%s], uid[%d]",
2212 } else if (ret == 0) {
2213 sqlite3_snprintf(MAX_QUERY_LEN, query, "INSERT INTO "
2214 "package_app_info_for_uid(app_id, uid, is_splash_screen_enabled) "
2215 "VALUES(%Q, %d, %Q)", appid, (int)uid,
2216 flag ? "true" : "false");
2218 sqlite3_snprintf(MAX_QUERY_LEN, query,
2219 "UPDATE package_app_info_for_uid SET "
2220 "is_splash_screen_enabled=%Q WHERE app_id=%Q AND "
2221 "uid=%d", flag ? "true" : "false", appid, (int)uid);
2224 ret = __exec_query(query);
2226 _LOGD("update global app splash screen info failed\n");
2231 static int __disable_app_splash_screen(const char *appid)
2234 char query[MAX_QUERY_LEN] = {'\0'};
2236 sqlite3_snprintf(MAX_QUERY_LEN, query,
2237 "UPDATE package_app_info SET app_splash_screen_display='false' WHERE app_id=%Q",
2239 ret = __exec_query(query);
2241 _LOGD("Failed to update app_palsh_screen_display");
2246 static int __enable_app_splash_screen(const char *appid)
2249 char query[MAX_QUERY_LEN] = {'\0'};
2251 sqlite3_snprintf(MAX_QUERY_LEN, query,
2252 "UPDATE package_app_info SET app_splash_screen_display='true' WHERE app_id=%Q",
2254 ret = __exec_query(query);
2256 _LOGD("Failed to update app_splash_screen_display");
2261 API int pkgmgr_parser_initialize_db(uid_t uid)
2267 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
2269 _LOGD("package info DB initialization failed\n");
2272 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_LOCALIZED_INFO);
2274 _LOGD("package localized info DB initialization failed\n");
2277 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_PRIVILEGE_INFO);
2279 _LOGD("package app app privilege DB initialization failed\n");
2282 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO);
2284 _LOGD("package app info DB initialization failed\n");
2287 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_LOCALIZED_INFO);
2289 _LOGD("package app localized info DB initialization failed\n");
2292 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_ICON_SECTION_INFO);
2294 _LOGD("package app icon localized info DB initialization failed\n");
2297 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_IMAGE_INFO);
2299 _LOGD("package app image info DB initialization failed\n");
2302 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CONTROL);
2304 _LOGD("package app app control DB initialization failed\n");
2307 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_CATEGORY);
2309 _LOGD("package app app category DB initialization failed\n");
2312 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_METADATA);
2314 _LOGD("package app app category DB initialization failed\n");
2317 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_APP_PERMISSION);
2319 _LOGD("package app app permission DB initialization failed\n");
2322 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED);
2324 _LOGD("package app share allowed DB initialization failed\n");
2327 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST);
2329 _LOGD("package app share request DB initialization failed\n");
2332 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL);
2334 _LOGD("package app data control DB initialization failed\n");
2338 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID);
2340 _LOGD("package_app_info_for_uid for user DB initialization failed\n");
2344 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN);
2346 _LOGD("package app splash screen DB initialization failed\n");
2350 /* Trigger package_app_info_for_uid */
2351 ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID);
2353 _LOGD("package app info for uid DB initialization failed\n");
2358 /* TODO: refactor this code */
2359 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INFO);
2361 _LOGD("package cert info DB initialization failed\n");
2364 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TABLE_PACKAGE_CERT_INDEX_INFO);
2366 _LOGD("package cert index info DB initialization failed\n");
2369 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO);
2371 _LOGD("package cert info DB initialization failed\n");
2374 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INFO2);
2376 _LOGD("package cert info DB initialization failed\n");
2379 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_DELETE_CERT_INFO);
2381 _LOGD("package cert info DB initialization failed\n");
2384 ret = __initialize_db(pkgmgr_cert_db, QUERY_CREATE_TRIGGER_UPDATE_CERT_INDEX_INFO);
2386 _LOGD("package cert index info DB initialization failed\n");
2390 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2391 if (db_path == NULL) {
2392 _LOGD("Failed to get user cert db path - GLOBAL_USER");
2394 ret = __parserdb_change_perm(db_path, GLOBAL_USER);
2396 _LOGD("Failed to change cert db permission");
2400 db_path = getUserPkgParserDBPathUID(uid);
2401 if (db_path == NULL) {
2402 _LOGD("Failed to get user pkg parser db path - %d", uid);
2404 ret = __parserdb_change_perm(db_path, uid);
2406 _LOGD("Failed to change parser db permission\n");
2413 static int __parserdb_change_perm(const char *db_file, uid_t uid)
2416 char pwuid_buf[1024];
2417 char journal_file[BUFSIZE];
2422 struct passwd userinfo, *result = NULL;
2423 files[0] = (char *)db_file;
2424 files[1] = journal_file;
2428 if (db_file == NULL)
2431 if (getuid() != OWNER_ROOT) /* At this time we should be root to apply this */
2433 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2434 if (uid == OWNER_ROOT)
2436 ret = getpwuid_r(uid, &userinfo, pwuid_buf, sizeof(pwuid_buf), &result);
2437 if (ret != 0 || result == NULL) {
2438 _LOGE("FAIL: user %d doesn't exist", uid);
2441 snprintf(journal_file, sizeof(journal_file), "%s%s", db_file, "-journal");
2443 for (i = 0; files[i]; i++) {
2444 fd = open(files[i], O_RDONLY);
2446 if (strerror_r(errno, buf, sizeof(buf)))
2447 strncpy(buf, "", BUFSIZE - 1);
2448 _LOGD("FAIL : open %s : %s", files[i], buf);
2451 ret = fstat(fd, &sb);
2453 if (strerror_r(errno, buf, sizeof(buf)))
2454 strncpy(buf, "", BUFSIZE - 1);
2455 _LOGD("FAIL : fstat %s : %s", files[i], buf);
2459 if (S_ISLNK(sb.st_mode)) {
2460 _LOGE("FAIL : %s is symlink!", files[i]);
2464 ret = fchown(fd, uid, userinfo.pw_gid);
2466 if (strerror_r(errno, buf, sizeof(buf)))
2467 strncpy(buf, "", BUFSIZE - 1);
2468 _LOGD("FAIL : fchown %s %d.%d : %s", files[i], uid,
2469 userinfo.pw_gid, buf);
2474 mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
2475 if (!strcmp(db_file, getUserPkgCertDBPathUID(GLOBAL_USER)))
2477 ret = fchmod(fd, mode);
2479 if (strerror_r(errno, buf, sizeof(buf)))
2480 strncpy(buf, "", BUFSIZE - 1);
2481 _LOGD("FAIL : fchmod %s 0664 : %s", files[i], buf);
2486 SET_SMACK_LABEL(files[i]);
2491 API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
2496 if (getuid() != OWNER_ROOT) {
2497 _LOGE("Only root user is allowed");
2501 db_path = getUserPkgParserDBPathUID(uid);
2502 if (db_path == NULL) {
2503 _LOGE("Failed to get pkg parser db path - %d", uid);
2507 if (access(db_path, F_OK) != -1) {
2508 _LOGE("Manifest db for user %d is already exists", uid);
2514 db_path = getUserPkgCertDBPathUID(uid);
2515 if (db_path == NULL) {
2516 _LOGE("Failed to get pkg cert db path - %d", uid);
2520 if (access(db_path, F_OK) != -1) {
2521 _LOGE("Cert db for user %d is already exists", uid);
2527 ret = pkgmgr_parser_check_and_create_db(uid);
2530 ret = pkgmgr_parser_initialize_db(uid);
2532 pkgmgr_parser_close_db();
2535 pkgmgr_parser_close_db();
2540 API int pkgmgr_parser_check_and_create_db(uid_t uid)
2545 db_path = getUserPkgParserDBPathUID(uid);
2546 if (db_path == NULL) {
2547 _LOGD("Failed to get pkg parser db path - %d", uid);
2552 ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
2554 _LOGD("Manifest DB creation Failed\n");
2560 db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
2561 if (db_path == NULL) {
2562 _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
2567 ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
2569 _LOGD("Cert DB creation Failed\n");
2579 void pkgmgr_parser_close_db(void)
2581 sqlite3_close(pkgmgr_parser_db);
2582 sqlite3_close(pkgmgr_cert_db);
2586 API int pkgmgr_parser_insert_manifest_info_in_db(manifest_x *mfx)
2588 _LOGD("pkgmgr_parser_insert_manifest_info_in_db\n");
2590 _LOGD("manifest pointer is NULL\n");
2594 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2596 _LOGD("Failed to open DB\n");
2599 ret = pkgmgr_parser_initialize_db(GLOBAL_USER);
2602 /*Begin transaction*/
2603 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2604 if (ret != SQLITE_OK) {
2605 _LOGD("Failed to begin transaction\n");
2609 _LOGD("Transaction Begin\n");
2610 ret = __insert_manifest_info_in_db(mfx, GLOBAL_USER);
2612 _LOGD("Insert into DB failed. Rollback now\n");
2613 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2616 /*Commit transaction*/
2617 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2618 if (ret != SQLITE_OK) {
2619 _LOGD("Failed to commit transaction. Rollback now\n");
2620 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2624 _LOGD("Transaction Commit and End\n");
2626 pkgmgr_parser_close_db();
2630 API int pkgmgr_parser_insert_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2632 _LOGD("pkgmgr_parser_insert_manifest_info_in_usr_db\n");
2634 _LOGD("manifest pointer is NULL\n");
2638 ret = pkgmgr_parser_check_and_create_db(uid);
2640 _LOGD("Failed to open DB\n");
2643 ret = pkgmgr_parser_initialize_db(uid);
2646 /*Begin transaction*/
2647 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2648 if (ret != SQLITE_OK) {
2649 _LOGD("Failed to begin transaction\n");
2653 _LOGD("Transaction Begin\n");
2654 ret = __insert_manifest_info_in_db(mfx, uid);
2656 _LOGD("Insert into DB failed. Rollback now\n");
2657 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2660 /*Commit transaction*/
2661 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2662 if (ret != SQLITE_OK) {
2663 _LOGD("Failed to commit transaction. Rollback now\n");
2664 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2668 _LOGD("Transaction Commit and End\n");
2670 pkgmgr_parser_close_db();
2674 API int pkgmgr_parser_update_tep_info_in_db(const char *pkgid, const char *tep_path)
2676 return pkgmgr_parser_update_tep_info_in_usr_db(pkgid, tep_path, _getuid());
2679 API int pkgmgr_parser_update_tep_info_in_usr_db(const char *pkgid, const char *tep_path, uid_t uid)
2681 if (pkgid == NULL || tep_path == NULL) {
2682 _LOGE("invalid parameter");
2689 ret = pkgmgr_parser_check_and_create_db(uid);
2691 _LOGD("Failed to open DB\n");
2694 ret = pkgmgr_parser_initialize_db(uid);
2698 /*Begin transaction*/
2699 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2700 if (ret != SQLITE_OK) {
2701 _LOGD("Failed to begin transaction\n");
2705 _LOGD("Transaction Begin\n");
2708 /* Updating TEP info in "package_info" table */
2709 query = sqlite3_mprintf("UPDATE package_info "\
2710 "SET package_tep_name = %Q "\
2711 "WHERE package = %Q", tep_path, pkgid);
2713 ret = __exec_query(query);
2714 sqlite3_free(query);
2715 if (ret != SQLITE_OK) {
2716 ret = PM_PARSER_R_ERROR;
2717 _LOGE("sqlite exec failed to insert entries into package_info!!");
2721 /* Updating TEP info in "package_app_info" table */
2722 query = sqlite3_mprintf("UPDATE package_app_info "\
2723 "SET app_tep_name = %Q "\
2724 "WHERE package = %Q", tep_path, pkgid);
2726 ret = __exec_query(query);
2727 sqlite3_free(query);
2728 if (ret != SQLITE_OK) {
2729 ret = PM_PARSER_R_ERROR;
2730 _LOGE("sqlite exec failed to insert entries into package_app_info!!");
2734 /*Commit transaction*/
2735 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2736 if (ret != SQLITE_OK) {
2737 _LOGE("Failed to commit transaction, Rollback now\n");
2738 ret = sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2739 if (ret != SQLITE_OK)
2740 _LOGE("Failed to Rollback\n");
2742 ret = PM_PARSER_R_ERROR;
2745 _LOGD("Transaction Commit and End\n");
2746 ret = PM_PARSER_R_OK;
2749 pkgmgr_parser_close_db();
2754 API int pkgmgr_parser_update_manifest_info_in_usr_db(manifest_x *mfx, uid_t uid)
2757 _LOGD("manifest pointer is NULL\n");
2761 ret = pkgmgr_parser_check_and_create_db(uid);
2763 _LOGD("Failed to open DB\n");
2766 ret = pkgmgr_parser_initialize_db(uid);
2769 /*Preserve guest mode visibility*/
2770 __preserve_guestmode_visibility_value(mfx);
2771 /*Begin transaction*/
2772 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2773 if (ret != SQLITE_OK) {
2774 _LOGD("Failed to begin transaction\n");
2778 _LOGD("Transaction Begin\n");
2779 ret = __delete_manifest_info_from_db(mfx, uid);
2781 _LOGD("Delete from DB failed. Rollback now\n");
2782 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2785 ret = __insert_manifest_info_in_db(mfx, uid);
2787 _LOGD("Insert into DB failed. Rollback now\n");
2788 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2792 /*Commit transaction*/
2793 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2794 if (ret != SQLITE_OK) {
2795 _LOGD("Failed to commit transaction. Rollback now\n");
2796 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2800 _LOGD("Transaction Commit and End\n");
2802 pkgmgr_parser_close_db();
2806 API int pkgmgr_parser_update_manifest_info_in_db(manifest_x *mfx)
2808 return pkgmgr_parser_update_manifest_info_in_usr_db(mfx, _getuid());
2811 API int pkgmgr_parser_delete_manifest_info_from_usr_db(manifest_x *mfx, uid_t uid)
2814 _LOGD("manifest pointer is NULL\n");
2818 ret = pkgmgr_parser_check_and_create_db(uid);
2820 _LOGD("Failed to open DB\n");
2823 /*Begin transaction*/
2824 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2825 if (ret != SQLITE_OK) {
2826 _LOGD("Failed to begin transaction\n");
2830 _LOGD("Transaction Begin\n");
2831 ret = __delete_manifest_info_from_db(mfx, uid);
2833 _LOGD("Delete from DB failed. Rollback now\n");
2834 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2837 /*Commit transaction*/
2838 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2839 if (ret != SQLITE_OK) {
2840 _LOGD("Failed to commit transaction, Rollback now\n");
2841 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2845 _LOGD("Transaction Commit and End\n");
2847 pkgmgr_parser_close_db();
2851 API int pkgmgr_parser_delete_manifest_info_from_db(manifest_x *mfx)
2853 return pkgmgr_parser_delete_manifest_info_from_usr_db(mfx, _getuid());
2856 API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(const char *appid, uid_t uid, int is_disable)
2860 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
2862 _LOGD("Failed to open DB\n");
2866 /*Begin transaction*/
2867 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2868 if (ret != SQLITE_OK) {
2869 _LOGD("Failed to begin transaction\n");
2873 _LOGD("Transaction Begin\n");
2875 ret = __disable_global_app_for_user(appid, uid);
2877 ret = __enable_global_app_for_user(appid, uid);
2879 _LOGD("__update_global_app_disable_condition_in_db failed. Rollback now\n");
2880 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2883 /*Commit transaction*/
2884 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2885 if (ret != SQLITE_OK) {
2886 _LOGD("Failed to commit transaction, Rollback now\n");
2887 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2891 _LOGD("Transaction Commit and End\n");
2893 pkgmgr_parser_close_db();
2898 API int pkgmgr_parser_update_app_disable_info_in_db(const char *appid, int is_disable)
2900 return pkgmgr_parser_update_app_disable_info_in_usr_db(appid, _getuid(), is_disable);
2903 API int pkgmgr_parser_update_pkg_disable_info_in_usr_db(const char *pkgid, uid_t uid, int is_disable)
2907 ret = pkgmgr_parser_check_and_create_db(uid);
2909 _LOGD("Failed to open DB\n");
2913 /*Begin transaction*/
2914 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2915 if (ret != SQLITE_OK) {
2916 _LOGD("Failed to begin transaction\n");
2921 _LOGD("Transaction Begin\n");
2923 ret = __disable_pkg(pkgid);
2925 ret = __enable_pkg(pkgid);
2928 _LOGD("__update_pkg_disable_condition_in_db failed. Rollback now\n");
2929 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2933 /*Commit transaction*/
2934 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2935 if (ret != SQLITE_OK) {
2936 _LOGD("Failed to commit transaction, Rollback now\n");
2937 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2941 _LOGD("Transaction Commit and End\n");
2944 pkgmgr_parser_close_db();
2948 API int pkgmgr_parser_update_pkg_disable_info_in_db(const char *pkgid, int is_disable)
2950 return pkgmgr_parser_update_pkg_disable_info_in_usr_db(pkgid, _getuid(), is_disable);
2953 API int pkgmgr_parser_update_app_disable_info_in_usr_db(const char *appid, uid_t uid, int is_disable)
2957 ret = pkgmgr_parser_check_and_create_db(uid);
2959 _LOGD("Failed to open DB\n");
2963 /*Begin transaction*/
2964 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
2965 if (ret != SQLITE_OK) {
2966 _LOGD("Failed to begin transaction\n");
2970 _LOGD("Transaction Begin\n");
2972 ret = __disable_app(appid);
2974 ret = __enable_app(appid);
2976 _LOGD("__update_app_disable_condition_in_db failed. Rollback now\n");
2977 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2980 /*Commit transaction*/
2981 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
2982 if (ret != SQLITE_OK) {
2983 _LOGD("Failed to commit transaction, Rollback now\n");
2984 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
2988 _LOGD("Transaction Commit and End\n");
2990 pkgmgr_parser_close_db();
2995 API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
2999 if (appid == NULL) {
3000 _LOGD("Invalid parameter");
3004 ret = pkgmgr_parser_check_and_create_db(GLOBAL_USER);
3006 _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");
3019 ret = __update_global_app_splash_screen_for_user(appid, uid, flag);
3021 _LOGD("__update_splash_screen_disable_condition_in_db failed. Rollback now\n");
3022 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3025 /* Commit transaction */
3026 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3027 if (ret != SQLITE_OK) {
3028 _LOGD("Failed to commit transaction, Rollback now\n");
3029 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3033 _LOGD("Transaction Commit and End\n");
3035 pkgmgr_parser_close_db();
3039 API int pkgmgr_parser_update_app_splash_screen_display_info_in_db(const char *appid, int flag)
3041 return pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(appid, _getuid(), flag);
3044 API int pkgmgr_parser_update_app_splash_screen_display_info_in_usr_db(const char *appid, uid_t uid, int flag)
3048 if (appid == NULL) {
3049 _LOGD("Invalid parameter");
3053 ret = pkgmgr_parser_check_and_create_db(uid);
3055 _LOGD("Failed to open DB");
3059 /* Begin transaction */
3060 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3061 if (ret != SQLITE_OK) {
3062 _LOGD("Failed to begin transaction");
3066 _LOGD("Transaction Begin");
3069 ret = __enable_app_splash_screen(appid);
3071 ret = __disable_app_splash_screen(appid);
3073 _LOGD("__update_app_splash_screen_condition_in_db. Rollback now");
3074 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3077 /* Commit transaction */
3078 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3079 if (ret != SQLITE_OK) {
3080 _LOGD("Failed to commit transaction, Rollback now");
3081 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3085 _LOGD("Transaction Commit and End");
3088 pkgmgr_parser_close_db();
3092 API int pkgmgr_parser_update_app_label_info_in_usr_db(const char *appid, uid_t uid, const char *label)
3095 char query[MAX_QUERY_LEN] = {'\0'};
3097 if (appid == NULL || label == NULL) {
3098 _LOGE("Invalid parameter");
3102 ret = pkgmgr_parser_check_and_create_db(uid);
3104 _LOGD("Failed to open DB");
3108 /*Begin transaction*/
3109 ret = sqlite3_exec(pkgmgr_parser_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
3110 if (ret != SQLITE_OK) {
3111 _LOGD("Failed to begin transaction\n");
3116 sqlite3_snprintf(MAX_QUERY_LEN, query,
3117 "UPDATE package_app_localized_info SET app_label=%Q WHERE " \
3118 "app_id=%Q AND app_label IS NOT NULL",
3120 ret = __exec_query(query);
3122 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3126 /* Commit transaction */
3127 ret = sqlite3_exec(pkgmgr_parser_db, "COMMIT", NULL, NULL, NULL);
3128 if (ret != SQLITE_OK) {
3129 _LOGD("Failed to commit transaction, Rollback now");
3130 sqlite3_exec(pkgmgr_parser_db, "ROLLBACK", NULL, NULL, NULL);
3134 _LOGD("Transaction Commit and End");
3137 pkgmgr_parser_close_db();
3141 API int pkgmgr_parser_update_app_label_info_in_db(const char *appid, const char *label)
3143 return pkgmgr_parser_update_app_label_info_in_usr_db(appid, _getuid(), label);