From dc1f454886cc3e7300dad5896bb5aa06ceeebedb Mon Sep 17 00:00:00 2001 From: Soyoung Kim Date: Thu, 29 Nov 2012 14:58:42 +0900 Subject: [PATCH] Add installation to external location(sdcard) [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Add feature about installation to sdcard using app2sd. [SCMRequest] N/A Change-Id: I493b9764ce7492d63d9fcaef6a8caec3f01eea85 --- packaging/wrt-installer.spec | 1 + src/CMakeLists.txt | 2 + src/commons/wrt_common_types.h | 8 ++ src/jobs/widget_install/job_widget_install.cpp | 37 ++++- src/jobs/widget_install/job_widget_install.h | 2 + src/jobs/widget_install/task_commons.cpp | 1 - src/jobs/widget_install/task_file_manipulation.cpp | 152 +++++++++++++++++++-- src/jobs/widget_install/task_file_manipulation.h | 10 +- src/jobs/widget_install/widget_install_context.h | 1 + src/jobs/widget_install/widget_install_errors.h | 3 + src/jobs/widget_uninstall/job_widget_uninstall.cpp | 14 ++ src/jobs/widget_uninstall/job_widget_uninstall.h | 1 + src/jobs/widget_uninstall/task_remove_files.cpp | 20 ++- src/jobs/widget_uninstall/task_remove_files.h | 2 + src/jobs/widget_uninstall/uninstaller_context.h | 1 + src/misc/widget_install_to_external.cpp | 134 ++++++++++++++++++ src/misc/widget_install_to_external.h | 59 ++++++++ src/misc/widget_location.cpp | 12 +- src/misc/widget_location.h | 7 +- 19 files changed, 447 insertions(+), 20 deletions(-) create mode 100644 src/misc/widget_install_to_external.cpp create mode 100644 src/misc/widget_install_to_external.h diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 0399c06..fa8b6b6 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -36,6 +36,7 @@ BuildRequires: pkgconfig(shortcut) BuildRequires: pkgconfig(dpl-encryption) BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(drm-service-core-intel) +BuildRequires: pkgconfig(app2sd) Requires: xmlsec1 %description diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9cfd43e..b22683d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,6 +95,7 @@ SET(INSTALLER_SOURCES ${INSTALLER_SRC_DIR}/misc/feature_logic.cpp ${INSTALLER_SRC_DIR}/misc/libxml_utils.cpp ${INSTALLER_SRC_DIR}/misc/widget_location.cpp + ${INSTALLER_SRC_DIR}/misc/widget_install_to_external.cpp ${INSTALLER_SRC_DIR}/pkg-manager/pkgmgr_signal.cpp ) @@ -131,6 +132,7 @@ PKG_CHECK_MODULES(SYS_INSTALLER_STATIC_DEP shortcut capi-appfw-app-manager drm-service-core-intel + app2sd REQUIRED ) diff --git a/src/commons/wrt_common_types.h b/src/commons/wrt_common_types.h index 49b3100..4fe586f 100644 --- a/src/commons/wrt_common_types.h +++ b/src/commons/wrt_common_types.h @@ -38,4 +38,12 @@ typedef WrtDB::DbWidgetSize WidgetSize; typedef WrtDB::DbPluginHandle PluginHandle; +enum InstallLocationType +{ + INSTALL_LOCATION_TYPE_UNKNOWN = 0, + INSTALL_LOCATION_TYPE_NOMAL, + INSTALL_LOCATION_TYPE_PRELOAD, + INSTALL_LOCATION_TYPE_EXTERNAL +}; + #endif /* PLUGIN_COMMON_TYPES_H */ diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp index 5debb82..5867245 100644 --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -74,6 +74,7 @@ #include #include +#include using namespace WrtDB; @@ -87,6 +88,10 @@ const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}$"; static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption"; static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable"; +const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME = + L"install-location-type"; +const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT = + L"prefer-external"; class InstallerTaskFail : public DPL::TaskDecl @@ -300,6 +305,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation( m_installerContext.widgetConfig.packagingType.pkgType); WidgetUpdateInfo update = detectWidgetUpdate(configData); m_needEncryption = detectResourceEncryption(configData); + setInstallLocationType(configData); // Configure installation result = ConfigureInstallation(widgetPath, configData, update, tempDir); @@ -391,7 +397,7 @@ void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname), widgetPath, tempPath, m_installerContext.widgetConfig.packagingType, - m_jobStruct.m_preload); + m_installerContext.locationType); LogInfo("widgetSource " << widgetPath); } @@ -696,6 +702,13 @@ void JobWidgetInstall::SendFinishedSuccess() // TODO : sync should move to separate task. sync(); + if (false == m_installerContext.existingWidgetInfo.isExist) { + WidgetInstallToExtSingleton::Instance().postInstallation(true); + } else { + WidgetInstallToExtSingleton::Instance().postUpgrade(true); + } + WidgetInstallToExtSingleton::Instance().deinitialize(); + // remove widget install information file unlink(m_installerContext.installInfo.c_str()); @@ -894,6 +907,28 @@ bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &c return false; } +void JobWidgetInstall::setInstallLocationType(const + WrtDB::ConfigParserData &configData) +{ + m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL; + + if (true == m_jobStruct.m_preload) { + m_installerContext.locationType = + INSTALL_LOCATION_TYPE_PRELOAD; + } else { + FOREACH(it, configData.settingsList) + { + if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME && + it->m_value == + SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) { + LogDebug("This widget will be installed to sd card"); + m_installerContext.locationType = + INSTALL_LOCATION_TYPE_EXTERNAL; + } + } + } +} + bool JobWidgetInstall::isDRMWidget(std::string widgetPath) { /* TODO : diff --git a/src/jobs/widget_install/job_widget_install.h b/src/jobs/widget_install/job_widget_install.h index 550214c..1f81498 100644 --- a/src/jobs/widget_install/job_widget_install.h +++ b/src/jobs/widget_install/job_widget_install.h @@ -82,6 +82,8 @@ class JobWidgetInstall : const std::string &widgetSource, const std::string &tempPath); bool detectResourceEncryption(const WrtDB::ConfigParserData &configData); + void setInstallLocationType(const WrtDB::ConfigParserData + &configData); bool isDRMWidget(std::string widgetPath); bool DecryptDRMWidget(std::string widgetPath, std::string destPath); ConfigureResult PrePareInstallation(const std::string &widgetPath); diff --git a/src/jobs/widget_install/task_commons.cpp b/src/jobs/widget_install/task_commons.cpp index abf6623..fea9ea1 100644 --- a/src/jobs/widget_install/task_commons.cpp +++ b/src/jobs/widget_install/task_commons.cpp @@ -50,7 +50,6 @@ std::string createTempPath(bool preload) // Temporary path std::ostringstream tempPathBuilder; - //tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath(); if (preload) { tempPathBuilder << WrtDB::GlobalConfig::GetUserPreloadedWidgetPath(); } else { diff --git a/src/jobs/widget_install/task_file_manipulation.cpp b/src/jobs/widget_install/task_file_manipulation.cpp index bf06030..45e6224 100644 --- a/src/jobs/widget_install/task_file_manipulation.cpp +++ b/src/jobs/widget_install/task_file_manipulation.cpp @@ -20,6 +20,7 @@ * @brief Implementation file for installer task database updating */ #include +#include #include #include #include @@ -28,7 +29,10 @@ #include #include #include +#include #include +#include +#include #define WEBAPP_DEFAULT_UID 5000 #define WEBAPP_DEFAULT_GID 5000 @@ -40,20 +44,76 @@ const mode_t SHARE_MODE = 0705; using namespace WrtDB; +namespace { +const char* GLIST_RES_DIR = "res"; +const char* GLIST_BIN_DIR = "bin"; + +bool _FolderCopy(std::string source, std::string dest) +{ + DIR* dir = opendir(source.c_str()); + if (NULL == dir) { + return false; + } + + struct dirent* dEntry = NULL; + do { + struct stat statInfo; + if (dEntry = readdir(dir)) { + std::string fileName = dEntry->d_name; + std::string fullName = source + "/" + fileName; + + if (stat(fullName.c_str(), &statInfo) != 0) { + return false; + } + + if (S_ISDIR(statInfo.st_mode)) { + if(("." == fileName) || (".." == fileName)) { + continue; + } + std::string destFolder = dest + "/" + fileName; + WrtUtilMakeDir(destFolder); + + if (!_FolderCopy(fullName, destFolder)) { + return false; + } + } + + std::string destFile = dest + "/" + fileName; + std::ifstream infile(fullName); + std::ofstream outfile(destFile); + outfile << infile.rdbuf(); + outfile.close(); + infile.close(); + } + } while(dEntry); + return true; +} +} + namespace Jobs { namespace WidgetInstall { TaskFileManipulation::TaskFileManipulation(InstallerContext& context) : DPL::TaskDecl(this), m_context(context) { - AddStep(&TaskFileManipulation::StepCreateDirs); - AddStep(&TaskFileManipulation::StepCreatePrivateStorageDir); - AddStep(&TaskFileManipulation::StepCreateShareDir); - if (m_context.widgetConfig.packagingType != - WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) - { - AddStep(&TaskFileManipulation::StepRenamePath); - AddAbortStep(&TaskFileManipulation::StepAbortRenamePath); + if (INSTALL_LOCATION_TYPE_EXTERNAL != + m_context.locationType) { + AddStep(&TaskFileManipulation::StepCreateDirs); + AddStep(&TaskFileManipulation::StepCreatePrivateStorageDir); + AddStep(&TaskFileManipulation::StepCreateShareDir); + if (m_context.widgetConfig.packagingType != + WrtDB::PKG_TYPE_DIRECTORY_WEB_APP) + { + AddStep(&TaskFileManipulation::StepRenamePath); + AddAbortStep(&TaskFileManipulation::StepAbortRenamePath); + } + } else { + AddStep(&TaskFileManipulation::StepPrepareExternalDir); + AddStep(&TaskFileManipulation::StepInstallToExternal); + AddStep(&TaskFileManipulation::StepCreatePrivateStorageDir); + AddStep(&TaskFileManipulation::StepCreateShareDir); + + AddAbortStep(&TaskFileManipulation::StepAbortCreateExternalDir); } } @@ -221,5 +281,81 @@ void TaskFileManipulation::StepAbortRenamePath() } LogDebug("Rename widget path sucessful!"); } + +void TaskFileManipulation::StepPrepareExternalDir() +{ + LogDebug("Step prepare to install in exernal directory"); + Try { + std::string pkgname = + DPL::ToUTF8String(*m_context.widgetConfig.pkgname); + + WidgetInstallToExtSingleton::Instance().initialize(pkgname); + + size_t totalSize = + Utils::getFolderSize(m_context.locations->getTemporaryPackageDir()); + + int folderSize = (int)(totalSize / (1024 * 1024)) + 1; + + GList *list = NULL; + app2ext_dir_details* dirDetail = NULL; + + std::string dirNames[2] = {GLIST_RES_DIR, GLIST_BIN_DIR}; + + for (int i = 0; i < 2; i++) { + dirDetail = (app2ext_dir_details*) calloc(1, + sizeof(app2ext_dir_details)); + if (NULL == dirDetail) { + ThrowMsg(Exceptions::ErrorExternalInstallingFailure, "error in app2ext"); + } + dirDetail->name = strdup(dirNames[i].c_str()); + dirDetail->type = APP2EXT_DIR_RO; + list = g_list_append(list, dirDetail); + } + + if (false == m_context.existingWidgetInfo.isExist) { + WidgetInstallToExtSingleton::Instance().preInstallation(list, + folderSize); + } else { + WidgetInstallToExtSingleton::Instance().preUpgrade(list, + folderSize); + } + free(dirDetail); + g_list_free(list); + } + Catch (WidgetInstallToExt::Exception::ErrorInstallToExt) + { + ReThrowMsg(Exceptions::ErrorExternalInstallingFailure, "Error during \ + create external folder "); + } +} + +void TaskFileManipulation::StepInstallToExternal() +{ + LogDebug("StepInstallExternal"); + if (!WrtUtilMakeDir(m_context.locations->getSourceDir())) { + ThrowMsg(Exceptions::ErrorExternalInstallingFailure, "To make src \ + directory failed"); + } + + LogDebug("Resource move to external storage " << + m_context.locations->getSourceDir()); + if (!_FolderCopy(m_context.locations->getTemporaryPackageDir(), + m_context.locations->getSourceDir())) + { + ThrowMsg(Exceptions::UnknownError, + "Error occurs during renaming widget folder"); + } +} + +void TaskFileManipulation::StepAbortCreateExternalDir() +{ + LogError("Abort StepAbortCreateExternalDir"); + if (false == m_context.existingWidgetInfo.isExist) { + WidgetInstallToExtSingleton::Instance().postInstallation(false); + } else { + WidgetInstallToExtSingleton::Instance().postUpgrade(false); + } + WidgetInstallToExtSingleton::Instance().deinitialize(); +} } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/task_file_manipulation.h b/src/jobs/widget_install/task_file_manipulation.h index 9bdfe9c..e3f615e 100644 --- a/src/jobs/widget_install/task_file_manipulation.h +++ b/src/jobs/widget_install/task_file_manipulation.h @@ -23,6 +23,7 @@ #define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_FILE_MANIPULATION_UPDATE_H #include +#include class InstallerContext; @@ -31,9 +32,10 @@ namespace WidgetInstall { class TaskFileManipulation : public DPL::TaskDecl { - private: InstallerContext& m_context; + app2ext_handle *m_extHandle; + // install internal location void StepCreateDirs(); void StepRenamePath(); void StepCreatePrivateStorageDir(); @@ -41,6 +43,12 @@ class TaskFileManipulation : void StepAbortRenamePath(); + // install external location + void StepPrepareExternalDir(); + void StepInstallToExternal(); + void StepFinishExternalInstallation(); + void StepAbortCreateExternalDir(); + public: TaskFileManipulation(InstallerContext& context); }; diff --git a/src/jobs/widget_install/widget_install_context.h b/src/jobs/widget_install/widget_install_context.h index cc3e668..284cc1b 100755 --- a/src/jobs/widget_install/widget_install_context.h +++ b/src/jobs/widget_install/widget_install_context.h @@ -102,6 +102,7 @@ struct InstallerContext RequestedDevCapsMap staticPermittedDevCaps; std::string installInfo; /// bool m_quiet; + InstallLocationType locationType; }; #endif // INSTALLER_CONTEXT_H diff --git a/src/jobs/widget_install/widget_install_errors.h b/src/jobs/widget_install/widget_install_errors.h index 78480c2..30f260f 100644 --- a/src/jobs/widget_install/widget_install_errors.h +++ b/src/jobs/widget_install/widget_install_errors.h @@ -49,6 +49,7 @@ enum Type ErrorRemovingFolderFailure, ///< Failure in removing existing widget folder ErrorInstallOspServcie, ///< Failure in installing osp service ErrorUpdateWidget, ///< Failure in widget update. + ErrorInstallToExt, ///< Failure in install to sdcard ErrorUnknown ///< Temporary error. Try to not use this. }; @@ -83,6 +84,8 @@ DECLARE_JOB_EXCEPTION(Base, RemovingFolderFailure, ErrorRemovingFolderFailure) DECLARE_JOB_EXCEPTION(Base, CopyIconFailed, ErrorUnknown) +DECLARE_JOB_EXCEPTION(Base, ErrorExternalInstallingFailure, ErrorInstallToExt) + // Installation osp service DECLARE_JOB_EXCEPTION(Base, RequestInstallOspsvc, ErrorInstallOspServcie) DECLARE_JOB_EXCEPTION(Base, InstallOspsvcFailed, ErrorInstallOspServcie) diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.cpp b/src/jobs/widget_uninstall/job_widget_uninstall.cpp index 1310d38..e6153ff 100644 --- a/src/jobs/widget_uninstall/job_widget_uninstall.cpp +++ b/src/jobs/widget_uninstall/job_widget_uninstall.cpp @@ -23,6 +23,7 @@ #include #include #include +#include using namespace WrtDB; @@ -66,6 +67,7 @@ JobWidgetUninstall::JobWidgetUninstall(const std::string & widgetPkgName, m_context.uninstallStep = UninstallerContext::UNINSTALL_START; m_context.job = this; m_context.pkgname = widgetPkgName; + m_context.isExternalWidget = getExternalWidgetFlag(); Try { @@ -168,5 +170,17 @@ void JobWidgetUninstall::SaveExceptionData(const Jobs::JobExceptionBase &e) m_exceptionCaught = static_cast(e.getParam()); m_exceptionMessage = e.GetMessage(); } + +bool JobWidgetUninstall::getExternalWidgetFlag() const +{ + + LogDebug("Get external widget"); + if (APP2EXT_SD_CARD == app2ext_get_app_location(m_context.pkgname.c_str())) { + LogDebug("This widget is in external stroage"); + return true; + } + return false; +} + } //namespace WidgetUninstall } //namespace Jobs diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.h b/src/jobs/widget_uninstall/job_widget_uninstall.h index 98cd62c..80c188c 100644 --- a/src/jobs/widget_uninstall/job_widget_uninstall.h +++ b/src/jobs/widget_uninstall/job_widget_uninstall.h @@ -55,6 +55,7 @@ class JobWidgetUninstall : std::string getRemovedTizenId() const; bool getRemoveStartedFlag() const; bool getRemoveFinishedFlag() const; + bool getExternalWidgetFlag() const; void SendProgress(); void SendFinishedSuccess(); diff --git a/src/jobs/widget_uninstall/task_remove_files.cpp b/src/jobs/widget_uninstall/task_remove_files.cpp index 1bc1984..b7e49a3 100644 --- a/src/jobs/widget_uninstall/task_remove_files.cpp +++ b/src/jobs/widget_uninstall/task_remove_files.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace Jobs { namespace WidgetUninstall { @@ -41,7 +42,11 @@ TaskRemoveFiles::TaskRemoveFiles(UninstallerContext& context) : DPL::TaskDecl(this), m_context(context) { - AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory); + if (!m_context.isExternalWidget) { + AddStep(&TaskRemoveFiles::StepRemoveInstallationDirectory); + } else { + AddStep(&TaskRemoveFiles::StepRemoveExternalWidget); + } //AddStep(&TaskRemoveFiles::StepRemoveDesktop); AddStep(&TaskRemoveFiles::StepRemoveManifest); AddStep(&TaskRemoveFiles::StepRemoveExternalLocations); @@ -164,5 +169,18 @@ void TaskRemoveFiles::StepRemoveExternalLocations() dao.unregisterAllExternalLocations(); } +void TaskRemoveFiles::StepRemoveExternalWidget() +{ + Try { + WidgetInstallToExtSingleton::Instance().initialize(m_context.pkgname); + WidgetInstallToExtSingleton::Instance().uninstallation(); + WidgetInstallToExtSingleton::Instance().deinitialize(); + } + Catch (WidgetInstallToExt::Exception::ErrorInstallToExt) + { + Throw(Jobs::WidgetUninstall::TaskRemoveFiles::Exception::RemoveFilesFailed); + } +} + } //namespace WidgetUninstall } //namespace Jobs diff --git a/src/jobs/widget_uninstall/task_remove_files.h b/src/jobs/widget_uninstall/task_remove_files.h index 6959242..ebce154 100644 --- a/src/jobs/widget_uninstall/task_remove_files.h +++ b/src/jobs/widget_uninstall/task_remove_files.h @@ -52,6 +52,8 @@ class TaskRemoveFiles : void StepRemoveManifest(); void StepRemoveExternalLocations(); + void StepRemoveExternalWidget(); + public: explicit TaskRemoveFiles(UninstallerContext& context); virtual ~TaskRemoveFiles(); diff --git a/src/jobs/widget_uninstall/uninstaller_context.h b/src/jobs/widget_uninstall/uninstaller_context.h index 1aeb086..caedcb7 100644 --- a/src/jobs/widget_uninstall/uninstaller_context.h +++ b/src/jobs/widget_uninstall/uninstaller_context.h @@ -60,6 +60,7 @@ struct UninstallerContext UninstallStep uninstallStep; ///< current step of installation Jobs::WidgetUninstall::JobWidgetUninstall *job; std::string pkgname; + bool isExternalWidget; }; #endif // WRT_SRC_INSTALLER_CORE_UNINSTALLER_TASKS_UNINSTALLER_CONTEXT_H_ diff --git a/src/misc/widget_install_to_external.cpp b/src/misc/widget_install_to_external.cpp new file mode 100644 index 0000000..3751d60 --- /dev/null +++ b/src/misc/widget_install_to_external.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file widget_install_to_external.cpp + * @author Soyoung Kim (sy037.kim@smasung.com) + */ +#include "widget_install_to_external.h" + +#include +#include +#include + +IMPLEMENT_SAFE_SINGLETON(WidgetInstallToExt) + +WidgetInstallToExt::WidgetInstallToExt() : + m_handle(NULL), + m_appId("") +{ +} + +WidgetInstallToExt::~WidgetInstallToExt() +{ +} + +void WidgetInstallToExt::initialize(std::string appId) +{ + LogDebug("WidgetInstallToExt::initialize()"); + m_appId = appId; + + m_handle = app2ext_init(APP2EXT_SD_CARD); + if (NULL == m_handle) { + ThrowMsg(Exception::ErrorInstallToExt, "initialize failed"); + } +} + +void WidgetInstallToExt::deinitialize() +{ + LogDebug("WidgetInstallToExt::deinitialize()"); + if (NULL != m_handle) { + if ( 0 < app2ext_deinit(m_handle)) { + ThrowMsg(Exception::ErrorInstallToExt, "app2ext deinitialize \ + failed"); + } + } +} + +void WidgetInstallToExt::preInstallation(GList *dirList, int dSize) +{ + LogDebug("WidgetInstallToExt::preInstallation()"); + Assert(m_handle); + + int ret = m_handle->interface.pre_install(m_appId.c_str(), dirList, dSize); + + if (APP2EXT_SUCCESS == ret ) { + LogDebug("App2Ext pre install success"); + } else { + postInstallation(false); + ThrowMsg(Exception::ErrorInstallToExt, "pre-install failed"); + } +} + +void WidgetInstallToExt::postInstallation(bool status) +{ + LogDebug("WidgetInstallToExt::postInstallation()"); + Assert(m_handle); + + if (status) { + m_handle->interface.post_install(m_appId.c_str(), + APP2EXT_STATUS_SUCCESS); + } else { + m_handle->interface.post_install(m_appId.c_str(), + APP2EXT_STATUS_FAILED); + } +} + +void WidgetInstallToExt::preUpgrade(GList *dirList, int dSize) +{ + LogDebug("WidgetInstallToExt::preUpgrade()"); + Assert(m_handle); + + int ret = m_handle->interface.pre_upgrade(m_appId.c_str(), dirList, dSize); + if (APP2EXT_SUCCESS == ret ) { + LogDebug("App2Ext pre-upgrade success"); + } else { + postUpgrade(false); + ThrowMsg(Exception::ErrorInstallToExt, "pre-upgrade failed"); + } +} + +void WidgetInstallToExt::postUpgrade(bool status) +{ + LogDebug("WidgetInstallToExt::postUpgrade()"); + Assert(m_handle); + + if (status) { + m_handle->interface.post_upgrade(m_appId.c_str(), + APP2EXT_STATUS_SUCCESS); + } else { + m_handle->interface.post_upgrade(m_appId.c_str(), + APP2EXT_STATUS_FAILED); + } +} + +void WidgetInstallToExt::uninstallation() +{ + LogDebug("WidgetInstallToExt::uninstallation()"); + + Assert(m_handle); + + int ret = m_handle->interface.pre_uninstall(m_appId.c_str()); + if (APP2EXT_SUCCESS == ret ) { + if (APP2EXT_SUCCESS == + m_handle->interface.post_uninstall(m_appId.c_str())) { + LogDebug("App2Ext pre-uninstall success"); + } else { + ThrowMsg(Exception::ErrorInstallToExt, "post-uninstall failed"); + } + } else { + ThrowMsg(Exception::ErrorInstallToExt, "pre-uninstall failed"); + } +} diff --git a/src/misc/widget_install_to_external.h b/src/misc/widget_install_to_external.h new file mode 100644 index 0000000..9f71906 --- /dev/null +++ b/src/misc/widget_install_to_external.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file widget_install_to_external.h + * @author Soyoung Kim (sy037.kim@smasung.com) + */ +#ifndef WRT_INSTALLER_SRC_MISC_WIDGET_INSTALL_TO_EXTERNAL_H +#define WRT_INSTALLER_SRC_MISC_WIDGET_INSTALL_TO_EXTERNAL_H + +#include +#include +#include +#include + + +class WidgetInstallToExt +{ +public: + class Exception + { + public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(Base, ErrorInstallToExt) + }; + + void initialize(std::string appId); + void deinitialize(); + void preInstallation(GList* dirList, int dSize); + void postInstallation(bool status); + void preUpgrade(GList* dirList, int dSize); + void postUpgrade(bool status); + void uninstallation(); + +private: + app2ext_handle *m_handle; + std::string m_appId; + + WidgetInstallToExt(); + ~WidgetInstallToExt(); + + friend class DPL::Singleton; +}; + +typedef DPL::Singleton WidgetInstallToExtSingleton; + +#endif // WRT_INSTALLER_SRC_MISC_WIDGET_INSTALL_TO_EXTERNAL_H diff --git a/src/misc/widget_location.cpp b/src/misc/widget_location.cpp index 13c5a65..35a8026 100644 --- a/src/misc/widget_location.cpp +++ b/src/misc/widget_location.cpp @@ -68,16 +68,16 @@ WidgetLocation::~WidgetLocation() WidgetLocation::WidgetLocation(const std::string & widgetname, std::string sourcePath, WrtDB::PackagingType t, - bool preload): + InstallLocationType locationType): m_pkgname(widgetname), m_widgetSource(sourcePath), m_type(t), m_temp(new WidgetLocation::DirectoryDeletor()) { - if (preload) { - m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath(); - } else { + if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) { m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath(); + } else { + m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath(); } } @@ -85,14 +85,14 @@ WidgetLocation::WidgetLocation(const std::string & widgetname, std::string sourcePath, std::string dirPath, WrtDB::PackagingType t, - bool preload): + InstallLocationType locationType): m_pkgname(widgetname), m_widgetSource(sourcePath), m_type(t), m_temp(new WidgetLocation::DirectoryDeletor(dirPath)) { - if (preload) { + if (INSTALL_LOCATION_TYPE_PRELOAD == locationType) { m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath(); } else { m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath(); diff --git a/src/misc/widget_location.h b/src/misc/widget_location.h index 5698fc0..e04c3dd 100644 --- a/src/misc/widget_location.h +++ b/src/misc/widget_location.h @@ -25,6 +25,7 @@ #include #include +#include /** * @brief The WidgetLocation class @@ -93,12 +94,14 @@ public: */ WidgetLocation(const std::string & widgetname, std::string sourcePath, WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP, - bool preload = false); + InstallLocationType ltype = + INSTALL_LOCATION_TYPE_NOMAL); WidgetLocation(const std::string & widgetname, std::string sourcePath, std::string dirPath, WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP, - bool preload = false); + InstallLocationType ltype = + INSTALL_LOCATION_TYPE_NOMAL); ~WidgetLocation(); -- 2.7.4