Remove redundant value is_privacy_requestable from privacy_package table 58/152458/1
authorYunjin Lee <yunjin-.lee@samsung.com>
Tue, 26 Sep 2017 07:37:31 +0000 (16:37 +0900)
committerYunjin Lee <yunjin-.lee@samsung.com>
Tue, 26 Sep 2017 07:37:31 +0000 (16:37 +0900)
Change-Id: I85ea9024671aef27b2cdb08748d1bb4c25f22873
Signed-off-by: Yunjin Lee <yunjin-.lee@samsung.com>
capi/include/privilege_db_manager.h
capi/res/dbspace/privacy_db_generator.sh
capi/src/privilege_db_manager.c
capi/src/privilege_package_info.c

index 90f999a..06bbcdc 100755 (executable)
@@ -297,7 +297,6 @@ int privilege_db_manager_check_black_list(uid_t uid, privilege_manager_package_t
  * @param [in] pkgid The package ID
  * @param [in] package_type The package type of the given privilege list
  * @param [in] api_version The api-version of package
- * @param [in] is_privacy_requestable Indicates if the application package can request privacy
  * @param [in] critical_privilege_list The ciritical privilege list
  * @return 0 on success, otherwise a negative error value.
  * @retval #PRIVILEGE_DB_MANAGER_ERR_NONE  Successful.
@@ -309,7 +308,7 @@ int privilege_db_manager_check_black_list(uid_t uid, privilege_manager_package_t
  * @retval #PRIVILEGE_DB_MANAGER_ERR_DB_FULL_FAIL Write could not complete due to the disk is full.
  * @retval #PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL DB update failed.
  */
-int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, bool is_privacy_requestable, GList* critical_privilege_list);
+int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, GList* critical_privilege_list);
 
 /**
  * @brief Set application package's privacy privilege information
@@ -320,7 +319,6 @@ int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, co
  * @param [in] pkgid The package ID
  * @param [in] package_type The package type of the given privilege list
  * @param [in] api_version The api-version of the package
- * @param [in] is_privacy_requestable Indicates if the application package can request privacy
  * @param [in] privilege_list The privacy privilege list
  * @return 0 on success, otherwise a negative error value.
  * @retval #PRIVILEGE_DB_MANAGER_ERR_NONE  Successful.
@@ -332,7 +330,7 @@ int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, co
  * @retval #PRIVILEGE_DB_MANAGER_ERR_DB_FULL_FAIL Write could not complete due to the disk is full.
  * @retval #PRIVILEGE_DB_MANAGER_ERR_DB_UPDATE_FAIL DB update failed.
  */
