Add package filter key(TPK)
[platform/framework/native/appfw.git] / src / app / package / FAppPkg_PackageManagerImpl.cpp
index 7d5aaf7..35efd1d 100755 (executable)
 #include <dlog.h>
 #include <unique_ptr.h>
 
-#include <FSysSystemTime.h>
+#include <package-manager-types.h>
+
 #include <FAppPkgPackageManager.h>
 #include <FAppPkgPackageAppInfo.h>
 #include <FAppPkgPackageInfo.h>
 #include <FAppPkgIPackageInstallationEventListener.h>
 #include <FAppPkgIPackageInstallationResponseListener.h>
 #include <FAppPkgIPackageUninstallationResponseListener.h>
+#include <FBaseSysLog.h>
 #include <FIo.h>
 #include <FIoRegistry.h>
-
-#include <FBaseSysLog.h>
+#include <FSysSystemTime.h>
 #include <FBase_StringConverter.h>
 
 #include "FAppPkg_PackageManagerImpl.h"
@@ -74,12 +75,12 @@ _PackageManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
                {
                        if (pArg->__install)
                        {
-                               SysLog(NID_APP, "Installation is Completed. [PackageId = %ls]", pArg->__packageId.GetPointer());
+                               SysLog(NID_APP, "Installation is Completed. [Package = %ls]", pArg->__packageId.GetPointer());
                                pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_SUCCESS);
                        }
                        else
                        {
-                               SysLog(NID_APP, "Uninstallation is Completed. [PackageId = %ls]", pArg->__packageId.GetPointer());
+                               SysLog(NID_APP, "Uninstallation is Completed. [Package = %ls]", pArg->__packageId.GetPointer());
                                pListener->OnPackageUninstallationCompleted(pArg->__packageId, true);
                        }
                }
@@ -87,12 +88,12 @@ _PackageManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
                {
                        if (pArg->__install)
                        {
-                               SysLog(NID_APP, "Installation is Completed(Error). [PackageId = %ls]", pArg->__packageId.GetPointer());
+                               SysLog(NID_APP, "Installation is Completed(Error). [Package = %ls]", pArg->__packageId.GetPointer());
                                pListener->OnPackageInstallationCompleted(pArg->__packageId, PACKAGE_INSTALLATION_RESULT_INVALID_PACKAGE);
                        }
                        else
                        {
-                               SysLog(NID_APP, "Uninstallation is Completed(Error). [PackageId = %ls]", pArg->__packageId.GetPointer());
+                               SysLog(NID_APP, "Uninstallation is Completed(Error). [Package = %ls]", pArg->__packageId.GetPointer());
                                pListener->OnPackageUninstallationCompleted(pArg->__packageId, false);
                        }
                }
@@ -130,7 +131,7 @@ _PackageManagerImpl::GetPackageIdByAppId(const AppId& appId)
                SysTryReturn(NID_APP, pAppId, L"", E_OUT_OF_MEMORY, "pAppId is null");
 
                result = pkgmgrinfo_appinfo_get_appinfo(pAppId.get(), &pAppInfoHandle);
-               SysTryReturn(NID_APP, result == 0, L"", E_PKG_NOT_INSTALLED, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], appId=[%s]", result, pAppId.get());
+               SysTryReturn(NID_APP, result == 0, L"", E_PKG_NOT_INSTALLED, "pkgmgrinfo_appinfo_get_appinfo() failed. result=[%d], app=[%s]", result, pAppId.get());
 
                result = pkgmgrinfo_appinfo_get_pkgname(pAppInfoHandle, &pPackageId);
 
@@ -142,7 +143,7 @@ _PackageManagerImpl::GetPackageIdByAppId(const AppId& appId)
                }
        }
 
-       SysLog(NID_APP, "appId = [%ls], packageId = [%ls]", appId.GetPointer(), packageId.GetPointer());
+       SysLog(NID_APP, "app = [%ls], package = [%ls]", appId.GetPointer(), packageId.GetPointer());
 
        return packageId;
 }
@@ -271,7 +272,7 @@ _PackageManagerImpl::GetPackageInfoN(const PackageId& packageId) const
 
        _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
        r = pPackageInfoImpl->Construct(packageId);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] packageId (%ls) is not found.", packageId.GetPointer());
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] package (%ls) is not found.", packageId.GetPointer());
 
        return pPackageInfo;
 
@@ -293,7 +294,7 @@ _PackageManagerImpl::GetPackageAppInfoN(const AppId& appId) const
 
        _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo);
        r = pPackageAppInfoImpl->Construct(appId);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] appId (%ls) is not found.", appId.GetPointer());
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[E_PKG_NOT_INSTALLED] app (%ls) is not found.", appId.GetPointer());
 
        return pPackageAppInfo;
 
@@ -340,7 +341,7 @@ _PackageManagerImpl::IsPackageInstalled(const PackageId& packageId) const
        result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
        if (result != 0)
        {
-               SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", result, pPackageId.get());
+               SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
                return false;
        }
 
@@ -349,7 +350,7 @@ _PackageManagerImpl::IsPackageInstalled(const PackageId& packageId) const
                pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle);
        }
 
-       SysLog(NID_APP, "packageId = [%ls] is installed.", packageId.GetPointer());
+       SysLog(NID_APP, "package = [%ls] is installed.", packageId.GetPointer());
 
        return true;
 }
@@ -359,20 +360,20 @@ _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& pa
 {
        SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty.");
        SysTryReturnResult(NID_APP, packagePath.IsEmpty() == false, E_INVALID_ARG, "packagePath is empty.");
-       SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_FILE_NOT_FOUND, "packagePath is not existed.");
+       SysTryReturnResult(NID_APP, File::IsFileExist(packagePath) == true, E_INVALID_ARG, "packagePath is not existed.");
 
        String extension = File::GetFileExtension(packagePath);
        SysTryReturnResult(NID_APP, extension.IsEmpty() == false, E_INVALID_ARG, "extension is empty.");
 
        std::unique_ptr<char[]> pPackagePath(_StringConverter::CopyToCharArrayN(packagePath));
-       SysTryReturnResult(NID_APP, pPackagePath, E_OUT_OF_MEMORY, "pPackagePath is null");
+       SysTryReturnResult(NID_APP, pPackagePath, E_OUT_OF_MEMORY, "pPackagePath is null.");
 
        std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
-       SysTryReturnResult(NID_APP, pExtension, E_OUT_OF_MEMORY, "pExtension is null");
+       SysTryReturnResult(NID_APP, pExtension, E_OUT_OF_MEMORY, "pExtension is null.");
 
        if ((strcasecmp(pExtension.get(), "tpk") == 0) || (strcasecmp(pExtension.get(), "wgt") == 0))
        {
-               SysLog(NID_APP, "packageId = [%ls], packagePath = [%s], extension = [%s]", packageId.GetPointer(), pPackagePath.get(), pExtension.get());
+               SysLog(NID_APP, "package = [%ls], packagePath = [%s], extension = [%s]", packageId.GetPointer(), pPackagePath.get(), pExtension.get());
        }
        else
        {
@@ -380,6 +381,18 @@ _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& pa
                return E_SYSTEM;
        }
 
+       // optionalData = 12345abcde:StoreClientId=XXXXX12345
+       PackageId StoreClientId = _AppInfo::GetPackageId();
+       String optionalData;
+       optionalData.Append(packageId);
+       optionalData.Append(":StoreClientId=");
+       optionalData.Append(StoreClientId);
+
+       std::unique_ptr<char[]> pOptionalData(_StringConverter::CopyToCharArrayN(optionalData));
+       SysTryReturnResult(NID_APP, pOptionalData, E_OUT_OF_MEMORY, "pOptionalData is null.");
+
+       SysLog(NID_APP, "optionalData = [%s]", pOptionalData.get());
+
        result r = E_SUCCESS;
        _PackageManagerProxy packageManagerProxy;
        r = packageManagerProxy.Construct();
@@ -394,7 +407,7 @@ _PackageManagerImpl::InstallPackage(const PackageId& packageId, const String& pa
                SysTryReturnResult(NID_APP, __pRequestClient != null, E_SYSTEM, "pkgmgr_client_new(PC_REQUEST) failed");
        }
 
