X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fapp%2Fpackage%2FFAppPkg_PackageManagerImpl.cpp;h=1a985af31c03e49c7f96724a98ebff4cd09ef3e0;hb=200a35e95e02968477c38c2ed7d57974c8cf30a9;hp=91d5e0be07edc7fbe7ecc031b617ec7b34f03cd1;hpb=6b44196c40a66b895028f7ba2e9b5e41bc715ab2;p=platform%2Fframework%2Fnative%2Fappfw.git diff --git a/src/app/package/FAppPkg_PackageManagerImpl.cpp b/src/app/package/FAppPkg_PackageManagerImpl.cpp index 91d5e0b..1a985af 100755 --- a/src/app/package/FAppPkg_PackageManagerImpl.cpp +++ b/src/app/package/FAppPkg_PackageManagerImpl.cpp @@ -26,22 +26,24 @@ #include #include -#include +#include + #include #include #include #include #include #include +#include #include #include - -#include +#include #include #include "FAppPkg_PackageManagerImpl.h" #include "FAppPkg_PackageInfoImpl.h" #include "FAppPkg_PackageAppInfoImpl.h" +#include "FAppPkg_PackageParser.h" #include "FApp_AppInfo.h" #include "FApp_PackageManagerProxy.h" @@ -58,8 +60,6 @@ PackageManager* pPackageManagerInstance = null; Tizen::Base::Collection::HashMap _PackageManagerImpl::__installationList; -const wchar_t PACKAGE_DATABASE_FILE_NAME[] = L"/opt/usr/dbspace/.app-package.db"; - void _PackageManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg) { @@ -360,7 +360,7 @@ _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."); @@ -511,10 +511,6 @@ _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId) SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty"); SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed."); -#if defined(_OSP_EMUL_) - SysLog(NID_APP, "MoveToExternalStorage() is unavailable on the emulator."); - return E_SYSTEM; -#else int res = 0; char* pType = null; pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE; @@ -574,7 +570,6 @@ _PackageManagerImpl::MoveToExternalStorage(const PackageId& packageId) } return E_SUCCESS; -#endif } result @@ -583,10 +578,6 @@ _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId) SysTryReturnResult(NID_APP, packageId.IsEmpty() == false, E_INVALID_ARG, "packageId is empty"); SysTryReturnResult(NID_APP, IsPackageInstalled(packageId) == true, E_PKG_NOT_INSTALLED, "package is not installed."); -#if defined(_OSP_EMUL_) - SysLog(NID_APP, "MoveToInternalStorage() is unavailable on the emulator."); - return E_SYSTEM; -#else int res = 0; char* pType = null; pkgmgrinfo_installed_storage storage = PMINFO_INTERNAL_STORAGE; @@ -646,7 +637,6 @@ _PackageManagerImpl::MoveToInternalStorage(const PackageId& packageId) } return E_SUCCESS; -#endif } int @@ -656,10 +646,10 @@ _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, cons if (pData) { + IPackageInstallationResponseListener* pListener = (IPackageInstallationResponseListener*) pData; + if (strcmp(pKey, "end") == 0) { - IPackageInstallationResponseListener* pListener = (IPackageInstallationResponseListener*) pData; - if (strcmp(pVal, "ok") == 0) { pListener->OnPackageInstallationResponseReceived(pPackageId, PACKAGE_INSTALLATION_RESULT_SUCCESS); @@ -673,6 +663,14 @@ _PackageManagerImpl::InstallationEventHandler(int reqId, const char* pType, cons delete pListener; } + else if (strcmp(pKey, "install_percent") == 0) + { + int progress = 0; + sscanf(pVal, "%d", &progress); + + pListener->OnPackageInstallationInProgressResponseReceived(pPackageId, progress); + SysLog(NID_APP, "OnPackageInstallationInProgressResponseReceived(%s, %d)", pPackageId, progress); + } } return 0; @@ -707,1128 +705,767 @@ _PackageManagerImpl::UninstallationEventHandler(int reqId, const char* pType, co return 0; } -_PackageManagerImpl* -_PackageManagerImpl::GetInstance(void) +PackageInfo* +_PackageManagerImpl::GetPackageInfoFromFileN(const String& filePath) const { - return PackageManager::GetInstance()->__pPackageManagerImpl; -} + SysTryReturn(NID_APP, filePath.IsEmpty() == false, null, E_INVALID_ARG, "filePath is empty."); + SysTryReturn(NID_APP, File::IsFileExist(filePath) == true, null, E_FILE_NOT_FOUND, "package is not existed."); -result -_PackageManagerImpl::Construct(void) -{ - ClearLastResult(); + String extension = File::GetFileExtension(filePath); + SysTryReturn(NID_APP, extension.IsEmpty() == false, null, E_INVALID_ARG, "extension is empty."); - result r = __installationList.Construct(); - SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient."); + std::unique_ptr pPackagePath(_StringConverter::CopyToCharArrayN(filePath)); + SysTryReturn(NID_APP, pPackagePath, null, E_OUT_OF_MEMORY, "pPackagePath is null."); - return E_SUCCESS; -} + std::unique_ptr pExtension(_StringConverter::CopyToCharArrayN(extension)); + SysTryReturn(NID_APP, pExtension, null, E_OUT_OF_MEMORY, "pExtension is null."); -_PackageManagerImpl::_PackageManagerImpl(void) -:__pRequestClient(null), -__pListeningClient(null), -__pDb(null) -{ - CreatePackageTables(); -} + std::unique_ptr< PackageInfo > pPackageInfo(new (std::nothrow) PackageInfo); + SysTryReturn(NID_APP, pPackageInfo, null, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null."); -_PackageManagerImpl::~_PackageManagerImpl(void) -{ -} + SysLog(NID_APP, "packagePath = [%s], extension = [%s]", pPackagePath.get(), pExtension.get()); -void -_PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue) -{ - result r = E_SUCCESS; - bool install = true; + bool res = true; - if (strcmp(pEventKey, "start") == 0) + if (strcasecmp(pExtension.get(), "tpk") == 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."); + _PackageParser packageParser; - String* pOperation = new (std::nothrow) String(pEventValue); - SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation instance must not be null."); + res = packageParser.Construct(pPackageInfo.get()); + SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Construct() is failed. [%s]", pPackagePath.get()); - r = __installationList.Add(*pAppId, *pOperation); - if (IsFailed(r)) - { - delete pAppId; - delete pOperation; - SysLog(NID_APP, "Failed to add installation condition."); - SetLastResult(E_SYSTEM); - return; - } - } + res = packageParser.Parse(filePath); + SysTryReturn(NID_APP, res, null, E_PARSING_FAILED, "Parse() is failed. [%s]", pPackagePath.get()); } - else if (strcmp(pEventKey, "end") == 0) + else if (strcasecmp(pExtension.get(), "wgt") == 0) { - String* pOperation = static_cast (__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()); - } - } - } + pkgmgr_info* pPkgmgrInfo = null; - std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN()); - SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient."); + 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()); - 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."); + _package_manager_pkg_detail_info_t* pPkgInfo = (_package_manager_pkg_detail_info_t*) pPkgmgrInfo; + _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get()); - String eventKey(pEventKey); - String eventValue(pEventValue); + 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); - pEventArg->__packageId = packageId; - pEventArg->__eventKey = eventKey; - pEventArg->__eventValue = eventValue; - pEventArg->__install = install; + 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); - r = pEvent->Fire(*pEventArg); - if (r != E_SUCCESS) + if (pPkgInfo->privilege_list) + { + GList* pList = null; + pList = g_list_first(pPkgInfo->privilege_list); + while (pList) { - SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r)); + char* pPrivilege = (char*)pList->data; + if (pPrivilege) + { + pPackageInfoImpl->AddPrivilege(*new (std::nothrow) String(pPrivilege)); + free(pPrivilege); + } + pList = g_list_next(pList); } - - SysLog(NID_APP, "PackageId = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install); + g_list_free(pPkgInfo->privilege_list); } - else + + std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo); + SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null."); + + _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)) { - SysLog(NID_APP, "pEvent is null."); + String iconPath("/tmp/icon.png"); + File file; + file.Construct(iconPath, "w+"); + file.Write(pPkgInfo->icon_buf, pPkgInfo->icon_size); + + pPackageAppInfoImpl->SetAppTempIconPath(iconPath); } + + pPackageInfoImpl->AddPackageAppInfo(*pPackageAppInfo.release()); + + 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(); } -PackageInfo* -_PackageManagerImpl::GetPackageInfoN(PackageType packageType, const String& packageName) const +IList* +_PackageManagerImpl::GetPackageInfoListN(const IMap& packageFilterMap) 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()); + SysTryReturn(NID_APP, packageFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageFilterMap.GetCount() is invalid."); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r)); + std::unique_ptr pEnum(packageFilterMap.GetMapEnumeratorN()); + SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed."); - pStmt = CreateStatementN(db, query); + int res = 0; + ArrayList* pList = null; + pkgmgrinfo_pkginfo_filter_h handle = null; - SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + res = pkgmgrinfo_pkginfo_filter_create(&handle); + SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_pkginfo_filter_create() is failed. [%d]", res); - pEnum = ExecuteStatementN(db, pStmt); - if (pEnum != null) + while(pEnum->MoveNext() == E_SUCCESS) { - 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."); + String* pKey = static_cast< String* >(pEnum->GetKey()); + SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed."); - _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); + Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue()); + SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed."); - String id; - String appVersion; - String appType; - String appMimeType; - String appApiVersion; - String appName; - String appVendor; - String appDescription; - String appUrl; - String appCid; - String appRootPath; - int appStorageType = 0; - DateTime appInstallationTime; - String appIconPath; + bool value = pVal->ToBool(); - pEnum->GetStringAt(1, id); - pEnum->GetStringAt(3, appVersion); - pEnum->GetStringAt(4, appType); - pEnum->GetStringAt(5, appMimeType); - pEnum->GetStringAt(6, appApiVersion); - pEnum->GetStringAt(7, appName); - pEnum->GetStringAt(8, appVendor); - pEnum->GetStringAt(9, appDescription); - pEnum->GetStringAt(10, appUrl); - pEnum->GetStringAt(11, appCid); - pEnum->GetStringAt(16, appRootPath); - pEnum->GetIntAt(17, appStorageType); - pEnum->GetDateTimeAt(18, appInstallationTime); - pEnum->GetStringAt(21, appIconPath); + SysLog(NID_APP, "Key[%ls], Value[%d]", pKey->GetPointer(), value); - pPackageInfoImpl->SetAppId(id); - pPackageInfoImpl->SetAppVersion(appVersion); - pPackageInfoImpl->SetAppMimeType(appMimeType); - pPackageInfoImpl->SetAppApiVersion(appApiVersion); - pPackageInfoImpl->SetAppName(appName); - pPackageInfoImpl->SetAppVendor(appVendor); - pPackageInfoImpl->SetAppDescription(appDescription); - pPackageInfoImpl->SetAppUrl(appUrl); - pPackageInfoImpl->SetAppCid(appCid); - pPackageInfoImpl->SetAppRootPath(appRootPath); - pPackageInfoImpl->SetAppStorageType(appStorageType); - pPackageInfoImpl->SetAppInstallationTime(appInstallationTime); - pPackageInfoImpl->SetAppIconPath(appIconPath); + 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_EXTERNAL_STORAGE) + { + String installedStorage; + if (value == true) + { + installedStorage = L"installed_external"; + } + else + { + installedStorage = L"installed_internal"; + } - delete pEnum; - } - else - { - r = E_OBJ_NOT_FOUND; - } - -CATCH: - delete pStmt; - return pPackageInfo; -} - -int -_PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData) -{ - SysTryReturn(NID_APP, handle != null, 0, E_SYSTEM, "[E_SYSTEM] handle must not be null."); + std::unique_ptr pInstalledStorage(_StringConverter::CopyToCharArrayN(installedStorage)); + SysTryCatch(NID_APP, pInstalledStorage, , E_OUT_OF_MEMORY, "pInstalledStorage is null."); - int result = 0; - char* pPackage = null; - ArrayList* pList = (ArrayList*)pUserData; + SysLog(NID_APP, "Value[%d]->[%s]", value, pInstalledStorage.get()); - 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."); + 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()); + } + } - _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); + pList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_APP, pList, , E_OUT_OF_MEMORY, "ArrayList creation failure."); + pList->Construct(); - result = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackage); - if (result == 0) + res = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, PackageInfoHandler, pList); + if (res != 0) { - SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname(): package = [%s]", pPackage); + SysLog(NID_APP, "pkgmgrinfo_pkginfo_filter_foreach_pkginfo() is failed. result = [%d]", res); + + pList->RemoveAll(true); + pList = null; } - else + +CATCH: + if (handle) { - SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname() is failed. result = [%d]", result); + pkgmgrinfo_pkginfo_filter_destroy(handle); } - pPackageInfoImpl->Construct(pPackage); - pList->Add(*pPackageInfo); - - return result; + return pList; } IList* -_PackageManagerImpl::GetFilteredAppIdListN(const String& feature, const String& value) const +_PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageAppFilterMap) const { - result r = E_SUCCESS; - Database db; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; - String query; - ArrayList* pList = null; + SysTryReturn(NID_APP, packageAppFilterMap.GetCount() > 0, null, E_INVALID_ARG, "packageAppFilterMap.GetCount() is invalid."); - query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, AppFeature WHERE AppFeature.ID = AppInfo.UNIQUE_ID and AppFeature.NAME = '%ls' and AppFeature.VALUE = '%ls' COLLATE NOCASE", feature.GetPointer(), value.GetPointer()); + std::unique_ptr pEnum(packageAppFilterMap.GetMapEnumeratorN()); + SysTryReturn(NID_APP, pEnum, null, E_INVALID_ARG, "GetMapEnumeratorN() is failed."); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r)); + int res = 0; + bool definedKey = false; + bool metadataKey = false; + ArrayList* pList = null; + ArrayList list; + ArrayList metadataList; + ArrayList appIdList; + pkgmgrinfo_appinfo_filter_h handle = null; + pkgmgrinfo_appinfo_metadata_filter_h metaHandle = null; - pStmt = CreateStatementN(db, query); - SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + res = pkgmgrinfo_appinfo_filter_create(&handle); + SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_appinfo_filter_create() is failed. [%d]", res); - pEnum = ExecuteStatementN(db, pStmt); + res = pkgmgrinfo_appinfo_metadata_filter_create(&metaHandle); + SysTryReturn(NID_APP, res == PMINFO_R_OK, null, E_SYSTEM, "pkgmgrinfo_appinfo_metadata_filter_create() is failed. [%d]", res); - if (pEnum != null) + while(pEnum->MoveNext() == E_SUCCESS) { - pList = new (std::nothrow) ArrayList(); - SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure."); - pList->Construct(); + String* pKey = static_cast< String* >(pEnum->GetKey()); + SysTryCatch(NID_APP, pKey, , E_INVALID_ARG, "GetKey() is failed."); - while (pEnum->MoveNext() == E_SUCCESS) + if ((*pKey) == PACKAGE_APP_FILTER_MENUICON_VISIBLE) { - String* pPackageName = new (std::nothrow) String; - SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null."); + definedKey = true; - pEnum->GetStringAt(0, *pPackageName); + Boolean* pVal = static_cast< Boolean* >(pEnum->GetValue()); + SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed."); - pList->Add(*pPackageName); + 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 ((*pKey) == PACKAGE_APP_FILTER_CATEGORY) + { + definedKey = true; - delete pEnum; + String* pVal = static_cast< String* >(pEnum->GetValue()); + SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed."); - } - else - { - r = E_OBJ_NOT_FOUND; - } + SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer()); -CATCH: - delete pStmt; - return pList; -} + std::unique_ptr pValue(_StringConverter::CopyToCharArrayN(*pVal)); + SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null."); -IList* -_PackageManagerImpl::GetDataControlInfoN(const String& providerId, const String& type) const -{ - result r = E_SUCCESS; - Database db; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; - String query; - ArrayList* pList = null; + res = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, pValue.get()); + SysTryCatch(NID_APP, res == PMINFO_R_OK, , E_SYSTEM, "pkgmgrinfo_appinfo_filter_add_string(CATEGORY, %s) is failed. [%d]", pValue.get(), res); + } + else + { + metadataKey = true; - query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME, DataControl.ACCESS FROM AppInfo, DataControl WHERE DataControl.ID = AppInfo.UNIQUE_ID and DataControl.PROVIDER_ID = '%ls' and DataControl.TYPE = '%ls' COLLATE NOCASE", providerId.GetPointer(), type.GetPointer()); + String* pVal = static_cast< String* >(pEnum->GetValue()); + SysTryCatch(NID_APP, pVal, , E_INVALID_ARG, "GetValue() is failed."); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r)); + SysLog(NID_APP, "Key[%ls], Value[%ls]", pKey->GetPointer(), pVal->GetPointer()); - pStmt = CreateStatementN(db, query); - SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + std::unique_ptr pMetaKey(_StringConverter::CopyToCharArrayN(*pKey)); + SysTryCatch(NID_APP, pMetaKey, , E_OUT_OF_MEMORY, "pMetaKey is null."); - pEnum = ExecuteStatementN(db, pStmt); + std::unique_ptr pValue(_StringConverter::CopyToCharArrayN(*pVal)); + SysTryCatch(NID_APP, pValue, , E_OUT_OF_MEMORY, "pValue is null."); - if (pEnum != null) + 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); + } + } + + if ((definedKey == true) && (metadataKey == false)) { pList = new (std::nothrow) ArrayList(); - SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure."); + SysTryCatch(NID_APP, pList, , E_OUT_OF_MEMORY, "ArrayList creation failure."); pList->Construct(); - while (pEnum->MoveNext() == E_SUCCESS) + res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, pList); + if (res != PMINFO_R_OK) { - String* pPackageName = new (std::nothrow) String; - SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null."); - - String* pAccess = new (std::nothrow) String; - SysTryReturn(NID_APP, pAccess != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pAccess instance must not be null."); + SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res); - pEnum->GetStringAt(0, *pPackageName); - pList->Add(*pPackageName); - - pEnum->GetStringAt(1, *pAccess); - pList->Add(*pAccess); + pList->RemoveAll(true); + pList = null; } + } + else if ((definedKey == false) && (metadataKey == true)) + { + pList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_APP, pList, , E_OUT_OF_MEMORY, "ArrayList creation failure."); + pList->Construct(); - delete pEnum; + res = pkgmgrinfo_appinfo_metadata_filter_foreach(metaHandle, PackageAppInfoMetadataHandler, pList); + if (res != PMINFO_R_OK) + { + SysLog(NID_APP, "pkgmgrinfo_appinfo_metadata_filter_foreach() is failed. result = [%d]", res); + pList->RemoveAll(true); + pList = null; + } } else { - r = E_OBJ_NOT_FOUND; - } - -CATCH: - delete pStmt; - return pList; -} + list.Construct(); -IMap* -_PackageManagerImpl::GetUiThemeListN(const PackageId& packageId) const -{ - result r = E_SUCCESS; - Database db; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; - String query; - HashMap* pList = null; + res = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, PackageAppInfoHandler, &list); + if (res != PMINFO_R_OK) + { + SysLog(NID_APP, "pkgmgrinfo_appinfo_filter_foreach_appinfo() is failed. result = [%d]", res); + goto CATCH; + } - query.Format(1024, L"SELECT AppFeature.NAME, AppFeature.VALUE FROM PkgInfo, AppInfo, AppFeature WHERE (AppFeature.ID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls') and (AppFeature.NAME = 'SystemTheme' or AppFeature.NAME = 'UserDefinedTheme')" - , packageId.GetPointer()); + metadataList.Construct(); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r)); + 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; + } - pStmt = CreateStatementN(db, query); - SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + for (int i = 0; i < list.GetCount(); i++) + { + PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(list.GetAt(i)); + if (pPackageAppInfo) + { + AppLog("PackageAppFilter - AppId [%ls]", pPackageAppInfo->GetAppId().GetPointer()); - pEnum = ExecuteStatementN(db, pStmt); + std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId())); + appIdList.Add(pAppId.release()); + } + } - if (pEnum != null) - { - pList = new (std::nothrow) HashMap(); - SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "HashMap creation failure."); + pList = new (std::nothrow) ArrayList(); + SysTryCatch(NID_APP, pList, , E_OUT_OF_MEMORY, "ArrayList creation failure."); pList->Construct(); - while (pEnum->MoveNext() == E_SUCCESS) + for (int j = 0; j < metadataList.GetCount(); j++) { - String* pName = new (std::nothrow) String; - SysTryCatch(NID_APP, pName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pName instance must not be null."); + PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(metadataList.GetAt(j)); + if (pPackageAppInfo) + { + if (appIdList.Contains(pPackageAppInfo->GetAppId()) == true) + { + AppLog("AppId [%ls] is matched.", pPackageAppInfo->GetAppId().GetPointer()); - String* pValue = new (std::nothrow) String; - SysTryCatch(NID_APP, pValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pValue instance must not be null."); + std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo); + SysTryCatch(NID_APP, pPackageAppInfo, , E_OUT_OF_MEMORY, "PackageAppInfo is null."); - pEnum->GetStringAt(0, *pName); - pEnum->GetStringAt(1, *pValue); + _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get()); + pPackageAppInfoImpl->Construct(pPackageAppInfo->GetAppId()); - pList->Add(*pName, *pValue); + pList->Add(pPackageAppInfo.release()); + } + else + { + AppLog("AppId [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer()); + } + } } - - delete pEnum; - } - else + +CATCH: + if (handle) { - r = E_OBJ_NOT_FOUND; + pkgmgrinfo_appinfo_filter_destroy(handle); } -CATCH: - delete pStmt; + if (metaHandle) + { + pkgmgrinfo_appinfo_metadata_filter_destroy(metaHandle); + } return pList; } -bool -_PackageManagerImpl::IsAppInstalled(const AppId& appId) +IList* +_PackageManagerImpl::GetPackageAppInfoListN(const IMap& packageFilterMap, const IMap& packageAppFilterMap) const { - if (appId == _AppInfo::GetPackageId()) + 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."); + + ArrayList appIdList; + + std::unique_ptr< IList > pPackageFilterList(GetPackageInfoListN(packageFilterMap)); + if (pPackageFilterList == null) { - return true; + SysLog(NID_APP, "GetPackageInfoListN(packageFilterMap) is null."); + return null; } - int result = 0; - pkgmgrinfo_pkginfo_h pPackageInfoHandle = null; + 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 - AppId [%ls]", pPackageAppInfo->GetAppId().GetPointer()); - std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(appId)); - SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null"); + std::unique_ptr< AppId > pAppId(new (std::nothrow) AppId(pPackageAppInfo->GetAppId())); + appIdList.Add(pAppId.release()); + } + } + } + } + } - 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()); + std::unique_ptr< ArrayList > pList(new (std::nothrow) ArrayList); + SysTryReturn(NID_APP, pList, null, E_OUT_OF_MEMORY, "pList is null."); - if(pPackageInfoHandle) + std::unique_ptr< IList > pAppFilterList(GetPackageAppInfoListN(packageAppFilterMap)); + if (pAppFilterList == null) { - pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle); + SysLog(NID_APP, "GetPackageAppInfoListN(packageAppFilterMap) is null."); + return null; } - return true; -} + for (int k = 0; k < pAppFilterList->GetCount(); k++) + { + PackageAppInfo* pPackageAppInfo = dynamic_cast < PackageAppInfo* >(pAppFilterList->GetAt(k)); + if (pPackageAppInfo) + { + AppId appId = pPackageAppInfo->GetAppId(); + AppLog("AppFilter - AppId [%ls]", appId.GetPointer()); -int -_PackageManagerImpl::PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name, - const char* key, const char* val, const void* pmsg, void* data) -{ - SysLog(NID_APP, "PackageEventHandler - req_id: %d, pkg_type: %s, pkg_name: %s, key: %s, val: %s", req_id, pkg_type, - pkg_name, key, val); + if (appIdList.Contains(appId) == true) + { + AppLog("AppId [%ls] is matched.", appId.GetPointer()); - PackageType type = PACKAGE_TYPE_TPK; - PackageId packageId(pkg_name); + std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo); + SysTryReturn(NID_APP, pPackageAppInfo, null, E_OUT_OF_MEMORY, "PackageAppInfo is null."); - if (strcmp(pkg_type, "tpk") == 0) - { - type = PACKAGE_TYPE_TPK; - } - else if (strcmp(pkg_type, "wgt") == 0) - { - type = PACKAGE_TYPE_WGT; + _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get()); + pPackageAppInfoImpl->Construct(appId); + + pList->Add(pPackageAppInfo.release()); + } + else + { + AppLog("AppId [%ls] is not matched.", pPackageAppInfo->GetAppId().GetPointer()); + } + } } - else + + if (pList->GetCount() <= 0) { - SysLog(NID_APP, "Invalid type - pkg_type: %s", pkg_type); - return 0; + AppLog("pList's count is 0."); + return null; } - _PackageManagerImpl* pThis = _PackageManagerImpl::GetInstance(); - pThis->SendPackageEvent(type, packageId, key, val); - - return 0; + return pList.release(); } -String* -_PackageManagerImpl::GetAppIdOfDataControlN(const String& providerId) +int +_PackageManagerImpl::PackageInfoHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData) { - result r = E_SUCCESS; - Database db; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; - String query; - String* pAppId = null; + SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null."); + SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null."); - query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, DataControl WHERE DataControl.PROVIDER_ID = '%ls' and DataControl.ID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID", - providerId.GetPointer()); - - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); - 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())); + result r = E_SUCCESS; + int res = PMINFO_R_OK; + char* pPackageId = null; + ArrayList* pList = (ArrayList*)pUserData; - pEnum = ExecuteStatementN(db, pStmt); + 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); - if (pEnum != null) - { - if (pEnum->MoveNext() == E_SUCCESS) - { - pAppId = new (std::nothrow) String; - SysTryReturn(NID_APP, pAppId != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory"); + std::unique_ptr pPackageInfo(new (std::nothrow) PackageInfo); + SysTryReturn(NID_APP, pPackageInfo, 0, E_OUT_OF_MEMORY, "pPackageInfo instance must not be null."); - pEnum->GetStringAt(0, *pAppId); - } + _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo.get()); + r = pPackageInfoImpl->Construct(pPackageId); + SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pPackageId); - delete pEnum; - } + pList->Add(*pPackageInfo.release()); -CATCH: - delete pStmt; - return pAppId; + return 0; } -result -_PackageManagerImpl::CreatePackageTables(void) +int +_PackageManagerImpl::PackageAppInfoHandler(const pkgmgrinfo_appinfo_h handle, void* pUserData) { - 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 )"); - 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(); + SysTryReturn(NID_APP, handle, 0, E_SYSTEM, "handle must not be null."); + SysTryReturn(NID_APP, pUserData, 0, E_SYSTEM, "pUserData must not be null."); - return r; -} - -result -_PackageManagerImpl::RegisterPackageInfo(_PackageInfoImpl& pkgInfoImpl) -{ result r = E_SUCCESS; - Database db; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; - String query; - String privileges; - String hmacPrivileges; - PackageInfo packageInfo; - int uniqueId = 0; + int res = PMINFO_R_OK; + char* pAppId = null; + ArrayList* pList = (ArrayList*)pUserData; - SysLog(NID_APP, "_PackageManagerImpl::RegisterPackageInfo()"); + 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); - 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 (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + std::unique_ptr pPackageAppInfo(new (std::nothrow) PackageAppInfo); + SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null."); - 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)); + _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get()); + r = pPackageAppInfoImpl->Construct(pAppId); + SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId); - pStmt = CreateStatementN(db, query); - //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + pList->Add(*pPackageAppInfo.release()); - 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(); + return 0; +} - pkgInfoImpl.GetPrivilegesValue(privileges, hmacPrivileges); - String appRootPath = pkgInfoImpl.GetAppRootPath(); - int appStorageType = pkgInfoImpl.GetAppStorageType(); - int certType = pkgInfoImpl.GetCertType(); - ArrayList* pAppInfoImplList = pkgInfoImpl.GetAppInfoList(); +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."); - DateTime time; - r = SystemTime::GetCurrentTime(time); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "An error occurs while getting a current time."); + result r = E_SUCCESS; + int res = PMINFO_R_OK; + char* pAppId = null; + ArrayList* pList = (ArrayList*)pUserData; - if (!packageId.IsEmpty()) - { - r = pStmt->BindString(0, packageId); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r)); - } + 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); - 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)); - } + std::unique_ptr< PackageAppInfo > pPackageAppInfo(new (std::nothrow) PackageAppInfo); + SysTryReturn(NID_APP, pPackageAppInfo, 0, E_OUT_OF_MEMORY, "pPackageAppInfo instance must not be null."); - 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)); - } + _PackageAppInfoImpl* pPackageAppInfoImpl = _PackageAppInfoImpl::GetInstance(pPackageAppInfo.get()); + r = pPackageAppInfoImpl->Construct(pAppId); + SysTryReturn(NID_APP, r == E_SUCCESS, 0, E_SYSTEM, "Construct(%s) is failed.", pAppId); - if (!appMimeType.IsEmpty()) - { - r = pStmt->BindString(4, appMimeType); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r)); - } + pList->Add(*pPackageAppInfo.release()); - 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)); - } + return 0; +} - 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)); - } +_PackageManagerImpl* +_PackageManagerImpl::GetInstance(void) +{ + return PackageManager::GetInstance()->__pPackageManagerImpl; +} - 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)); - } +result +_PackageManagerImpl::Construct(void) +{ + ClearLastResult(); - 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)); - } + result r = __installationList.Construct(); + SysTryReturnResult(NID_APP, r == E_SUCCESS, r, "The memory is insufficient."); - 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)); - } + return E_SUCCESS; +} - 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; +_PackageManagerImpl::_PackageManagerImpl(void) +:__pRequestClient(null), +__pListeningClient(null) +{ } -result -_PackageManagerImpl::UnregisterPackageInfo(const PackageId& packageId) +_PackageManagerImpl::~_PackageManagerImpl(void) { - SysLog(NID_APP, "packageId = [%ls]", packageId.GetPointer()); +} +void +_PackageManagerImpl::SendPackageEvent(PackageType type, const PackageId& packageId, const char* pEventKey, const char* pEventValue) +{ 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)); + bool install = true; - // AppInfoLookup - pList = pPackageInfoImpl->GetAppInfoListN(); - if (pList != null) + if (strcmp(pEventKey, "start") == 0) { - for (int i = 0; i < pList->GetCount(); i++) + if ((strcmp(pEventValue, "install") == 0) || (strcmp(pEventValue, "uninstall") == 0)) { - _PackageAppInfoImpl* pAppInfoImpl = dynamic_cast <_PackageAppInfoImpl*>(pList->GetAt(i)); + String* pAppId = new (std::nothrow) String(packageId); + SysTryReturnVoidResult(NID_APP, pAppId != null, E_OUT_OF_MEMORY, "pAppId instance must not be null."); - if (pAppInfoImpl != null) - { - int uniqueId = 0; - uniqueId = pAppInfoImpl->GetUniqueId(); + String* pOperation = new (std::nothrow) String(pEventValue); + SysTryReturnVoidResult(NID_APP, pOperation != null, E_OUT_OF_MEMORY, "pOperation instance must not be null."); - 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(); + r = __installationList.Add(*pAppId, *pOperation); + if (IsFailed(r)) + { + delete pAppId; + delete pOperation; + SysLog(NID_APP, "Failed to add installation condition."); + SetLastResult(E_SYSTEM); + return; } } - 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, false); - 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) + else if (strcmp(pEventKey, "end") == 0) { - if (pEnum->MoveNext() == E_SUCCESS) + String* pOperation = static_cast (__installationList.GetValue(packageId)); + if (pOperation) { - PackageId packageId; - pEnum->GetStringAt(0, packageId); + if (pOperation->Equals("uninstall", true) == true) + { + install = false; + } - pPkgInfo = GetPackageInfoN(packageId); + 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()); + } } - - delete pEnum; - } - else - { - r = E_OBJ_NOT_FOUND; } -CATCH: - delete pStmt; - return pPkgInfo; -} + std::unique_ptr< IEnumeratorT<_PackageManagerEvent*> > pEnum(__packageEventListenerList.GetEnumeratorN()); + SysTryReturnVoidResult(NID_APP, pEnum, E_OUT_OF_MEMORY, "The memory is insufficient."); -result -_PackageManagerImpl::GetAppInfo(int uniqueId, _PackageAppInfoImpl& appInfo) const -{ - result r = E_SUCCESS; - Database db; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; - String query; + 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."); - query.Format(1024, L"SELECT * FROM AppInfo WHERE UNIQUE_ID = %d", uniqueId); + String eventKey(pEventKey); + String eventValue(pEventValue); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while opening a database.", GetErrorMessage(r)); + pEventArg->__packageId = packageId; + pEventArg->__eventKey = eventKey; + pEventArg->__eventValue = eventValue; + pEventArg->__install = install; - pStmt = CreateStatementN(db, query); - SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + r = pEvent->Fire(*pEventArg); + if (r != E_SUCCESS) + { + SysLog(NID_APP, "pEvent->Fire(*pEventArg) failed. [%s]", GetErrorMessage(r)); + } - pEnum = ExecuteStatementN(db, pStmt); - if (pEnum != null) - { - if (pEnum->MoveNext() == E_SUCCESS) + SysLog(NID_APP, "PackageId = [%ls], Key = [%ls], Value = [%ls], install = [%d]", pEventArg->__packageId.GetPointer(), pEventArg->__eventKey.GetPointer(), pEventArg->__eventValue.GetPointer(), pEventArg->__install); + } + else { - 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); + SysLog(NID_APP, "pEvent is null."); } - - delete pEnum; - } - else - { - r = E_OBJ_NOT_FOUND; } - -CATCH: - delete pStmt; - return r; } -ArrayList* -_PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const +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; - //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)); + PackageInfo *pPackageInfo = null; - pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo); - query.Format(1024, L"SELECT * FROM AppInfo WHERE ID = %d", pPackageInfoImpl->GetUniqueId()); + 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, false); + 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); + 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) { - pList = new (std::nothrow) ArrayList; - SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure."); - - pList->Construct(); - - while (pEnum->MoveNext() == E_SUCCESS) + if (pEnum->MoveNext() == E_SUCCESS) { - _PackageAppInfoImpl* pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl; - SysTryReturn(NID_APP, pPackageAppInfoImpl != null, null, E_OUT_OF_MEMORY, "pPackageAppInfoImpl instance must not be null."); + 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."); - int uniqueId = 0; - int pkgId = 0; - String name; - String defaultapp; - String mainmenuIcon; - String settingIcon; - String quickpanelIcon; - int appFeature = 0; - String packageName; + _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); - 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); + String id; + String appVersion; + String appType; + String appMimeType; + String appApiVersion; + String appName; + String appVendor; + String appDescription; + String appUrl; + String appCid; + String appRootPath; + int appStorageType = 0; + DateTime appInstallationTime; + String appIconPath; - pPackageAppInfoImpl->SetUniqueId(uniqueId); - pPackageAppInfoImpl->SetPkgId(pkgId); - pPackageAppInfoImpl->SetName(name); - pPackageAppInfoImpl->SetDefault(defaultapp); - pPackageAppInfoImpl->SetMainmenuIcon(mainmenuIcon); - pPackageAppInfoImpl->SetSettingIcon(settingIcon); - pPackageAppInfoImpl->SetQuickpanelIcon(quickpanelIcon); - pPackageAppInfoImpl->SetAppFeature(appFeature); - pPackageAppInfoImpl->SetPackageName(packageName); + pEnum->GetStringAt(1, id); + pEnum->GetStringAt(3, appVersion); + pEnum->GetStringAt(4, appType); + pEnum->GetStringAt(5, appMimeType); + pEnum->GetStringAt(6, appApiVersion); + pEnum->GetStringAt(7, appName); + pEnum->GetStringAt(8, appVendor); + pEnum->GetStringAt(9, appDescription); + pEnum->GetStringAt(10, appUrl); + pEnum->GetStringAt(11, appCid); + pEnum->GetStringAt(16, appRootPath); + pEnum->GetIntAt(17, appStorageType); + pEnum->GetDateTimeAt(18, appInstallationTime); + pEnum->GetStringAt(21, appIconPath); - pList->Add(*pPackageAppInfoImpl); + pPackageInfoImpl->SetAppId(id); + pPackageInfoImpl->SetAppVersion(appVersion); + pPackageInfoImpl->SetAppMimeType(appMimeType); + pPackageInfoImpl->SetAppApiVersion(appApiVersion); + pPackageInfoImpl->SetAppName(appName); + pPackageInfoImpl->SetAppVendor(appVendor); + pPackageInfoImpl->SetAppDescription(appDescription); + pPackageInfoImpl->SetAppUrl(appUrl); + pPackageInfoImpl->SetAppCid(appCid); + pPackageInfoImpl->SetAppRootPath(appRootPath); + pPackageInfoImpl->SetAppStorageType(appStorageType); + pPackageInfoImpl->SetAppInstallationTime(appInstallationTime); + pPackageInfoImpl->SetAppIconPath(appIconPath); } delete pEnum; } - -CATCH: - delete pPkgInfo; - delete pStmt; - return pList; -} - -ArrayList* -_PackageManagerImpl::GetPackageAppFeatureListN(const PackageId& packageId, const Tizen::Base::String& appExecutableName) const -{ - ArrayList* pAppInfoList = GetPackageAppInfoImplListN(packageId); - SysTryReturn(NID_APP, pAppInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppInfo list instance must not be null."); - - ArrayList* pResult = null; - - for (int i = 0; i < pAppInfoList->GetCount(); i++) + else { - const _PackageAppInfoImpl* pAppInfoImpl = static_cast(pAppInfoList->GetAt(i)); - if (pAppInfoImpl == null) - { - continue; - } - - if (pAppInfoImpl->GetName() == appExecutableName) - { - pResult = pAppInfoImpl->GetAppFeatureListN(); - goto OUT; - } + r = E_OBJ_NOT_FOUND; } -OUT: - pAppInfoList->RemoveAll(true); - delete pAppInfoList; - - return pResult; +CATCH: + delete pStmt; + return pPackageInfo; } -HashMapT* -_PackageManagerImpl::GetPackageAppFeatureMapN(const PackageId& packageId, const Tizen::Base::String& appExecutableName) const +int +_PackageManagerImpl::PackageInfoEventHandler(const pkgmgrinfo_pkginfo_h handle, void* pUserData) { - ArrayList* pAppInfoList = GetPackageAppInfoImplListN(packageId); - SysTryReturn(NID_APP, pAppInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppInfo list instance must not be null."); + SysTryReturn(NID_APP, handle != null, 0, E_SYSTEM, "[E_SYSTEM] handle must not be null."); - HashMapT* pResult = null; + int result = 0; + char* pPackage = null; + ArrayList* pList = (ArrayList*)pUserData; - std::auto_ptr pEnum(pAppInfoList->GetEnumeratorN()); + 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."); - while (pEnum->MoveNext() == E_SUCCESS) - { - const _PackageAppInfoImpl* pAppInfoImpl = static_cast(pEnum->GetCurrent()); - if (pAppInfoImpl == null) - { - continue; - } + _PackageInfoImpl* pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo); - if (pAppInfoImpl->GetName() == appExecutableName) - { - pResult = pAppInfoImpl->GetAppFeatureMapN(); - goto OUT; - } + result = pkgmgrinfo_pkginfo_get_pkgname(handle, &pPackage); + if (result == 0) + { + SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname(): package = [%s]", pPackage); + } + else + { + SysLog(NID_APP, "pkgmgrinfo_pkginfo_get_pkgname() is failed. result = [%d]", result); } -OUT: - pAppInfoList->RemoveAll(true); - delete pAppInfoList; + pPackageInfoImpl->Construct(pPackage); + pList->Add(*pPackageInfo); - return pResult; + return result; } -ArrayList* -_PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const +IList* +_PackageManagerImpl::GetFilteredAppIdListN(const String& feature, const String& value) const { result r = E_SUCCESS; Database db; @@ -1837,43 +1474,38 @@ _PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const String query; ArrayList* pList = null; - query.Format(1024, L"SELECT LaunchCondition.* FROM LaunchCondition, AppInfo WHERE AppInfo.UNIQUE_ID = LaunchCondition.ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer()); + query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME FROM AppInfo, AppFeature WHERE AppFeature.ID = AppInfo.UNIQUE_ID and AppFeature.NAME = '%ls' and AppFeature.VALUE = '%ls' COLLATE NOCASE", feature.GetPointer(), value.GetPointer()); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); + 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())); + 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) { - pList = new (std::nothrow) ArrayList; - SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure."); - + pList = new (std::nothrow) ArrayList(); + SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure."); pList->Construct(); while (pEnum->MoveNext() == E_SUCCESS) { - _LaunchConditionInfoImpl* pLaunchCondtion = new (std::nothrow) _LaunchConditionInfoImpl; - SysTryReturn(NID_APP, pLaunchCondtion != null, null, E_OUT_OF_MEMORY, "pLaunchCondtion instance must not be null."); - - String name; - String value; - - pEnum->GetStringAt(1, name); - pEnum->GetStringAt(2, value); - - pLaunchCondtion->SetName(name); - pLaunchCondtion->SetValue(value); + String* pPackageName = new (std::nothrow) String; + SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null."); - pList->Add(*pLaunchCondtion); + pEnum->GetStringAt(0, *pPackageName); - SysLog(NID_APP, "Name[%ls], Value[%ls]", name.GetPointer(), value.GetPointer()); + pList->Add(*pPackageName); } delete pEnum; + + } + else + { + r = E_OBJ_NOT_FOUND; } CATCH: @@ -1881,523 +1513,449 @@ CATCH: return pList; } -result -_PackageManagerImpl::RegisterAppInfoList(int id, ArrayList* pList) +IList* +_PackageManagerImpl::GetDataControlInfoN(const String& providerId, const String& type) const { - SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null"); - result r = E_SUCCESS; - String query; + Database db; DbStatement* pStmt = null; + DbEnumerator* pEnum = null; + String query; + ArrayList* pList = 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)); - } + query.Format(1024, L"SELECT AppInfo.PACKAGE_NAME, DataControl.ACCESS FROM AppInfo, DataControl WHERE DataControl.ID = AppInfo.UNIQUE_ID and DataControl.PROVIDER_ID = '%ls' and DataControl.TYPE = '%ls' COLLATE NOCASE", providerId.GetPointer(), type.GetPointer()); - 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)); - } + 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)); - 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)); - } + pStmt = CreateStatementN(db, query); + SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); - 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)); - } + pEnum = ExecuteStatementN(db, pStmt); - 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 (pEnum != null) + { + pList = new (std::nothrow) ArrayList(); + SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "ArrayList creation failure."); + pList->Construct(); - 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)); - } + while (pEnum->MoveNext() == E_SUCCESS) + { + String* pPackageName = new (std::nothrow) String; + SysTryReturn(NID_APP, pPackageName != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pPackageName instance must not be null."); - 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)); - } + String* pAccess = new (std::nothrow) String; + SysTryReturn(NID_APP, pAccess != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pAccess instance must not be null."); - 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->GetStringAt(0, *pPackageName); + pList->Add(*pPackageName); - pEnum = ExecuteStatementN(*__pDb, pStmt); + pEnum->GetStringAt(1, *pAccess); + pList->Add(*pAccess); + } - query.Clear(); - delete pStmt; - pStmt = null; - delete pEnum; + 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(); + else + { + r = E_OBJ_NOT_FOUND; + } CATCH: delete pStmt; - - return r; + return pList; } -result -_PackageManagerImpl::RegisterLaunchConditionList(int id, ArrayList* pList) +IMap* +_PackageManagerImpl::GetUiThemeListN(const PackageId& packageId) const { - SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null"); - result r = E_SUCCESS; - String query; + Database db; DbStatement* pStmt = null; + DbEnumerator* pEnum = null; + String query; + HashMap* pList = 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; + query.Format(1024, L"SELECT AppFeature.NAME, AppFeature.VALUE FROM PkgInfo, AppInfo, AppFeature WHERE (AppFeature.ID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID and PkgInfo.PKG_ID = '%ls') and (AppFeature.NAME = 'SystemTheme' or AppFeature.NAME = 'UserDefinedTheme')" + , packageId.GetPointer()); - String name = pLaunchCondition->GetName(); - String value = pLaunchCondition->GetValue(); + 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)); - query.Format(1024, L"INSERT INTO LaunchCondition (ID, NAME, VALUE) VALUES (?,?,?)"); + pStmt = CreateStatementN(db, query); + SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); - pStmt = CreateStatementN(*__pDb, query); - //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + pEnum = ExecuteStatementN(db, pStmt); - 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 (pEnum != null) + { + pList = new (std::nothrow) HashMap(); + SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "HashMap creation failure."); + pList->Construct(); - 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)); - } + while (pEnum->MoveNext() == E_SUCCESS) + { + String* pName = new (std::nothrow) String; + SysTryCatch(NID_APP, pName != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pName instance must not be null."); - 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)); - } + String* pValue = new (std::nothrow) String; + SysTryCatch(NID_APP, pValue != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] pValue instance must not be null."); - pEnum = ExecuteStatementN(*__pDb, pStmt); + pEnum->GetStringAt(0, *pName); + pEnum->GetStringAt(1, *pValue); - query.Clear(); - delete pStmt; - pStmt = null; - delete pEnum; - } + pList->Add(*pName, *pValue); } - } - r = GetLastResult(); + delete pEnum; + + } + else + { + r = E_OBJ_NOT_FOUND; + } CATCH: delete pStmt; - - return r; + return pList; } -result -_PackageManagerImpl::RegisterNotificationList(int id, ArrayList* pList) +bool +_PackageManagerImpl::IsAppInstalled(const AppId& appId) { - SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null"); - - result r = E_SUCCESS; - String query; - DbStatement* pStmt = null; - - if (pList != null) + if (appId == _AppInfo::GetPackageId()) { - for (int i = 0; i < pList->GetCount(); i++) - { - _NotificationInfoImpl* pNotification = dynamic_cast<_NotificationInfoImpl*>(pList->GetAt(i)); - - if (pNotification != null) - { - DbEnumerator* pEnum = null; + return true; + } - String name = pNotification->GetName(); - String value = pNotification->GetValue(); + int result = 0; + pkgmgrinfo_pkginfo_h pPackageInfoHandle = null; - query.Format(1024, L"INSERT INTO Notification (ID, NAME, VALUE) VALUES (?,?,?)"); + std::unique_ptr pPackageId(_StringConverter::CopyToCharArrayN(appId)); + SysTryReturn(NID_APP, pPackageId, false, E_OUT_OF_MEMORY, "pPackageId is null"); - pStmt = CreateStatementN(*__pDb, query); - //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + 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()); - 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(pPackageInfoHandle) + { + pkgmgrinfo_pkginfo_destroy_pkginfo(pPackageInfoHandle); + } - 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)); - } + return true; +} - 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)); - } +int +_PackageManagerImpl::PackageEventHandler(int req_id, const char* pkg_type, const char* pkg_name, + const char* key, const char* val, const void* pmsg, void* data) +{ + SysLog(NID_APP, "PackageEventHandler - req_id: %d, pkg_type: %s, pkg_name: %s, key: %s, val: %s", req_id, pkg_type, + pkg_name, key, val); - pEnum = ExecuteStatementN(*__pDb, pStmt); + PackageType type = PACKAGE_TYPE_TPK; + PackageId packageId(pkg_name); - query.Clear(); - delete pStmt; - pStmt = null; - delete pEnum; - } - } + if (strcmp(pkg_type, "tpk") == 0) + { + type = PACKAGE_TYPE_TPK; + } + else if (strcmp(pkg_type, "wgt") == 0) + { + type = PACKAGE_TYPE_WGT; + } + else + { + SysLog(NID_APP, "Invalid type - pkg_type: %s", pkg_type); + return 0; } - r = GetLastResult(); - -CATCH: - delete pStmt; + _PackageManagerImpl* pThis = _PackageManagerImpl::GetInstance(); + pThis->SendPackageEvent(type, packageId, key, val); - return r; + return 0; } -result -_PackageManagerImpl::RegisterAppFeatureList(int id, ArrayList* pList) +String* +_PackageManagerImpl::GetAppIdOfDataControlN(const String& providerId) { - SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null"); - result r = E_SUCCESS; - String query; + Database db; DbStatement* pStmt = null; + DbEnumerator* pEnum = null; + String query; + String* pAppId = 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())); + query.Format(1024, L"SELECT PkgInfo.PKG_ID FROM PkgInfo, AppInfo, DataControl WHERE DataControl.PROVIDER_ID = '%ls' and DataControl.ID = AppInfo.UNIQUE_ID and AppInfo.ID = PkgInfo.UNIQUE_ID", + providerId.GetPointer()); - 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)); - } + 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)); - 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)); - } + pStmt = CreateStatementN(db, query); + SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); - 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(db, pStmt); - pEnum = ExecuteStatementN(*__pDb, pStmt); + if (pEnum != null) + { + if (pEnum->MoveNext() == E_SUCCESS) + { + pAppId = new (std::nothrow) String; + SysTryReturn(NID_APP, pAppId != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Insufficient memory"); - query.Clear(); - delete pStmt; - pStmt = null; - delete pEnum; - } + pEnum->GetStringAt(0, *pAppId); } - } - r = GetLastResult(); + delete pEnum; + } CATCH: delete pStmt; - - return r; + return pAppId; } -result -_PackageManagerImpl::RegisterDataControlList(int id, ArrayList* pList) +PackageInfo* +_PackageManagerImpl::GetPackageInfoN(const String& providerId, const String& operationId) const { - SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null"); - result r = E_SUCCESS; - String query; + PackageInfo* pPkgInfo = null; + Database db; DbStatement* pStmt = null; + DbEnumerator* pEnum = null; + String query; - if (pList != null) - { - for (int i = 0; i < pList->GetCount(); i++) - { - _DataControlInfoImpl* pDataControl = dynamic_cast<_DataControlInfoImpl*>(pList->GetAt(i)); + 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()); - if (pDataControl != null) - { - DbEnumerator* pEnum = 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)); - String providerId = pDataControl->GetProviderId(); - ArrayList* pTypeList = pDataControl->GetControlTypeList(); + pStmt = CreateStatementN(db, query); + SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); - 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; - } - } - } - } + pEnum = ExecuteStatementN(db, pStmt); + if (pEnum != null) + { + if (pEnum->MoveNext() == E_SUCCESS) + { + PackageId packageId; + pEnum->GetStringAt(0, packageId); + + pPkgInfo = GetPackageInfoN(packageId); } - } - r = GetLastResult(); + delete pEnum; + } + else + { + r = E_OBJ_NOT_FOUND; + } CATCH: delete pStmt; - - return r; + return pPkgInfo; } -int -_PackageManagerImpl::FindRecord(const String& tableName, const String& columnName, const String& value) const +ArrayList* +_PackageManagerImpl::GetPackageAppInfoImplListN(const String& packageId) const { - result r = E_SUCCESS; Database db; - String query; DbStatement* pStmt = null; DbEnumerator* pEnum = null; - int uniqueId = 0; + 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)); - 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)); + pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPkgInfo); + query.Format(1024, L"SELECT * FROM AppInfo WHERE ID = %d", pPackageInfoImpl->GetUniqueId()); - query.Format(1024, L"SELECT * FROM %ls WHERE %ls = '%ls'", tableName.GetPointer(), columnName.GetPointer(), value.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())); + 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) + pList = new (std::nothrow) ArrayList; + SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure."); + + pList->Construct(); + + while (pEnum->MoveNext() == E_SUCCESS) { + _PackageAppInfoImpl* pPackageAppInfoImpl = new (std::nothrow) _PackageAppInfoImpl; + SysTryReturn(NID_APP, pPackageAppInfoImpl != null, null, E_OUT_OF_MEMORY, "pPackageAppInfoImpl instance must not be null."); + + int uniqueId = 0; + int pkgId = 0; + String name; + String defaultapp; + String mainmenuIcon; + String settingIcon; + String quickpanelIcon; + 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); + + pPackageAppInfoImpl->SetUniqueId(uniqueId); + pPackageAppInfoImpl->SetPkgId(pkgId); + pPackageAppInfoImpl->SetName(name); + pPackageAppInfoImpl->SetDefault(defaultapp); + pPackageAppInfoImpl->SetMainmenuIcon(mainmenuIcon); + pPackageAppInfoImpl->SetSettingIcon(settingIcon); + pPackageAppInfoImpl->SetQuickpanelIcon(quickpanelIcon); + pPackageAppInfoImpl->SetAppFeature(appFeature); + pPackageAppInfoImpl->SetPackageName(packageName); + + pList->Add(*pPackageAppInfoImpl); } delete pEnum; } -//CATCH: +CATCH: + delete pPkgInfo; delete pStmt; - - return uniqueId; + return pList; } -result -_PackageManagerImpl::GetRecord(const String& tableName, int uniqueId, const String& columnName, String& value) const +ArrayList* +_PackageManagerImpl::GetPackageAppFeatureListN(const PackageId& packageId, const Tizen::Base::String& appExecutableName) const { - result r = E_SUCCESS; - Database db; - String query; - DbStatement* pStmt = null; - DbEnumerator* pEnum = null; + ArrayList* pAppInfoList = GetPackageAppInfoImplListN(packageId); + SysTryReturn(NID_APP, pAppInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppInfo list instance must not be null."); + + ArrayList* pResult = null; - 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)); + for (int i = 0; i < pAppInfoList->GetCount(); i++) + { + const _PackageAppInfoImpl* pAppInfoImpl = static_cast(pAppInfoList->GetAt(i)); + if (pAppInfoImpl == null) + { + continue; + } - query.Format(1024, L"SELECT %ls FROM %ls WHERE UNIQUE_ID = %d", columnName.GetPointer(), tableName.GetPointer(), uniqueId); + if (pAppInfoImpl->GetName() == appExecutableName) + { + pResult = pAppInfoImpl->GetAppFeatureListN(); + goto OUT; + } + } - pStmt = CreateStatementN(db, query); - //SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); +OUT: + pAppInfoList->RemoveAll(true); + delete pAppInfoList; - pEnum = ExecuteStatementN(db, pStmt); + return pResult; +} - if (pEnum != null) +HashMapT* +_PackageManagerImpl::GetPackageAppFeatureMapN(const PackageId& packageId, const Tizen::Base::String& appExecutableName) const +{ + ArrayList* pAppInfoList = GetPackageAppInfoImplListN(packageId); + SysTryReturn(NID_APP, pAppInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] AppInfo list instance must not be null."); + + HashMapT* pResult = null; + + std::auto_ptr pEnum(pAppInfoList->GetEnumeratorN()); + + while (pEnum->MoveNext() == E_SUCCESS) { - if (pEnum->MoveNext() == E_SUCCESS) + const _PackageAppInfoImpl* pAppInfoImpl = static_cast(pEnum->GetCurrent()); + if (pAppInfoImpl == null) { - pEnum->GetStringAt(0, value); + continue; } - delete pEnum; + if (pAppInfoImpl->GetName() == appExecutableName) + { + pResult = pAppInfoImpl->GetAppFeatureMapN(); + goto OUT; + } } -//CATCH: - delete pStmt; +OUT: + pAppInfoList->RemoveAll(true); + delete pAppInfoList; - return r; + return pResult; } -result -_PackageManagerImpl::RegisterPrivileges(int id, const String& privileges, const String& hmacPrivileges, int certType) +ArrayList* +_PackageManagerImpl::GetAppLaunchConditionListN(const String& packageName) const { - SysTryReturnResult(NID_APP, __pDb != null, E_SYSTEM, "__pDb is null"); - result r = E_SUCCESS; - String query; + Database db; DbStatement* pStmt = null; DbEnumerator* pEnum = null; + String query; + ArrayList* pList = null; - query.Format(1024, L"INSERT INTO PkgPrivileges (ID, PRIVILEGES, HMAC_PPRIVILEGES, CERTIFICATE_TYPE) VALUES (?,?,?,?)"); + query.Format(1024, L"SELECT LaunchCondition.* FROM LaunchCondition, AppInfo WHERE AppInfo.UNIQUE_ID = LaunchCondition.ID and AppInfo.PACKAGE_NAME = '%ls'", packageName.GetPointer()); - pStmt = CreateStatementN(*__pDb, query); - SysTryCatch(NID_APP, pStmt != null, GetLastResult(), GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); + 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)); - 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)); - } + pStmt = CreateStatementN(db, query); + SysTryCatch(NID_APP, pStmt != null, GetLastResult(), + GetLastResult(), "[%s] An error occurs while creating a database statement.", GetErrorMessage(GetLastResult())); - if (!privileges.IsEmpty()) + pEnum = ExecuteStatementN(db, pStmt); + if (pEnum != null) { - r = pStmt->BindString(1, privileges); - SysTryCatch(NID_APP, r == E_SUCCESS, , r, "[%s] An error occurs while constructing a database.", GetErrorMessage(r)); - } + pList = new (std::nothrow) ArrayList; + SysTryReturn(NID_APP, pList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Container allocation failure."); - 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)); - } + pList->Construct(); - 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)); - } + while (pEnum->MoveNext() == E_SUCCESS) + { + _LaunchConditionInfoImpl* pLaunchCondtion = new (std::nothrow) _LaunchConditionInfoImpl; + SysTryReturn(NID_APP, pLaunchCondtion != null, null, E_OUT_OF_MEMORY, "pLaunchCondtion instance must not be null."); + + String name; + String value; + + pEnum->GetStringAt(1, name); + pEnum->GetStringAt(2, value); - pEnum = ExecuteStatementN(*__pDb, pStmt); + pLaunchCondtion->SetName(name); + pLaunchCondtion->SetValue(value); - delete pStmt; - pStmt = null; - delete pEnum; - pEnum = null; + pList->Add(*pLaunchCondtion); + + SysLog(NID_APP, "Name[%ls], Value[%ls]", name.GetPointer(), value.GetPointer()); + } - r = GetLastResult(); + delete pEnum; + } CATCH: delete pStmt; - return r; + return pList; } result @@ -2425,7 +1983,7 @@ _PackageManagerImpl::GetPackageName(const PackageId& packageId, const String* pN pName->GetPointer(), packageId.GetPointer()); } - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); + 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); @@ -2468,7 +2026,7 @@ _PackageManagerImpl::GetDefaultAppExecutableName(const PackageId& packageId) L"SELECT AppInfo.APP_NAME FROM AppInfo, PkgInfo WHERE AppInfo.ID = PkgInfo.UNIQUE_ID and AppInfo.APP_DEFAULT = '%s' and PkgInfo.PKG_ID = '%ls'", "True", packageId.GetPointer()); - r = db.Construct(PACKAGE_DATABASE_FILE_NAME, false); + 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);