diff options
author | Abhishek Vijay <abhishek.v@samsung.com> | 2018-07-26 12:32:29 +0530 |
---|---|---|
committer | Abhishek Vijay <abhishek.v@samsung.com> | 2018-07-26 10:37:06 +0000 |
commit | 6d11a2367ea789b826179b171af4ee8002a9676b (patch) | |
tree | 686d50cee7feb82362d4ff1428079f223b2332af | |
parent | 055de9fccda150f58ceb7f24f909a12687b2e5c5 (diff) | |
download | account-common-6d11a2367ea789b826179b171af4ee8002a9676b.tar.gz account-common-6d11a2367ea789b826179b171af4ee8002a9676b.tar.bz2 account-common-6d11a2367ea789b826179b171af4ee8002a9676b.zip |
[Refactoring get app-id list]submit/tizen/20180726.120608accepted/tizen/unified/20180727.063747
Change-Id: I247b7519216b9150fdfc08f5c8faca5ca285bc30
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
-rw-r--r-- | common/include/account_db_helper.h | 3 | ||||
-rw-r--r-- | common/src/account_db_helper.c | 115 |
2 files changed, 62 insertions, 56 deletions
diff --git a/common/include/account_db_helper.h b/common/include/account_db_helper.h index 1a6deff..6e38801 100644 --- a/common/include/account_db_helper.h +++ b/common/include/account_db_helper.h @@ -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); diff --git a/common/src/account_db_helper.c b/common/src/account_db_helper.c index 5516c8e..3ef3a72 100644 --- a/common/src/account_db_helper.c +++ b/common/src/account_db_helper.c @@ -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)) { |