Add the plug-in about upgrading of account provider
authorhs321.lee <hs321.lee@samsung.com>
Fri, 11 Oct 2013 05:52:39 +0000 (14:52 +0900)
committerhs321.lee <hs321.lee@samsung.com>
Mon, 14 Oct 2013 08:04:50 +0000 (17:04 +0900)
Change-Id: I1c32659d7d9e85c94e55a6b24483d360314eed39
Signed-off-by: hs321.lee <hs321.lee@samsung.com>
packaging/osp-social.spec [changed mode: 0755->0644]
pkgmgr_account/src/account.cpp

old mode 100755 (executable)
new mode 100644 (file)
index 8f51f8e..cbc5128
@@ -23,10 +23,14 @@ BuildRequires:  pkgconfig(osp-image)
 BuildRequires:  osp-image-internal-devel
 BuildRequires:  pkgconfig(osp-image-core)
 BuildRequires:  osp-image-core-internal-devel
+BuildRequires:  pkgconfig(pkgmgr)
+BuildRequires:  pkgconfig(pkgmgr-info)
 
 # runtime requires
-Requires: osp-appfw 
+Requires: osp-appfw
 Requires: osp-image
+Requires: capi-appfw-application
+Requires: capi-appfw-package-manager
 
 %description
 osp social library
index fd7d9f5..10cbaf9 100644 (file)
 #include <libxml/tree.h>
 #include <account.h>
 #include <account-types.h>
+#include <FApp.h>
+#include <FAppPkgPackageInfo.h>
+#include <FAppPkgPackageManager.h>
+#include <FAppPkg_PackageManagerImpl.h>
+#include <FBaseColIEnumerator.h>
+#include <FBaseColIList.h>
 #include <FBaseDataType.h>
 #include <FBaseString.h>
 #include <FBaseSysLog.h>
+#include <FBase_StringConverter.h>
 #include <FBaseUtilStringTokenizer.h>
 #include <FBaseUtilStringUtil.h>
 
        } \
        else {;}
 
+using namespace Tizen::App;
+using namespace Tizen::App::Package;
 using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Utility;
 
 static const xmlChar _NODE_ACCOUNT_PROVIDER[]                          = "account-provider";
@@ -63,35 +73,65 @@ static const xmlChar _VALUE_XHIGH[]                                                 = "Xhigh";
 
 static const char _DEFAULT_LOCALE[]                                                    = "default";
 
