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>
51 //#include <drm_client.h>
52 #include <drm-oem-intel.h> //temporary code
54 #include "root_parser.h"
55 #include "widget_parser.h"
56 #include "parser_runner.h"
57 #include <widget_install/job_widget_install.h>
58 #include <widget_install/task_certify.h>
59 #include <widget_install/task_widget_config.h>
60 #include <widget_install/task_file_manipulation.h>
61 #include <widget_install/task_ace_check.h>
62 #include <widget_install/task_smack.h>
63 #include <widget_install/task_manifest_file.h>
64 #include <widget_install/task_prepare_files.h>
65 #include <widget_install/task_recovery.h>
66 #include <widget_install/task_install_ospsvc.h>
67 #include <widget_install/task_update_files.h>
68 #include <widget_install/task_database.h>
69 #include <widget_install/task_remove_backup.h>
70 #include <widget_install/task_encrypt_resource.h>
71 #include <widget_install/task_certificates.h>
72 #include <widget_install/task_unzip.h>
73 #include <widget_install/task_commons.h>
75 #include <widget_install/task_plugins_copy.h>
77 #include <widget_install/widget_install_errors.h>
78 #include <widget_install/widget_install_context.h>
79 #include <widget_install_to_external.h>
81 using namespace WrtDB;
82 using namespace Jobs::Exceptions;
84 namespace // anonymous
86 const char * const CONFIG_XML = "config.xml";
87 const char * const WITH_OSP_XML = "res/wgt/config.xml";
89 //allowed: a-z, A-Z, 0-9
90 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
91 const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
92 const size_t PACKAGE_ID_LENGTH = 10;
94 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
95 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
96 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
97 L"install-location-type";
98 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
101 const std::string XML_EXTENSION = ".xml";
103 bool hasExtension(const std::string& filename, const std::string& extension)
105 LogDebug("Looking for extension " << extension << " in: " << filename);
106 size_t fileLen = filename.length();
107 size_t extLen = extension.length();
108 if (fileLen < extLen) {
109 LogError("Filename " << filename << " is shorter than extension "
113 return (0 == filename.compare(fileLen - extLen, extLen, extension));
116 bool checkTizenPkgIdExist(const std::string& tizenPkgId)
118 std::string installPath =
119 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
121 std::string preinstallPath =
122 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
126 if ((stat(installPath.c_str(), &dirStat) == 0) ||
127 (stat(preinstallPath.c_str(), &dirStat) == 0))
133 } // namespace anonymous
136 namespace WidgetInstall {
137 class InstallerTaskFail :
138 public DPL::TaskDecl<InstallerTaskFail>
141 ConfigureResult m_result;
145 if (m_result == ConfigureResult::Deferred) {
146 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
147 "widget installation or update deferred!");
148 } else if (m_result == ConfigureResult::Failed_InvalidConfig) {
149 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid,
151 } else if (m_result == ConfigureResult::Failed_LowerVersion) {
152 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageLowerVersion,
153 "package version is lower than installed version");
154 } else if (m_result == ConfigureResult::Failed_AlreadyInstalled) {
155 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageAlreadyInstalled,
156 "package is already installed");
157 } else if (m_result == ConfigureResult::Failed_WidgetRunning) {
158 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
159 "widget is running");
160 } else if (m_result == ConfigureResult::Failed_DrmError) {
161 ThrowMsg(Jobs::WidgetInstall::Exceptions::DRMFailed,
164 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
165 "widget installation or update not allowed!");
170 InstallerTaskFail(ConfigureResult result) :
171 DPL::TaskDecl<InstallerTaskFail>(this),
174 AddStep(&InstallerTaskFail::StepFail);
178 JobWidgetInstall::JobWidgetInstall(
179 std::string const &widgetPath,
180 const WidgetInstallationStruct &
183 JobContextBase<WidgetInstallationStruct>(installerStruct),
184 m_exceptionCaught(Jobs::Exceptions::Success)
186 m_installerContext.m_quiet = m_jobStruct.m_quiet;
188 ConfigureResult result = PrePareInstallation(widgetPath);
190 if (result == ConfigureResult::Ok) {
191 LogInfo("Configure installation succeeded");
192 m_installerContext.job->SetProgressFlag(true);
194 AddTask(new TaskRecovery(m_installerContext));
196 // Create installation tasks
197 if (m_installerContext.widgetConfig.packagingType !=
198 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
199 m_installerContext.widgetConfig.packagingType !=
200 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
203 AddTask(new TaskUnzip(m_installerContext));
206 AddTask(new TaskWidgetConfig(m_installerContext));
207 if (m_installerContext.widgetConfig.packagingType ==
208 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
210 AddTask(new TaskPrepareFiles(m_installerContext));
212 AddTask(new TaskCertify(m_installerContext));
213 if (m_needEncryption) {
214 AddTask(new TaskEncryptResource(m_installerContext));
217 AddTask(new TaskFileManipulation(m_installerContext));
218 // TODO: Update progress information for this task
220 //This is sort of quick solution, because ACE verdicts are based upon
221 //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
223 AddTask(new TaskSmack(m_installerContext));
225 AddTask(new TaskManifestFile(m_installerContext));
226 if (m_installerContext.widgetConfig.packagingType ==
227 PKG_TYPE_HYBRID_WEB_APP)
229 AddTask(new TaskInstallOspsvc(m_installerContext));
231 AddTask(new TaskCertificates(m_installerContext));
232 AddTask(new TaskPluginsCopy(m_installerContext));
233 AddTask(new TaskDatabase(m_installerContext));
234 AddTask(new TaskAceCheck(m_installerContext));
235 } else if (result == ConfigureResult::Updated) {
236 LogInfo("Configure installation updated");
237 LogInfo("Widget Update");
238 m_installerContext.job->SetProgressFlag(true);
239 if (m_installerContext.widgetConfig.packagingType !=
240 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
241 m_installerContext.widgetConfig.packagingType !=
242 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
245 AddTask(new TaskUnzip(m_installerContext));
248 AddTask(new TaskWidgetConfig(m_installerContext));
250 if (m_installerContext.widgetConfig.packagingType ==
251 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
253 AddTask(new TaskPrepareFiles(m_installerContext));
256 AddTask(new TaskCertify(m_installerContext));
257 if (m_installerContext.widgetConfig.packagingType !=
258 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
260 AddTask(new TaskUpdateFiles(m_installerContext));
263 /* TODO : To backup file, save md5 values */
264 AddTask(new TaskSmack(m_installerContext));
266 AddTask(new TaskManifestFile(m_installerContext));
267 if (m_installerContext.widgetConfig.packagingType ==
268 PKG_TYPE_HYBRID_WEB_APP)
270 AddTask(new TaskInstallOspsvc(m_installerContext));
272 if (m_installerContext.widgetConfig.packagingType !=
273 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
275 AddTask(new TaskRemoveBackupFiles(m_installerContext));
277 AddTask(new TaskPluginsCopy(m_installerContext));
278 AddTask(new TaskDatabase(m_installerContext));
279 AddTask(new TaskAceCheck(m_installerContext));
280 //TODO: remove widgetHandle from this task and move before database task
281 // by now widget handle is needed in ace check
282 // Any error in acecheck while update will break widget
283 } else if (result == ConfigureResult::Deferred) {
284 // Installation is deferred
285 LogInfo("Configure installation deferred");
287 AddTask(new InstallerTaskFail(result));
288 } else if (result >= ConfigureResult::Failed &&
289 result <= ConfigureResult::Failed_DrmError) {
290 // Installation is not allowed to proceed due to widget update policy
291 LogWarning("Configure installation failed!");
293 AddTask(new InstallerTaskFail(result));
295 Assert(false && "Invalid configure result!");
299 ConfigureResult JobWidgetInstall::PrePareInstallation(
300 const std::string &widgetPath)
302 ConfigureResult result;
303 m_needEncryption = false;
307 std::string tempDir =
308 Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
310 m_isDRM = isDRMWidget(widgetPath);
311 if (true == m_isDRM) {
312 LogDebug("decrypt DRM widget");
313 if (DecryptDRMWidget(widgetPath, tempDir)) {
314 LogDebug("Failed decrypt DRM widget");
315 return ConfigureResult::Failed_DrmError;
319 LogDebug("widgetPath:" << widgetPath);
321 m_installerContext.widgetConfig.packagingType =
322 checkPackageType(widgetPath, tempDir);
323 ConfigParserData configData = getWidgetDataFromXML(
326 m_installerContext.widgetConfig.packagingType,
328 LogDebug("widget packaging type : " <<
329 m_installerContext.widgetConfig.packagingType.pkgType);
331 setTizenId(configData);
332 setApplicationType(configData);
333 m_needEncryption = detectResourceEncryption(configData);
334 setInstallLocationType(configData);
336 // Configure installation
337 result = ConfigureInstallation(widgetPath, configData, tempDir);
339 Catch(Exceptions::ExtractFileFailed)
341 LogError("Failed to create temporary path for widget");
342 result = ConfigureResult::Failed_InvalidConfig;
348 void JobWidgetInstall::setTizenId(
349 const WrtDB::ConfigParserData &configInfo)
351 bool shouldMakeAppid = false;
352 using namespace PackageManager;
353 if (!!configInfo.tizenAppId) {
354 LogDebug("Setting tizenAppId provided in config.xml: " <<
355 configInfo.tizenAppId);
357 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
359 if (!!configInfo.tizenPkgId) {
360 LogDebug("Setting tizenPkgId provided in config.xml: " <<
361 configInfo.tizenPkgId);
363 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
365 DPL::String appid = *configInfo.tizenAppId;
366 if (appid.length() > PACKAGE_ID_LENGTH) {
367 m_installerContext.widgetConfig.tzPkgid =
368 appid.substr(0, PACKAGE_ID_LENGTH);
370 //old version appid only has 10byte random character is able to install for a while.
371 //this case appid equal pkgid.
372 m_installerContext.widgetConfig.tzPkgid =
373 *configInfo.tizenAppId;
374 shouldMakeAppid = true;
378 shouldMakeAppid = true;
379 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
380 LogDebug("Checking if pkg id is unique");
382 if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) {
383 //path exist, chose another one
384 pkgId = WidgetDAOReadOnly::generatePkgId();
389 m_installerContext.widgetConfig.tzPkgid = pkgId;
390 LogInfo("tizen_id name was generated by WRT: " <<
391 m_installerContext.widgetConfig.tzPkgid);
394 if (shouldMakeAppid == true) {
395 DPL::OptionalString name;
396 DPL::OptionalString defaultLocale = configInfo.defaultlocale;
398 FOREACH(localizedData, configInfo.localizedDataSet)
400 Locale i = localizedData->first;
401 if (!!defaultLocale) {
402 if (defaultLocale == i) {
403 name = localizedData->second.name;
407 name = localizedData->second.name;
412 if (regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
413 LogDebug("Regcomp failed");
416 LogDebug("Name : " << name);
417 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
418 static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
420 // TODO : generate name move to wrt-commons
421 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
422 std::ostringstream genName;
424 gettimeofday(&tv, NULL);
425 unsigned int seed = time(NULL) + tv.tv_usec;
427 genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
428 name = DPL::FromUTF8String(genName.str());
429 LogDebug("name was generated by WRT");
432 LogDebug("Name : " << name);
433 std::ostringstream genid;
434 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
435 LogDebug("tizen appid was generated by WRT : " << genid.str());
437 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
438 NormalizeAndTrimSpaceString(appid);
439 m_installerContext.widgetConfig.tzAppid = *appid;
442 // send start signal of pkgmgr
443 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
447 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
448 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
449 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
452 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
453 const std::string& tempPath)
455 m_installerContext.locations =
456 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.
458 widgetPath, tempPath,
459 m_installerContext.widgetConfig.packagingType,
460 m_installerContext.locationType);
461 m_installerContext.locations->registerAppid(
462 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
464 LogInfo("widgetSource " << widgetPath);
467 ConfigureResult JobWidgetInstall::ConfigureInstallation(
468 const std::string &widgetSource,
469 const WrtDB::ConfigParserData &configData,
470 const std::string &tempPath)
472 WidgetUpdateInfo update = detectWidgetUpdate(
475 widgetConfig.webAppType,
477 widgetConfig.tzAppid);
478 ConfigureResult result = checkWidgetUpdate(update);
482 if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
483 LogDebug("Regcomp failed");
487 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid).
489 static_cast<size_t>(0), NULL, 0) == REG_NOMATCH) ||
490 (checkTizenPkgIdExist(DPL::ToUTF8String(m_installerContext.widgetConfig
492 result != ConfigureResult::Updated))
494 //it is true when tizenId does not fit REG_TIZENID_PATTERN
495 LogError("tizen_id provided but not proper or pkgId directory exists");
496 //TODO(t.iwanek): appId is unique, what about installation of
497 // abcdefghij.test1 and abcdefghij.test2?
499 return ConfigureResult::Failed_AlreadyInstalled;
503 configureWidgetLocation(widgetSource, tempPath);
505 // Init installer context
506 m_installerContext.installStep = InstallerContext::INSTALL_START;
507 m_installerContext.job = this;
508 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
509 m_installerContext.widgetConfig.shareHref = std::string();
514 ConfigureResult JobWidgetInstall::checkWidgetUpdate(
515 const WidgetUpdateInfo &update)
518 "Widget install/update: incoming guid = '" <<
519 update.incomingGUID << "'");
521 "Widget install/update: incoming version = '" <<
522 update.incomingVersion << "'");
525 WidgetUpdateMode::Type updateTypeCheckBit;
527 if (update.existingWidgetInfo.isExist == false) {
528 LogInfo("Widget info does not exist");
529 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
531 getInstallerStruct().pkgmgrInterface->sendSignal(
533 PKGMGR_START_INSTALL);
536 LogInfo("Widget info exists. appid: " <<
537 update.existingWidgetInfo.tzAppid);
539 getInstallerStruct().pkgmgrInterface->sendSignal(
541 PKGMGR_START_UPDATE);
543 TizenAppId tzAppid = update.existingWidgetInfo.tzAppid;
545 LogInfo("Widget model exists. tizen app id: " << tzAppid);
547 // Check running state
548 bool isRunning = false;
549 int retval = app_manager_is_running(DPL::ToUTF8String(
550 tzAppid).c_str(), &isRunning);
551 if (APP_MANAGER_ERROR_NONE != retval) {
552 LogError("Fail to get running state");
553 return ConfigureResult::Failed_WidgetRunning;
556 if (true == isRunning) {
557 // Must be deferred when update in progress
558 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
560 "Widget is already running. Policy is update according to WAC");
562 return ConfigureResult::Deferred;
565 "Widget is already running. Policy is not update according to WAC");
567 return ConfigureResult::Failed_WidgetRunning;
571 m_installerContext.widgetConfig.tzAppid = tzAppid;
572 OptionalWidgetVersion existingVersion;
573 existingVersion = update.existingWidgetInfo.existingVersion;
574 OptionalWidgetVersion incomingVersion = update.incomingVersion;
576 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
579 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
580 m_jobStruct.updateMode ==
581 WidgetUpdateMode::PolicyDirectoryForceInstall)
583 LogInfo("Whether widget policy allow proceed ok");
584 return ConfigureResult::Updated;
586 return ConfigureResult::Failed_LowerVersion;
589 return ConfigureResult::Ok;
592 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
593 const OptionalWidgetVersion &existingVersion,
594 const OptionalWidgetVersion &incomingVersion) const
596 // Widget is installed, check versions
597 if (!existingVersion && !incomingVersion) {
598 return WidgetUpdateMode::ExistingVersionEqual;
599 } else if (!existingVersion && !!incomingVersion) {
600 return WidgetUpdateMode::ExistingVersionNewer;
601 } else if (!!existingVersion && !incomingVersion) {
602 return WidgetUpdateMode::ExistingVersionOlder;
604 LogInfo("Existing widget: version = '" << *existingVersion << "'");
606 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
607 return WidgetUpdateMode::BothVersionsNotStd;
608 } else if (!existingVersion->IsWac()) {
609 return WidgetUpdateMode::ExistingVersionNotStd;
610 } else if (!incomingVersion->IsWac()) {
611 return WidgetUpdateMode::IncomingVersionNotStd;
613 // Both versions are WAC-comparable. Do compare.
614 if (*incomingVersion == *existingVersion) {
615 return WidgetUpdateMode::ExistingVersionEqual;
616 } else if (*incomingVersion > *existingVersion) {
617 return WidgetUpdateMode::ExistingVersionOlder;
619 return WidgetUpdateMode::ExistingVersionNewer;
625 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
626 const std::string &widgetSource,
627 const std::string &tempPath,
628 WrtDB::PackagingType pkgType,
633 ConfigParserData configInfo;
637 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
638 parser.Parse(widgetSource,
640 new RootParser<WidgetParser>(configInfo,
641 DPL::FromUTF32String(
643 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
644 parser.Parse(widgetSource + '/' + WITH_OSP_XML,
646 new RootParser<WidgetParser>(
648 DPL::FromUTF32String(L"widget"))));
651 std::unique_ptr<DPL::ZipInput> zipFile(
652 new DPL::ZipInput(widgetSource));
654 std::unique_ptr<DPL::ZipInput::File> configFile;
656 // Open config.xml file
657 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
658 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
660 configFile.reset(zipFile->OpenFile(CONFIG_XML));
664 DPL::BinaryQueue buffer;
665 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
666 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
667 DPL::Copy(&inputAdapter, &outputAdapter);
668 parser.Parse(&buffer,
670 new RootParser<WidgetParser>(configInfo,
676 std::string configFile;
677 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
678 configFile = tempPath + "/" + WITH_OSP_XML;
680 configFile = tempPath + "/" + CONFIG_XML;
683 parser.Parse(configFile,
685 new RootParser<WidgetParser>(configInfo,
692 Catch(DPL::ZipInput::Exception::OpenFailed)
694 LogError("Failed to open widget package");
695 return ConfigParserData();
697 Catch(DPL::ZipInput::Exception::OpenFileFailed)
699 LogError("Failed to open config.xml file");
700 return ConfigParserData();
702 Catch(DPL::CopyFailed)
704 LogError("Failed to extract config.xml file");
705 return ConfigParserData();
707 Catch(DPL::FileInput::Exception::OpenFailed)
709 LogError("Failed to open config.xml file");
710 return ConfigParserData();
712 Catch(ElementParser::Exception::ParseError)
714 LogError("Failed to parse config.xml file");
715 return ConfigParserData();
717 Catch(DPL::ZipInput::Exception::SeekFileFailed)
719 LogError("Failed to seek widget archive - corrupted package?");
720 return ConfigParserData();
725 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
726 const ConfigParserData &configInfo,
727 const WrtDB::WidgetType appType,
728 const WrtDB::TizenAppId &tizenId)
730 LogInfo("Checking up widget package for config.xml...");
732 DPL::OptionalString widgetGUID;
733 OptionalWidgetVersion widgetVersion;
736 widgetGUID = configInfo.widget_id;
738 if (widgetGUID.IsNull()) {
739 LogWarning("Installed widget has no GUID");
740 return WidgetUpdateInfo();
743 LogDebug("Installed widget GUID: " << *widgetGUID);
745 // Locate widget ID with this GUID
746 // Incoming widget version
747 if (!configInfo.version.IsNull()) {
749 DPL::Optional<WidgetVersion>(
750 WidgetVersion(*configInfo.version));
753 if (appType == APP_TYPE_WAC20) {
756 // Search widget handle by GUID
757 WidgetDAOReadOnly dao(widgetGUID);
758 return WidgetUpdateInfo(
761 WidgetUpdateInfo::ExistingWidgetInfo(
762 dao.getTzAppId(), dao.getVersion()));
764 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
766 // GUID isn't installed
767 return WidgetUpdateInfo(
770 WidgetUpdateInfo::ExistingWidgetInfo());
775 // Search widget handle by appId
776 WidgetDAOReadOnly dao(tizenId);
777 return WidgetUpdateInfo(
780 WidgetUpdateInfo::ExistingWidgetInfo(
781 dao.getTzAppId(), dao.getVersion()));
783 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
785 // GUID isn't installed
786 return WidgetUpdateInfo(
789 WidgetUpdateInfo::ExistingWidgetInfo());
794 void JobWidgetInstall::SendProgress()
796 using namespace PackageManager;
797 if (GetProgressFlag() != false) {
798 if (getInstallerStruct().progressCallback != NULL) {
799 // send progress signal of pkgmgr
800 std::ostringstream percent;
801 percent << static_cast<int>(GetProgressPercent());
802 getInstallerStruct().pkgmgrInterface->sendSignal(
806 LogDebug("Call widget install progressCallbak");
807 getInstallerStruct().progressCallback(
808 getInstallerStruct().userParam,
809 GetProgressPercent(),
810 GetProgressDescription());
815 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
817 using namespace PackageManager;
818 if (GetProgressFlag() != false) {
819 if (getInstallerStruct().progressCallback != NULL) {
820 // send progress signal of pkgmgr
821 getInstallerStruct().pkgmgrInterface->sendSignal(
828 void JobWidgetInstall::SendFinishedSuccess()
830 using namespace PackageManager;
831 // TODO : sync should move to separate task.
834 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
835 if (false == m_installerContext.existingWidgetInfo.isExist) {
836 WidgetInstallToExtSingleton::Instance().postInstallation(true);
838 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
840 WidgetInstallToExtSingleton::Instance().deinitialize();
843 // remove widget install information file
844 unlink(m_installerContext.installInfo.c_str());
847 JobWidgetInstall::displayWidgetInfo();
849 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
851 // send signal of pkgmgr
852 getInstallerStruct().pkgmgrInterface->sendSignal(
856 LogDebug("Call widget install successfinishedCallback");
857 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
859 tizenId), Jobs::Exceptions::Success);
862 void JobWidgetInstall::SendFinishedFailure()
864 using namespace PackageManager;
865 // remove widget install information file
866 unlink(m_installerContext.installInfo.c_str());
868 LogError("Error number: " << m_exceptionCaught);
869 LogError("Message: " << m_exceptionMessage);
870 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
872 LogDebug("Call widget install failure finishedCallback");
873 std::stringstream errorNum;
874 errorNum << m_exceptionCaught;
876 // send signal of pkgmgr
877 getInstallerStruct().pkgmgrInterface->sendSignal(
881 getInstallerStruct().pkgmgrInterface->sendSignal(
885 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
887 tizenId), m_exceptionCaught);
890 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
892 m_exceptionCaught = static_cast<Jobs::Exceptions::Type>(e.getParam());
893 m_exceptionMessage = e.GetMessage();
896 void JobWidgetInstall::displayWidgetInfo()
898 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
900 std::ostringstream out;
901 WidgetLocalizedInfo localizedInfo =
902 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
905 "===================================== INSTALLED WIDGET INFO =========" \
906 "============================";
907 out << std::endl << "Name: " << localizedInfo.name;
908 out << std::endl << "AppId: " << dao.getTzAppId();
909 WidgetSize size = dao.getPreferredSize();
910 out << std::endl << "Width: " << size.width;
911 out << std::endl << "Height: " << size.height;
912 out << std::endl << "Start File: " <<
913 W3CFileLocalization::getStartFile(dao.getTzAppId());
914 out << std::endl << "Version: " << dao.getVersion();
915 out << std::endl << "Licence: " <<
916 localizedInfo.license;
917 out << std::endl << "Licence Href: " <<
918 localizedInfo.licenseHref;
919 out << std::endl << "Description: " <<
920 localizedInfo.description;
921 out << std::endl << "Widget Id: " << dao.getGUID();
922 out << std::endl << "Widget recognized: " << dao.isRecognized();
923 out << std::endl << "Widget distributor signed: " <<
924 dao.isDistributorSigned();
925 out << std::endl << "Widget trusted: " << dao.isTrusted();
927 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
928 DPL::OptionalString iconSrc =
929 !!icon ? icon->src : DPL::OptionalString::Null;
930 out << std::endl << "Icon: " << iconSrc;
932 out << std::endl << "Preferences:";
934 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
937 out << std::endl << " Key: " <<
939 out << std::endl << " Readonly: " <<
944 out << std::endl << "Features:";
946 WidgetFeatureSet list = dao.getFeaturesList();
949 out << std::endl << " Name: " << it->name;
958 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
959 const std::string &widgetSource,
960 const std::string &tempPath)
962 // Check installation type (direcotory/ or config.xml or widget.wgt)
963 if (WidgetUpdateMode::PolicyDirectoryForceInstall ==
964 m_jobStruct.updateMode)
966 LogDebug("Install directly from directory");
967 return PKG_TYPE_DIRECTORY_WEB_APP;
969 if (hasExtension(widgetSource, XML_EXTENSION)) {
970 LogInfo("Hosted app installation");
971 return PKG_TYPE_HOSTED_WEB_APP;
975 std::string configFile = tempPath + "/" + CONFIG_XML;
976 if (WrtUtilFileExists(configFile)) {
977 return PKG_TYPE_NOMAL_WEB_APP;
980 configFile = tempPath + "/" + WITH_OSP_XML;
981 if (WrtUtilFileExists(configFile)) {
982 return PKG_TYPE_HYBRID_WEB_APP;
985 std::unique_ptr<DPL::ZipInput> zipFile;
990 zipFile.reset(new DPL::ZipInput(widgetSource));
992 Catch(DPL::ZipInput::Exception::OpenFailed)
994 LogDebug("Failed to open widget package");
995 return PKG_TYPE_UNKNOWN;
997 Catch(DPL::ZipInput::Exception::SeekFileFailed)
999 LogError("Failed to seek widget package file");
1000 return PKG_TYPE_UNKNOWN;
1005 // Open config.xml file in package root
1006 std::unique_ptr<DPL::ZipInput::File> configFile(
1007 zipFile->OpenFile(CONFIG_XML));
1008 return PKG_TYPE_NOMAL_WEB_APP;
1010 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1012 LogDebug("Could not find config.xml");
1017 // Open config.xml file in package root
1018 std::unique_ptr<DPL::ZipInput::File> configFile(
1019 zipFile->OpenFile(WITH_OSP_XML));
1021 return PKG_TYPE_HYBRID_WEB_APP;
1023 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1025 LogDebug("Could not find wgt/config.xml");
1026 return PKG_TYPE_UNKNOWN;
1030 return PKG_TYPE_UNKNOWN;
1033 void JobWidgetInstall::setApplicationType(
1034 const WrtDB::ConfigParserData &configInfo)
1036 FOREACH(iterator, configInfo.nameSpaces) {
1037 LogInfo("namespace = [" << *iterator << "]");
1038 AppType currentAppType = APP_TYPE_UNKNOWN;
1040 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
1044 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
1046 ConfigurationNamespace::WacWidgetNamespaceName)
1048 currentAppType = APP_TYPE_WAC20;
1049 } else if (*iterator ==
1050 ConfigurationNamespace::TizenWebAppNamespaceName)
1052 currentAppType = APP_TYPE_TIZENWEBAPP;
1055 if (m_installerContext.widgetConfig.webAppType ==
1058 m_installerContext.widgetConfig.webAppType = currentAppType;
1059 } else if (m_installerContext.widgetConfig.webAppType ==
1064 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
1065 "Config.xml has more than one namespace");
1069 // If there is no define, type set to WAC 2.0
1070 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
1071 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
1074 LogInfo("type = [" <<
1075 m_installerContext.widgetConfig.webAppType.getApptypeToString() <<
1079 bool JobWidgetInstall::detectResourceEncryption(
1080 const WrtDB::ConfigParserData &configData)
1082 FOREACH(it, configData.settingsList)
1084 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
1085 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
1087 LogDebug("resource need encryption");
1094 void JobWidgetInstall::setInstallLocationType(
1096 WrtDB::ConfigParserData &
1099 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
1101 if (true == m_jobStruct.m_preload) {
1102 m_installerContext.locationType =
1103 INSTALL_LOCATION_TYPE_PRELOAD;
1105 FOREACH(it, configData.settingsList)
1107 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
1109 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
1111 LogDebug("This widget will be installed to sd card");
1112 m_installerContext.locationType =
1113 INSTALL_LOCATION_TYPE_EXTERNAL;
1119 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
1122 * drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1125 * ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
1126 * if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
1129 /* blow code temporary code for drm. */
1130 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
1138 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
1139 std::string destPath)
1142 * drm_trusted_sapps_decrypt_package_info_s package_info;
1144 * strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
1145 * sizeof(package_info.sadcf_filepath));
1146 * strncpy(package_info.decrypt_filepath, destPath.c_str(),
1147 * sizeof(package_info.decrypt_filepath));
1149 * drm_trusted_request_type_e requestType =
1150 * DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
1152 * int ret = drm_trusted_handle_request(requestType,
1153 * (void *)&package_info, NULL);
1154 * if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
1160 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
1161 const_cast<char*>(destPath.c_str())) != 0)
1168 } //namespace WidgetInstall