-       int res = pkgmgr_client_install(__pRequestClient, pExtension.get(), null, pPackagePath.get(), null, PM_QUIET, InstallationEventHandler, pListener);
+       int res = pkgmgr_client_install(__pRequestClient, pExtension.get(), null, pPackagePath.get(), pOptionalData.get(), PM_QUIET, InstallationEventHandler, pListener);
 
        if (res < PKGMGR_R_OK)
        {
@@ -452,10 +465,10 @@ _PackageManagerImpl::UninstallPackage(const PackageId& packageId, IPackageUninst
        SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
 
        res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        res = pkgmgrinfo_pkginfo_get_type(pPackageInfoHandle, &pType);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        if (__pRequestClient == null)
        {
@@ -464,7 +477,7 @@ _PackageManagerImpl::UninstallPackage(const PackageId& packageId, IPackageUninst
        }
 
        res = pkgmgr_client_uninstall(__pRequestClient, pType, pPackageId.get(), PM_QUIET, UninstallationEventHandler, pListener);
-       SysLog(NID_APP, "pkgmgr_client_uninstall - req_id=[%d], packageId=[%s], type=[%s]", res, pPackageId.get(), pType);
+       SysLog(NID_APP, "pkgmgr_client_uninstall - req_id=[%d], package=[%s], type=[%s]", res, pPackageId.get(), pType);
 
        if(pPackageInfoHandle)
        {
@@ -519,13 +532,13 @@ _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId)
        SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
 
        res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        if (storage == PMINFO_EXTERNAL_STORAGE)
        {
@@ -586,13 +599,13 @@ _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId)
        SysTryReturnResult(NID_APP, pPackageId != null, E_OUT_OF_MEMORY, "pPackageId is null");
 
        res = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &packageInfoHandle);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        res = pkgmgrinfo_pkginfo_get_type(packageInfoHandle, &pType);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_type() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        res = pkgmgrinfo_pkginfo_get_installed_storage(packageInfoHandle, &storage);
-       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], packageId=[%s]", res, pPackageId.get());
+       SysTryReturnResult(NID_APP, res == 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_installed_storage() failed. result=[%d], package=[%s]", res, pPackageId.get());
 
        if (storage == PMINFO_INTERNAL_STORAGE)
        {
@@ -641,7 +654,7 @@ _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId)
 int
 _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
 {
-       SysLog(NID_APP, "reqId[%d], Type[%s], PackageId[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
+       SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
 
        if (pData)
        {
@@ -678,7 +691,7 @@ _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, cons
 int
 _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, const char* pPackageId, const char* pKey, const char* pVal, const void* pMsg, void* pData)
 {
-       SysLog(NID_APP, "reqId[%d], Type[%s], PackageId[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
+       SysLog(NID_APP, "reqId[%d], Type[%s], Package[%s], Key[%s], Val[%s]", reqId, pType, pPackageId, pKey, pVal);
 
        if (pData)
        {
@@ -704,23 +717,6 @@ _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, co
        return 0;
 }
 
-_PackageManagerImpl*
-_PackageManagerImpl::GetInstance(void)
-{
-       return PackageManager::GetInstance()->__pPackageManagerImpl;
-}
-
-result
-_PackageManagerImpl::Construct(void)
-{
-       ClearLastResult();
-
-       result r = __installationList.Construct();
-       SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient.");
-
-       return E_SUCCESS;
-}
-
 PackageInfo*
 _PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const
 {
@@ -736,27 +732,98 @@ _PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const
        std::unique_ptr<char[]> pExtension(_StringConverter::CopyToCharArrayN(extension));
        SysTryReturn(NID_APP, pExtension, null, E_OUT_OF_MEMORY, "pExtension is null.");
 
-       bool res = false;
+       std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
+       SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
 
-       if ((strcasecmp(pExtension.get(), "tpk") == 0) || (strcasecmp(pExtension.get(), "wgt") == 0))
+       SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
+
+       bool res = true;
+       result r = E_SUCCESS;
+
+       if (strcasecmp(pExtension.get(), "tpk") == 0)
        {
-               SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
-               res = true;
+               _PackageParser packageParser;
+
+               res = packageParser.Construct(pPackageInfo.get());
+               SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
+
+               res = packageParser.Parse(filePath);
+               SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
        }
-       SysTryReturn(NID_APP, res == true, null, E_UNSUPPORTED_FORMAT, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
+       else if (strcasecmp(pExtension.get(), "wgt") == 0)
+       {
+               pkgmgr_info* pPkgmgrInfo = null;
 
-       _PackageParser packageParser;
+               pPkgmgrInfo = pkgmgr_client_check_pkginfo_from_file(pPackagePath.get());
+               SysTryReturn(NID_APP, pPkgmgrInfo, null, E_PARSING_FAILED, "pkgmgr_client_check_pkginfo_from_file(%s) is failed.", pPackagePath.get());
 
-       PackageInfo* pPackageInfo = new (std::nothrow) PackageInfo;
-       SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
+               _package_manager_pkg_detail_info_t* pPkgInfo = (_package_manager_pkg_detail_info_t*) pPkgmgrInfo;
+               _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
 
-       res = packageParser.Construct(pPackageInfo);
-       SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get());
+               SysLog(NID_APP, "id(%s), version(%s), label(%s), description(%s), author(%s), icon_size(%d), pkgname(%s)", pPkgInfo->pkgid, pPkgInfo->version, pPkgInfo->label,
+                               pPkgInfo->pkg_description, pPkgInfo->author, pPkgInfo->icon_size, pPkgInfo->pkg_name);
 
-       res = packageParser.Parse(filePath);
-       SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get());
+               pPackageInfoImpl->SetType(PACKAGE_TYPE_WGT);
+               pPackageInfoImpl->SetId(pPkgInfo->pkgid);
+               pPackageInfoImpl->SetVersion(pPkgInfo->version);
+               pPackageInfoImpl->SetDisplayName(pPkgInfo->label);
+               pPackageInfoImpl->SetDescription(pPkgInfo->pkg_description);
+               pPackageInfoImpl->SetAuthor(pPkgInfo->author);
+               pPackageInfoImpl->SetMainAppId(pPkgInfo->pkg_name);
 
-       return pPackageInfo;
+               if (pPkgInfo->privilege_list)
+               {
+                       GList* pList = null;
+                       pList = g_list_first(pPkgInfo->privilege_list);
+                       while (pList)
+                       {
+                               char* pPrivilege = (char*)pList->data;
+                               if (pPrivilege)
+                               {
+                                       pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pPrivilege));
+                                       free(pPrivilege);
+                               }
+                               pList = g_list_next(pList);
+                       }
+                       g_list_free(pPkgInfo->privilege_list);
+               }
+
+               std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
+               if (pPackageAppInfo)
+               {
+                       _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
+
+                       pPackageAppInfoImpl->SetAppId(pPkgInfo->pkg_name);
+                       pPackageAppInfoImpl->SetAppName(pPkgInfo->label);
+                       pPackageAppInfoImpl->SetAppDisplayName(pPkgInfo->label);
+                       pPackageAppInfoImpl->SetMainApp(true);
+                       if ((pPkgInfo->icon_buf) && (pPkgInfo->icon_size > 0))
+                       {
+                               String iconPath("/tmp/icon.png");
+                               File file;
+                               r = file.Construct(iconPath, "w+");
+                               r = file.Write(pPkgInfo->icon_buf, pPkgInfo->icon_size);
+
+                               pPackageAppInfoImpl->SetAppTempIconPath(iconPath);
+                       }
+
+                       pPackageInfoImpl->AddPackageAppInfo(*pPackageAppInfo.release());
+               }
+               else
+               {
+                       SysLog(NID_APP, "pPackageAppInfo instance must not be null.");
+                       pkgmgr_client_free_pkginfo(pPkgmgrInfo);
+                       return null;
+               }
+
+               pkgmgr_client_free_pkginfo(pPkgmgrInfo);
+       }
+       else
+       {
+               SysTryReturn(NID_APP, false, null, E_UNSUPPORTED_FORMAT, "invalid extension! - packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get());
+       }
+
+       return pPackageInfo.release();
 }
 
 IList*
@@ -764,7 +831,96 @@ _PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) const
 {
        SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
 
-       return null;
+       std::unique_ptr<IMapEnumerator> pEnum(packageFilterMap.GetMapEnumeratorN());
+       SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
+
+       std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
+
+       pList->Construct();
+
+       int res = PMINFO_R_OK;
+       pkgmgrinfo_pkginfo_filter_h handle = null;
+
+       res = pkgmgrinfo_pkginfo_filter_create(&handle);
+       SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res);
+
+       while(pEnum->MoveNext() == E_SUCCESS)
+       {
+               String* pKey = static_cast< String* >(pEnum->GetKey());
+               SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
+
+               Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
+               SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
+
+               bool value = pVal->ToBool();
+
+               SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value);
+
+               if ((*pKey) == PACKAGE_FILTER_UNINSTALLABLE)
+               {
+                       res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, value);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(REMOVABLE, %d) is failed. [%d]", value, res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_DOWNLOADED)
+               {
+                       res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, !value);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(PRELOAD, %d) is failed. [%d]", !value, res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_APP_SETTING)
+               {
+                       res = pkgmgrinfo_pkginfo_filter_add_bool(handle, PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, value);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(APPSETTING, %d) is failed. [%d]", value, res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_TPK)
+               {
+                       SysTryCatch(NID_APP, value == true, , E_SYSTEM, "Value(false) is invalid for PACKAGE_FILTER_TPK.");
+
+                       res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, "tpk");
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(TYPE, tpk) is failed. [%d]", res);
+               }
+               else if ((*pKey) == PACKAGE_FILTER_EXTERNAL_STORAGE)
+               {
+                       String installedStorage;
+                       if (value == true)
+                       {
+                               installedStorage = L"installed_external";
+                       }
+                       else
+                       {
+                               installedStorage = L"installed_internal";
+                       }
+
+                       std::unique_ptr<char[]> pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage));
+                       SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null.");
+
+                       SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get());
+
+                       res = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, pInstalledStorage.get());
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_string(STORAGE, %s) is failed. [%d]", pInstalledStorage.get(), res);
+               }
+               else
+               {
+                       SysTryCatch(NID_APP, false, , E_INVALID_ARG, "Invalid key(%ls)", pKey->GetPointer());
+               }
+       }
+
+       res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList.get());
+       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() failed. [%d]", res);
+
+CATCH:
+       if (handle)
+       {
+               pkgmgrinfo_pkginfo_filter_destroy(handle);
+       }
+
+       if (pList->GetCount() <= 0)
+       {
+               AppLog("pList's count is 0.");
+               return null;
+       }
+
+       return pList.release();
 }
 
 IList*
