[Refactoring get app-id list] 31/185131/2 accepted/tizen/unified/20180727.063747 submit/tizen/20180726.120608
authorAbhishek Vijay <abhishek.v@samsung.com>
Thu, 26 Jul 2018 07:02:29 +0000 (12:32 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Thu, 26 Jul 2018 10:37:06 +0000 (10:37 +0000)
Change-Id: I247b7519216b9150fdfc08f5c8faca5ca285bc30
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
common/include/account_db_helper.h
common/src/account_db_helper.c

index 1a6deff9857e566275ffcb948c3fb9326eef1a87..6e38801a0e1daab022835e8aec43160606ffca8b 100644 (file)
@@ -170,6 +170,7 @@ int _account_db_handle_close(sqlite3 *account_db_handle);
 
 
 int _account_type_query_app_id_exist_from_all_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *app_id);
+void _account_get_appid_from_db(pkgmgrinfo_appinfo_h *ahandle, pkgmgrinfo_pkginfo_h *phandle, char **package_id, const char *appid, uid_t uid, GSList **appid_list);
 int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *appid, uid_t uid, char **verified_appid);
 int _account_check_appid_group_with_package_name(const char *appid, char *package_name, uid_t uid);
 
@@ -180,7 +181,7 @@ GList *_account_query_account_by_package_name(sqlite3 *account_db_handle, const
 int _account_check_duplicated(sqlite3 *account_db_handle, account_s *data, const char *verified_appid, uid_t uid);
 
 int _account_delete_table(sqlite3 *account_db_handle, account_stmt *phstmt, GSList *account_id_list,
-                                       const char *package_name, const char *app_id, const char* table);
+                                               const char *package_name, const char *app_id, const char* table);
 int _account_delete_account_by_package_name(sqlite3 *account_db_handle, const char *package_name, gboolean permission, int pid, uid_t uid);
 
 
index 5516c8e9a84622263408d6d89421befed0a5ffb9..3ef3a724728d5266652e08ba39fe0d53d1b07e6d 100644 (file)
@@ -864,6 +864,53 @@ int _account_type_query_app_id_exist_from_all_db(sqlite3 *account_user_db, sqlit
        return return_code;
 }
 
+void _account_get_appid_from_db(pkgmgrinfo_appinfo_h *ahandle, pkgmgrinfo_pkginfo_h *phandle, char **package_id, const char *appid, uid_t uid, GSList **appid_list)
+{
+       _INFO("_account_get_appid_from_db start");
+       int pkgmgr_ret = -1;
+
+       pkgmgrinfo_appinfo_h app_handle = NULL;
+       pkgmgrinfo_pkginfo_h pkg_handle = NULL;
+       char *pkg_id = NULL;
+       GSList *list = NULL;
+
+       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+               pkgmgr_ret = pkgmgrinfo_appinfo_get_appinfo(appid, &app_handle);
+       else
+               pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &app_handle);
+
+       if (pkgmgr_ret != PMINFO_R_OK)
+               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appinfo(%d)", pkgmgr_ret);
+
+       pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgid(app_handle, &pkg_id);
+       if (pkgmgr_ret != PMINFO_R_OK)
+               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_pkgid(%d)", pkgmgr_ret);
+
+       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+               pkgmgr_ret = pkgmgrinfo_pkginfo_get_pkginfo(pkg_id, &pkg_handle);
+       else
+               pkgmgr_ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id, uid, &pkg_handle);
+
+       if (pkgmgr_ret != PMINFO_R_OK)
+               ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_get_pkginfo(%d)", pkgmgr_ret);
+
+       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+               pkgmgr_ret = pkgmgrinfo_appinfo_get_list(pkg_handle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&list);
+       else
+               pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_list(pkg_handle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&list, uid);
+
+       if (pkgmgr_ret != PMINFO_R_OK)
+               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_list(%d)", pkgmgr_ret);
+
+       *ahandle = app_handle;
+       *phandle = pkg_handle;
+       *package_id = pkg_id;
+       *appid_list = list;
+
+       _INFO("_account_get_appid_from_db end");
+       return;
+}
+
 int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *appid, uid_t uid, char **verified_appid)
 {
        int error_code = _ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER;
@@ -872,6 +919,7 @@ int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *ac
        char *package_id = NULL;
        GSList *appid_list = NULL;
        GSList *iter = NULL;
+       int pkgmgr_ret = -1;
 
        if (!appid) {
                ACCOUNT_ERROR("input param is null\n");
@@ -912,36 +960,14 @@ int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *ac
                }
                return _ACCOUNT_ERROR_NONE;
        }
