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 static const DPL::String SETTING_VALUE_ENCRYPTION_DISABLE = L"disable";
94 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
96 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
99 const std::string XML_EXTENSION = ".xml";
101 bool hasExtension(const std::string& filename, const std::string& extension)
103 LogDebug("Looking for extension " << extension << " in: " << filename);
104 size_t fileLen = filename.length();
105 size_t extLen = extension.length();
106 if (fileLen < extLen) {
107 LogError("Filename " << filename << " is shorter than extension "
111 return (0 == filename.compare(fileLen - extLen, extLen, extension));
113 } // namespace anonymous
116 namespace WidgetInstall {
117 class InstallerTaskFail :
118 public DPL::TaskDecl<InstallerTaskFail>
121 ConfigureResult m_result;
125 if (m_result == ConfigureResult::Deferred) {
126 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
127 "widget installation or update deferred!");
128 } else if (m_result == ConfigureResult::Failed_InvalidConfig) {
129 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid,
131 } else if (m_result == ConfigureResult::Failed_LowerVersion) {
132 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageLowerVersion,
133 "package version is lower than installed version");
134 } else if (m_result == ConfigureResult::Failed_AlreadyInstalled) {
135 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageAlreadyInstalled,
136 "package is already installed");
137 } else if (m_result == ConfigureResult::Failed_WidgetRunning) {
138 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
139 "widget is running");
140 } else if (m_result == ConfigureResult::Failed_DrmError) {
141 ThrowMsg(Jobs::WidgetInstall::Exceptions::DRMFailed,
143 } else if (m_result == ConfigureResult::Failed_NotSupportRDSUpdate) {
144 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotSupportRDSUpdate,
145 "RDS update failed");
147 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
148 "widget installation or update not allowed!");
153 InstallerTaskFail(ConfigureResult result) :
154 DPL::TaskDecl<InstallerTaskFail>(this),
157 AddStep(&InstallerTaskFail::StepFail);
161 JobWidgetInstall::JobWidgetInstall(
162 std::string const &widgetPath,
163 const WidgetInstallationStruct &
166 JobContextBase<WidgetInstallationStruct>(installerStruct),
167 m_exceptionCaught(Jobs::Exceptions::Success)
169 m_installerContext.mode = m_jobStruct.m_installMode;
170 ConfigureResult result = PrePareInstallation(widgetPath);
172 if (result == ConfigureResult::Ok) {
173 LogInfo("Configure installation succeeded");
174 m_installerContext.job->SetProgressFlag(true);
176 AddTask(new TaskRecovery(m_installerContext));
178 // Create installation tasks
179 if (m_installerContext.widgetConfig.packagingType !=
180 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
181 m_installerContext.widgetConfig.packagingType !=
182 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
185 AddTask(new TaskUnzip(m_installerContext));
188 AddTask(new TaskWidgetConfig(m_installerContext));
189 if (m_installerContext.widgetConfig.packagingType ==
190 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
192 AddTask(new TaskPrepareFiles(m_installerContext));
194 AddTask(new TaskCertify(m_installerContext));
195 if (m_needEncryption) {
196 AddTask(new TaskEncryptResource(m_installerContext));
199 AddTask(new TaskFileManipulation(m_installerContext));
201 AddTask(new TaskManifestFile(m_installerContext));
202 if (m_installerContext.widgetConfig.packagingType ==
203 PKG_TYPE_HYBRID_WEB_APP)
205 AddTask(new TaskInstallOspsvc(m_installerContext));
207 AddTask(new TaskCertificates(m_installerContext));
208 AddTask(new TaskDatabase(m_installerContext));
209 AddTask(new TaskAceCheck(m_installerContext));
210 AddTask(new TaskSmack(m_installerContext));
211 } else if (result == ConfigureResult::Updated) {
212 LogInfo("Configure installation updated");
213 LogInfo("Widget Update");
214 m_installerContext.job->SetProgressFlag(true);
216 if (m_installerContext.mode.command ==
217 InstallMode::Command::REINSTALL)
219 AddTask(new TaskPrepareReinstall(m_installerContext));
222 if (m_installerContext.widgetConfig.packagingType !=
223 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
224 m_installerContext.widgetConfig.packagingType !=
225 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
228 AddTask(new TaskUnzip(m_installerContext));
231 AddTask(new TaskWidgetConfig(m_installerContext));
233 if (m_installerContext.widgetConfig.packagingType ==
234 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
236 AddTask(new TaskPrepareFiles(m_installerContext));
239 AddTask(new TaskCertify(m_installerContext));
240 if (m_needEncryption) {
241 AddTask(new TaskEncryptResource(m_installerContext));
244 if (m_installerContext.widgetConfig.packagingType !=
245 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
247 AddTask(new TaskUpdateFiles(m_installerContext));
248 AddTask(new TaskFileManipulation(m_installerContext));
251 AddTask(new TaskManifestFile(m_installerContext));
252 if (m_installerContext.widgetConfig.packagingType ==
253 PKG_TYPE_HYBRID_WEB_APP)
255 AddTask(new TaskInstallOspsvc(m_installerContext));
257 AddTask(new TaskCertificates(m_installerContext));
258 AddTask(new TaskDatabase(m_installerContext));
259 AddTask(new TaskAceCheck(m_installerContext));
260 //TODO: remove widgetHandle from this task and move before database task
261 // by now widget handle is needed in ace check
262 // Any error in acecheck while update will break widget
263 AddTask(new TaskSmack(m_installerContext));
264 AddTask(new TaskRemoveBackupFiles(m_installerContext));
265 } else if (result == ConfigureResult::Deferred) {
266 // Installation is deferred
267 LogInfo("Configure installation deferred");
269 AddTask(new InstallerTaskFail(result));
270 } else if (result >= ConfigureResult::Failed &&
271 result <= ConfigureResult::Failed_DrmError) {
272 // Installation is not allowed to proceed due to widget update policy
273 LogWarning("Configure installation failed!");
275 AddTask(new InstallerTaskFail(result));
277 Assert(false && "Invalid configure result!");
281 ConfigureResult JobWidgetInstall::PrePareInstallation(
282 const std::string &widgetPath)
284 ConfigureResult result;
285 m_needEncryption = false;
290 if (m_installerContext.mode.extension == InstallMode::ExtensionType::DIR) {
291 std::ostringstream tempPathBuilder;
292 tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
293 tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
294 tempPathBuilder << "/";
295 tempPathBuilder << widgetPath;
296 tempDir = tempPathBuilder.str();;
299 Jobs::WidgetInstall::createTempPath(
300 m_installerContext.mode.rootPath ==
301 InstallMode::RootPath::RO);
304 m_isDRM = isDRMWidget(widgetPath);
305 if (true == m_isDRM) {
306 LogDebug("decrypt DRM widget");
307 if (DecryptDRMWidget(widgetPath, tempDir)) {
308 LogDebug("Failed decrypt DRM widget");
309 return ConfigureResult::Failed_DrmError;
313 LogDebug("widgetPath:" << widgetPath);
315 m_installerContext.widgetConfig.packagingType =
316 checkPackageType(widgetPath, tempDir);
317 ConfigParserData configData = getWidgetDataFromXML(
320 m_installerContext.widgetConfig.packagingType,
322 m_installerContext.mode.command == InstallMode::Command::REINSTALL);
323 LogDebug("widget packaging type : " <<
324 m_installerContext.widgetConfig.packagingType.pkgType);
326 setTizenId(configData);
327 setApplicationType(configData);
328 m_needEncryption = detectResourceEncryption(configData);
329 setInstallLocationType(configData);
331 // Configure installation
332 result = ConfigureInstallation(widgetPath, configData, tempDir);
334 Catch(Exceptions::ExtractFileFailed)
336 LogError("Failed to create temporary path for widget");
337 result = ConfigureResult::Failed_InvalidConfig;
343 void JobWidgetInstall::setTizenId(
344 const WrtDB::ConfigParserData &configInfo)
346 bool shouldMakeAppid = false;
347 using namespace PackageManager;
348 if (!!configInfo.tizenAppId) {
349 LogDebug("Setting tizenAppId provided in config.xml: " <<
350 configInfo.tizenAppId);
352 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
354 if (!!configInfo.tizenPkgId) {
355 LogDebug("Setting tizenPkgId provided in config.xml: " <<
356 configInfo.tizenPkgId);
358 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
360 DPL::String appid = *configInfo.tizenAppId;
361 if (appid.length() > PACKAGE_ID_LENGTH) {
362 m_installerContext.widgetConfig.tzPkgid =
363 appid.substr(0, PACKAGE_ID_LENGTH);
365 //old version appid only has 10byte random character is able to install for a while.
366 //this case appid equal pkgid.
367 m_installerContext.widgetConfig.tzPkgid =
368 *configInfo.tizenAppId;
369 shouldMakeAppid = true;
373 shouldMakeAppid = true;
374 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
375 LogDebug("Checking if pkg id is unique");
377 if (!validateTizenPackageID(pkgId)) {
378 //path exist, chose another one
379 pkgId = WidgetDAOReadOnly::generatePkgId();
384 m_installerContext.widgetConfig.tzPkgid = pkgId;
385 LogInfo("tizen_id name was generated by WRT: " <<
386 m_installerContext.widgetConfig.tzPkgid);
389 if (shouldMakeAppid == true) {
390 DPL::OptionalString name;
391 DPL::OptionalString defaultLocale = configInfo.defaultlocale;
393 FOREACH(localizedData, configInfo.localizedDataSet)
395 Locale i = localizedData->first;
396 if (!!defaultLocale) {
397 if (defaultLocale == i) {
398 name = localizedData->second.name;
402 name = localizedData->second.name;
407 if (regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
408 LogDebug("Regcomp failed");
411 LogDebug("Name : " << name);
412 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
413 static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
415 // TODO : generate name move to wrt-commons
416 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
417 std::ostringstream genName;
419 gettimeofday(&tv, NULL);
420 unsigned int seed = time(NULL) + tv.tv_usec;
422 genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
423 name = DPL::FromUTF8String(genName.str());
424 LogDebug("name was generated by WRT");
427 LogDebug("Name : " << name);
428 std::ostringstream genid;
429 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
430 LogDebug("tizen appid was generated by WRT : " << genid.str());
432 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
433 NormalizeAndTrimSpaceString(appid);
434 m_installerContext.widgetConfig.tzAppid = *appid;
437 // send start signal of pkgmgr
438 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
442 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
443 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
444 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
447 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
448 const std::string& tempPath)
450 m_installerContext.locations =
451 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.
453 widgetPath, tempPath,
454 m_installerContext.widgetConfig.packagingType,
455 m_installerContext.mode.rootPath ==
456 InstallMode::RootPath::RO);
457 m_installerContext.locations->registerAppid(
458 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
460 LogInfo("widgetSource " << widgetPath);
463 ConfigureResult JobWidgetInstall::ConfigureInstallation(
464 const std::string &widgetSource,
465 const WrtDB::ConfigParserData &configData,
466 const std::string &tempPath)
468 ConfigureResult result = ConfigureResult::Failed;
469 WidgetUpdateInfo update;
471 // checking installed web application
473 // checking existing application is installed
474 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
475 // no excpetion means, it isn't update mode
476 getInstallerStruct().pkgmgrInterface->sendSignal(
478 PKGMGR_START_UPDATE);
480 update = detectWidgetUpdate(configData,
481 m_installerContext.widgetConfig.tzAppid);
482 result = checkWidgetUpdate(update);
483 if (result != ConfigureResult::Updated) {
484 // Already installed TizenAppId. return failed
485 return ConfigureResult::Failed_AlreadyInstalled;
487 if (!checkSupportRDSUpdate(configData)) {
488 return ConfigureResult::Failed_NotSupportRDSUpdate;
490 m_installerContext.isUpdateMode = true;
492 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
493 result = ConfigureResult::Ok;
494 getInstallerStruct().pkgmgrInterface->sendSignal(
496 PKGMGR_START_INSTALL);
497 m_installerContext.isUpdateMode = false;
499 if (!validateTizenApplicationID(
500 m_installerContext.widgetConfig.tzAppid))
502 LogError("tizen application ID is already used");
503 return ConfigureResult::Failed_InvalidConfig;
505 if (!validateTizenPackageID(m_installerContext.widgetConfig.tzPkgid)) {
506 LogError("tizen package ID is already used");
507 return ConfigureResult::Failed_AlreadyInstalled;
511 configureWidgetLocation(widgetSource, tempPath);
513 // Init installer context
514 m_installerContext.installStep = InstallerContext::INSTALL_START;
515 m_installerContext.job = this;
516 m_installerContext.widgetConfig.shareHref = std::string();
521 bool JobWidgetInstall::validateTizenApplicationID(
522 const WrtDB::TizenAppId &tizenAppId)
524 LogInfo("tizen application ID = [" << tizenAppId << "]");
527 if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
528 LogDebug("Regcomp failed");
531 if (regexec(®, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
541 bool JobWidgetInstall::validateTizenPackageID(
542 const WrtDB::TizenPkgId &tizenPkgId)
544 std::string pkgId = DPL::ToUTF8String(tizenPkgId);
546 std::string installPath =
547 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
549 std::string preinstallPath =
550 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
554 if ((stat(installPath.c_str(), &dirStat) == 0) ||
555 (stat(preinstallPath.c_str(), &dirStat) == 0))
562 ConfigureResult JobWidgetInstall::checkWidgetUpdate(
563 const WidgetUpdateInfo &update)
565 if (update.existingVersion.IsNull() || update.incomingVersion.IsNull()) {
566 return ConfigureResult::Failed;
569 LogInfo("existing version = '" << update.existingVersion);
570 LogInfo("incoming version = '" << update.incomingVersion);
571 LogInfo("Tizen AppID = " << update.tzAppId);
573 // Check running state
574 bool isRunning = false;
576 app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
578 if (APP_MANAGER_ERROR_NONE != ret) {
579 LogError("Fail to get running state");
580 return ConfigureResult::Failed_WidgetRunning;
583 if (true == isRunning) {
584 // get app_context for running application
585 // app_context must be released with app_context_destroy
586 app_context_h appCtx = NULL;
588 app_manager_get_app_context(
589 DPL::ToUTF8String(update.tzAppId).c_str(),
591 if (APP_MANAGER_ERROR_NONE != ret) {
592 LogError("Fail to get app_context");
593 return ConfigureResult::Failed_WidgetRunning;
596 // terminate app_context_h
597 ret = app_manager_terminate_app(appCtx);
598 if (APP_MANAGER_ERROR_NONE != ret) {
599 LogError("Fail to terminate running application");
600 app_context_destroy(appCtx);
601 return ConfigureResult::Failed_WidgetRunning;
603 app_context_destroy(appCtx);
604 // app_manager_terminate_app isn't sync API
605 // wait until application isn't running (50ms * 100)
606 bool isStillRunning = true;
607 int checkingloop = 100;
608 struct timespec duration = { 0, 50 * 1000 * 1000 };
609 while (--checkingloop >= 0) {
610 nanosleep(&duration, NULL);
612 app_manager_is_running(
613 DPL::ToUTF8String(update.tzAppId).c_str(),
615 if (APP_MANAGER_ERROR_NONE != ret) {
616 LogError("Fail to get running state");
617 return ConfigureResult::Failed_WidgetRunning;
619 if (!isStillRunning) {
623 if (isStillRunning) {
624 LogError("Fail to terminate running application");
625 return ConfigureResult::Failed_WidgetRunning;
627 LogInfo("terminate application");
631 m_installerContext.widgetConfig.tzAppid = update.tzAppId;
633 if (!!update.existingVersion ||
634 m_installerContext.mode.extension ==
635 InstallMode::ExtensionType::DIR) {
636 return ConfigureResult::Updated;
639 return ConfigureResult::Failed;
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_installerContext.mode.extension == InstallMode::ExtensionType::DIR) {
956 LogDebug("Install directly from directory");
957 return PKG_TYPE_DIRECTORY_WEB_APP;
959 if (hasExtension(widgetSource, XML_EXTENSION)) {
960 LogInfo("Hosted app installation");
961 return PKG_TYPE_HOSTED_WEB_APP;
965 std::string configFile = tempPath + "/" + CONFIG_XML;
966 if (WrtUtilFileExists(configFile)) {
967 return PKG_TYPE_NOMAL_WEB_APP;
970 configFile = tempPath + "/" + WITH_OSP_XML;
971 if (WrtUtilFileExists(configFile)) {
972 return PKG_TYPE_HYBRID_WEB_APP;
975 std::unique_ptr<DPL::ZipInput> zipFile;
980 zipFile.reset(new DPL::ZipInput(widgetSource));
982 Catch(DPL::ZipInput::Exception::OpenFailed)
984 LogDebug("Failed to open widget package");
985 return PKG_TYPE_UNKNOWN;
987 Catch(DPL::ZipInput::Exception::SeekFileFailed)
989 LogError("Failed to seek widget package file");
990 return PKG_TYPE_UNKNOWN;
995 // Open config.xml file in package root
996 std::unique_ptr<DPL::ZipInput::File> configFile(
997 zipFile->OpenFile(CONFIG_XML));
998 return PKG_TYPE_NOMAL_WEB_APP;
1000 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1002 LogDebug("Could not find config.xml");
1007 // Open config.xml file in package root
1008 std::unique_ptr<DPL::ZipInput::File> configFile(
1009 zipFile->OpenFile(WITH_OSP_XML));
1011 return PKG_TYPE_HYBRID_WEB_APP;
1013 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1015 LogDebug("Could not find wgt/config.xml");
1016 return PKG_TYPE_UNKNOWN;
1020 return PKG_TYPE_UNKNOWN;
1023 void JobWidgetInstall::setApplicationType(
1024 const WrtDB::ConfigParserData &configInfo)
1026 FOREACH(iterator, configInfo.nameSpaces) {
1027 LogInfo("namespace = [" << *iterator << "]");
1028 AppType currentAppType = APP_TYPE_UNKNOWN;
1030 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
1034 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
1036 ConfigurationNamespace::WacWidgetNamespaceName)
1038 currentAppType = APP_TYPE_WAC20;
1039 } else if (*iterator ==
1040 ConfigurationNamespace::TizenWebAppNamespaceName)
1042 currentAppType = APP_TYPE_TIZENWEBAPP;
1045 if (m_installerContext.widgetConfig.webAppType ==
1048 m_installerContext.widgetConfig.webAppType = currentAppType;
1049 } else if (m_installerContext.widgetConfig.webAppType ==
1054 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
1055 "Config.xml has more than one namespace");
1059 // If there is no define, type set to WAC 2.0
1060 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
1061 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
1064 LogInfo("type = [" <<
1065 m_installerContext.widgetConfig.webAppType.getApptypeToString() <<
1069 bool JobWidgetInstall::detectResourceEncryption(
1070 const WrtDB::ConfigParserData &configData)
1072 FOREACH(it, configData.settingsList)
1074 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
1075 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
1077 LogDebug("resource need encryption");
1084 void JobWidgetInstall::setInstallLocationType(
1085 const WrtDB::ConfigParserData & configData)
1087 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
1088 if (m_installerContext.mode.installTime != InstallMode::InstallTime::PRELOAD) {
1089 FOREACH(it, configData.settingsList) {
1090 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
1092 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
1094 LogDebug("This widget will be installed to sd card");
1095 m_installerContext.locationType =
1096 INSTALL_LOCATION_TYPE_EXTERNAL;
1102 bool JobWidgetInstall::isDRMWidget(std::string /*widgetPath*/)
1108 bool JobWidgetInstall::DecryptDRMWidget(std::string /*widgetPath*/,
1109 std::string /*destPath*/)
1115 bool JobWidgetInstall::checkSupportRDSUpdate(const WrtDB::ConfigParserData
1118 if (m_installerContext.mode.command ==
1119 InstallMode::Command::REINSTALL)
1121 DPL::String configValue = SETTING_VALUE_ENCRYPTION_DISABLE;
1122 DPL::String dbValue = SETTING_VALUE_ENCRYPTION_DISABLE;
1124 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
1125 WrtDB::WidgetSettings widgetSettings;
1126 dao.getWidgetSettings(widgetSettings);
1128 FOREACH(it, widgetSettings) {
1129 if (it->settingName == SETTING_VALUE_ENCRYPTION) {
1130 dbValue = it->settingValue;
1134 FOREACH(data, configInfo.settingsList)
1136 if (data->m_name == SETTING_VALUE_ENCRYPTION)
1138 configValue = data->m_value;
1141 if (configValue != dbValue) {
1142 LogError("Not Support RDS mode because of encryption setting");
1149 } //namespace WidgetInstall