[Refactoring account-parser] 89/185389/2 accepted/tizen/unified/20180802.134849 submit/tizen/20180730.113742
authorAbhishek Vijay <abhishek.v@samsung.com>
Mon, 30 Jul 2018 06:31:45 +0000 (12:01 +0530)
committerAbhishek Vijay <abhishek.v@samsung.com>
Mon, 30 Jul 2018 08:46:08 +0000 (14:16 +0530)
Change-Id: Id3de2aa4e0d80e411c8a3aa649991ee484ef0195
Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
packaging/account-parser.spec
src/account.c

index dd3f6b2..8ffbd29 100644 (file)
@@ -1,6 +1,6 @@
 Name:          account-parser
 Summary:       Account Parser Library
-Version:       0.1.4
+Version:       0.1.5
 Release:       0
 Group:         Social & Content/Other
 License:       Apache-2.0
index ac39d0a..223f504 100644 (file)
 #define OWNER_ROOT 0
 #define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
 
-static const xmlChar _NODE_ACCOUNT_PROVIDER[]                          = "account-provider";
-static const xmlChar _NODE_ICON[]                                                      = "icon";
-static const xmlChar _NODE_LABEL[]                                                     = "label";
-static const xmlChar _NODE_CAPABILITY[]                                                = "capability";
+#define ACCOUNT_TYPE_SAMSUNG                                   "com.samsung.samsungaccount"
+#define ACCOUNT_TYPE_TIZEN                                     "com.samsung.tizenaccount"
+#define PKGMGR_PLUGIN_UINSTALL                                 "plugin_uninstall"
+#define PKGMGR_PLUGIN_UPGRADE                                  "plugin_pre_upgrade"
 
-static const xmlChar _ATTRIBUTE_APP_ID[]                                       = "appid";
+static const xmlChar _NODE_ACCOUNT_PROVIDER[]                  = "account-provider";
+static const xmlChar _NODE_ICON[]                              = "icon";
+static const xmlChar _NODE_LABEL[]                             = "label";
+static const xmlChar _NODE_CAPABILITY[]                                = "capability";
+
+static const xmlChar _ATTRIBUTE_APP_ID[]                       = "appid";
 static const xmlChar _ATTRIBUTE_MULTIPLE_ACCOUNTS_SUPPORT[]    = "multiple-accounts-support";
 static const xmlChar _ATTRIBUTE_SERVICE_PROVIDER_ID[]          = "providerid";
-static const xmlChar _ATTRIBUTE_SECTION[]                                      = "section";
+static const xmlChar _ATTRIBUTE_SECTION[]                      = "section";
 
-static const xmlChar _VALUE_TRUE[]                                                     = "true";
-static const xmlChar _VALUE_ACCOUNT[]                                          = "account";
-static const xmlChar _VALUE_ACCOUNT_SMALL[]                                    = "account-small";
+static const xmlChar _VALUE_TRUE[]                             = "true";
+static const xmlChar _VALUE_ACCOUNT[]                          = "account";
+static const xmlChar _VALUE_ACCOUNT_SMALL[]                    = "account-small";
 
-static const char _DEFAULT_LOCALE[]                                                    = "default";
+static const char _DEFAULT_LOCALE[]                            = "default";
 
 static char __old_account_provider_app_id[1024];
 
@@ -82,6 +87,37 @@ bool _on_account_received_cb(account_h account, void* user_data)
        return true;
 }
 
