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-rw/global_dao.h> // TODO remove
45 #include <dpl/localization/w3c_file_localization.h>
47 #include <libiriwrapper.h>
48 #include <pkg-manager/pkgmgr_signal.h>
49 #include <app_manager.h>
50 //#include <drm_client.h>
51 #include <drm-oem-intel.h> //temporary code
53 #include "root_parser.h"
54 #include "widget_parser.h"
55 #include "parser_runner.h"
56 #include <widget_install/job_widget_install.h>
57 #include <widget_install/task_certify.h>
58 #include <widget_install/task_widget_config.h>
59 #include <widget_install/task_file_manipulation.h>
60 #include <widget_install/task_ace_check.h>
61 #include <widget_install/task_smack.h>
62 #include <widget_install/task_manifest_file.h>
63 #include <widget_install/task_prepare_files.h>
64 #include <widget_install/task_recovery.h>
65 #include <widget_install/task_install_ospsvc.h>
66 #include <widget_install/task_update_files.h>
67 #include <widget_install/task_database.h>
68 #include <widget_install/task_remove_backup.h>
69 #include <widget_install/task_encrypt_resource.h>
70 #include <widget_install/task_certificates.h>
71 #include <widget_install/task_unzip.h>
72 #include <widget_install/task_commons.h>
74 #include <widget_install/task_plugins_copy.h>
76 #include <widget_install/widget_install_errors.h>
77 #include <widget_install/widget_install_context.h>
78 #include <widget_install_to_external.h>
80 using namespace WrtDB;
82 namespace // anonymous
84 const char * const CONFIG_XML = "config.xml";
85 const char * const WITH_OSP_XML = "res/wgt/config.xml";
87 //allowed: a-z, A-Z, 0-9
88 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}$";
90 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
91 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
92 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
93 L"install-location-type";
94 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
97 class InstallerTaskFail :
98 public DPL::TaskDecl<InstallerTaskFail>
106 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
107 "Widget installation or update deferred!");
109 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
110 "Widget installation or update not allowed!");
115 InstallerTaskFail(bool deferred) :
116 DPL::TaskDecl<InstallerTaskFail>(this),
119 AddStep(&InstallerTaskFail::StepFail);
123 const std::string XML_EXTENSION = ".xml";
125 bool hasExtension(const std::string& filename, const std::string& extension) {
126 LogDebug("Looking for extension " << extension << " in: " << filename);
127 size_t fileLen = filename.length();
128 size_t extLen = extension.length();
129 if (fileLen < extLen) {
130 LogError("Filename " << filename << " is shorter than extension "
134 return (0 == filename.compare(fileLen-extLen, extLen, extension));
137 bool checkTizenIdExist(const std::string& tizenId) {
138 std::string installPath =
139 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
141 std::string preinstallPath =
142 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
146 if ((stat(installPath.c_str(), &dirStat) == 0) &&
147 (stat(preinstallPath.c_str(), &dirStat) == 0)) {
152 } // namespace anonymous
155 namespace WidgetInstall {
156 JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
157 const WidgetInstallationStruct &installerStruct) :
159 JobContextBase<WidgetInstallationStruct>(installerStruct),
160 m_exceptionCaught(Exceptions::Success)
163 gettimeofday(&tv, NULL);
164 srand(time(NULL) + tv.tv_usec);
166 m_installerContext.m_quiet = m_jobStruct.m_quiet;
168 ConfigureResult result = PrePareInstallation(widgetPath);
170 if (result == ConfigureResult::Ok) {
171 LogInfo("Configure installation succeeded");
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 AddTask(new TaskCertificates(m_installerContext));
206 if (m_installerContext.widgetConfig.packagingType ==
207 PKG_TYPE_HYBRID_WEB_APP) {
208 AddTask(new TaskInstallOspsvc(m_installerContext));
210 AddTask(new TaskPluginsCopy(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 if (m_installerContext.widgetConfig.packagingType !=
217 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
218 m_installerContext.widgetConfig.packagingType !=
219 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
222 AddTask(new TaskUnzip(m_installerContext));
225 AddTask(new TaskWidgetConfig(m_installerContext));
227 if (m_installerContext.widgetConfig.packagingType ==
228 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
230 AddTask(new TaskPrepareFiles(m_installerContext));
233 AddTask(new TaskCertify(m_installerContext));
234 if (m_installerContext.widgetConfig.packagingType !=
235 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
237 AddTask(new TaskUpdateFiles(m_installerContext));
240 /* TODO : To backup file, save md5 values */
241 AddTask(new TaskSmack(m_installerContext));
243 AddTask(new TaskManifestFile(m_installerContext));
244 if (m_installerContext.widgetConfig.packagingType ==
245 PKG_TYPE_HYBRID_WEB_APP) {
246 AddTask(new TaskInstallOspsvc(m_installerContext));
248 if (m_installerContext.widgetConfig.packagingType !=
249 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
251 AddTask(new TaskRemoveBackupFiles(m_installerContext));
253 AddTask(new TaskPluginsCopy(m_installerContext));
254 AddTask(new TaskDatabase(m_installerContext));
255 AddTask(new TaskAceCheck(m_installerContext));
256 //TODO: remove widgetHandle from this task and move before database task
257 // by now widget handle is needed in ace check
258 // Any error in acecheck while update will break widget
260 } else if (result == ConfigureResult::Deferred) {
261 // Installation is deferred
262 LogInfo("Configure installation deferred");
264 AddTask(new InstallerTaskFail(true));
265 } else if (result == ConfigureResult::Failed) {
266 // Installation is not allowed to proceed due to widget update policy
267 LogWarning("Configure installation failed!");
269 AddTask(new InstallerTaskFail(false));
271 Assert(false && "Invalid configure result!");
275 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
276 const std::string &widgetPath)
278 ConfigureResult result;
279 m_needEncryption = false;
283 std::string tempDir =
284 Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
286 m_isDRM = isDRMWidget(widgetPath);
287 if (true == m_isDRM) {
288 LogDebug("decrypt DRM widget");
289 if(DecryptDRMWidget(widgetPath, tempDir)) {
290 LogDebug("Failed decrypt DRM widget");
291 return ConfigureResult::Failed;
295 LogDebug("widgetPath:" << widgetPath);
297 m_installerContext.widgetConfig.packagingType =
298 checkPackageType(widgetPath, tempDir);
299 ConfigParserData configData = getWidgetDataFromXML(
302 m_installerContext.widgetConfig.packagingType,
304 LogDebug("widget packaging type : " <<
305 m_installerContext.widgetConfig.packagingType.pkgType);
306 WidgetUpdateInfo update = detectWidgetUpdate(configData);
307 m_needEncryption = detectResourceEncryption(configData);
308 setInstallLocationType(configData);
310 // Configure installation
311 result = ConfigureInstallation(widgetPath, configData, update, tempDir);
313 Catch(Exceptions::ExtractFileFailed)
315 LogError("Failed to create temporary path for widget");
316 result = ConfigureResult::Failed;
322 bool JobWidgetInstall::setTizenId(
323 const WrtDB::ConfigParserData &configInfo,
324 const WidgetUpdateInfo &update,
327 using namespace PackageManager;
329 if(regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
330 LogDebug("Regcomp failed");
333 ConfigureResult result = checkWidgetUpdate(update);
334 if(!!configInfo.tizenId) {
335 LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId);
336 // send start signal of pkgmgr
337 getInstallerStruct().pkgmgrInterface->setPkgname(
338 DPL::ToUTF8String(*(configInfo.tizenId)));
339 getInstallerStruct().pkgmgrInterface->sendSignal(
341 PKGMGR_START_INSTALL);
343 if (result == ConfigureResult::Failed) {
347 if ((regexec(®, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
348 static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
349 (checkTizenIdExist(DPL::ToUTF8String(*(configInfo.tizenId))) &&
350 result != ConfigureResult::Updated))
352 //it is true when tizenId does not fit REG_TIZENID_PATTERN
353 LogError("tizen_id provided but not proper.");
357 m_installerContext.widgetConfig.pkgname = configInfo.tizenId;
360 WidgetPkgName tizenId = WidgetDAOReadOnly::generateTizenId();
362 // only for installation, not for update
363 if (result == ConfigureResult::Ok) {
364 //check if there is package with same name and if generate different name
366 LogDebug("Checking if tizen id is unique");
368 if (checkTizenIdExist(DPL::ToUTF8String(tizenId))) {
369 //path exist, chose another one
370 tizenId = WidgetDAOReadOnly::generateTizenId();
376 m_installerContext.widgetConfig.pkgname = tizenId;
378 LogInfo("tizen_id name was generated by WRT: " << tizenId);
379 // send start signal of pkgmgr
380 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
381 *m_installerContext.widgetConfig.pkgname));
382 getInstallerStruct().pkgmgrInterface->sendSignal(
384 PKGMGR_START_INSTALL);
388 LogInfo("Tizen Id : " << m_installerContext.widgetConfig.pkgname);
389 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
393 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
394 const std::string& tempPath)
396 m_installerContext.locations =
397 WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
398 widgetPath, tempPath,
399 m_installerContext.widgetConfig.packagingType,
400 m_installerContext.locationType);
402 LogInfo("widgetSource " << widgetPath);
405 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
406 const std::string &widgetSource,
407 const WrtDB::ConfigParserData &configData,
408 const WidgetUpdateInfo &update,
409 const std::string &tempPath)
412 if (!setTizenId(configData, update, m_jobStruct.m_preload)) {
413 return ConfigureResult::Failed;
415 LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
417 configureWidgetLocation(widgetSource, tempPath);
420 // Init installer context
421 m_installerContext.installStep = InstallerContext::INSTALL_START;
422 m_installerContext.job = this;
423 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
424 m_installerContext.widgetConfig.shareHref = std::string();
426 return ConfigureResult::Ok;
429 JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
430 const WidgetUpdateInfo &update)
433 "Widget install/update: incoming guid = '" <<
434 update.incomingGUID << "'");
436 "Widget install/update: incoming version = '" <<
437 update.incomingVersion << "'");
440 WidgetUpdateMode::Type updateTypeCheckBit;
442 if (update.existingWidgetInfo.isExist == false) {
443 LogInfo("Widget info does not exist");
444 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
446 LogInfo("Widget info exists. PkgName: " <<
447 update.existingWidgetInfo.pkgname);
449 DPL::OptionalString pkgname = update.existingWidgetInfo.pkgname;
451 if(pkgname.IsNull()) {
452 LogInfo("But package name doesn't exist");
453 return ConfigureResult::Failed;
456 LogInfo("Widget model exists. package name: " << pkgname);
458 // Check running state
459 int retval = APP_MANAGER_ERROR_NONE;
460 bool isRunning = false;
461 retval = app_manager_is_running(DPL::ToUTF8String(*pkgname).c_str(), &isRunning);
462 if (APP_MANAGER_ERROR_NONE != retval) {
463 LogError("Fail to get running state");
464 return ConfigureResult::Failed;
467 if (true == isRunning) {
468 // Must be deferred when update in progress
469 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
471 "Widget is already running. Policy is update according to WAC");
473 return ConfigureResult::Deferred;
476 "Widget is already running. Policy is not update according to WAC");
478 return ConfigureResult::Failed;
482 m_installerContext.widgetConfig.pkgname = pkgname;
483 OptionalWidgetVersion existingVersion;
484 existingVersion = update.existingWidgetInfo.existingVersion;
485 OptionalWidgetVersion incomingVersion = update.incomingVersion;
487 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
490 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
491 m_jobStruct.updateMode ==
492 WidgetUpdateMode::PolicyDirectoryForceInstall)
494 LogInfo("Whether widget policy allow proceed ok");
495 return ConfigureResult::Updated;
498 return ConfigureResult::Failed;
500 return ConfigureResult::Ok;
503 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
504 const OptionalWidgetVersion &existingVersion,
505 const OptionalWidgetVersion &incomingVersion) const
507 // Widget is installed, check versions
508 if (!existingVersion && !incomingVersion) {
509 return WidgetUpdateMode::ExistingVersionEqual;
510 } else if (!existingVersion && !!incomingVersion) {
511 return WidgetUpdateMode::ExistingVersionNewer;
512 } else if (!!existingVersion && !incomingVersion) {
513 return WidgetUpdateMode::ExistingVersionOlder;
515 LogInfo("Existing widget: version = '" << *existingVersion << "'");
517 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
518 return WidgetUpdateMode::BothVersionsNotStd;
519 } else if (!existingVersion->IsWac()) {
520 return WidgetUpdateMode::ExistingVersionNotStd;
521 } else if (!incomingVersion->IsWac()) {
522 return WidgetUpdateMode::IncomingVersionNotStd;
524 // Both versions are WAC-comparable. Do compare.
525 if (*incomingVersion == *existingVersion) {
526 return WidgetUpdateMode::ExistingVersionEqual;
527 } else if (*incomingVersion > *existingVersion) {
528 return WidgetUpdateMode::ExistingVersionOlder;
530 return WidgetUpdateMode::ExistingVersionNewer;
536 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
537 const std::string &widgetSource,
538 const std::string &tempPath,
539 WrtDB::PackagingType pkgType,
544 ConfigParserData configInfo;
548 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
549 parser.Parse(widgetSource,
551 new RootParser<WidgetParser>(configInfo,
552 DPL::FromUTF32String(
554 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
555 parser.Parse(widgetSource + '/' + WITH_OSP_XML,
557 new RootParser<WidgetParser>(
559 DPL::FromUTF32String(L"widget"))));
562 std::unique_ptr<DPL::ZipInput> zipFile(
563 new DPL::ZipInput(widgetSource));
565 std::unique_ptr<DPL::ZipInput::File> configFile;
567 // Open config.xml file
568 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
569 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
571 configFile.reset(zipFile->OpenFile(CONFIG_XML));
575 DPL::BinaryQueue buffer;
576 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
577 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
578 DPL::Copy(&inputAdapter, &outputAdapter);
579 parser.Parse(&buffer,
581 new RootParser<WidgetParser>(configInfo,
582 DPL::FromUTF32String(
586 std::string configFile;
587 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
588 configFile = tempPath + "/" + WITH_OSP_XML;
590 configFile = tempPath + "/" + CONFIG_XML;
593 parser.Parse(configFile,
595 new RootParser<WidgetParser>(configInfo,
596 DPL::FromUTF32String(
601 Catch(DPL::ZipInput::Exception::OpenFailed)
603 LogError("Failed to open widget package");
604 return ConfigParserData();
606 Catch(DPL::ZipInput::Exception::OpenFileFailed)
608 LogError("Failed to open config.xml file");
609 return ConfigParserData();
611 Catch(DPL::CopyFailed)
613 LogError("Failed to extract config.xml file");
614 return ConfigParserData();
616 Catch(DPL::FileInput::Exception::OpenFailed)
618 LogError("Failed to open config.xml file");
619 return ConfigParserData();
621 Catch(ElementParser::Exception::ParseError)
623 LogError("Failed to parse config.xml file");
624 return ConfigParserData();
626 Catch(DPL::ZipInput::Exception::SeekFileFailed)
628 LogError("Failed to seek widget archive - corrupted package?");
629 return ConfigParserData();
634 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
635 const ConfigParserData &configInfo)
637 LogInfo("Checking up widget package for config.xml...");
639 DPL::OptionalString widgetGUID;
640 OptionalWidgetVersion widgetVersion;
643 widgetGUID = configInfo.widget_id;
645 if (widgetGUID.IsNull()) {
646 LogWarning("Installed widget has no GUID");
647 return WidgetUpdateInfo();
650 LogDebug("Installed widget GUID: " << *widgetGUID);
652 // Locate widget ID with this GUID
653 // Incoming widget version
654 if (!configInfo.version.IsNull()) {
656 DPL::Optional<WidgetVersion>(
657 WidgetVersion(*configInfo.version));
662 // Search widget handle by GUID
663 WidgetDAOReadOnly dao(widgetGUID);
664 return WidgetUpdateInfo(
667 WidgetUpdateInfo::ExistingWidgetInfo(
668 *dao.getPkgname(), dao.getVersion()));
670 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
672 // GUID isn't installed
673 return WidgetUpdateInfo(
676 WidgetUpdateInfo::ExistingWidgetInfo());
680 void JobWidgetInstall::SendProgress()
682 using namespace PackageManager;
683 if (GetProgressFlag() != false) {
684 if (getInstallerStruct().progressCallback != NULL) {
685 // send progress signal of pkgmgr
686 std::ostringstream percent;
687 percent << static_cast<int>(GetProgressPercent());
688 getInstallerStruct().pkgmgrInterface->sendSignal(
692 LogDebug("Call widget install progressCallbak");
693 getInstallerStruct().progressCallback(getInstallerStruct().userParam,
694 GetProgressPercent(),GetProgressDescription());
699 void JobWidgetInstall::SendFinishedSuccess()
701 using namespace PackageManager;
702 // TODO : sync should move to separate task.
706 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
707 if (false == m_installerContext.existingWidgetInfo.isExist) {
708 WidgetInstallToExtSingleton::Instance().postInstallation(true);
710 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
712 WidgetInstallToExtSingleton::Instance().deinitialize();
715 // remove widget install information file
716 unlink(m_installerContext.installInfo.c_str());
719 JobWidgetInstall::displayWidgetInfo();
721 DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
723 // send signal of pkgmgr
724 getInstallerStruct().pkgmgrInterface->sendSignal(
728 LogDebug("Call widget install successfinishedCallback");
729 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
730 tizenId.IsNull() ? "" : DPL::ToUTF8String(*tizenId), Exceptions::Success);
733 void JobWidgetInstall::SendFinishedFailure()
735 using namespace PackageManager;
736 // remove widget install information file
737 unlink(m_installerContext.installInfo.c_str());
739 LogError("Error in installation step: " << m_exceptionCaught);
740 LogError("Message: " << m_exceptionMessage);
741 DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
743 LogDebug("Call widget install failure finishedCallback");
745 // send signal of pkgmgr
746 getInstallerStruct().pkgmgrInterface->sendSignal(
750 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
751 tizenId.IsNull() ? "" : DPL::ToUTF8String(*tizenId), m_exceptionCaught);
754 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
756 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
757 m_exceptionMessage = e.GetMessage();
760 void JobWidgetInstall::displayWidgetInfo()
762 WidgetDAOReadOnly dao(m_installerContext.locations->getPkgname());
764 std::ostringstream out;
765 WidgetLocalizedInfo localizedInfo =
766 W3CFileLocalization::getLocalizedInfo(*dao.getPkgname());
769 "===================================== INSTALLED WIDGET INFO ========="\
770 "============================";
771 out << std::endl << "Name: " << localizedInfo.name;
772 out << std::endl << "PkgName: " << dao.getPkgname();
773 WidgetSize size = dao.getPreferredSize();
774 out << std::endl << "Width: " << size.width;
775 out << std::endl << "Height: " << size.height;
776 out << std::endl << "Start File: " <<
777 W3CFileLocalization::getStartFile(*dao.getPkgname());
778 out << std::endl << "Version: " << dao.getVersion();
779 out << std::endl << "Licence: " <<
780 localizedInfo.license;
781 out << std::endl << "Licence Href: " <<
782 localizedInfo.licenseHref;
783 out << std::endl << "Description: " <<
784 localizedInfo.description;
785 out << std::endl << "Widget Id: " << dao.getGUID();
786 out << std::endl << "Widget recognized: " << dao.isRecognized();
787 out << std::endl << "Widget wac signed: " << dao.isWacSigned();
788 out << std::endl << "Widget distributor signed: " <<
789 dao.isDistributorSigned();
790 out << std::endl << "Widget trusted: " << dao.isTrusted();
792 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(*dao.getPkgname());
793 DPL::OptionalString iconSrc =
794 !!icon ? icon->src : DPL::OptionalString::Null;
795 out << std::endl << "Icon: " << iconSrc;
797 out << std::endl << "Preferences:";
799 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
802 out << std::endl << " Key: " <<
804 out << std::endl << " Readonly: " <<
809 out << std::endl << "Features:";
811 WidgetFeatureSet list = dao.getFeaturesList();
814 out << std::endl << " Name: " << it->name;
815 out << std::endl << " Required: " << it->required;
816 out << std::endl << " Params:";
825 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
826 const std::string &widgetSource,
827 const std::string &tempPath)
829 // Check installation type (direcotory/ or config.xml or widget.wgt)
830 if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
832 LogDebug("Install directly from directory");
833 return PKG_TYPE_DIRECTORY_WEB_APP;
835 if (hasExtension(widgetSource, XML_EXTENSION)) {
836 LogInfo("Hosted app installation");
837 return PKG_TYPE_HOSTED_WEB_APP;
841 std::string configFile = tempPath + "/" + CONFIG_XML;
842 if (WrtUtilFileExists(configFile)) {
843 return PKG_TYPE_NOMAL_WEB_APP;
846 configFile = tempPath + "/" + WITH_OSP_XML;
847 if (WrtUtilFileExists(configFile)) {
848 return PKG_TYPE_HYBRID_WEB_APP;
851 std::unique_ptr<DPL::ZipInput> zipFile;
856 zipFile.reset(new DPL::ZipInput(widgetSource));
859 Catch(DPL::ZipInput::Exception::OpenFailed)
861 LogDebug("Failed to open widget package");
862 return PKG_TYPE_UNKNOWN;
864 Catch(DPL::ZipInput::Exception::SeekFileFailed)
866 LogError("Failed to seek widget package file");
867 return PKG_TYPE_UNKNOWN;
872 // Open config.xml file in package root
873 std::unique_ptr<DPL::ZipInput::File> configFile(
874 zipFile->OpenFile(CONFIG_XML));
875 return PKG_TYPE_NOMAL_WEB_APP;
877 Catch(DPL::ZipInput::Exception::OpenFileFailed)
879 LogDebug("Could not find config.xml");
884 // Open config.xml file in package root
885 std::unique_ptr<DPL::ZipInput::File> configFile(
886 zipFile->OpenFile(WITH_OSP_XML));
888 return PKG_TYPE_HYBRID_WEB_APP;
890 Catch(DPL::ZipInput::Exception::OpenFileFailed)
892 LogDebug("Could not find wgt/config.xml");
893 return PKG_TYPE_UNKNOWN;
897 return PKG_TYPE_UNKNOWN;
900 bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
902 FOREACH(it, configData.settingsList)
904 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
905 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
906 LogDebug("resource need encryption");
913 void JobWidgetInstall::setInstallLocationType(const
914 WrtDB::ConfigParserData &configData)
916 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
918 if (true == m_jobStruct.m_preload) {
919 m_installerContext.locationType =
920 INSTALL_LOCATION_TYPE_PRELOAD;
922 FOREACH(it, configData.settingsList)
924 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
926 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
927 LogDebug("This widget will be installed to sd card");
928 m_installerContext.locationType =
929 INSTALL_LOCATION_TYPE_EXTERNAL;
935 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
938 drm_bool_type_e is_drm_file = DRM_UNKNOWN;
941 ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
942 if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
945 /* blow code temporary code for drm. */
946 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
954 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
955 std::string destPath)
958 drm_trusted_sapps_decrypt_package_info_s package_info;
960 strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
961 sizeof(package_info.sadcf_filepath));
962 strncpy(package_info.decrypt_filepath, destPath.c_str(),
963 sizeof(package_info.decrypt_filepath));
965 drm_trusted_request_type_e requestType =
966 DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
968 int ret = drm_trusted_handle_request(requestType,
969 (void *)&package_info, NULL);
970 if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
976 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
977 const_cast<char*>(destPath.c_str())) != 0) {
984 } //namespace WidgetInstall