2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file job_widget_install.cpp
18 * @author Radoslaw Wicik r.wicik@samsung.com
19 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
21 * @brief Implementation file for main installer task
31 #include <dpl/noncopyable.h>
32 #include <dpl/abstract_waitable_input_adapter.h>
33 #include <dpl/abstract_waitable_output_adapter.h>
34 #include <dpl/zip_input.h>
35 #include <dpl/binary_queue.h>
37 #include <dpl/assert.h>
38 #include <dpl/sstream.h>
39 #include <dpl/file_input.h>
40 #include <dpl/utils/wrt_utility.h>
41 #include <dpl/wrt-dao-ro/common_dao_types.h>
42 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
43 #include <dpl/wrt-dao-ro/global_config.h>
44 #include <dpl/wrt-dao-ro/config_parser_data.h>
45 #include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
46 #include <dpl/localization/w3c_file_localization.h>
48 #include <libiriwrapper.h>
49 #include <pkg-manager/pkgmgr_signal.h>
50 #include <app_manager.h>
52 #include "root_parser.h"
53 #include "widget_parser.h"
54 #include "parser_runner.h"
55 #include <widget_install/job_widget_install.h>
56 #include <widget_install/task_certify.h>
57 #include <widget_install/task_widget_config.h>
58 #include <widget_install/task_file_manipulation.h>
59 #include <widget_install/task_ace_check.h>
60 #include <widget_install/task_smack.h>
61 #include <widget_install/task_manifest_file.h>
62 #include <widget_install/task_prepare_files.h>
63 #include <widget_install/task_recovery.h>
64 #include <widget_install/task_install_ospsvc.h>
65 #include <widget_install/task_update_files.h>
66 #include <widget_install/task_database.h>
67 #include <widget_install/task_remove_backup.h>
68 #include <widget_install/task_encrypt_resource.h>
69 #include <widget_install/task_certificates.h>
70 #include <widget_install/task_unzip.h>
71 #include <widget_install/task_commons.h>
72 #include <widget_install/task_prepare_reinstall.h>
74 #include <widget_install/widget_install_errors.h>
75 #include <widget_install/widget_install_context.h>
76 #include <widget_install_to_external.h>
78 using namespace WrtDB;
79 using namespace Jobs::Exceptions;
81 namespace // anonymous
83 const char * const CONFIG_XML = "config.xml";
84 const char * const WITH_OSP_XML = "res/wgt/config.xml";
86 //allowed: a-z, A-Z, 0-9
87 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
88 const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
89 const size_t PACKAGE_ID_LENGTH = 10;
91 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
92 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
93 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
95 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
98 const std::string XML_EXTENSION = ".xml";
100 bool hasExtension(const std::string& filename, const std::string& extension)
102 LogDebug("Looking for extension " << extension << " in: " << filename);
103 size_t fileLen = filename.length();
104 size_t extLen = extension.length();
105 if (fileLen < extLen) {
106 LogError("Filename " << filename << " is shorter than extension "
110 return (0 == filename.compare(fileLen - extLen, extLen, extension));
112 } // namespace anonymous
115 namespace WidgetInstall {
116 class InstallerTaskFail :
117 public DPL::TaskDecl<InstallerTaskFail>
120 ConfigureResult m_result;
124 if (m_result == ConfigureResult::Deferred) {
125 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
126 "widget installation or update deferred!");
127 } else if (m_result == ConfigureResult::Failed_InvalidConfig) {
128 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid,
130 } else if (m_result == ConfigureResult::Failed_LowerVersion) {
131 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageLowerVersion,
132 "package version is lower than installed version");
133 } else if (m_result == ConfigureResult::Failed_AlreadyInstalled) {
134 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageAlreadyInstalled,
135 "package is already installed");
136 } else if (m_result == ConfigureResult::Failed_WidgetRunning) {
137 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
138 "widget is running");
139 } else if (m_result == ConfigureResult::Failed_DrmError) {
140 ThrowMsg(Jobs::WidgetInstall::Exceptions::DRMFailed,
143 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
144 "widget installation or update not allowed!");
149 InstallerTaskFail(ConfigureResult result) :
150 DPL::TaskDecl<InstallerTaskFail>(this),
153 AddStep(&InstallerTaskFail::StepFail);
157 JobWidgetInstall::JobWidgetInstall(
158 std::string const &widgetPath,
159 const WidgetInstallationStruct &
162 JobContextBase<WidgetInstallationStruct>(installerStruct),
163 m_exceptionCaught(Jobs::Exceptions::Success)
165 m_installerContext.m_quiet = m_jobStruct.m_quiet;
167 ConfigureResult result = PrePareInstallation(widgetPath);
169 if (result == ConfigureResult::Ok) {
170 LogInfo("Configure installation succeeded");
171 m_installerContext.job->SetProgressFlag(true);
173 AddTask(new TaskRecovery(m_installerContext));
175 // Create installation tasks
176 if (m_installerContext.widgetConfig.packagingType !=
177 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
178 m_installerContext.widgetConfig.packagingType !=
179 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
182 AddTask(new TaskUnzip(m_installerContext));
185 AddTask(new TaskWidgetConfig(m_installerContext));
186 if (m_installerContext.widgetConfig.packagingType ==
187 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
189 AddTask(new TaskPrepareFiles(m_installerContext));
191 AddTask(new TaskCertify(m_installerContext));
192 if (m_needEncryption) {
193 AddTask(new TaskEncryptResource(m_installerContext));
196 AddTask(new TaskFileManipulation(m_installerContext));
197 // TODO: Update progress information for this task
199 //This is sort of quick solution, because ACE verdicts are based upon
200 //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
202 AddTask(new TaskSmack(m_installerContext));
204 AddTask(new TaskManifestFile(m_installerContext));
205 if (m_installerContext.widgetConfig.packagingType ==
206 PKG_TYPE_HYBRID_WEB_APP)
208 AddTask(new TaskInstallOspsvc(m_installerContext));
210 AddTask(new TaskCertificates(m_installerContext));
211 AddTask(new TaskDatabase(m_installerContext));
212 AddTask(new TaskAceCheck(m_installerContext));
213 } else if (result == ConfigureResult::Updated) {
214 LogInfo("Configure installation updated");
215 LogInfo("Widget Update");
216 m_installerContext.job->SetProgressFlag(true);
218 if (m_jobStruct.m_installMode ==
219 InstallMode::REINSTALL_MODE_DIRECTORY)
221 AddTask(new TaskPrepareReinstall(m_installerContext));
224 if (m_installerContext.widgetConfig.packagingType !=
225 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
226 m_installerContext.widgetConfig.packagingType !=
227 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
230 AddTask(new TaskUnzip(m_installerContext));
233 AddTask(new TaskWidgetConfig(m_installerContext));
235 if (m_installerContext.widgetConfig.packagingType ==
236 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
238 AddTask(new TaskPrepareFiles(m_installerContext));
241 AddTask(new TaskCertify(m_installerContext));
242 if (m_needEncryption) {
243 AddTask(new TaskEncryptResource(m_installerContext));
246 if (m_installerContext.widgetConfig.packagingType !=
247 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
249 AddTask(new TaskUpdateFiles(m_installerContext));
252 /* TODO : To backup file, save md5 values */
253 AddTask(new TaskSmack(m_installerContext));
255 AddTask(new TaskManifestFile(m_installerContext));
256 if (m_installerContext.widgetConfig.packagingType ==
257 PKG_TYPE_HYBRID_WEB_APP)
259 AddTask(new TaskInstallOspsvc(m_installerContext));
261 if (m_installerContext.widgetConfig.packagingType !=
262 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
264 AddTask(new TaskRemoveBackupFiles(m_installerContext));
266 AddTask(new TaskDatabase(m_installerContext));
267 AddTask(new TaskAceCheck(m_installerContext));
268 //TODO: remove widgetHandle from this task and move before database task
269 // by now widget handle is needed in ace check
270 // Any error in acecheck while update will break widget
271 } else if (result == ConfigureResult::Deferred) {
272 // Installation is deferred
273 LogInfo("Configure installation deferred");
275 AddTask(new InstallerTaskFail(result));
276 } else if (result >= ConfigureResult::Failed &&
277 result <= ConfigureResult::Failed_DrmError) {
278 // Installation is not allowed to proceed due to widget update policy
279 LogWarning("Configure installation failed!");
281 AddTask(new InstallerTaskFail(result));
283 Assert(false && "Invalid configure result!");
287 ConfigureResult JobWidgetInstall::PrePareInstallation(
288 const std::string &widgetPath)
290 ConfigureResult result;
291 m_needEncryption = false;
296 if (m_jobStruct.m_installMode ==
297 InstallMode::REINSTALL_MODE_DIRECTORY)
299 std::ostringstream tempPathBuilder;
300 tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
301 tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
302 tempPathBuilder << "/";
303 tempPathBuilder << widgetPath;
304 tempDir = tempPathBuilder.str();;
307 Jobs::WidgetInstall::createTempPath(
308 m_jobStruct.m_installMode ==
309 InstallMode::INSTALL_MODE_PRELOAD);
312 m_isDRM = isDRMWidget(widgetPath);
313 if (true == m_isDRM) {
314 LogDebug("decrypt DRM widget");
315 if (DecryptDRMWidget(widgetPath, tempDir)) {
316 LogDebug("Failed decrypt DRM widget");
317 return ConfigureResult::Failed_DrmError;
321 LogDebug("widgetPath:" << widgetPath);
323 m_installerContext.widgetConfig.packagingType =
324 checkPackageType(widgetPath, tempDir);
325 ConfigParserData configData = getWidgetDataFromXML(
328 m_installerContext.widgetConfig.packagingType,
330 m_jobStruct.m_installMode ==
331 InstallMode::REINSTALL_MODE_DIRECTORY);
332 LogDebug("widget packaging type : " <<
333 m_installerContext.widgetConfig.packagingType.pkgType);
335 setTizenId(configData);
336 setApplicationType(configData);
337 m_needEncryption = detectResourceEncryption(configData);
338 setInstallLocationType(configData);
340 // Configure installation
341 result = ConfigureInstallation(widgetPath, configData, tempDir);
343 Catch(Exceptions::ExtractFileFailed)
345 LogError("Failed to create temporary path for widget");
346 result = ConfigureResult::Failed_InvalidConfig;
352 void JobWidgetInstall::setTizenId(
353 const WrtDB::ConfigParserData &configInfo)
355 bool shouldMakeAppid = false;
356 using namespace PackageManager;
357 if (!!configInfo.tizenAppId) {
358 LogDebug("Setting tizenAppId provided in config.xml: " <<
359 configInfo.tizenAppId);
361 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
363 if (!!configInfo.tizenPkgId) {
364 LogDebug("Setting tizenPkgId provided in config.xml: " <<
365 configInfo.tizenPkgId);
367 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
369 DPL::String appid = *configInfo.tizenAppId;
370 if (appid.length() > PACKAGE_ID_LENGTH) {
371 m_installerContext.widgetConfig.tzPkgid =
372 appid.substr(0, PACKAGE_ID_LENGTH);
374 //old version appid only has 10byte random character is able to install for a while.
375 //this case appid equal pkgid.
376 m_installerContext.widgetConfig.tzPkgid =
377 *configInfo.tizenAppId;
378 shouldMakeAppid = true;
382 shouldMakeAppid = true;
383 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
384 LogDebug("Checking if pkg id is unique");
386 if (!validateTizenPackageID(pkgId)) {
387 //path exist, chose another one
388 pkgId = WidgetDAOReadOnly::generatePkgId();
393 m_installerContext.widgetConfig.tzPkgid = pkgId;
394 LogInfo("tizen_id name was generated by WRT: " <<
395 m_installerContext.widgetConfig.tzPkgid);
398 if (shouldMakeAppid == true) {
399 DPL::OptionalString name;
400 DPL::OptionalString defaultLocale = configInfo.defaultlocale;
402 FOREACH(localizedData, configInfo.localizedDataSet)
404 Locale i = localizedData->first;
405 if (!!defaultLocale) {
406 if (defaultLocale == i) {
407 name = localizedData->second.name;
411 name = localizedData->second.name;
416 if (regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
417 LogDebug("Regcomp failed");
420 LogDebug("Name : " << name);
421 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
422 static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
424 // TODO : generate name move to wrt-commons
425 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
426 std::ostringstream genName;
428 gettimeofday(&tv, NULL);
429 unsigned int seed = time(NULL) + tv.tv_usec;
431 genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
432 name = DPL::FromUTF8String(genName.str());
433 LogDebug("name was generated by WRT");
436 LogDebug("Name : " << name);
437 std::ostringstream genid;
438 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
439 LogDebug("tizen appid was generated by WRT : " << genid.str());
441 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
442 NormalizeAndTrimSpaceString(appid);
443 m_installerContext.widgetConfig.tzAppid = *appid;
446 // send start signal of pkgmgr
447 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
451 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
452 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
453 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
456 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
457 const std::string& tempPath)
459 if (m_jobStruct.m_installMode ==
460 InstallMode::REINSTALL_MODE_DIRECTORY)
462 // replace widget path to installed path
463 m_installerContext.locations =
464 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.
466 widgetPath, tempPath,
467 m_installerContext.widgetConfig.packagingType,
468 m_installerContext.locationType);
470 m_installerContext.locations =
471 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.
473 widgetPath, tempPath,
474 m_installerContext.widgetConfig.packagingType,
475 m_installerContext.locationType);
477 m_installerContext.locations->registerAppid(
478 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
480 LogInfo("widgetSource " << widgetPath);
483 ConfigureResult JobWidgetInstall::ConfigureInstallation(
484 const std::string &widgetSource,
485 const WrtDB::ConfigParserData &configData,
486 const std::string &tempPath)
488 ConfigureResult result = ConfigureResult::Failed;
489 WidgetUpdateInfo update;
491 // checking installed web application
493 // checking existing application is installed
494 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
495 // no excpetion means, it isn't update mode
496 getInstallerStruct().pkgmgrInterface->sendSignal(
498 PKGMGR_START_UPDATE);
500 update = detectWidgetUpdate(configData,
501 m_installerContext.widgetConfig.tzAppid);
502 result = checkWidgetUpdate(update);
503 if (result != ConfigureResult::Updated) {
504 // Already installed TizenAppId. return failed
505 return ConfigureResult::Failed_AlreadyInstalled;
507 m_installerContext.isUpdateMode = true;
509 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
510 result = ConfigureResult::Ok;
511 getInstallerStruct().pkgmgrInterface->sendSignal(
513 PKGMGR_START_INSTALL);
514 m_installerContext.isUpdateMode = false;
516 if (!validateTizenApplicationID(
517 m_installerContext.widgetConfig.tzAppid))
519 LogError("tizen application ID is already used");
520 return ConfigureResult::Failed_InvalidConfig;
522 if (!validateTizenPackageID(m_installerContext.widgetConfig.tzPkgid)) {
523 LogError("tizen package ID is already used");
524 return ConfigureResult::Failed_AlreadyInstalled;
528 configureWidgetLocation(widgetSource, tempPath);
530 // Init installer context
531 m_installerContext.installStep = InstallerContext::INSTALL_START;
532 m_installerContext.job = this;
533 m_installerContext.widgetConfig.shareHref = std::string();
538 bool JobWidgetInstall::validateTizenApplicationID(
539 const WrtDB::TizenAppId &tizenAppId)
541 LogInfo("tizen application ID = [" << tizenAppId << "]");
544 if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
545 LogDebug("Regcomp failed");
548 if (regexec(®, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
558 bool JobWidgetInstall::validateTizenPackageID(
559 const WrtDB::TizenPkgId &tizenPkgId)
561 std::string pkgId = DPL::ToUTF8String(tizenPkgId);
563 std::string installPath =
564 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
566 std::string preinstallPath =
567 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
571 if ((stat(installPath.c_str(), &dirStat) == 0) ||
572 (stat(preinstallPath.c_str(), &dirStat) == 0))
579 ConfigureResult JobWidgetInstall::checkWidgetUpdate(
580 const WidgetUpdateInfo &update)
582 LogInfo("incoming version = '" << update.incomingVersion);
583 LogInfo("Tizen AppID = " << update.tzAppId);
585 if (update.existingVersion.IsNull() || update.incomingVersion.IsNull()) {
586 return ConfigureResult::Failed;
589 // Check running state
590 bool isRunning = false;
592 app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
594 if (APP_MANAGER_ERROR_NONE != retval || isRunning) {
595 LogError("Fail to get running state");
596 return ConfigureResult::Failed_WidgetRunning;
599 m_installerContext.widgetConfig.tzAppid = update.tzAppId;
601 if (isUpperVersion(update.existingVersion, update.incomingVersion) ||
602 (m_jobStruct.m_installMode == InstallMode::INSTALL_MODE_DIRECTORY) ||
603 (m_jobStruct.m_installMode == InstallMode::REINSTALL_MODE_DIRECTORY))
605 LogInfo("Whether widget policy allow proceed ok");
606 return ConfigureResult::Updated;
608 return ConfigureResult::Failed_LowerVersion;
611 return ConfigureResult::Failed;
614 bool JobWidgetInstall::isUpperVersion(
615 const OptionalWidgetVersion &existingVersion,
616 const OptionalWidgetVersion &incomingVersion)
618 LogInfo("Existing version = '" << *existingVersion);
619 LogInfo("Incoming version = '" << *incomingVersion);
621 if (!existingVersion && !incomingVersion) {
623 } else if (!existingVersion && !!incomingVersion) {
625 } else if (!!existingVersion && !incomingVersion) {
628 if (!existingVersion->IsWac() || !incomingVersion->IsWac()) {
631 if (*incomingVersion == *existingVersion) {
633 } else if (*incomingVersion > *existingVersion) {
642 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
643 const std::string &widgetSource,
644 const std::string &tempPath,
645 WrtDB::PackagingType pkgType,
651 ConfigParserData configInfo;
655 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
656 parser.Parse(widgetSource,
658 new RootParser<WidgetParser>(configInfo,
659 DPL::FromUTF32String(
661 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
662 std::string configPath;
663 configPath = tempPath;
665 configPath += WITH_OSP_XML;
668 // checking RDS data directory
669 if (access(configPath.c_str(), F_OK) != 0) {
670 std::string tzAppId =
671 widgetSource.substr(widgetSource.find_last_of("/")+1);
672 WidgetDAOReadOnly dao(WidgetDAOReadOnly::getTzAppId(DPL::FromUTF8String(tzAppId)));
673 configPath = DPL::ToUTF8String(*dao.getWidgetInstalledPath());
675 configPath += WITH_OSP_XML;
678 parser.Parse(configPath,
680 new RootParser<WidgetParser>(
682 DPL::FromUTF32String(L"widget"))));
685 std::unique_ptr<DPL::ZipInput> zipFile(
686 new DPL::ZipInput(widgetSource));
688 std::unique_ptr<DPL::ZipInput::File> configFile;
690 // Open config.xml file
691 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
692 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
694 configFile.reset(zipFile->OpenFile(CONFIG_XML));
698 DPL::BinaryQueue buffer;
699 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
700 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
701 DPL::Copy(&inputAdapter, &outputAdapter);
702 parser.Parse(&buffer,
704 new RootParser<WidgetParser>(configInfo,
710 std::string configFile;
711 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
712 configFile = tempPath + "/" + WITH_OSP_XML;
714 configFile = tempPath + "/" + CONFIG_XML;
717 parser.Parse(configFile,
719 new RootParser<WidgetParser>(configInfo,
726 Catch(DPL::ZipInput::Exception::OpenFailed)
728 LogError("Failed to open widget package");
729 return ConfigParserData();
731 Catch(DPL::ZipInput::Exception::OpenFileFailed)
733 LogError("Failed to open config.xml file");
734 return ConfigParserData();
736 Catch(DPL::CopyFailed)
738 LogError("Failed to extract config.xml file");
739 return ConfigParserData();
741 Catch(DPL::FileInput::Exception::OpenFailed)
743 LogError("Failed to open config.xml file");
744 return ConfigParserData();
746 Catch(ElementParser::Exception::ParseError)
748 LogError("Failed to parse config.xml file");
749 return ConfigParserData();
751 Catch(DPL::ZipInput::Exception::SeekFileFailed)
753 LogError("Failed to seek widget archive - corrupted package?");
754 return ConfigParserData();
759 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
760 const ConfigParserData &configInfo,
761 const WrtDB::TizenAppId &tizenId)
763 LogInfo("Checking up widget package for config.xml...");
764 OptionalWidgetVersion incomingVersion;
766 if (!configInfo.version.IsNull()) {
768 DPL::Optional<WidgetVersion>(
769 WidgetVersion(*configInfo.version));
772 WidgetDAOReadOnly dao(tizenId);
774 OptionalWidgetVersion optVersion;
775 DPL::OptionalString version = dao.getVersion();
776 if (!version.IsNull()) {
777 optVersion = OptionalWidgetVersion(WidgetVersion(*version));
780 return WidgetUpdateInfo(
786 void JobWidgetInstall::SendProgress()
788 using namespace PackageManager;
789 if (GetProgressFlag() != false) {
790 if (getInstallerStruct().progressCallback != NULL) {
791 // send progress signal of pkgmgr
792 std::ostringstream percent;
793 percent << static_cast<int>(GetProgressPercent());
794 getInstallerStruct().pkgmgrInterface->sendSignal(
798 LogDebug("Call widget install progressCallbak");
799 getInstallerStruct().progressCallback(
800 getInstallerStruct().userParam,
801 GetProgressPercent(),
802 GetProgressDescription());
807 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
809 using namespace PackageManager;
810 if (GetProgressFlag() != false) {
811 if (getInstallerStruct().progressCallback != NULL) {
812 // send progress signal of pkgmgr
813 getInstallerStruct().pkgmgrInterface->sendSignal(
820 void JobWidgetInstall::SendFinishedSuccess()
822 using namespace PackageManager;
823 // TODO : sync should move to separate task.
826 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
827 if (m_installerContext.isUpdateMode) {
828 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
830 WidgetInstallToExtSingleton::Instance().postInstallation(true);
832 WidgetInstallToExtSingleton::Instance().deinitialize();
835 // remove widget install information file
836 unlink(m_installerContext.installInfo.c_str());
839 JobWidgetInstall::displayWidgetInfo();
841 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
843 // send signal of pkgmgr
844 getInstallerStruct().pkgmgrInterface->sendSignal(
848 LogDebug("Call widget install successfinishedCallback");
849 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
851 tizenId), Jobs::Exceptions::Success);
854 void JobWidgetInstall::SendFinishedFailure()
856 using namespace PackageManager;
857 // remove widget install information file
858 unlink(m_installerContext.installInfo.c_str());
860 LogError("Error number: " << m_exceptionCaught);
861 LogError("Message: " << m_exceptionMessage);
862 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
864 LogDebug("Call widget install failure finishedCallback");
865 std::stringstream errorNum;
866 errorNum << m_exceptionCaught;
868 // send signal of pkgmgr
869 getInstallerStruct().pkgmgrInterface->sendSignal(
873 getInstallerStruct().pkgmgrInterface->sendSignal(
877 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
879 tizenId), m_exceptionCaught);
882 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
884 m_exceptionCaught = static_cast<Jobs::Exceptions::Type>(e.getParam());
885 m_exceptionMessage = e.GetMessage();
888 void JobWidgetInstall::displayWidgetInfo()
890 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
892 std::ostringstream out;
893 WidgetLocalizedInfo localizedInfo =
894 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
897 "===================================== INSTALLED WIDGET INFO =========" \
898 "============================";
899 out << std::endl << "Name: " << localizedInfo.name;
900 out << std::endl << "AppId: " << dao.getTzAppId();
901 WidgetSize size = dao.getPreferredSize();
902 out << std::endl << "Width: " << size.width;
903 out << std::endl << "Height: " << size.height;
904 out << std::endl << "Start File: " <<
905 W3CFileLocalization::getStartFile(dao.getTzAppId());
906 out << std::endl << "Version: " << dao.getVersion();
907 out << std::endl << "Licence: " <<
908 localizedInfo.license;
909 out << std::endl << "Licence Href: " <<
910 localizedInfo.licenseHref;
911 out << std::endl << "Description: " <<
912 localizedInfo.description;
913 out << std::endl << "Widget Id: " << dao.getGUID();
914 out << std::endl << "Widget recognized: " << dao.isRecognized();
915 out << std::endl << "Widget distributor signed: " <<
916 dao.isDistributorSigned();
917 out << std::endl << "Widget trusted: " << dao.isTrusted();
919 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
920 DPL::OptionalString iconSrc =
921 !!icon ? icon->src : DPL::OptionalString::Null;
922 out << std::endl << "Icon: " << iconSrc;
924 out << std::endl << "Preferences:";
926 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
929 out << std::endl << " Key: " <<
931 out << std::endl << " Readonly: " <<
936 out << std::endl << "Features:";
938 WidgetFeatureSet list = dao.getFeaturesList();
941 out << std::endl << " Name: " << it->name;
950 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
951 const std::string &widgetSource,
952 const std::string &tempPath)
954 // Check installation type (direcotory/ or config.xml or widget.wgt)
955 if (m_jobStruct.m_installMode == InstallMode::INSTALL_MODE_DIRECTORY ||
956 m_jobStruct.m_installMode == InstallMode::REINSTALL_MODE_DIRECTORY)
958 LogDebug("Install directly from directory");
959 return PKG_TYPE_DIRECTORY_WEB_APP;
961 if (hasExtension(widgetSource, XML_EXTENSION)) {
962 LogInfo("Hosted app installation");
963 return PKG_TYPE_HOSTED_WEB_APP;
967 std::string configFile = tempPath + "/" + CONFIG_XML;
968 if (WrtUtilFileExists(configFile)) {
969 return PKG_TYPE_NOMAL_WEB_APP;
972 configFile = tempPath + "/" + WITH_OSP_XML;
973 if (WrtUtilFileExists(configFile)) {
974 return PKG_TYPE_HYBRID_WEB_APP;
977 std::unique_ptr<DPL::ZipInput> zipFile;
982 zipFile.reset(new DPL::ZipInput(widgetSource));
984 Catch(DPL::ZipInput::Exception::OpenFailed)
986 LogDebug("Failed to open widget package");
987 return PKG_TYPE_UNKNOWN;
989 Catch(DPL::ZipInput::Exception::SeekFileFailed)
991 LogError("Failed to seek widget package file");
992 return PKG_TYPE_UNKNOWN;
997 // Open config.xml file in package root
998 std::unique_ptr<DPL::ZipInput::File> configFile(
999 zipFile->OpenFile(CONFIG_XML));
1000 return PKG_TYPE_NOMAL_WEB_APP;
1002 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1004 LogDebug("Could not find config.xml");
1009 // Open config.xml file in package root
1010 std::unique_ptr<DPL::ZipInput::File> configFile(
1011 zipFile->OpenFile(WITH_OSP_XML));
1013 return PKG_TYPE_HYBRID_WEB_APP;
1015 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1017 LogDebug("Could not find wgt/config.xml");
1018 return PKG_TYPE_UNKNOWN;
1022 return PKG_TYPE_UNKNOWN;
1025 void JobWidgetInstall::setApplicationType(
1026 const WrtDB::ConfigParserData &configInfo)
1028 FOREACH(iterator, configInfo.nameSpaces) {
1029 LogInfo("namespace = [" << *iterator << "]");
1030 AppType currentAppType = APP_TYPE_UNKNOWN;
1032 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
1036 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
1038 ConfigurationNamespace::WacWidgetNamespaceName)
1040 currentAppType = APP_TYPE_WAC20;
1041 } else if (*iterator ==
1042 ConfigurationNamespace::TizenWebAppNamespaceName)
1044 currentAppType = APP_TYPE_TIZENWEBAPP;
1047 if (m_installerContext.widgetConfig.webAppType ==
1050 m_installerContext.widgetConfig.webAppType = currentAppType;
1051 } else if (m_installerContext.widgetConfig.webAppType ==
1056 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
1057 "Config.xml has more than one namespace");
1061 // If there is no define, type set to WAC 2.0
1062 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
1063 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
1066 LogInfo("type = [" <<
1067 m_installerContext.widgetConfig.webAppType.getApptypeToString() <<
1071 bool JobWidgetInstall::detectResourceEncryption(
1072 const WrtDB::ConfigParserData &configData)
1074 FOREACH(it, configData.settingsList)
1076 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
1077 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
1079 LogDebug("resource need encryption");
1086 void JobWidgetInstall::setInstallLocationType(
1088 WrtDB::ConfigParserData &
1091 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
1093 if (m_jobStruct.m_installMode == InstallMode::INSTALL_MODE_PRELOAD) {
1094 m_installerContext.locationType =
1095 INSTALL_LOCATION_TYPE_PRELOAD;
1097 FOREACH(it, configData.settingsList)
1099 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
1101 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
1103 LogDebug("This widget will be installed to sd card");
1104 m_installerContext.locationType =
1105 INSTALL_LOCATION_TYPE_EXTERNAL;
1111 bool JobWidgetInstall::isDRMWidget(std::string /*widgetPath*/)
1117 bool JobWidgetInstall::DecryptDRMWidget(std::string /*widgetPath*/,
1118 std::string /*destPath*/)
1123 } //namespace WidgetInstall