@@ -772,140 +928,484 @@ _PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageAppFilterMap) con
 {
        SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid.");
 
-       return null;
-}
+       std::unique_ptr< IMapEnumerator > pEnum(packageAppFilterMap.GetMapEnumeratorN());
+       SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed.");
 
-IList*
-_PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const
-{
-       SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid.");
-       SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid.");
+       std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
 
-       return null;
-}
+       pList->Construct();
 
-_PackageManagerImpl::_PackageManagerImpl(void)
-:__pRequestClient(null),
-__pListeningClient(null),
-__pDb(null)
-{
-       CreatePackageTables();
-}
+       int res = 0;
+       bool definedKey = false;
+       bool metadataKey = false;
+       ArrayList list;
+       ArrayList metadataList;
+       ArrayList appIdList;
+       pkgmgrinfo_appinfo_filter_h handle = null;
+       pkgmgrinfo_appinfo_metadata_filter_h metaHandle = null;
 
-_PackageManagerImpl::~_PackageManagerImpl(void)
-{
-}
+       res = pkgmgrinfo_appinfo_filter_create(&handle);
+       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_create() is failed. [%d]", res);
 
-void
-_PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue)
-{
-       result r = E_SUCCESS;
-       bool install = true;
+       res = pkgmgrinfo_appinfo_metadata_filter_create(&metaHandle);
+       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_create() is failed. [%d]", res);
 
-       if (strcmp(pEventKey, "start") == 0)
+       while(pEnum->MoveNext() == E_SUCCESS)
        {
-               if ((strcmp(pEventValue, "install") == 0) || (strcmp(pEventValue, "uninstall") == 0))
+               String* pKey = static_cast< String* >(pEnum->GetKey());
+               SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed.");
+
+               if ((*pKey) == PACKAGE_APP_FILTER_MENUICON_VISIBLE)
                {
-                       String* pAppId = new (std::nothrow) String(packageId);
-                       SysTryReturnVoidResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "pAppId instance must not be null.");
+                       definedKey = true;
 
-                       String* pOperation = new (std::nothrow) String(pEventValue);
-                       SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation instance must not be null.");
+                       Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
+                       SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
 
-                       r = __installationList.Add(*pAppId, *pOperation);
-                       if (IsFailed(r))
-                       {
-                               delete pAppId;
-                               delete pOperation;
-                               SysLog(NID_APP, "Failed to add installation condition.");
-                               SetLastResult(E_SYSTEM);
-                               return;
-                       }
+                       bool nodisplay = !(pVal->ToBool());
+                       SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), nodisplay);
+
+                       res = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, nodisplay);
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_pkginfo_filter_add_bool(NODISPLAY, %d) is failed. [%d]", nodisplay, res);
                }
-       }
-       else if (strcmp(pEventKey, "end") == 0)
-       {
-               String* pOperation = static_cast <String*>(__installationList.GetValue(packageId));
-               if (pOperation)
+               else if ((*pKey) == PACKAGE_APP_FILTER_CATEGORY_HOMEAPP || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_LOCKAPP
+                                               || (*pKey) == PACKAGE_APP_FILTER_CATEGORY_MENUAPP)
                {
-                       if (pOperation->Equals("uninstall", true) == true)
+                       definedKey = true;
+
+                       std::unique_ptr<char[]> pDefinedKey(_StringConverter::CopyToCharArrayN(*pKey));
+                       SysTryCatch(NID_APP, pDefinedKey, , E_OUT_OF_MEMORY, "pDefinedKey is null.");
+
+                       Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue());
+                       SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
+
+                       SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), pVal->ToBool());
+                       SysTryCatch(NID_APP, pVal->ToBool() == true, , E_INVALID_ARG, "Value(false) is not allowed.");
+
+                       res = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, pDefinedKey.get());
+                       SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_add_string(CATEGORY, %s) is failed. [%d]", pDefinedKey.get(), res);
+               }
+               else
+               {
+                       metadataKey = true;
+
+                       String* pVal = static_cast< String* >(pEnum->GetValue());
+                       SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed.");
+
+                       SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer());
+
+                       std::unique_ptr<char[]> pMetaKey(_StringConverter::CopyToCharArrayN(*pKey));
+                       SysTryCatch(NID_APP, pMetaKey, , E_OUT_OF_MEMORY, "pMetaKey is null.");
+
+                       std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pVal));
+                       SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null.");
+
+                       if ((*pVal) == L"*")
                        {
-                               install = false;
+                               res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), null);
+                               SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, null) is failed. [%d]", pMetaKey.get(), res);
                        }
-
-                       r = __installationList.Remove(packageId, true);
-                       if (IsFailed(r))
+                       else
                        {
-                               SysLogException(NID_APP, r, "[%s] Remove Element [%ls] is failed from installing list.", GetErrorMessage(r), packageId.GetPointer());
+                               res = pkgmgrinfo_appinfo_metadata_filter_add(metaHandle, pMetaKey.get(), pValue.get());
+                               SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_add(%s, %s) is failed. [%d]", pMetaKey.get(), pValue.get(), res);
                        }
                }
        }
 
-       std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
-       SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
-
-       while (pEnum->MoveNext() == E_SUCCESS)
+       if ((definedKey == true) && (metadataKey == false))
        {
-               _PackageManagerEvent*   pEvent = null;
-               pEnum->GetCurrent(pEvent);
-               if (pEvent)
+               res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, pList.get());
+               SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_foreach_appinfo() failed. [%d]", res);
+       }
+       else if ((definedKey == false) && (metadataKey == true))
+       {
+               res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, pList.get());
+               SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_foreach() failed. [%d]", res);
+       }
+       else
+       {
+               list.Construct();
+
+               res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, &list);
+               if (res != PMINFO_R_OK)
                {
-                       _PackageManagerEventArg* pEventArg= new (std::nothrow) _PackageManagerEventArg();
-                       SysTryReturnVoidResult(NID_APP, pEventArg, E_OUT_OF_MEMORY, "The memory is insufficient.");
+                       SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res);
+                       goto CATCH;
+               }
 
-                       String eventKey(pEventKey);
-                       String eventValue(pEventValue);
+               metadataList.Construct();
 
-                       pEventArg->__packageId = packageId;
-                       pEventArg->__eventKey = eventKey;
-                       pEventArg->__eventValue = eventValue;
-                       pEventArg->__install = install;
+               res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, &metadataList);
+               if (res != PMINFO_R_OK)
+               {
+                       SysLog(NID_APP, "pkgmgrinfo_appinfo_metadata_filter_foreach() is failed. result = [%d]", res);
+                       goto CATCH;
+               }
 
-                       r = pEvent->Fire(*pEventArg);
-                       if (r != E_SUCCESS)
+               for (int i = 0; i < list.GetCount(); i++)
+               {
+                       PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(list.GetAt(i));
+                       if (pPackageAppInfo)
                        {
-                               SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r));
-                       }
+                               AppLog("PackageAppFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
 
-                       SysLog(NID_APP, "PackageId = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install);
+                               std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
+                               appIdList.Add(pAppId.release());
+                       }
                }
-               else
+
+               for (int j = 0; j < metadataList.GetCount(); j++)
                {
-                       SysLog(NID_APP, "pEvent is null.");
+                       PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(metadataList.GetAt(j));
+                       if (pPackageAppInfo)
+                       {
+                               AppId appId = pPackageAppInfo->GetAppId();
+
+                               if (appIdList.Contains(appId) == true)
+                               {
+                                       AppLog("App [%ls] is matched.", appId.GetPointer());
+
+                                       std::unique_ptr< PackageAppInfo > pAppInfo(new (std::nothrow) PackageAppInfo);
+                                       SysTryCatch(NID_APP, pAppInfo, , E_OUT_OF_MEMORY, "pAppInfo is null.");
+
+                                       _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pAppInfo.get());
+                                       pPackageAppInfoImpl->Construct(appId);
+
+                                       pList->Add(pAppInfo.release());
+                               }
+                               else
+                               {
+                                       AppLog("App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
+                               }
+                       }
                }
        }
