#define SVC_COLLATION "appsvc_collation"
-#define QUERY_ATTACH "attach database '%s' as Global"
-#define QUERY_CREATE_VIEW_1 "CREATE temp VIEW package_app_app_control as select * "\
- "from (select *,0 as for_all_users from main.package_app_app_control union select *,1 as for_all_users from Global.package_app_app_control)"
-#define QUERY_CREATE_VIEW_2 "CREATE temp VIEW package_app_info as select * "\
- "from (select *,0 as for_all_users from main.package_app_info union select *,1 as for_all_users from Global.package_app_info)"
#define QUERY_CREATE_TABLE_APPSVC "create table if not exists appsvc " \
"(operation text, " \
"mime_type text, " \
static sqlite3 *svc_db;
static sqlite3 *app_info_db;
-
-static int __attach_create_view_appinfo_db(sqlite3 *handle, uid_t uid)
-{
- char *error_message = NULL;
- char query_attach[QUERY_MAX_LEN] = {'\0'};
- if (uid != GLOBAL_USER) {
- snprintf(query_attach, QUERY_MAX_LEN - 1, QUERY_ATTACH, APP_INFO_DB_PATH);
- if (SQLITE_OK !=
- sqlite3_exec(handle, query_attach,
- NULL, NULL, &error_message)) {
- _D("Don't execute query = %s error message = %s\n",
- query_attach, error_message);
- sqlite3_free(error_message);
- }
- if (SQLITE_OK !=
- sqlite3_exec(handle, QUERY_CREATE_VIEW_1,
- NULL, NULL, &error_message)) {
- _D("Don't execute query = %s error message = %s\n",
- QUERY_CREATE_VIEW_1, error_message);
- sqlite3_free(error_message);
- }
- if (SQLITE_OK !=
- sqlite3_exec(handle, QUERY_CREATE_VIEW_2,
- NULL, NULL, &error_message)) {
- _D("Don't execute query = %s error message = %s\n",
- QUERY_CREATE_VIEW_2, error_message);
- sqlite3_free(error_message);
- }
- }
- return SQLITE_OK;
-}
+static sqlite3 *global_app_info_db;
static char *__get_svc_db(uid_t uid)
{
int rc;
char *db_path;
- if (app_info_db) {
+ if (app_info_db && global_app_info_db) {
_D("Already initialized\n");
return 0;
}
goto err;
}
- rc = __attach_create_view_appinfo_db(app_info_db, uid);
+ rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST",
+ NULL, NULL, NULL);
if (SQLITE_OK != rc) {
_D("Fail to change journal mode\n");
goto err;
}
- rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST",
+ sqlite3_create_collation(app_info_db, SVC_COLLATION, SQLITE_UTF8,
+ NULL, __collate_appsvc);
+
+ rc = sqlite3_open_v2(APP_INFO_DB_PATH, &global_app_info_db, SQLITE_OPEN_READONLY, NULL);
+ if (rc) {
+ _E("Can't open database: %d, %s, extended: %d", rc, sqlite3_errmsg(global_app_info_db),
+ sqlite3_extended_errcode(global_app_info_db));
+ goto err;
+ }
+
+ rc = sqlite3_exec(global_app_info_db, "PRAGMA journal_mode = PERSIST",
NULL, NULL, NULL);
if (SQLITE_OK != rc) {
_D("Fail to change journal mode\n");
goto err;
}
- sqlite3_create_collation(app_info_db, SVC_COLLATION, SQLITE_UTF8,
+ sqlite3_create_collation(global_app_info_db, SVC_COLLATION, SQLITE_UTF8,
NULL, __collate_appsvc);
return 0;
err:
- sqlite3_close(app_info_db);
- app_info_db = NULL;
+ if (app_info_db) {
+ sqlite3_close(app_info_db);
+ app_info_db = NULL;
+ }
+
+ if (global_app_info_db) {
+ sqlite3_close(global_app_info_db);
+ global_app_info_db = NULL;
+ }
return -1;
}
}
}
- ret = sqlite3_finalize(stmt);
+ sqlite3_finalize(stmt);
+ ret = sqlite3_prepare(global_app_info_db, query, sizeof(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n", ret,
+ sqlite3_extended_errcode(app_info_db));
+ return -1;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ subappid = (char *)sqlite3_column_text(stmt, 0);
+ submode_mainid = (char *)sqlite3_column_text(stmt, 1);
+ subapp = g_slist_find_custom(*pkg_list, subappid, __appid_compare);
+
+ if (subapp == NULL)
+ continue;
+
+ /* find if the main app is in the pkg_list */
+ mainapp = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare);
+ if (mainapp == NULL)
+ continue;
+
+ if (win_id && !mainapp_mode)
+ /* subapp mode - remove mainapp from list */
+ excluded_appid = (char *)mainapp->data;
+ else
+ /* mainapp mode - remove subapp from list */
+ excluded_appid = (char *)subapp->data;
+
+ if (excluded_appid) {
+ _E("remove %s from app list with submode", excluded_appid);
+ *pkg_list = g_slist_remove(*pkg_list, excluded_appid);
+ free(excluded_appid);
+ excluded_appid = NULL;
+ }
+ }
+
+ sqlite3_finalize(stmt);
return 0;
}
}
}
- ret = sqlite3_finalize(stmt);
+ sqlite3_finalize(stmt);
+ ret = sqlite3_prepare(global_app_info_db, query, strlen(query), &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ _E("prepare error, ret = %d, extended = %d\n",
+ ret, sqlite3_extended_errcode(global_app_info_db));
+ return -1;
+ }
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ str = (char *)sqlite3_column_text(stmt, 0);
+ found = 0;
+ for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
+ pkgname = (char *)iter->data;
+ if (strncmp(str, pkgname, MAX_PACKAGE_STR_SIZE - 1) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found == 0) {
+ pkgname = strdup(str);
+ *pkg_list = g_slist_append(*pkg_list, (void *)pkgname);
+ _D("%s is added", pkgname);
+ }
+ }
+
+ sqlite3_finalize(stmt);
return 0;
}