+int _account_type_set_icon_path(xmlChar* account_icon, account_type_h handle, const char* account_type)
+{
+       _D("setting icon path for - %s", account_type);
+
+       int ret = ACCOUNT_ERROR_NONE;
+       char *icon_path = NULL;
+
+       if (g_strcmp0(account_type, ACCOUNT_TYPE_SAMSUNG) == 0) {
+               icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.samsungaccount/shared/res/", (const char*)account_icon);
+       } else if (g_strcmp0(account_type, ACCOUNT_TYPE_TIZEN) == 0) {
+               icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.samsungaccount/shared/res/", (const char*)account_icon);
+       }
+
+       if (icon_path == NULL) {
+               _E("icon_path is NULL.");
+               ret = ACCOUNT_ERROR_NO_DATA;
+               goto END;
+       }
+
+       _D("icon_path[%s]", icon_path);
+       ret = account_type_set_icon_path(handle, icon_path);
+       if (ret != ACCOUNT_ERROR_NONE) {
+               _E("Failed to set the icon path.");
+               g_free(icon_path);
+               goto END;
+       }
+       g_free(icon_path);
+END:
+       _D("_account_type_set_icon_path ends");
+       return ret;
+}
 int _register_account_provider(xmlDocPtr docPtr, char* account_provider_app_id)
 {
        ENTER();
@@ -215,37 +251,19 @@ int _register_account_provider(xmlDocPtr docPtr, char* account_provider_app_id)
                                                        }
                                                } else {
                                                        if (!strcmp((const char*)attribute_app_id, "com.samsung.samsungaccount")) {
-                                                               char *icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.samsungaccount/shared/res/", (const char*)account_icon);
-                                                               if (icon_path == NULL) {
-                                                                       _E("icon_path is NULL.");
-                                                                       free(resource_path);
-                                                                       goto CATCH;
-                                                               }
-
-                                                               _D("icon_path[%s]", icon_path);
-                                                               ret = account_type_set_icon_path(account_type_handle, icon_path);
+                                                               ret = _account_type_set_icon_path(account_icon, account_type_handle, "com.samsung.samsungaccount");
                                                                if (ret != ACCOUNT_ERROR_NONE) {
                                                                        _E("Failed to set the icon path.");
-                                                                       g_free(icon_path);
-                                                                       goto CATCH;
-                                                               }
-                                                               g_free(icon_path);
-                                                       } else if (!strcmp((const char*)attribute_app_id, "com.samsung.tizenaccount")) {
-                                                               char *icon_path = g_strdup_printf("%s%s", "/usr/apps/com.samsung.tizenaccount/shared/res/", (char*)account_icon);
-                                                               if (icon_path == NULL) {
-                                                                       _E("icon_path is NULL.");
                                                                        free(resource_path);
                                                                        goto CATCH;
                                                                }
-
-                                                               _D("icon_path[%s]", icon_path);
-                                                               ret = account_type_set_icon_path(account_type_handle, icon_path);
+                                                       } else if (!strcmp((const char*)attribute_app_id, "com.samsung.tizenaccount")) {
+                                                               ret = _account_type_set_icon_path(account_icon, account_type_handle, "com.samsung.tizenaccount");
                                                                if (ret != ACCOUNT_ERROR_NONE) {
                                                                        _E("Failed to set the icon path.");
-                                                                       g_free(icon_path);
+                                                                       free(resource_path);
                                                                        goto CATCH;
                                                                }
-                                                               g_free(icon_path);
                                                        } else {
                                                                uid_t uid = -1;
                                                                if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
@@ -574,94 +592,112 @@ int _on_package_app_list_received_cb(pkgmgrinfo_appinfo_h handle, void *user_dat
        return 0;
 }
 
-EXPORT_API
-int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
+int _pkgmgr_parser_handle_plugin(const char* package_id, const char* pkgmgr_plugin_action)
 {
-       ENTER();
-       _D("PKGMGR_PARSER_PLUGIN_INSTALL");
+       _D("_pkgmgr_parser_handle_plugin start - [%s] [%s]", package_id, pkgmgr_plugin_action);
 
-       char* account_provider_app_id = NULL;
-       int ret = _register_account_provider(docPtr, account_provider_app_id);
-       retvm_if(ret != 0, -1, "Failed to register the account provider.");
-
-       return 0;
-}
-
-EXPORT_API
-int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
-{
-       ENTER();
-       _D("PKGMGR_PARSER_PLUGIN_UNINSTALL");
+       int ret = -1;
+       if (package_id == NULL) {
+               _E("invalid package_id param");
+               goto FINISH;
+       }
+       if (pkgmgr_plugin_action == NULL) {
+               _E("invalid pkgmgr_plugin_action param");
+               goto FINISH;
+       }
 
        pkgmgrinfo_pkginfo_h package_info_handle = NULL;
-       int ret = -1;
        uid_t uid = 0;
 
        if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
                _E("pkgmgr_installer_info_get_target_uid() fail");
-               return -1;
+               goto FINISH;
        }
 
        if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               ret = pkgmgrinfo_pkginfo_get_pkginfo(packageId, &package_info_handle);
+               ret = pkgmgrinfo_pkginfo_get_pkginfo(package_id, &package_info_handle);
        else
-               ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(packageId, uid, &package_info_handle);
-       retvm_if(ret != PMINFO_R_OK, ret, "[%d]Failed to pkgmgrinfo_pkginfo_get_pkginfo().", ret);
+               ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package_id, uid, &package_info_handle);
 
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               ret = pkgmgrinfo_appinfo_get_list(package_info_handle, PMINFO_ALL_APP, _unregister_account_provider, NULL);
-       else
-               ret = pkgmgrinfo_appinfo_get_usr_list(package_info_handle, PMINFO_ALL_APP, _unregister_account_provider, NULL, uid);
+       if (ret != PMINFO_R_OK) {
+               _E("[%d]Failed to pkgmgrinfo_pkginfo_get_pkginfo().", ret);
+               ret = -1;
+               goto FINISH;
+       }
+
+       if (g_strcmp0(pkgmgr_plugin_action, PKGMGR_PLUGIN_UINSTALL) == 0) {
+               _D("pkgmgr plugin uninstall");
+               if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+                       ret = pkgmgrinfo_appinfo_get_list(package_info_handle, PMINFO_ALL_APP, _unregister_account_provider, NULL);
+               else
+                       ret = pkgmgrinfo_appinfo_get_usr_list(package_info_handle, PMINFO_ALL_APP, _unregister_account_provider, NULL, uid);
+       } else if (g_strcmp0(pkgmgr_plugin_action, PKGMGR_PLUGIN_UPGRADE) == 0) {
+               _D("pkgmgr plugin upgrade");
+               if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+                       ret = pkgmgrinfo_appinfo_get_list(package_info_handle, PMINFO_ALL_APP, _on_package_app_list_received_cb, NULL);
+               else
+                       ret = pkgmgrinfo_appinfo_get_usr_list(package_info_handle, PMINFO_ALL_APP, _on_package_app_list_received_cb, NULL, uid);
+       }
 
        if (ret != PMINFO_R_OK) {
                _D("Failed to get the application information list.");
                pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
-
-               return -1;
+               ret = -1;
+               goto FINISH;
        }
-
        pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
-       return 0;
+FINISH:
+       _D("_pkgmgr_parser_handle_plugin END");
+       return ret;
 }
 
 EXPORT_API