+
+CATCH:
+       if (handle)
+       {
+               pkgmgrinfo_appinfo_filter_destroy(handle);
+       }
+
+       if (metaHandle)
+       {
+               pkgmgrinfo_appinfo_metadata_filter_destroy(metaHandle);
+       }
+
+       if (pList->GetCount() <= 0)
+       {
+               AppLog("pList's count is 0.");
+               return null;
+       }
+
+       return pList.release();
 }
 
-PackageInfo*
-_PackageManagerImpl::GetPackageInfoN(PackageType packageType, const String& packageName) const
+IList*
+_PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const
 {
-       SysTryReturn(NID_APP, packageName.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageName is empty.");
+       SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap Count is invalid.");
+       SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap Count is invalid.");
 
-       result r = E_SUCCESS;
-       Database db;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-       String query;
-       PackageInfo *pPackageInfo = null;
+       ArrayList appIdList;
 
-       query.Format(   1024, L"SELECT PkgInfo.*, AppInfo.APP_MAINMENU_ICON FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
+       std::unique_ptr< IList > pPackageFilterList(GetPackageInfoListN(packageFilterMap));
+       if (pPackageFilterList == null)
+       {
+               SysLog(NID_APP, "GetPackageInfoListN(packageFilterMap) is null.");
+               return null;
+       }
 
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
+       for (int i = 0; i < pPackageFilterList->GetCount(); i++)
+       {
+               PackageInfo* pPackageInfo = dynamic_cast < PackageInfo* >(pPackageFilterList->GetAt(i));
+               if (pPackageInfo)
+               {
+                       std::unique_ptr< IList > pPackageAppInfoList(pPackageInfo->GetPackageAppInfoListN());
+                       if (pPackageAppInfoList)
+                       {
+                               for (int j = 0; j < pPackageAppInfoList->GetCount(); j++)
+                               {
+                                       PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pPackageAppInfoList->GetAt(j));
+                                       if (pPackageAppInfo)
+                                       {
+                                               AppLog("PackageFilter - App [%ls]", pPackageAppInfo->GetAppId().GetPointer());
 
-       pStmt = CreateStatementN(db, query);
+                                               std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId()));
+                                               appIdList.Add(pAppId.release());
+                                       }
+                               }
+                       }
+               }
+       }
 
-       SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
+       std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList);
+       SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null.");
 