-extern "C"
-__attribute__ ((visibility("default")))
-int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
+static String __oldAccountProviderAppId;
+
+bool
+OnAccountReceived(account_h accountHandle, void* pUserData)
+{
+       SysTryReturn(NID_SCL, accountHandle != null && pUserData != null, false, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       String* pAccountProviderAppId = static_cast<String*> (pUserData);
+       SysTryReturn(NID_SCL, pAccountProviderAppId != null, false, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       // Get the account ID
+       int accountDbId = 0;
+       int ret = account_get_account_id(accountHandle, &accountDbId);
+       SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, null, E_SYSTEM, "[%s] The method cannot proceed due to a severe system error.", GetErrorMessage(E_SYSTEM));
+
+       // Set the new app ID
+       std::unique_ptr<char[]> pCharArrayAppId(_StringConverter::CopyToCharArrayN(*pAccountProviderAppId));
+       SysTryReturn(NID_SCL, pCharArrayAppId != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       ret = account_set_package_name(accountHandle, pCharArrayAppId.get());
+       SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       // Update the account
+       ret = account_update_to_db_by_id_ex(accountHandle, accountDbId);
+       SysTryReturn(NID_SCL, ret != ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER, false, E_INVALID_OPERATION, "[%s] The application does not register the account provider.", GetErrorMessage(E_INVALID_OPERATION));
+       SysTryReturn(NID_SCL, ret != ACCOUNT_ERROR_PERMISSION_DENIED, false, E_INVALID_OPERATION, "[%s] The application has no permission to update this account.", GetErrorMessage(E_INVALID_OPERATION));
+       SysTryReturn(NID_SCL, ret != ACCOUNT_ERROR_RECORD_NOT_FOUND, false, E_OBJ_NOT_FOUND, "[%s] The account does not exist.", GetErrorMessage(E_OBJ_NOT_FOUND));
+       SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, false, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       return true;
+}
+
+result
+RegisterAccountProvider(xmlDocPtr docPtr, String& accountProviderAppId)
 {
        SysLog(NID_SCL, "Registering the Account Provider.");
 
        int ret = account_connect();
-       _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
+       SysTryReturnResult(NID_SCL, ret == ACCOUNT_ERROR_NONE, E_SYSTEM, "A system error has occurred.");
 
        account_type_h accountTypeHandle = null;
        ret = account_type_create(&accountTypeHandle);
        if (ret != ACCOUNT_ERROR_NONE || accountTypeHandle == null)
        {
-               ret = account_disconnect();
-               _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
-
                SysLog(NID_SCL, "Memory allocation failed.");
-               return -ENOMEM;
+               return E_OUT_OF_MEMORY;
        }
 
+       result r = E_SUCCESS;
+
        // Node: <account>
        xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
-       _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the element.");
+       SysTryCatch(NID_SCL, curPtr != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the element.", GetErrorMessage(E_INVALID_ARG));
 
        SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
        // Get the children nodes
        curPtr = curPtr->xmlChildrenNode;
-       _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the child element.");
+       SysTryCatch(NID_SCL, curPtr != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the child element.", GetErrorMessage(E_INVALID_ARG));
 
        while(curPtr != null)
        {
@@ -102,31 +142,34 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                {
                        // Attribute: appid
                        xmlChar* pAppIdId = xmlGetProp(curPtr, _ATTRIBUTE_APP_ID);
-                       _SysTryCatch(NID_SCL, pAppIdId != null, ret = -EINVAL, "Failed to get the attribute.");
+                       SysTryCatch(NID_SCL, pAppIdId != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the attribute.", GetErrorMessage(E_INVALID_ARG));
 
                        SysSecureLog(NID_SCL, "Attribute: appid - %s", pAppIdId);
                        ret = account_type_set_app_id(accountTypeHandle, reinterpret_cast<char*> (pAppIdId));
-                       _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the app ID.");
+                       SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the app ID.", GetErrorMessage(E_SYSTEM));
+
+                       accountProviderAppId.Clear();
+                       accountProviderAppId.Append(String(reinterpret_cast<char*> (pAppIdId)));
 
                        // Attribute: multiple-accounts-support
                        xmlChar* pMultipleAccountsSupport = xmlGetProp(curPtr, _ATTRIBUTE_MULTIPLE_ACCOUNTS_SUPPORT);
-                       _SysTryCatch(NID_SCL, pMultipleAccountsSupport != null, ret = -EINVAL, "Failed to get the attribute.");
+                       SysTryCatch(NID_SCL, pMultipleAccountsSupport != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the attribute.", GetErrorMessage(E_INVALID_ARG));
 
                        SysSecureLog(NID_SCL, "Attribute: multiple-accounts-support - %s", pMultipleAccountsSupport);
                        if ((!xmlStrcmp(pMultipleAccountsSupport, _VALUE_TRUE)))
                        {
                                ret = account_type_set_multiple_account_support(accountTypeHandle, true);
-                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the multiple accounts support.");
+                               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the multiple accounts support.", GetErrorMessage(E_SYSTEM));
                        }
                        else
                        {
                                ret = account_type_set_multiple_account_support(accountTypeHandle, false);
-                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the multiple accounts support.");
+                               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the multiple accounts support.", GetErrorMessage(E_SYSTEM));
                        }
 
                        // Get the children nodes
                        curPtr = curPtr->xmlChildrenNode;
-                       _SysTryCatch(NID_SCL, curPtr != null, ret = -EINVAL, "Failed to get the child element.");
+                       SysTryCatch(NID_SCL, curPtr != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the child element.", GetErrorMessage(E_INVALID_ARG));
 
                        while (curPtr != NULL)
                        {
@@ -137,27 +180,27 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                                {
                                        // Attribute: section
                                        xmlChar* pSection = xmlGetProp(curPtr, _ATTRIBUTE_SECTION);
-                                       _SysTryCatch(NID_SCL, pSection != null, ret = -EINVAL, "Failed to get the attribute.");
+                                       SysTryCatch(NID_SCL, pSection != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the attribute.", GetErrorMessage(E_INVALID_ARG));
 
                                        SysSecureLog(NID_SCL, "Attribute: section - %s", pSection);
 
                                        if ((!xmlStrcmp(pSection, _VALUE_ACCOUNT)))
                                        {
                                                xmlChar* pAccountIcon = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
-                                               _SysTryCatch(NID_SCL, pAccountIcon != null, ret = -EINVAL, "Failed to get the value.");
+                                               SysTryCatch(NID_SCL, pAccountIcon != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the value.", GetErrorMessage(E_INVALID_ARG));
 
                                                SysSecureLog(NID_SCL, "Node: icon - %s", pAccountIcon);
                                                ret = account_type_set_icon_path(accountTypeHandle, reinterpret_cast<char*> (pAccountIcon));
-                                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the icon path.");
+                                               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the icon path.", GetErrorMessage(E_SYSTEM));
                                        }
                                        else if ((!xmlStrcmp(pSection, _VALUE_ACCOUNT_SMALL)))
                                        {
                                                xmlChar* pAccountSmallIcon = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
-                                               _SysTryCatch(NID_SCL, pAccountSmallIcon != null, ret = -EINVAL, "Failed to get the value.");
+                                               SysTryCatch(NID_SCL, pAccountSmallIcon != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the value.", GetErrorMessage(E_INVALID_ARG));
 
                                                SysSecureLog(NID_SCL, "Node: icon (small) - %s",  pAccountSmallIcon);
                                                ret = account_type_set_small_icon_path(accountTypeHandle, reinterpret_cast<char*> (pAccountSmallIcon));
-                                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the small icon path.");
+                                               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the small icon path.", GetErrorMessage(E_SYSTEM));
                                        }
                                }
                                // Node: <label>
@@ -185,25 +228,25 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                                                convertedLang.Append(token);
 
                                                std::unique_ptr<ByteBuffer> pConvertedLangBuf(StringUtil::StringToUtf8N(convertedLang));
-                                               _SysTryCatch(NID_SCL, pConvertedLangBuf != null, ret = -1, "Failed to convert String to Utf8N.");
+                                               SysTryCatch(NID_SCL, pConvertedLangBuf != null, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to convert String to Utf8N.", GetErrorMessage(E_SYSTEM));
 
                                                SysSecureLog(NID_SCL, "Attribute: converted lang - %s", pConvertedLangBuf->GetPointer());
 
                                                xmlChar* pLabel = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
-                                               _SysTryCatch(NID_SCL, pLabel != null, ret = -EINVAL, "Failed to get the value.");
+                                               SysTryCatch(NID_SCL, pLabel != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the value.", GetErrorMessage(E_INVALID_ARG));
 
                                                SysSecureLog(NID_SCL, "Node: label - %s", pLabel);
                                                ret = account_type_set_label(accountTypeHandle, reinterpret_cast<char*> (pLabel), reinterpret_cast<char*> (pConvertedLangBuf->GetPointer()));
-                                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the display name.");
+                                               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the display name.", GetErrorMessage(E_SYSTEM));
                                        }
                                        else
                                        {
                                                xmlChar* pLabel = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
-                                               _SysTryCatch(NID_SCL, pLabel != null, ret = -EINVAL, "Failed to get the value.");
+                                               SysTryCatch(NID_SCL, pLabel != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the value.", GetErrorMessage(E_INVALID_ARG));
 
                                                SysSecureLog(NID_SCL, "Node: label - %s",  pLabel);
                                                ret = account_type_set_label(accountTypeHandle, reinterpret_cast<char*> (pLabel), _DEFAULT_LOCALE);
-                                               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the display name.");
+                                               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the display name.", GetErrorMessage(E_SYSTEM));
                                        }
                                }
                                // Node: <capability>
@@ -212,11 +255,11 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                                        SysSecureLog(NID_SCL, "Node: %s", curPtr->name);
 
                                        xmlChar* pCapability = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
-                                       _SysTryCatch(NID_SCL, pCapability != null, ret = -EINVAL, "Failed to get the value.");
+                                       SysTryCatch(NID_SCL, pCapability != null, r = E_INVALID_ARG, E_INVALID_ARG, "[%s] Failed to get the value.", GetErrorMessage(E_INVALID_ARG));
 
                                        SysSecureLog(NID_SCL, "Node: capability - %s",  pCapability);
                                        ret = account_type_set_provider_feature(accountTypeHandle, reinterpret_cast<char*> (pCapability));
-                                       _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "Failed to set the capability.");
+                                       SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] Failed to set the capability.", GetErrorMessage(E_SYSTEM));
                                }
 
                                curPtr = curPtr->next;
@@ -228,31 +271,43 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                curPtr = curPtr->next;
        }
 
-       // Insert the account to the account DB
+       // Insert the account type to the account DB
        {
                int accountTypeDbId = 0;
                ret = account_type_insert_to_db(accountTypeHandle, &accountTypeDbId);
-               _SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, ret = -1, "A system error has occurred.");
+               SysTryCatch(NID_SCL, ret == ACCOUNT_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
        }
 
        account_type_destroy(accountTypeHandle);
-       ret = account_disconnect();
-       _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
+       SysTryReturnResult(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, E_SYSTEM, "A system error has occurred.");
 
-       return 0;
+       return E_SUCCESS;
 
 CATCH:
        account_type_destroy(accountTypeHandle);
-       _SysTryReturn(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
+       SysTryReturnResult(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, E_SYSTEM, "A system error has occurred.");
 
-       return ret;
+       return r;
+}
+
+extern "C"
+__attribute__ ((visibility("default")))
+int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
+{
+       SysLog(NID_SCL, "PKGMGR_PARSER_PLUGIN_INSTALL");
+
+       String accountProviderAppId;
+       result r = RegisterAccountProvider(docPtr, accountProviderAppId);
+       _SysTryReturn(NID_SCL, r == E_SUCCESS, -1, "Failed to register the account provider.");
+
+       return 0;
 }
 
 extern "C"
 __attribute__ ((visibility("default")))
 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
 {
-       SysLog(NID_SCL, "Unregistering the Account Provider.");
+       SysLog(NID_SCL, "PKGMGR_PARSER_PLUGIN_UNINSTALL");
 
        int ret = account_connect();
        _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
@@ -292,6 +347,94 @@ int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
                curPtr = curPtr->next;
        }
 
+       SysTryReturn(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       return 0;
+
+CATCH:
+       SysTryReturn(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       return ret;
+}
+
+extern "C"
+__attribute__ ((visibility("default")))
+int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char* packageId)
+{
+       SysLog(NID_SCL, "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE");
+
+       result r = E_SUCCESS;
+
+       __oldAccountProviderAppId.Clear();
+
+       _PackageManagerImpl* pPackageManagerImpl = _PackageManagerImpl::GetInstance();
+       _SysTryReturn(NID_SCL, pPackageManagerImpl != null, -1, "Failed to get the PackageManagerImpl instance.");
+
+       String pkgId(packageId);
+       std::unique_ptr<PackageInfo> pPackageInfo(pPackageManagerImpl->GetPackageInfoN(pkgId));
+       r = GetLastResult();
+       _SysTryReturn(NID_SCL, r != E_PKG_NOT_INSTALLED, -1, "The package is not installed.");
+       _SysTryReturn(NID_SCL, pPackageInfo != null && r == E_SUCCESS, -1, "Failed to get the package information.");
+
+       std::unique_ptr<IList, AllElementsDeleter> pPackageAppInfoList(pPackageInfo->GetPackageAppInfoListN());
+       _SysTryReturn(NID_SCL, pPackageAppInfoList != null, -1, "Failed to get the application information list.");
+
+       std::unique_ptr<IEnumerator> pEnum(pPackageAppInfoList->GetEnumeratorN());
+       _SysTryReturn(NID_SCL, pEnum != null, -1, "A system error has occurred.");
+
+       int ret = account_connect();
+       _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               PackageAppInfo* pPackageAppInfo = dynamic_cast<PackageAppInfo*> (pEnum->GetCurrent());
+               _SysTryCatch(NID_SCL, pPackageAppInfo != null, ret = -1, "A system error has occurred.");
+
+               std::unique_ptr<char[]> pCharArrayAppId(_StringConverter::CopyToCharArrayN(pPackageAppInfo->GetAppId()));
+               _SysTryCatch(NID_SCL, pCharArrayAppId != null, ret = -1, "Memory allocation failed.");
+
+               ret = account_type_delete_by_app_id(pCharArrayAppId.get());
+               if (ret == ACCOUNT_ERROR_NONE)
+               {
+                       SysLog(NID_SCL, "PKGMGR_PARSER_PLUGIN_PRE_UPGRADE: app ID - %ls", (pPackageAppInfo->GetAppId()).GetPointer());
+
+                       __oldAccountProviderAppId = pPackageAppInfo->GetAppId();
+                       break;
+               }
+       }
+
+       SysTryReturn(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       return 0;
+
+CATCH:
+       SysTryReturn(NID_SCL, account_disconnect() == ACCOUNT_ERROR_NONE, -1, E_SYSTEM, "[%s] A system error has occurred.", GetErrorMessage(E_SYSTEM));
+
+       return ret;
+}
+
+extern "C"
+__attribute__ ((visibility("default")))
+int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char* packageId)
+{
+       SysLog(NID_SCL, "PKGMGR_PARSER_PLUGIN_UPGRADE");
+
+       String accountProviderAppId;
+       result r = RegisterAccountProvider(docPtr, accountProviderAppId);
+       _SysTryReturn(NID_SCL, r == E_SUCCESS, -1, "Failed to register the account provider.");
+
+       int ret = account_connect();
+       _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");
+
+       std::unique_ptr<char[]> pCharArrayAppId(_StringConverter::CopyToCharArrayN(__oldAccountProviderAppId));
+       _SysTryCatch(NID_SCL, pCharArrayAppId != null, ret = -1, "Memory allocation failed.");
+
+       ret = account_query_account_by_package_name(OnAccountReceived, pCharArrayAppId.get(), (void*) &accountProviderAppId);
+       _SysTryCatch(NID_SCL, (ret == ACCOUNT_ERROR_NONE) || (ret == ACCOUNT_ERROR_RECORD_NOT_FOUND), ret = -1, "A system error has occurred.");
+
+       r = GetLastResult();
+       _SysTryCatch(NID_SCL, r == E_SUCCESS, ret = -1, "Failed to update accounts.");
+
        ret = account_disconnect();
        _SysTryReturn(NID_SCL, ret == ACCOUNT_ERROR_NONE, -1, "A system error has occurred.");