-       /* Get app id family which is stored in account database */
-       int pkgmgr_ret = -1;
-
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_appinfo(appid, &ahandle);
-       else
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &ahandle);
-
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appinfo(%d)", pkgmgr_ret);
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgid(ahandle, &package_id);
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_pkgid(%d)", pkgmgr_ret);
-
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               pkgmgr_ret = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &phandle);
-       else
-               pkgmgr_ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &phandle);
-
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_get_pkginfo(%d)", pkgmgr_ret);
 
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list);
-       else
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list, uid);
+       /* Get app id family which is stored in account database */
+       _account_get_appid_from_db(&ahandle, &phandle, &package_id, appid, uid, &appid_list);
 
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_list(%d)", pkgmgr_ret);
+       ACCOUNT_RETURN_VAL((ahandle != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("appinfo handle is NULL"));
+       ACCOUNT_RETURN_VAL((phandle != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("pkginfo handle is NULL"));
+       ACCOUNT_RETURN_VAL((package_id != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("package_id is NULL"));
+       ACCOUNT_RETURN_VAL((appid_list != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("appid_list is NULL"));
 
        /* Compare current app id with the stored app id family */
        for (iter = appid_list; iter != NULL; iter = g_slist_next(iter)) {
@@ -984,6 +1010,7 @@ int _account_check_appid_group_with_package_name(const char *appid, char *packag
        char *package_id = NULL;
        GSList *appid_list = NULL;
        GSList *iter = NULL;
+       int pkgmgr_ret = -1;
 
        if (!appid) {
                ACCOUNT_ERROR("input param -appid is null\n");
@@ -996,34 +1023,12 @@ int _account_check_appid_group_with_package_name(const char *appid, char *packag
        }
 
        /* Get app id family which is stored in account database */
-       int pkgmgr_ret = -1;
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_appinfo(appid, &ahandle);
-       else
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &ahandle);
-
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_appinfo(%d)", pkgmgr_ret);
-
-       pkgmgr_ret = pkgmgrinfo_appinfo_get_pkgid(ahandle, &package_id);
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_pkgid(%d)", pkgmgr_ret);
-
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               pkgmgr_ret = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &phandle);
-       else
-               pkgmgr_ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &phandle);
+       _account_get_appid_from_db(&ahandle, &phandle, &package_id, appid, uid, &appid_list);
 
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_pkginfo_get_pkginfo(%d)", pkgmgr_ret);
-
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list);
-       else
-               pkgmgr_ret = pkgmgrinfo_appinfo_get_usr_list(phandle, PMINFO_ALL_APP, _account_get_current_appid_cb, (void *)&appid_list, uid);
-
-       if (pkgmgr_ret != PMINFO_R_OK)
-               ACCOUNT_DEBUG("pkgmgrinfo_appinfo_get_list(%d)", pkgmgr_ret);
+       ACCOUNT_RETURN_VAL((ahandle != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("appinfo handle is NULL"));
+       ACCOUNT_RETURN_VAL((phandle != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("pkginfo handle is NULL"));
+       ACCOUNT_RETURN_VAL((package_id != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("package_id is NULL"));
+       ACCOUNT_RETURN_VAL((appid_list != NULL), {}, _ACCOUNT_ERROR_NO_DATA, ("appid_list is NULL"));
 
        /* Compare current app id with the stored app id family */
        for (iter = appid_list; iter != NULL; iter = g_slist_next(iter)) {