-       pEnum = ExecuteStatementN(db, pStmt);
-       if (pEnum != null)
+       std::unique_ptr< IList > pAppFilterList(GetPackageAppInfoListN(packageAppFilterMap));
+       if (pAppFilterList == null)
        {
-               if (pEnum->MoveNext() == E_SUCCESS)
+               SysLog(NID_APP, "GetPackageAppInfoListN(packageAppFilterMap) is null.");
+               return null;
+       }
+
+       for (int k = 0; k < pAppFilterList->GetCount(); k++)
+       {
+               PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pAppFilterList->GetAt(k));
+               if (pPackageAppInfo)
                {
-                       pPackageInfo = new (std::nothrow) PackageInfo;
-                       SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
+                       AppId appId = pPackageAppInfo->GetAppId();
+                       AppLog("AppFilter - App [%ls]", appId.GetPointer());
 
-                       _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
+                       if (appIdList.Contains(appId) == true)
+                       {
+                               AppLog("App [%ls] is matched.", appId.GetPointer());
+
+                               std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
+                               SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "PackageAppInfo is null.");
+
+                               _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
+                               pPackageAppInfoImpl->Construct(appId);
+
+                               pList->Add(pPackageAppInfo.release());
+                       }
+                       else
+                       {
+                               AppLog("App [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer());
+                       }
+               }
+       }
+
+       if (pList->GetCount() <= 0)
+       {
+               AppLog("pList's count is 0.");
+               return null;
+       }
+
+       return pList.release();
+}
+
+int
+_PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData)
+{
+       SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
+       SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
+
+       result r = E_SUCCESS;
+       int res = PMINFO_R_OK;
+       char* pPackageId = null;
+       ArrayList* pList = (ArrayList*)pUserData;
+
+       res = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackageId);
+       SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_pkginfo_get_pkgname() is failed. [%d]", res);
+
+       std::unique_ptr<PackageInfo> pPackageInfo(new (std::nothrow) PackageInfo);
+       SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
+
+       _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
+       r = pPackageInfoImpl->Construct(pPackageId);
+       SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId);
+
+       pList->Add(*pPackageInfo.release());
+
+       return 0;
+}
+
+int
+_PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
+{
+       SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
+       SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
+
+       result r = E_SUCCESS;
+       int res = PMINFO_R_OK;
+       char* pAppId = null;
+       ArrayList* pList = (ArrayList*)pUserData;
+
+       res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
+       SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
+
+       SysLog(NID_APP, "app = [%s]", pAppId);
+
+       std::unique_ptr<PackageAppInfo> pPackageAppInfo(new (std::nothrow) PackageAppInfo);
+       SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
+
+       _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
+       r = pPackageAppInfoImpl->Construct(pAppId);
+       SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
+
+       pList->Add(*pPackageAppInfo.release());
+
+       return 0;
+}
+
+int
+_PackageManagerImpl::PackageAppInfoMetadataHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData)
+{
+       SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null.");
+       SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null.");
+
+       result r = E_SUCCESS;
+       int res = PMINFO_R_OK;
+       char* pAppId = null;
+       ArrayList* pList = (ArrayList*)pUserData;
+
+       res = pkgmgrinfo_appinfo_get_appid(handle, &pAppId);
+       SysTryReturn(NID_APP, res == PMINFO_R_OK, 0, E_SYSTEM, "pkgmgrinfo_appinfo_get_appid is failed. [%d]", res);
+
+       SysLog(NID_APP, "app = [%s]", pAppId);
+
+       std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo);
+       SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null.");
+
+       _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get());
+       r = pPackageAppInfoImpl->Construct(pAppId);
+       SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId);
+
+       pList->Add(*pPackageAppInfo.release());
+
+       return 0;
+}
+
+_PackageManagerImpl*
+_PackageManagerImpl::GetInstance(void)
+{
+       return PackageManager::GetInstance()->__pPackageManagerImpl;
+}
+
+result
+_PackageManagerImpl::Construct(void)
+{
+       ClearLastResult();
+
+       result r = __installationList.Construct();
+       SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient.");
+
+       return E_SUCCESS;
+}
+
+_PackageManagerImpl::_PackageManagerImpl(void)
+:__pRequestClient(null),
+__pListeningClient(null)
+{
+}
+
+_PackageManagerImpl::~_PackageManagerImpl(void)
+{
+}
+
+void
+_PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue)
+{
+       result r = E_SUCCESS;
+       bool install = true;
+
+       if (strcmp(pEventKey, "start") == 0)
+       {
+               if ((strcmp(pEventValue, "install") == 0) || (strcmp(pEventValue, "uninstall") == 0))
+               {
+                       String* pAppId = new (std::nothrow) String(packageId);
+                       SysTryReturnVoidResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "pAppId instance must not be null.");
+
+                       String* pOperation = new (std::nothrow) String(pEventValue);
+                       SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation instance must not be null.");
+
+                       r = __installationList.Add(*pAppId, *pOperation);
+                       if (IsFailed(r))
+                       {
+                               delete pAppId;
+                               delete pOperation;
+                               SysLog(NID_APP, "Failed to add installation condition.");
+                               SetLastResult(E_SYSTEM);
+                               return;
+                       }
+               }
+       }
+       else if (strcmp(pEventKey, "end") == 0)
+       {
+               String* pOperation = static_cast <String*>(__installationList.GetValue(packageId));
+               if (pOperation)
+               {
+                       if (pOperation->Equals("uninstall", true) == true)
+                       {
+                               install = false;
+                       }
+
+                       r = __installationList.Remove(packageId, true);
+                       if (IsFailed(r))
+                       {
+                               SysLogException(NID_APP, r, "[%s] Remove Element [%ls] is failed from installing list.", GetErrorMessage(r), packageId.GetPointer());
+                       }
+               }
+       }
+
+       std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN());
+       SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               _PackageManagerEvent*   pEvent = null;
+               pEnum->GetCurrent(pEvent);
+               if (pEvent)
+               {
+                       _PackageManagerEventArg* pEventArg= new (std::nothrow) _PackageManagerEventArg();
+                       SysTryReturnVoidResult(NID_APP, pEventArg, E_OUT_OF_MEMORY, "The memory is insufficient.");
+
+                       String eventKey(pEventKey);
+                       String eventValue(pEventValue);
+
+                       pEventArg->__packageId = packageId;
+                       pEventArg->__eventKey = eventKey;
+                       pEventArg->__eventValue = eventValue;
+                       pEventArg->__install = install;
+
+                       r = pEvent->Fire(*pEventArg);
+                       if (r != E_SUCCESS)
+                       {
+                               SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r));
+                       }
+
+                       SysLog(NID_APP, "Package = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install);
+               }
+               else
+               {
+                       SysLog(NID_APP, "pEvent is null.");
+               }
+       }
+}
+
+PackageInfo*
+_PackageManagerImpl::GetPackageInfoN(PackageType packageType, const String& packageName) const
+{
+       SysTryReturn(NID_APP, packageName.IsEmpty() == false, null, E_INVALID_ARG, "[E_INVALID_ARG] packageName is empty.");
+
+       result r = E_SUCCESS;
+       Database db;
+       DbStatement* pStmt = null;
+       DbEnumerator* pEnum = null;
+       String query;
+       PackageInfo *pPackageInfo = null;
+
+       query.Format(   1024, L"SELECT PkgInfo.*, AppInfo.APP_MAINMENU_ICON FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer());
+
+       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
+
+       pStmt = CreateStatementN(db, query);
+
+       SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
+
+       pEnum = ExecuteStatementN(db, pStmt);
+       if (pEnum != null)
+       {
+               if (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       pPackageInfo = new (std::nothrow) PackageInfo;
+                       SysTryReturn(NID_APP, pPackageInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
+
+                       _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
 
                        String id;
                        String appVersion;
@@ -969,14 +1469,15 @@ _PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle,
 {
        SysTryReturn(NID_APP, handle != null, 0, E_SYSTEM, "[E_SYSTEM] handle must not be null.");
 
+       result r = E_SUCCESS;
        int result = 0;
        char* pPackage = null;
        ArrayList* pList = (ArrayList*)pUserData;
 
-       PackageInfo *pPackageInfo = new (std::nothrow) PackageInfo;
-       SysTryReturn(NID_APP, pPackageInfo != null, 0, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageInfo instance must not be null.");
+       std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo);
+       SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null.");
 
-       _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
+       _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get());
 
        result = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackage);
        if (result == 0)
@@ -988,8 +1489,11 @@ _PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle,
                SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname() is failed. result = [%d]", result);
        }
 
-       pPackageInfoImpl->Construct(pPackage);
-       pList->Add(*pPackageInfo);
+       r = pPackageInfoImpl->Construct(pPackage);
+       SysTryReturn(NID_APP, r == E_SUCCESS, -1, E_SYSTEM, "pPackageInfoImpl->Construct() failed.");
+
+       r = pList->Add(*pPackageInfo.release());
+       SysTryReturn(NID_APP, r == E_SUCCESS, -1, E_SYSTEM, "pList->Add() failed.");
 
        return result;
 }
@@ -1166,7 +1670,7 @@ _PackageManagerImpl::IsAppInstalled(const AppId& appId)
        SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null");
 
        result = pkgmgrinfo_pkginfo_get_pkginfo(pPackageId.get(), &pPackageInfoHandle);
-       SysTryReturn(NID_APP, result == 0, false, E_APP_NOT_INSTALLED, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], packageId=[%s]", result, pPackageId.get());
+       SysTryReturn(NID_APP, result == 0, false, E_APP_NOT_INSTALLED, "pkgmgrinfo_pkginfo_get_pkginfo() failed. result=[%d], package=[%s]", result, pPackageId.get());
 
        if(pPackageInfoHandle)
        {
@@ -1245,517 +1749,63 @@ CATCH:
        return pAppId;
 }
 
-result
-_PackageManagerImpl::CreatePackageTables(void)
-{
-       result r = E_SUCCESS;
-       Database db;
-       String createQuery;
-
-       if (File::IsFileExist(PACKAGE_DATABASE_FILE_NAME) == true)
-       {
-               SysLog(NID_APP, ".app-package.db is already existed!");
-               return r;
-       }
-
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.Construct is failed. [%s]", GetErrorMessage(r));
-
-       // PkgInfo
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS PkgInfo"
-                                                        "( UNIQUE_ID                                   INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
-                                                        "PKG_ID                        TEXT,"
-                                                        "PKG_SECRET                    TEXT,"
-                                                        "PKG_VERSION                   TEXT,"
-                                                        "PKG_TYPE                  TEXT,"
-                                                        "PKG_MIMETYPE              TEXT,"
-                                                        "PKG_APIVERSION                TEXT,"
-                                                        "PKG_NAME                  TEXT,"
-                                                        "PKG_VENDOR                    TEXT,"
-                                                        "PKG_DESCRIPTION           TEXT,"
-                                                        "PKG_URL                       TEXT,"
-                                                        "PKG_CID                       TEXT,"
-                                                        "PKG_READONLY_SIZE             INTEGER,"
-                                                        "PKG_DATA_SIZE                 INTEGER,"
-                                                        "PKG_PARENT_ID                         TEXT,"
-                                                        "PKG_ATTRIBUTE                         INTEGER,"
-                                                        "PKG_ROOTPATH              TEXT,"
-                                                        "PKG_STORAGE_TYPE          INTEGER,"
-                                                        "PKG_INSTALLATION_DATE         TEXT,"
-                                                        "PKG_STATE                     INTEGER,"
-                                                        "PKG_INITIATOR                 INTEGER )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // PkgPrivileges
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS PkgPrivileges"
-                                                        "( ID                          INTEGER,"
-                                                        "PRIVILEGES                                    TEXT,"
-                                                        "HMAC_PPRIVILEGES                      TEXT,"
-                                                        "CERTIFICATE_TYPE              INTEGER,"
-                                                    "STR_PRIVILEGES            TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // PkgIntegrity
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS PkgIntegrity"
-                                                        "( ID                          INTEGER,"
-                                                        "HMAC_APPID                                    TEXT,"
-                                                        "HMAC_APPSECRET                                TEXT,"
-                                                        "HMAC_HTB                                              TEXT,"
-                                                        "SLOT_NUM                              INTEGER )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // AppInfo
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppInfo"
-                                                        "( UNIQUE_ID                                   INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
-                                                        "ID                            INTEGER,"
-                                                        "APP_NAME                  TEXT,"
-                                                        "APP_TYPE                  TEXT,"
-                                                        "APP_DEFAULT                   TEXT,"
-                                                        "APP_MAINMENU_ICON             TEXT,"
-                                                        "APP_SETTING_ICON          TEXT,"
-                                                        "APP_TICKER_ICON                               TEXT,"
-                                                        "APP_QUICKPANEL_ICON                   TEXT,"
-                                                        "APP_LAUNCHIMAGE_ICON      TEXT,"
-                                                        "APP_FEATURE               INTEGER,"
-                                                        "PACKAGE_NAME              TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // Notification
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS Notification"
-                                                        "( ID                          INTEGER,"
-                                                        "NAME                      TEXT,"
-                                                        "VALUE                     TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // AppFeature
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppFeature"
-                                                        "( ID                          INTEGER,"
-                                                        "NAME                      TEXT,"
-                                                        "VALUE                     TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // LaunchCondition
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS LaunchCondition"
-                                                        "( ID                          INTEGER,"
-                                                        "NAME                      TEXT,"
-                                                        "VALUE                     TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // DataControl
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS DataControl"
-                                                        "( ID INTEGER,"
-                                                        "PROVIDER_ID TEXT,"
-                                                        "TYPE TEXT,"
-                                                        "ACCESS TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // Capability
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS Capability"
-                                                        "( ID                          INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
-                                                        "OPERATION_ID                          TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // ResolutionUriScheme
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS ResolutionUriScheme"
-                                                        "( ID                          INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
-                                                        "URI_SCHEME                            TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // ResolutionMimeType
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS ResolutionMimeType"
-                                                        "( ID                          INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
-                                                        "MIME_TYPE                             TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // AppControl
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppControl"
-                                                        "( ID                          INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
-                                                        "PROVIDER_ID                   TEXT,"
-                                                        "CATEGORY                                      TEXT )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       // AppInfoLookup
-       createQuery.Format(1024, L"CREATE TABLE IF NOT EXISTS AppInfoLookup"
-                                                        "( AppInfoID                   INTEGER,"
-                                                        "CapabilityID              INTEGER,"
-                                                        "ResolutionUriSchemeID         INTEGER,"
-                                                        "ResolutionMimeTypeID      INTEGER,"
-                                                        "AppControlID                              INTEGER )");
-       r = db.ExecuteSql(createQuery, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "MakePackageDb: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       createQuery.Clear();
-
-       return r;
-}
-
-result
-_PackageManagerImpl::RegisterPackageInfo(_PackageInfoImpl& pkgInfoImpl)
+PackageInfo*
+_PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const
 {
        result r = E_SUCCESS;
+       PackageInfo* pPkgInfo = null;
        Database db;
        DbStatement* pStmt = null;
        DbEnumerator* pEnum = null;
        String query;
-       String privileges;
-       String hmacPrivileges;
-       PackageInfo packageInfo;
-       int uniqueId = 0;
-
-       SysLog(NID_APP, "_PackageManagerImpl::RegisterPackageInfo()");
 
-       query.Format(
-               1024, L"INSERT INTO PkgInfo "
-                         "(PKG_ID, PKG_SECRET, PKG_VERSION, PKG_TYPE, PKG_MIMETYPE, PKG_APIVERSION, PKG_NAME, PKG_VENDOR, PKG_DESCRIPTION, PKG_URL, PKG_CID, PKG_READONLY_SIZE, PKG_DATA_SIZE, PKG_PARENT_ID,"
-                         " PKG_ATTRIBUTE, PKG_ROOTPATH, PKG_STORAGE_TYPE, PKG_INSTALLATION_DATE, PKG_STATE, PKG_INITIATOR) "
-                         "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+       query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, AppInfoLookup, AppControl, Capability "
+                       "WHERE AppControl.PROVIDER_ID ='%ls' and Capability.OPERATION_ID ='%ls' and AppControl.ID = AppInfoLookup.AppControlID "
+                       "and Capability.ID = AppInfoLookup.CapabilityID and AppInfoLookup.AppInfoID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID "
+                       "GROUP BY AppInfoID"
+                       , providerId.GetPointer(), operationId.GetPointer());
 
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false);
-       //SysTryCatch(NID_APP, r == E_SUCCESS, r, r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
+       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
+       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
 
        pStmt = CreateStatementN(db, query);
-       //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-       PackageId packageId = pkgInfoImpl.GetAppId();
-       String appVersion = pkgInfoImpl.GetAppVersion();
-       String type = pkgInfoImpl.GetAppType();
-       String appMimeType = pkgInfoImpl.GetAppMimeType();
-       String appApiVersion = pkgInfoImpl.GetAppApiVersion();
-       String appName = pkgInfoImpl.GetAppName();
-       String appVendor = pkgInfoImpl.GetAppVendor();
-       String appDescription = pkgInfoImpl.GetAppDescription();
-       String appUrl = pkgInfoImpl.GetAppUrl();
-       String appCid = pkgInfoImpl.GetAppCid();
-
-       pkgInfoImpl.GetPrivilegesValue(privileges, hmacPrivileges);
-       String appRootPath = pkgInfoImpl.GetAppRootPath();
-       int appStorageType = pkgInfoImpl.GetAppStorageType();
-       int certType = pkgInfoImpl.GetCertType();
-       ArrayList* pAppInfoImplList = pkgInfoImpl.GetAppInfoList();
-
-       DateTime time;
-       r = SystemTime::GetCurrentTime(time);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "An error occurs while getting a current time.");
+       SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
 
-       if (!packageId.IsEmpty())
+       pEnum = ExecuteStatementN(db, pStmt);
+       if (pEnum != null)
        {
-               r = pStmt->BindString(0, packageId);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
+               if (pEnum->MoveNext() == E_SUCCESS)
+               {
+                       PackageId packageId;
+                       pEnum->GetStringAt(0, packageId);
 
-       if (!appVersion.IsEmpty())
-       {
-               r = pStmt->BindString(2, appVersion);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
+                       pPkgInfo = GetPackageInfoN(packageId);
+               }
 
-       if (!type.IsEmpty())
-       {
-               r = pStmt->BindString(3, type);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
+               delete pEnum;
        }
-
-       if (!appMimeType.IsEmpty())
+       else
        {
-               r = pStmt->BindString(4, appMimeType);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
+               r = E_OBJ_NOT_FOUND;
        }
 
-       if (!appApiVersion.IsEmpty())
-       {
-               r = pStmt->BindString(5, appApiVersion);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
+CATCH:
+       delete pStmt;
+       return pPkgInfo;
+}
 
-       if (!appName.IsEmpty())
-       {
-               r = pStmt->BindString(6, appName);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!appVendor.IsEmpty())
-       {
-               r = pStmt->BindString(7, appVendor);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!appDescription.IsEmpty())
-       {
-               r = pStmt->BindString(8, appDescription);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!appUrl.IsEmpty())
-       {
-               r = pStmt->BindString(9, appUrl);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!appCid.IsEmpty())
-       {
-               r = pStmt->BindString(10, appCid);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!appRootPath.IsEmpty())
-       {
-               r = pStmt->BindString(15, appRootPath);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (appStorageType != 0)
-       {
-               r = pStmt->BindInt(16, appStorageType);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       r = pStmt->BindDateTime(17, time);
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-
-       pEnum = ExecuteStatementN(db, pStmt);
-
-       r = GetLastResult();
-
-       uniqueId = pkgInfoImpl.GetUniqueId();
-
-       SysLog(NID_APP, "_PackageManagerImpl::RegisterPackageInfo()-GetUniqueId(%d)", uniqueId);
-
-       __pDb = &db;
-
-       // AppInfo
-       RegisterAppInfoList(uniqueId, pAppInfoImplList);
-
-       // PkgPrivileges
-       RegisterPrivileges(uniqueId, privileges, hmacPrivileges, certType);
-
-CATCH:
-       __pDb = null;
-       delete pEnum;
-       delete pStmt;
-       return r;
-}
-
-result
-_PackageManagerImpl::UnregisterPackageInfo(const PackageId& packageId)
-{
-       SysLog(NID_APP, "packageId = [%ls]", packageId.GetPointer());
-
-       result r = E_SUCCESS;
-       Database db;
-       String query;
-       int id = 0;
-       PackageInfo* pPkgInfo;
-       _PackageInfoImpl* pPackageInfoImpl = null;
-       ArrayList* pList = null;
-
-       pPkgInfo = GetPackageInfoN(packageId);
-       SysTryReturn(NID_APP, pPkgInfo != null, r, r, "UnregisterPackageInfo: GetUniqueId() is invalid. [%d]", id);
-
-       pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo);
-       pPackageInfoImpl->SetAppId(packageId);
-       id = pPackageInfoImpl->GetUniqueId();
-       SysTryReturn(NID_APP, id > 0, r, r, "UnregisterPackageInfo: GetUniqueId() is invalid. [%d]", id);
-
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "UnregisterPackageInfo: db.Construct is failed. [%s]", GetErrorMessage(r));
-
-       // AppInfoLookup
-       pList = pPackageInfoImpl->GetAppInfoListN();
-       if (pList != null)
-       {
-               for (int i = 0; i < pList->GetCount(); i++)
-               {
-                       _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast <_PackageAppInfoImpl*>(pList->GetAt(i));
-
-                       if (pAppInfoImpl != null)
-                       {
-                               int uniqueId = 0;
-                               uniqueId = pAppInfoImpl->GetUniqueId();
-
-                               query.Format(1024, L"DELETE FROM AppInfoLookup WHERE AppInfoID = %d", uniqueId);
-                               r = db.ExecuteSql(query, true);
-                               SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "UnregisterPackageInfo: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-                               query.Clear();
-                       }
-               }
-               delete pList;
-       }
-
-       // PkgInfo
-       query.Format(1024, L"DELETE FROM PkgInfo WHERE PKG_ID = '%ls'", packageId.GetPointer());
-       r = db.ExecuteSql(query, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "UnregisterPackageInfo: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       query.Clear();
-
-       // AppInfo
-       query.Format(1024, L"DELETE FROM AppInfo WHERE ID = %d", id);
-       r = db.ExecuteSql(query, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "UnregisterPackageInfo: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       query.Clear();
-
-       // PkgPrivileges
-       query.Format(1024, L"DELETE FROM PkgPrivileges WHERE ID = %d", id);
-       r = db.ExecuteSql(query, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "UnregisterPackageInfo: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       query.Clear();
-
-       // DataControl
-       query.Format(1024, L"DELETE FROM DataControl WHERE ID = %d", id);
-       r = db.ExecuteSql(query, true);
-       SysTryReturn(NID_APP, r == E_SUCCESS, r, r, "UnregisterPackageInfo: db.ExecuteSql is failed. [%s]", GetErrorMessage(r));
-       query.Clear();
-
-       delete pPkgInfo;
-       return r;
-}
-
-PackageInfo*
-_PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const
-{
-       result r = E_SUCCESS;
-       PackageInfo* pPkgInfo = null;
-       Database db;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-       String query;
-
-       query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, AppInfoLookup, AppControl, Capability "
-                       "WHERE AppControl.PROVIDER_ID ='%ls' and Capability.OPERATION_ID ='%ls' and AppControl.ID = AppInfoLookup.AppControlID "
-                       "and Capability.ID = AppInfoLookup.CapabilityID and AppInfoLookup.AppInfoID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID "
-                       "GROUP BY AppInfoID"
-                       , providerId.GetPointer(), operationId.GetPointer());
-
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
-
-       pStmt = CreateStatementN(db, query);
-       SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-       pEnum = ExecuteStatementN(db, pStmt);
-       if (pEnum != null)
-       {
-               if (pEnum->MoveNext() == E_SUCCESS)
-               {
-                       PackageId packageId;
-                       pEnum->GetStringAt(0, packageId);
-
-                       pPkgInfo = GetPackageInfoN(packageId);
-               }
-
-               delete pEnum;
-       }
-       else
-       {
-               r = E_OBJ_NOT_FOUND;
-       }
-
-CATCH:
-       delete pStmt;
-       return pPkgInfo;
-}
-
-result
-_PackageManagerImpl::GetAppInfo(int uniqueId, _PackageAppInfoImpl& appInfo) const
-{
-       result r = E_SUCCESS;
-       Database db;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-       String query;
-
-       query.Format(1024, L"SELECT * FROM AppInfo WHERE UNIQUE_ID = %d", uniqueId);
-
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
-       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
-
-       pStmt = CreateStatementN(db, query);
-       SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-       pEnum = ExecuteStatementN(db, pStmt);
-       if (pEnum != null)
-       {
-               if (pEnum->MoveNext() == E_SUCCESS)
-               {
-                       int uniqueId = 0;
-                       int pkgId = 0;
-                       String name;
-                       String defaultapp;
-                       String mainmenuIcon;
-                       String settingIcon;
-                       String tickerIcon;
-                       String quickpanelIcon;
-                       String launchImageIcon;
-                       int appFeature = 0;
-                       String packageName;
-
-                       pEnum->GetIntAt(0, uniqueId);
-                       pEnum->GetIntAt(1, pkgId);
-                       pEnum->GetStringAt(2, name);
-                       pEnum->GetStringAt(3, defaultapp);
-                       pEnum->GetStringAt(4, mainmenuIcon);
-                       pEnum->GetStringAt(5, settingIcon);
-                       pEnum->GetStringAt(7, quickpanelIcon);
-                       pEnum->GetIntAt(9, appFeature);
-                       pEnum->GetStringAt(10, packageName);
-
-                       appInfo.SetUniqueId(uniqueId);
-                       appInfo.SetPkgId(pkgId);
-                       appInfo.SetName(name);
-                       appInfo.SetDefault(defaultapp);
-                       appInfo.SetMainmenuIcon(mainmenuIcon);
-                       appInfo.SetSettingIcon(settingIcon);
-                       appInfo.SetQuickpanelIcon(quickpanelIcon);
-                       appInfo.SetAppFeature(appFeature);
-                       appInfo.SetPackageName(packageName);
-               }
-
-               delete pEnum;
-       }
-       else
-       {
-               r = E_OBJ_NOT_FOUND;
-       }
-
-CATCH:
-       delete pStmt;
-       return r;
-}
-
-ArrayList*
-_PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const
-{
-       result r = E_SUCCESS;
-       Database db;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-       String query;
-       //int id = 0;
-       PackageInfo* pPkgInfo = null;
-       _PackageInfoImpl* pPackageInfoImpl = null;
-       ArrayList* pList = null;
+ArrayList*
+_PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const
+{
+       result r = E_SUCCESS;
+       Database db;
+       DbStatement* pStmt = null;
+       DbEnumerator* pEnum = null;
+       String query;
+       //int id = 0;
+       PackageInfo* pPkgInfo = null;
+       _PackageInfoImpl* pPackageInfoImpl = null;
+       ArrayList* pList = null;
 
        pPkgInfo = GetPackageInfoN(packageId);
        SysTryCatch(NID_APP, pPkgInfo != null, , r, "[%s] GetPackageInfoN() is failed", GetErrorMessage(r));
@@ -1943,525 +1993,6 @@ CATCH:
 }
 
 result
-_PackageManagerImpl::RegisterAppInfoList(int id, ArrayList* pList)
-{
-       SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null");
-
-       result r = E_SUCCESS;
-       String query;
-       DbStatement* pStmt = null;
-
-       if (pList != null)
-       {
-               for (int i = 0; i < pList->GetCount(); i++)
-               {
-                       _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast <_PackageAppInfoImpl*>(pList->GetAt(i));
-
-                       if (pAppInfoImpl != null)
-                       {
-                               DbEnumerator* pEnum = null;
-                               int uniqueId = 0;
-
-                               String name = pAppInfoImpl->GetName();
-                               String defaultapp = pAppInfoImpl->GetDefault();
-                               String mainmenuIcon = pAppInfoImpl->GetMainmenuIcon();
-                               String settingIcon = pAppInfoImpl->GetSettingIcon();
-                               String quickpanelIcon = pAppInfoImpl->GetQuickpanelIcon();
-                               int appFeature = pAppInfoImpl->GetAppFeature();
-                               String packageName = pAppInfoImpl->GetPackageName();
-                               String type = pAppInfoImpl->GetType();
-
-                               ArrayList* pLaunchConditionImplList = pAppInfoImpl->GetLaunchConditionList();
-                               ArrayList* pNotificationImplList = pAppInfoImpl->GetNotificationList();
-                               ArrayList* pAppFeatureImplList = pAppInfoImpl->GetAppFeatureList();
-                               ArrayList* pDataControlImplList = pAppInfoImpl->GetDataControlList();
-
-                               query.Format(
-                                       1024, L"INSERT INTO AppInfo "
-                                                 "(ID, APP_NAME, APP_DEFAULT, APP_MAINMENU_ICON, APP_SETTING_ICON, APP_TICKER_ICON, APP_QUICKPANEL_ICON, APP_LAUNCHIMAGE_ICON, APP_FEATURE, PACKAGE_NAME, APP_TYPE) "
-                                                 "VALUES (?,?,?,?,?,?,?,?,?,?,?)");
-
-                               pStmt = CreateStatementN(*__pDb, query);
-                               //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-                               if (id != 0)
-                               {
-                                       r = pStmt->BindInt(0, id);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!name.IsEmpty())
-                               {
-                                       r = pStmt->BindString(1, name);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!defaultapp.IsEmpty())
-                               {
-                                       r = pStmt->BindString(2, defaultapp);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!mainmenuIcon.IsEmpty())
-                               {
-                                       r = pStmt->BindString(3, mainmenuIcon);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!settingIcon.IsEmpty())
-                               {
-                                       r = pStmt->BindString(4, settingIcon);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!quickpanelIcon.IsEmpty())
-                               {
-                                       r = pStmt->BindString(6, quickpanelIcon);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (appFeature != 0)
-                               {
-                                       r = pStmt->BindInt(8, appFeature);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!packageName.IsEmpty())
-                               {
-                                       r = pStmt->BindString(9, packageName);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!type.IsEmpty())
-                               {
-                                       r = pStmt->BindString(10, type);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               pEnum = ExecuteStatementN(*__pDb, pStmt);
-
-                               query.Clear();
-                               delete pStmt;
-                               pStmt = null;
-                               delete pEnum;
-
-                               pAppInfoImpl->SetPkgId(id);
-                               uniqueId = pAppInfoImpl->GetUniqueId();
-                               RegisterLaunchConditionList(uniqueId, pLaunchConditionImplList);
-                               RegisterNotificationList(uniqueId, pNotificationImplList);
-                               RegisterAppFeatureList(uniqueId, pAppFeatureImplList);
-                               RegisterDataControlList(uniqueId, pDataControlImplList);
-                               //RegisterAppControlList(uniqueId, pAppControlImplList);
-                       }
-               }
-       }
-
-       r = GetLastResult();
-
-CATCH:
-       delete pStmt;
-
-       return r;
-}
-
-result
-_PackageManagerImpl::RegisterLaunchConditionList(int id, ArrayList* pList)
-{
-       SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null");
-
-       result r = E_SUCCESS;
-       String query;
-       DbStatement* pStmt = null;
-
-       if (pList != null)
-       {
-               for (int i = 0; i < pList->GetCount(); i++)
-               {
-                       _LaunchConditionInfoImpl* pLaunchCondition = dynamic_cast<_LaunchConditionInfoImpl*>(pList->GetAt(i));
-
-                       if (pLaunchCondition != null)
-                       {
-                               DbEnumerator* pEnum = null;
-
-                               String name = pLaunchCondition->GetName();
-                               String value = pLaunchCondition->GetValue();
-
-                               query.Format(1024, L"INSERT INTO LaunchCondition (ID, NAME, VALUE) VALUES (?,?,?)");
-
-                               pStmt = CreateStatementN(*__pDb, query);
-                               //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-                               if (id != 0)
-                               {
-                                       r = pStmt->BindInt(0, id);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!name.IsEmpty())
-                               {
-                                       r = pStmt->BindString(1, name);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!value.IsEmpty())
-                               {
-                                       r = pStmt->BindString(2, value);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               pEnum = ExecuteStatementN(*__pDb, pStmt);
-
-                               query.Clear();
-                               delete pStmt;
-                               pStmt = null;
-                               delete pEnum;
-                       }
-               }
-       }
-
-       r = GetLastResult();
-
-CATCH:
-       delete pStmt;
-
-       return r;
-}
-
-result
-_PackageManagerImpl::RegisterNotificationList(int id, ArrayList* pList)
-{
-       SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null");
-
-       result r = E_SUCCESS;
-       String query;
-       DbStatement* pStmt = null;
-
-       if (pList != null)
-       {
-               for (int i = 0; i < pList->GetCount(); i++)
-               {
-                       _NotificationInfoImpl* pNotification = dynamic_cast<_NotificationInfoImpl*>(pList->GetAt(i));
-
-                       if (pNotification != null)
-                       {
-                               DbEnumerator* pEnum = null;
-
-                               String name = pNotification->GetName();
-                               String value = pNotification->GetValue();
-
-                               query.Format(1024, L"INSERT INTO Notification (ID, NAME, VALUE) VALUES (?,?,?)");
-
-                               pStmt = CreateStatementN(*__pDb, query);
-                               //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-                               if (id != 0)
-                               {
-                                       r = pStmt->BindInt(0, id);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!name.IsEmpty())
-                               {
-                                       r = pStmt->BindString(1, name);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!value.IsEmpty())
-                               {
-                                       r = pStmt->BindString(2, value);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               pEnum = ExecuteStatementN(*__pDb, pStmt);
-
-                               query.Clear();
-                               delete pStmt;
-                               pStmt = null;
-                               delete pEnum;
-                       }
-               }
-       }
-
-       r = GetLastResult();
-
-CATCH:
-       delete pStmt;
-
-       return r;
-}
-
-result
-_PackageManagerImpl::RegisterAppFeatureList(int id, ArrayList* pList)
-{
-       SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null");
-
-       result r = E_SUCCESS;
-       String query;
-       DbStatement* pStmt = null;
-
-       if (pList != null)
-       {
-               for (int i = 0; i < pList->GetCount(); i++)
-               {
-                       _AppFeatureInfoImpl* pAppFeature = dynamic_cast<_AppFeatureInfoImpl*>(pList->GetAt(i));
-
-                       if (pAppFeature != null)
-                       {
-                               DbEnumerator* pEnum = null;
-
-                               String name = pAppFeature->GetName();
-                               String value = pAppFeature->GetValue();
-
-                               query.Format(1024, L"INSERT INTO AppFeature (ID, NAME, VALUE) VALUES (?,?,?)");
-
-                               pStmt = CreateStatementN(*__pDb, query);
-                               //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-                               if (id != 0)
-                               {
-                                       r = pStmt->BindInt(0, id);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!name.IsEmpty())
-                               {
-                                       r = pStmt->BindString(1, name);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               if (!value.IsEmpty())
-                               {
-                                       r = pStmt->BindString(2, value);
-                                       SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                               }
-
-                               pEnum = ExecuteStatementN(*__pDb, pStmt);
-
-                               query.Clear();
-                               delete pStmt;
-                               pStmt = null;
-                               delete pEnum;
-                       }
-               }
-       }
-
-       r = GetLastResult();
-
-CATCH:
-       delete pStmt;
-
-       return r;
-}
-
-result
-_PackageManagerImpl::RegisterDataControlList(int id, ArrayList* pList)
-{
-       SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null");
-
-       result r = E_SUCCESS;
-       String query;
-       DbStatement* pStmt = null;
-
-       if (pList != null)
-       {
-               for (int i = 0; i < pList->GetCount(); i++)
-               {
-                       _DataControlInfoImpl* pDataControl = dynamic_cast<_DataControlInfoImpl*>(pList->GetAt(i));
-
-                       if (pDataControl != null)
-                       {
-                               DbEnumerator* pEnum = null;
-
-                               String providerId = pDataControl->GetProviderId();
-                               ArrayList* pTypeList = pDataControl->GetControlTypeList();
-
-                               if (pTypeList != null)
-                               {
-                                       for (int j = 0; j < pTypeList->GetCount(); j++)
-                                       {
-                                               _DataControlTypeImpl* pControlType = dynamic_cast<_DataControlTypeImpl*>(pTypeList->GetAt(j));
-
-                                               if (pControlType != null)
-                                               {
-                                                       String access = pControlType->GetAccess();
-                                                       String type = pControlType->GetType();
-
-                                                       query.Format(1024, L"INSERT INTO DataControl (ID, PROVIDER_ID, TYPE, ACCESS) VALUES (?,?,?,?)");
-
-                                                       pStmt = CreateStatementN(*__pDb, query);
-                                                       //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-                                                       if (id != 0)
-                                                       {
-                                                               r = pStmt->BindInt(0, id);
-                                                               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                                                       }
-
-                                                       if (!providerId.IsEmpty())
-                                                       {
-                                                               r = pStmt->BindString(1, providerId);
-                                                               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                                                       }
-
-                                                       if (!type.IsEmpty())
-                                                       {
-                                                               r = pStmt->BindString(2, type);
-                                                               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                                                       }
-
-                                                       if (!access.IsEmpty())
-                                                       {
-                                                               r = pStmt->BindString(3, access);
-                                                               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-                                                       }
-
-                                                       pEnum = ExecuteStatementN(*__pDb, pStmt);
-
-                                                       query.Clear();
-                                                       delete pStmt;
-                                                       pStmt = null;
-                                                       delete pEnum;
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-
-       r = GetLastResult();
-
-CATCH:
-       delete pStmt;
-
-       return r;
-}
-
-int
-_PackageManagerImpl::FindRecord(const String& tableName, const String& columnName, const String& value) const
-{
-
-       result r = E_SUCCESS;
-       Database db;
-       String query;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-       int uniqueId = 0;
-
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
-       //SysTryCatch(NID_APP, r == E_SUCCESS, r, r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
-
-       query.Format(1024, L"SELECT * FROM %ls WHERE %ls = '%ls'", tableName.GetPointer(), columnName.GetPointer(), value.GetPointer());
-
-       pStmt = CreateStatementN(db, query);
-       //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-       pEnum = ExecuteStatementN(db, pStmt);
-
-       if (pEnum != null)
-       {
-               if (pEnum->MoveNext() == E_SUCCESS)
-               {
-                       pEnum->GetIntAt(0, uniqueId);
-               }
-
-               delete pEnum;
-       }
-
-//CATCH:
-       delete pStmt;
-
-       return uniqueId;
-}
-
-result
-_PackageManagerImpl::GetRecord(const String& tableName, int uniqueId, const String& columnName, String& value) const
-{
-       result r = E_SUCCESS;
-       Database db;
-       String query;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-
-       r = db.Construct(PACKAGE_DATABASE_FILE_NAME, "r");
-       //SysTryCatch(NID_APP, r == E_SUCCESS, r, r, "[%s] An error occurs while opening a database.", GetErrorMessage(r));
-
-       query.Format(1024, L"SELECT %ls FROM %ls WHERE UNIQUE_ID = %d", columnName.GetPointer(), tableName.GetPointer(), uniqueId);
-
-       pStmt = CreateStatementN(db, query);
-       //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-       pEnum = ExecuteStatementN(db, pStmt);
-
-       if (pEnum != null)
-       {
-               if (pEnum->MoveNext() == E_SUCCESS)
-               {
-                       pEnum->GetStringAt(0, value);
-               }
-
-               delete pEnum;
-       }
-
-//CATCH:
-       delete pStmt;
-
-       return r;
-}
-
-result
-_PackageManagerImpl::RegisterPrivileges(int id, const String& privileges, const String& hmacPrivileges, int certType)
-{
-       SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null");
-
-       result r = E_SUCCESS;
-       String query;
-       DbStatement* pStmt = null;
-       DbEnumerator* pEnum = null;
-
-       query.Format(1024, L"INSERT INTO PkgPrivileges (ID, PRIVILEGES, HMAC_PPRIVILEGES, CERTIFICATE_TYPE) VALUES (?,?,?,?)");
-
-       pStmt = CreateStatementN(*__pDb, query);
-       SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult()));
-
-       if (id != 0)
-       {
-               r = pStmt->BindInt(0, id);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!privileges.IsEmpty())
-       {
-               r = pStmt->BindString(1, privileges);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (!hmacPrivileges.IsEmpty())
-       {
-               r = pStmt->BindString(2, hmacPrivileges);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       if (certType != 0)
-       {
-               r = pStmt->BindInt(3, certType);
-               SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r));
-       }
-
-       pEnum = ExecuteStatementN(*__pDb, pStmt);
-
-       delete pStmt;
-       pStmt = null;
-       delete pEnum;
-       pEnum = null;
-
-       r = GetLastResult();
-
-CATCH:
-       delete pStmt;
-       return r;
-}
-
-result
 _PackageManagerImpl::GetPackageName(const PackageId& packageId, const String* pName, char* pPackageName, int bufferSize)
 {
        result r = E_SUCCESS;