-int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char* packageId)
+int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
 {
        ENTER();
-       _D("PKGMGR_PARSER_PLUGIN_PRE_UPGRADE");
+       _D("PKGMGR_PARSER_PLUGIN_INSTALL");
 
-       memset(__old_account_provider_app_id, 0x00, sizeof(__old_account_provider_app_id));
+       char* account_provider_app_id = NULL;
+       int ret = _register_account_provider(docPtr, account_provider_app_id);
+       retvm_if(ret != 0, -1, "Failed to register the account provider.");
 
-       pkgmgrinfo_pkginfo_h package_info_handle = NULL;
-       int ret = -1;
-       uid_t uid = 0;
+       return 0;
+}
 
-       if (pkgmgr_installer_info_get_target_uid(&uid) < 0) {
-               _E("pkgmgr_installer_info_get_target_uid() fail");
-               return -1;
+EXPORT_API
+int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
+{
+       ENTER();
+       _D("PKGMGR_PARSER_PLUGIN_UNINSTALL");
+
+       int ret = 0;
+       ret = _pkgmgr_parser_handle_plugin(packageId, PKGMGR_PLUGIN_UINSTALL);
+       if (ret == -1) {
+               _E("_pkgmgr_parser_handle_plugin failed [%d]", ret);
+               return ret;
        }
 
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               ret = pkgmgrinfo_pkginfo_get_pkginfo(packageId, &package_info_handle);
-       else
-               ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(packageId, uid, &package_info_handle);
-       retvm_if(ret != PMINFO_R_OK, ret, "[%d]Failed to pkgmgrinfo_pkginfo_get_pkginfo().", ret);
+       _D("PKGMGR_PARSER_PLUGIN_UNINSTALL Success");
+       return ret;
+}
 
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               ret = pkgmgrinfo_appinfo_get_list(package_info_handle, PMINFO_ALL_APP, _on_package_app_list_received_cb, NULL);
-       else
-               ret = pkgmgrinfo_appinfo_get_usr_list(package_info_handle, PMINFO_ALL_APP, _on_package_app_list_received_cb, NULL, uid);
+EXPORT_API
+int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char* packageId)
+{
+       ENTER();
+       _D("PKGMGR_PARSER_PLUGIN_PRE_UPGRADE");
 
-       if (ret != PMINFO_R_OK) {
-               _D("Failed to get the application information list.");
-               pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
+       memset(__old_account_provider_app_id, 0x00, sizeof(__old_account_provider_app_id));
 
-               return -1;
+       int ret = 0;
+       ret = _pkgmgr_parser_handle_plugin(packageId, PKGMGR_PLUGIN_UPGRADE);
+       if (ret == -1) {
+               _E("_pkgmgr_parser_handle_plugin failed [%d]", ret);
+               return ret;
        }
 
-       pkgmgrinfo_pkginfo_destroy_pkginfo(package_info_handle);
-
-       return 0;
+       _D("PKGMGR_PARSER_PLUGIN_PRE_UPGRADE Success");
+       return ret;
 }
 
 EXPORT_API