-int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, bool is_privacy_requestable,  GList* privilege_list);
+int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, GList* privilege_list);
 
 /**
  * @brief Delete all privacy, critical privilege info of the given application package.
@@ -350,7 +348,7 @@ int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, con
 int privilege_db_manager_unset_package_privilege_info(const uid_t uid, const char* pkgid);
 
 /**
- * @brief Get is_privacy_requestable value of the package
+ * @brief See if the package's api_version says it can request privacy to the user
  * @remarks If the package have no privacy privilege then it will return PRIVILEGE_DB_MANAGER_ERR_NO_EXIST_RESULT
  * @param [in]  uid The uid
  * @param [in]  pkgid The package ID
index 36cb246..b6a6099 100755 (executable)
@@ -7,5 +7,5 @@ echo "Creating $DB_NAME ..."
 touch $DB_NAME
 
 echo "Creating PRIVACY_PACKAGE table ..."
-sqlite3 $DB_NAME "CREATE TABLE PRIVACY_PACKAGE (PKG_ID TEXT not null, UID NUMERIC not null, PRIVACY_NAME TEXT not null, PRIVILEGE_NAME TEXT not null, IS_CRITICAL NUMERIC not null, API_VERSION TEXT not null, IS_PRIVACY_REQUESTABLE NUMERIC not null, UNIQUE(PKG_ID, UID, PRIVILEGE_NAME));"
+sqlite3 $DB_NAME "CREATE TABLE PRIVACY_PACKAGE (PKG_ID TEXT not null, UID NUMERIC not null, PRIVACY_NAME TEXT not null, PRIVILEGE_NAME TEXT not null, IS_CRITICAL NUMERIC not null, API_VERSION TEXT not null, UNIQUE(PKG_ID, UID, PRIVILEGE_NAME));"
 
index 48ef157..4172ddb 100755 (executable)
@@ -878,7 +878,7 @@ int privilege_db_manager_unset_black_list(privilege_manager_policy_type_e policy
        return PRIVILEGE_DB_MANAGER_ERR_NONE;
 }
 
-int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, bool is_privacy_requestable, GList* critical_privilege_list)
+int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, GList* critical_privilege_list)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
@@ -899,7 +899,7 @@ int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, co
                        char * privacy_name = NULL;
                        ret = privilege_db_manager_get_privacy_by_privilege(privilege_name, &privacy_name);
                        if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE && privacy_name != NULL && strstr(privacy_name, "N/A") == NULL) {
-                               sql = sqlite3_mprintf("insert or replace into privacy_package (uid, pkg_id, privacy_name, privilege_name, api_version, is_privacy_requestable, is_critical) values (%d, %Q, %Q, %Q, %Q, %d, 1)", uid, pkgid, privacy_name, privilege_name, api_version, is_privacy_requestable);
+                               sql = sqlite3_mprintf("insert or replace into privacy_package (uid, pkg_id, privacy_name, privilege_name, api_version, is_critical) values (%d, %Q, %Q, %Q, %Q, 1)", uid, pkgid, privacy_name, privilege_name, api_version);
                                TryReturn(sql != NULL, sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL); g_list_free_full(mapped_privilege_list, free); free(privacy_name); __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] sqlite3_mprintf failed");
                                ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
                                TryReturn(ret == SQLITE_OK, sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL); g_list_free_full(mapped_privilege_list, free); free(privacy_name); __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] fail to prepare database: %s", sqlite3_errmsg(db));
@@ -925,7 +925,7 @@ int privilege_db_manager_set_package_critical_privilege_info(const uid_t uid, co
        return PRIVILEGE_DB_MANAGER_ERR_NONE;
 }
 
-int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, bool is_privacy_requestable,  GList* privilege_list)
+int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, const char* pkgid, privilege_manager_package_type_e package_type, const char* api_version, GList* privilege_list)
 {
        sqlite3 *db = NULL;
        sqlite3_stmt *stmt = NULL;
@@ -945,7 +945,7 @@ int privilege_db_manager_set_package_privacy_privilege_info(const uid_t uid, con
                        char * privacy_name = NULL;
                        ret = privilege_db_manager_get_privacy_by_privilege(privilege_name, &privacy_name);
                        if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE && privacy_name != NULL && strstr(privacy_name, "N/A") == NULL) {
-                               sql = sqlite3_mprintf("insert or ignore into privacy_package (uid, pkg_id, privacy_name, privilege_name, api_version, is_privacy_requestable, is_critical) values (%d, %Q, %Q, %Q, %Q, %d, 0)", uid, pkgid, privacy_name, privilege_name, api_version, is_privacy_requestable);
+                               sql = sqlite3_mprintf("insert or ignore into privacy_package (uid, pkg_id, privacy_name, privilege_name, api_version, is_critical) values (%d, %Q, %Q, %Q, %Q, 0)", uid, pkgid, privacy_name, privilege_name, api_version);
                                TryReturn(sql != NULL, sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL); g_list_free_full(mapped_privilege_list, free); free(privacy_name); __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] sqlite3_mprintf failed");
                                ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
                                TryReturn(ret == SQLITE_OK, sqlite3_exec(db, "ROLLBACK TRANSACTION", NULL, NULL, NULL); g_list_free_full(mapped_privilege_list, free); free(privacy_name); __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] fail to prepare database: %s", sqlite3_errmsg(db));
@@ -1003,7 +1003,7 @@ int privilege_db_manager_is_privacy_requestable(const uid_t uid, const char* pkg
        if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE)
                return ret;
 
-       char* sql = sqlite3_mprintf("select is_privacy_requestable from privacy_package where (uid=%d or uid=%d) and pkg_id=%Q", uid, GLOBAL_USER, pkgid);
+       char* sql = sqlite3_mprintf("select (case when api_version < 4.0 then 0 else 1 end) from privacy_package where (uid=%d or uid=%d) and pkg_id=%Q", uid, GLOBAL_USER, pkgid);
        TryReturn(sql != NULL, __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] sqlite3_mprintf failed");
        ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
        TryReturn(ret == SQLITE_OK, __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] fail to prepare database: %s", sqlite3_errmsg(db));
index 62afa5c..715f365 100755 (executable)
@@ -50,9 +50,7 @@ static int __is_privacy_requestable_api_version(const char* api_version)
 int privilege_package_info_set_privacy_privilege(const uid_t uid, const char* pkgid, privilege_manager_package_type_e pkg_type, const char* api_version, GList* privilege_list)
 {
        TryReturn(pkgid != NULL && api_version != NULL && privilege_list != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] pkgid, api_version, and privilege_list must not be NULL.");
-       int is_privacy_requestable = __is_privacy_requestable_api_version(api_version);
-       TryReturn(is_privacy_requestable == 1 || is_privacy_requestable == 0, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] fail to get is_privacy_requestable value.");
-       int ret = privilege_db_manager_set_package_privacy_privilege_info(uid, pkgid, pkg_type, api_version, is_privacy_requestable, privilege_list);
+       int ret = privilege_db_manager_set_package_privacy_privilege_info(uid, pkgid, pkg_type, api_version, privilege_list);
        if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE) {
                LOGE("privilege_db_manager_set_package_privacy_privilege_info failed. ret = %d", ret);
                return PRVMGR_ERR_INTERNAL_ERROR;
@@ -63,9 +61,7 @@ int privilege_package_info_set_privacy_privilege(const uid_t uid, const char* pk
 int privilege_package_info_set_critical_privilege(const uid_t uid, const char* pkgid, privilege_manager_package_type_e pkg_type, const char* api_version, GList* critical_privilege_list)
 {
        TryReturn(pkgid != NULL && api_version != NULL && critical_privilege_list != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] pkgid, api_version, and critical_privilege_list must not be NULL.");
-       int is_privacy_requestable = __is_privacy_requestable_api_version(api_version);
-       TryReturn(is_privacy_requestable == 1 || is_privacy_requestable == 0, , PRVMGR_ERR_INTERNAL_ERROR, "[PRVMGR_ERR_INTERNAL_ERROR] fail to get is_privacy_requestable value.");
-       int ret = privilege_db_manager_set_package_critical_privilege_info(uid, pkgid, pkg_type, api_version, is_privacy_requestable, critical_privilege_list);
+       int ret = privilege_db_manager_set_package_critical_privilege_info(uid, pkgid, pkg_type, api_version, critical_privilege_list);
        if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE) {
                LOGE("privilege_db_manager_set_package_critical_privilege_info failed. ret = %d", ret);
                return PRVMGR_ERR_INTERNAL_ERROR;