enum InstallLocationType
{
INSTALL_LOCATION_TYPE_UNKNOWN = 0,
- INSTALL_LOCATION_TYPE_NOMAL,
- INSTALL_LOCATION_TYPE_EXTERNAL
+ INSTALL_LOCATION_TYPE_INTERNAL_ONLY,
+ INSTALL_LOCATION_TYPE_AUTO,
+ INSTALL_LOCATION_TYPE_PREFER_EXTERNAL,
};
#endif /* PLUGIN_COMMON_TYPES_H */
// TODO : sync should move to separate task.
sync();
- if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
+ if (INSTALL_LOCATION_TYPE_PREFER_EXTERNAL == m_installerContext.locationType) {
if (m_installerContext.isUpdateMode) {
WidgetInstallToExtSingleton::Instance().postUpgrade(true);
} else {
void TaskConfiguration::EndStep()
{
+ m_context.job->UpdateProgress(InstallerContext::INSTALL_PARSE_CONFIG,
+ "Parse config.xml and set structure");
_D("--------- <TaskConfiguration> : END ----------");
}
if (m_context.mode.extension != InstallMode::ExtensionType::DIR) {
if(!hasExtension(m_context.requestedPath, XML_EXTENSION)) //unzip everything except xml files
{
- WidgetUnzip wgtUnzip;
- wgtUnzip.unzipConfiguration(m_context.requestedPath, m_tempDir,
- &m_context.widgetConfig.packagingType);
+ WidgetUnzip wgtUnzip(m_context.requestedPath);
+ wgtUnzip.unzipConfiguration(m_tempDir, &m_context.widgetConfig.packagingType);
m_configuration += m_tempDir + "/" + CONFIG_XML;
} else{
m_context.widgetConfig.packagingType = PKG_TYPE_HOSTED_WEB_APP;
}
}
-bool TaskConfiguration::getMMCStatus()
-{
- int mmcStatus;
- if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus)) {
- _E("vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
- return false;
- }
-
- switch(mmcStatus)
- {
- case VCONFKEY_SYSMAN_MMC_MOUNTED:
- _D("mmcStatus is MMC_MOUNTED.");
- return true;
- case VCONFKEY_SYSMAN_MMC_REMOVED:
- case VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED:
- _D("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
- return false;
- default:
- _E("Platform is not supported, use the default settings");
- return false;
- }
-}
-
-bool TaskConfiguration::getDefaultExternalStorage()
-{
- // XXX NOT IMPLEMENTED.
- return false;
-}
-
void TaskConfiguration::InstallationFSLocationStep()
{
- m_context.locationType = INSTALL_LOCATION_TYPE_NOMAL;
- DPL::String locationValue;
-
if (m_context.mode.installTime != InstallMode::InstallTime::PRELOAD) {
FOREACH(it, m_widgetConfig.settingsList) {
if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME) {
- locationValue = it->m_value;
+ if (it->m_value == SETTING_VALUE_INSTALLTOEXT_AUTO) {
+ m_context.locationType = INSTALL_LOCATION_TYPE_AUTO;
+ } else if (it->m_value == SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
+ m_context.locationType =
+ INSTALL_LOCATION_TYPE_PREFER_EXTERNAL;
+ } else {
+ m_context.locationType =
+ INSTALL_LOCATION_TYPE_INTERNAL_ONLY;
+ }
break;
}
}
-
- if ((SETTING_VALUE_INSTALLTOEXT_PREPER_EXT == locationValue
- && getMMCStatus()) ||
- (SETTING_VALUE_INSTALLTOEXT_AUTO == locationValue
- && getDefaultExternalStorage())) {
- _D("This webapp will be installed to sd card");
- m_context.locationType = INSTALL_LOCATION_TYPE_EXTERNAL;
- }
}
}
#include <unistd.h>
#include <sys/stat.h>
#include <dirent.h>
+#include <string>
+#include <fstream>
+#include <vconf.h>
+
#include <widget_install/task_file_manipulation.h>
#include <widget_install/job_widget_install.h>
#include <widget_install/widget_install_errors.h>
#include <dpl/errno_string.h>
#include <dpl/utils/folder_size.h>
#include <dpl/wrt-dao-ro/global_config.h>
-#include <string>
-#include <fstream>
+
#include <widget_install_to_external.h>
#include <installer_log.h>
#include <widget_unzip.h>
m_extHandle(NULL)
{
AddStep(&TaskFileManipulation::StartStep);
- if (INSTALL_LOCATION_TYPE_EXTERNAL !=
- m_context.locationType)
+ AddStep(&TaskFileManipulation::StepCheckInstallLocation);
+ AddStep(&TaskFileManipulation::StepPrepareRootDirectory);
+ if (m_context.mode.extension != InstallMode::ExtensionType::DIR)
{
- AddStep(&TaskFileManipulation::StepCreateDirs);
- if (m_context.mode.extension != InstallMode::ExtensionType::DIR)
- {
- AddStep(&TaskFileManipulation::StepUnzipWgtFile);
- AddAbortStep(&TaskFileManipulation::StepAbortRenamePath);
- }
- } else {
- AddStep(&TaskFileManipulation::StepPrepareExternalDir);
- AddStep(&TaskFileManipulation::StepInstallToExternal);
-
- AddAbortStep(&TaskFileManipulation::StepAbortCreateExternalDir);
+ AddStep(&TaskFileManipulation::StepUnzipWgtFile);
}
AddStep(&TaskFileManipulation::EndStep);
+
+ AddAbortStep(&TaskFileManipulation::StepAbortPrepareRootDirectory);
}
-void TaskFileManipulation::StepCreateDirs()
+void TaskFileManipulation::StepCheckInstallLocation()
{
- std::string widgetPath;
+ _D("StepCheckInstallLocation");
+ if (m_context.mode.rootPath == InstallMode::RootPath::RO) {
+ m_context.locationType = INSTALL_LOCATION_TYPE_INTERNAL_ONLY;
+ return;
+ }
- widgetPath = m_context.locations->getPackageInstallationDir();
+ std::string installedPath = WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
+ WidgetUnzip wgtUnzip(m_context.requestedPath);
+
+ if (m_context.locationType == INSTALL_LOCATION_TYPE_AUTO) {
+ int storage = 0;
+ // vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT)
+ // 0 : phone internal memory
+ // 1 : SD card
+ if (vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
+ &storage)) {
+ _E("vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT) \
+ failed.");
+ }
+ _D("default setting : storage [%d]", storage);
+ if (storage) {
+ m_context.locationType = INSTALL_LOCATION_TYPE_PREFER_EXTERNAL;
+ } else {
+ m_context.locationType = INSTALL_LOCATION_TYPE_INTERNAL_ONLY;
+ if(!wgtUnzip.checkAvailableSpace(installedPath)) {
+ m_context.locationType = INSTALL_LOCATION_TYPE_PREFER_EXTERNAL;
+ }
+ }
+ }
- std::string widgetBinPath = m_context.locations->getBinaryDir();
- std::string widgetSrcPath = m_context.locations->getSourceDir();
+ if (m_context.locationType == INSTALL_LOCATION_TYPE_PREFER_EXTERNAL) {
+ int mmcStatus;
+ if (vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmcStatus)) {
+ _E("vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) failed.");
+ mmcStatus = VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED;
+ }
+
+ if (VCONFKEY_SYSMAN_MMC_MOUNTED != mmcStatus) {
+ _D("mmcStatus is MMC_REMOVED or NOT_MOUNTED.");
+ m_context.locationType = INSTALL_LOCATION_TYPE_INTERNAL_ONLY;
+ }
+ }
- WrtUtilMakeDir(widgetPath);
+ if (m_context.locationType == INSTALL_LOCATION_TYPE_INTERNAL_ONLY) {
+ if(!wgtUnzip.checkAvailableSpace(installedPath)) {
+ ThrowMsg(Exceptions::OutOfStorageFailed, "There is no space for installation");
+ }
+ }
+}
- // If package type is widget with osp service, we don't need to make bin
- // and src directory
- if (m_context.widgetConfig.packagingType == PKG_TYPE_HYBRID_WEB_APP) {
- _D("Doesn't need to create resource directory");
+void TaskFileManipulation::StepPrepareRootDirectory()
+{
+ if (m_context.locationType == INSTALL_LOCATION_TYPE_PREFER_EXTERNAL) {
+ prepareExternalDir();
} else {
+ std::string widgetPath = m_context.locations->getPackageInstallationDir();
+ std::string widgetBinPath = m_context.locations->getBinaryDir();
+ std::string widgetSrcPath = m_context.locations->getSourceDir();
+
+ WrtUtilMakeDir(widgetPath);
+
_D("Create resource directory");
WrtUtilMakeDir(widgetBinPath);
WrtUtilMakeDir(widgetSrcPath);
_D("unzip file to %s", instDir.c_str());
- WidgetUnzip wgtUnzip;
- wgtUnzip.unzipWgtFile(m_context.requestedPath, instDir);
+ WidgetUnzip wgtUnzip(m_context.requestedPath);
+ wgtUnzip.unzipWgtFile(instDir);
} else {
_D("From browser installation - unzip is not done");
}
m_context.job->UpdateProgress(
InstallerContext::INSTALL_UNZIP_WGT,
- "Unzip WGT File");
+ "Unzip Wgt file");
}
-/* TODO : modify name */
-void TaskFileManipulation::StepAbortRenamePath()
+void TaskFileManipulation::StepAbortPrepareRootDirectory()
{
- _D("[Rename Widget Path] Aborting.... (Rename path)");
- std::string widgetPath;
- widgetPath = m_context.locations->getPackageInstallationDir();
- if (!WrtUtilRemove(widgetPath)) {
- _E("Error occurs during removing existing folder");
- }
- // Remove user data directory if preload web app.
- std::string userData = m_context.locations->getUserDataRootDir();
- if (0 == access(userData.c_str(), F_OK)) {
- if (!WrtUtilRemove(userData)) {
- _E("Error occurs during removing user data directory");
+ _D("[Create Root Directory] Aborting.... (Rename path)");
+ if (m_context.locationType == INSTALL_LOCATION_TYPE_PREFER_EXTERNAL) {
+ if (m_context.isUpdateMode) {
+ WidgetInstallToExtSingleton::Instance().postUpgrade(false);
+ } else {
+ WidgetInstallToExtSingleton::Instance().postInstallation(false);
+ }
+ WidgetInstallToExtSingleton::Instance().deinitialize();
+ } else {
+ std::string widgetPath;
+ widgetPath = m_context.locations->getPackageInstallationDir();
+ if (!WrtUtilRemove(widgetPath)) {
+ _E("Error occurs during removing existing folder");
+ }
+ // Remove user data directory if preload web app.
+ std::string userData = m_context.locations->getUserDataRootDir();
+ if (0 == access(userData.c_str(), F_OK)) {
+ if (!WrtUtilRemove(userData)) {
+ _E("Error occurs during removing user data directory");
+ }
}
}
-
- _D("Rename widget path sucessful!");
}
-void TaskFileManipulation::StepPrepareExternalDir()
+void TaskFileManipulation::prepareExternalDir()
{
_D("Step prepare to install in exernal directory");
Try {
WidgetInstallToExtSingleton::Instance().initialize(pkgid);
- size_t totalSize =
- Utils::getFolderSize(m_context.locations->getTemporaryPackageDir());
-
- int folderSize = (int)(totalSize / (1024 * 1024)) + 1;
+ std::unique_ptr<DPL::ZipInput> zipFile(new
+ DPL::ZipInput(m_context.requestedPath));
+ double unzipSize = zipFile->GetTotalUncompressedSize();
+ int folderSize = (int)(unzipSize / (1024 * 1024)) + 1;
GList *list = NULL;
app2ext_dir_details* dirDetail = NULL;
/* make bin directory */
std::string widgetBinPath = m_context.locations->getBinaryDir();
WrtUtilMakeDir(widgetBinPath);
+ std::string sourceDir = m_context.locations->getSourceDir();
+ WrtUtilMakeDir(sourceDir);
}
- Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
- {
+ Catch(DPL::ZipInput::Exception::OpenFailed) {
ReThrowMsg(Exceptions::ErrorExternalInstallingFailure,
"Error during \
create external folder ");
}
-}
-
-void TaskFileManipulation::StepInstallToExternal()
-{
- _D("StepInstallExternal");
- if (!WrtUtilMakeDir(m_context.locations->getSourceDir())) {
- ThrowMsg(Exceptions::ErrorExternalInstallingFailure,
- "To make src \
- directory failed");
- }
-
- _D("Resource move to external storage %s", m_context.locations->getSourceDir().c_str());
- if (!_FolderCopy(m_context.locations->getTemporaryPackageDir(),
- m_context.locations->getSourceDir()))
+ Catch(WidgetInstallToExt::Exception::ErrorInstallToExt)
{
- ThrowMsg(Exceptions::ErrorExternalInstallingFailure,
- "Error occurs during renaming widget folder");
- }
-}
-
-void TaskFileManipulation::StepAbortCreateExternalDir()
-{
- _E("Abort StepAbortCreateExternalDir");
- if (m_context.isUpdateMode) {
- WidgetInstallToExtSingleton::Instance().postUpgrade(false);
- } else {
- WidgetInstallToExtSingleton::Instance().postInstallation(false);
+ ReThrowMsg(Exceptions::ErrorExternalInstallingFailure,
+ "Error during create external folder ");
}
- WidgetInstallToExtSingleton::Instance().deinitialize();
}
void TaskFileManipulation::StartStep()
app2ext_handle *m_extHandle;
// install internal location
- void StepCreateDirs();
+ void StepCheckInstallLocation();
+ void StepPrepareRootDirectory();
void StepUnzipWgtFile();
-
- void StepAbortRenamePath();
-
- // install external location
- void StepPrepareExternalDir();
- void StepInstallToExternal();
- void StepFinishExternalInstallation();
- void StepAbortCreateExternalDir();
-
+ void StepAbortPrepareRootDirectory();
+ void StepLinkForPreload();
void StartStep();
void EndStep();
+ // install external location
+ void prepareExternalDir();
+
public:
TaskFileManipulation(InstallerContext& context);
};
typedef enum InstallStepEnum
{
INSTALL_START = 0,
+ INSTALL_PARSE_CONFIG,
INSTALL_CHECK_FILE,
INSTALL_RDS_DELTA_CHECK,
namespace Jobs {
namespace WidgetInstall {
+
+WidgetUnzip::WidgetUnzip(const std::string &source)
+{
+ Try {
+ m_requestFile = getDecryptedPackage(source);
+ m_zip.reset(new DPL::ZipInput(m_requestFile));
+ }
+ Catch(DPL::ZipInput::Exception::OpenFailed)
+ {
+ ReThrowMsg(Exceptions::OpenZipFailed, source);
+ }
+ Catch(Exceptions::DrmDecryptFailed)
+ {
+ ReThrowMsg(Exceptions::ExtractFileFailed, source);
+ }
+}
+
void WidgetUnzip::ExtractFile(DPL::ZipInput::File *input,
const std::string &destFileName)
{
return source;
}
-void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &destination)
+void WidgetUnzip::unzipWgtFile(const std::string &destination)
{
_D("Prepare to unzip...");
- std::string wgtFile;
Try
{
- wgtFile = getDecryptedPackage(source);
- _D("wgtFile : %s", wgtFile.c_str());
-
- m_zip.reset(new DPL::ZipInput(wgtFile));
+ _D("wgtFile : %s", m_requestFile.c_str());
_D("Widget package comment: %s", m_zip->GetGlobalComment().c_str());
-
// Widget package must not be empty
if (m_zip->empty()) {
- ThrowMsg(Exceptions::ZipEmpty, wgtFile);
+ ThrowMsg(Exceptions::ZipEmpty, m_requestFile);
}
- checkAvailableSpace(destination);
-
// Set iterator to first file
m_zipIterator = m_zip->begin();
}
Catch(DPL::ZipInput::Exception::OpenFailed)
{
- ReThrowMsg(Exceptions::OpenZipFailed, wgtFile);
+ ReThrowMsg(Exceptions::OpenZipFailed, m_requestFile);
}
Catch(DPL::ZipInput::Exception::SeekFileFailed)
{
- ThrowMsg(Exceptions::ExtractFileFailed, wgtFile);
+ ThrowMsg(Exceptions::ExtractFileFailed, m_requestFile);
}
Catch(Exceptions::DrmDecryptFailed)
{
- ReThrowMsg(Exceptions::ExtractFileFailed, wgtFile);
+ ReThrowMsg(Exceptions::ExtractFileFailed, m_requestFile);
}
}
-void WidgetUnzip::checkAvailableSpace(const std::string &destination)
+bool WidgetUnzip::checkAvailableSpace(const std::string &destination)
{
_D("checkAvailableSpace ... ");
struct statvfs vfs;
if (-1 == statvfs(destination.c_str(), &vfs)) {
- ThrowMsg(Exceptions::OutOfStorageFailed, "There is no space for installation");
+ _E("There is no space for installation");
+ return false;
}
double freeSize = (double)vfs.f_bsize * vfs.f_bavail;
_D("Space Size : %ld", freeSize);
if (unCompressedSize + SPACE_SIZE >= freeSize) {
- ThrowMsg(Exceptions::OutOfStorageFailed, "There is no space for installation");
+ _E("There is no space for installation");
+ return false;
}
+ return true;
}
-void WidgetUnzip::unzipConfiguration(const std::string &source,
- const std::string &destination, WrtDB::PackagingType* type)
+void WidgetUnzip::unzipConfiguration(const std::string &destination,
+ WrtDB::PackagingType* type)
{
_D("unzipConfiguration");
Try {
- std::string wgtFile = getDecryptedPackage(source);
- _D("wgtFile : %s", wgtFile.c_str());
-
- std::unique_ptr<DPL::ZipInput> zipFile(new DPL::ZipInput(source));
+ _D("wgtFile : %s", m_requestFile.c_str());
std::unique_ptr<DPL::ZipInput::File> configFile;
Try {
- configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
+ configFile.reset(m_zip->OpenFile(HYBRID_CONFIG_XML));
*type = PKG_TYPE_HYBRID_WEB_APP;
} Catch(DPL::ZipInput::Exception::OpenFileFailed) {
- configFile.reset(zipFile->OpenFile(WEB_APP_CONFIG_XML));
+ configFile.reset(m_zip->OpenFile(WEB_APP_CONFIG_XML));
*type = PKG_TYPE_NOMAL_WEB_APP;
}
}
Catch(DPL::ZipInput::Exception::OpenFailed)
{
- ReThrowMsg(Exceptions::OpenZipFailed, source);
+ ReThrowMsg(Exceptions::OpenZipFailed, m_requestFile);
}
Catch(DPL::ZipInput::Exception::OpenFileFailed)
{
}
Catch(Exceptions::DrmDecryptFailed)
{
- ReThrowMsg(Exceptions::ExtractFileFailed, source);
+ ReThrowMsg(Exceptions::ExtractFileFailed, m_requestFile);
}
}
class WidgetUnzip
{
public:
- void unzipWgtFile(const std::string &source, const std::string &destination);
- void unzipConfiguration(const std::string &source, const std::string
- &destination, WrtDB::PackagingType *type);
+ WidgetUnzip(const std::string &source);
+ void unzipWgtFile(const std::string &destination);
+ void unzipConfiguration(const std::string &destination, WrtDB::PackagingType *type);
+ bool checkAvailableSpace(const std::string &destination);
private:
// Unzip state
std::unique_ptr<DPL::ZipInput> m_zip;
DPL::ZipInput::const_iterator m_zipIterator;
+ std::string m_requestFile;
void unzipProgress(const std::string &destination);
void ExtractFile(DPL::ZipInput::File *input, const std::string
bool decryptDRMPackage(const std::string &source, const std::string
&decryptedSource);
std::string getDecryptedPackage(const std::string &source);
- void checkAvailableSpace(const std::string &destination);
};
} //namespace WidgetInstall