Use list of string for datacontrol privilege
[platform/core/appfw/pkgmgr-info.git] / parser / src / pkgmgr_parser_db.c
index 9394c87..eac7640 100644 (file)
@@ -313,6 +313,7 @@ static const char *parser_init_queries[] = {
        QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_ALLOWED, /* ? */
        QUERY_CREATE_TABLE_PACKAGE_APP_SHARE_REQUEST, /* ? */
        QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL,
+       QUERY_CREATE_TABLE_PACKAGE_APP_DATA_CONTROL_PRIVILEGE,
        QUERY_CREATE_TABLE_PACKAGE_APP_INFO_FOR_UID,
        QUERY_CREATE_TRIGGER_UPDATE_PACKAGE_APP_INFO_FOR_UID,
        QUERY_CREATE_TABLE_PACKAGE_APP_SPLASH_SCREEN,
@@ -474,6 +475,14 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
        if (ret != SQLITE_OK)
                return ret;
 
+       ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("failed to register busy handler: %s",
+                               sqlite3_errmsg(*db));
+               sqlite3_close_v2(*db);
+               return ret;
+       }
+
        if (flags & SQLITE_OPEN_CREATE) {
                ret = __initialize_db(*db, path, uid);
                if (ret) {
@@ -491,14 +500,6 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
                return ret;
        }
 
-       ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
-       if (ret != SQLITE_OK) {
-               _LOGE("failed to register busy handler: %s",
-                               sqlite3_errmsg(*db));
-               sqlite3_close_v2(*db);
-               return ret;
-       }
-
        return ret;
 }
 
@@ -695,6 +696,53 @@ static int __insert_metadata_info(sqlite3 *db, application_x *app)
        return 0;
 }
 
+static int __insert_app_data_control_privilege_info(sqlite3 *db,
+               datacontrol_x *datacontrol)
+{
+       static const char query[] =
+               "INSERT INTO package_app_data_control_privilege (providerid,"
+               "  privilege, type) VALUES (?, ?, ?)";
+
+       int ret;
+       sqlite3_stmt *stmt;
+       int idx;
+       GList *privileges;
+       char *priv;
+
+       if (datacontrol == NULL)
+               return 0;
+
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("prepare failed: %s", sqlite3_errmsg(db));
+               return -1;
+       }
+
+       for (privileges = datacontrol->privileges; privileges;
+                       privileges = privileges->next) {
+               priv = (char *)privileges->data;
+               if (priv == NULL)
+                       continue;
+
+               idx = 1;
+               __BIND_TEXT(db, stmt, idx++, datacontrol->providerid);
+               __BIND_TEXT(db, stmt, idx++, priv);
+               __BIND_TEXT(db, stmt, idx++, datacontrol->type);
+
+               ret = sqlite3_step(stmt);
+               if (ret != SQLITE_DONE) {
+                       _LOGE("step failed: %s", sqlite3_errmsg(db));
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
+               sqlite3_reset(stmt);
+       }
+
+       sqlite3_finalize(stmt);
+       return 0;
+}
+
 static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
 {
        static const char query[] =
@@ -733,6 +781,12 @@ static int __insert_datacontrol_info(sqlite3 *db, application_x *app)
                        return -1;
                }
 
+               if (dc->privileges &&
+                               __insert_app_data_control_privilege_info(db, dc)) {
+                       sqlite3_finalize(stmt);
+                       return -1;
+               }
+
                sqlite3_reset(stmt);
        }
 
@@ -1400,7 +1454,7 @@ static int __insert_app_localized_info(sqlite3 *db, application_x *app)
 
                sqlite3_reset(stmt);
 
-               if (strcasecmp(app->mainapp, "true")) {
+               if (strcasecmp(app->mainapp, "true") == 0) {
                        if (__insert_mainapp_localized_info(db, app, locale,
                                                label, icon))
                                _LOGE("insert mainapp localized info failed");
@@ -1561,7 +1615,7 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
                __BIND_TEXT(db, stmt, idx++, mfx->api_version);
                __BIND_TEXT(db, stmt, idx++, effective_appid);
                __BIND_TEXT(db, stmt, idx++,
-                               __get_bool(app->splash_screen_display, false));
+                               __get_bool(app->splash_screen_display, true));
                __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->system, false));
                __BIND_TEXT(db, stmt, idx++, __get_bool(mfx->removable, false));
                __BIND_TEXT(db, stmt, idx++, mfx->installed_time);
@@ -1970,9 +2024,9 @@ API int pkgmgr_parser_update_global_app_disable_for_uid_info_in_db(
                return PM_PARSER_R_EINVAL;
        }
 
-       dbpath = __get_parser_db_path(uid);
+       dbpath = __get_parser_db_path(GLOBAL_USER);
 
-       ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
+       ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
        if (ret != SQLITE_OK) {
                _LOGE("open db failed: %d", ret);
                return PM_PARSER_R_ERROR;
@@ -2169,9 +2223,9 @@ API int pkgmgr_parser_update_global_app_splash_screen_display_info_in_usr_db(
                return PM_PARSER_R_EINVAL;
        }
 
-       dbpath = __get_parser_db_path(uid);
+       dbpath = __get_parser_db_path(GLOBAL_USER);
 
-       ret = __open_db(uid, dbpath, &db, SQLITE_OPEN_READWRITE);
+       ret = __open_db(GLOBAL_USER, dbpath, &db, SQLITE_OPEN_READWRITE);
        if (ret != SQLITE_OK) {
                _LOGE("open db failed: %d", ret);
                return PM_PARSER_R_ERROR;