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>
73 #include <widget_install/task_plugins_copy.h>
75 #include <widget_install/widget_install_errors.h>
76 #include <widget_install/widget_install_context.h>
77 #include <widget_install_to_external.h>
79 using namespace WrtDB;
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}$";
89 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
90 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
91 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
92 L"install-location-type";
93 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
96 class InstallerTaskFail :
97 public DPL::TaskDecl<InstallerTaskFail>
105 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
106 "Widget installation or update deferred!");
108 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
109 "Widget installation or update not allowed!");
114 InstallerTaskFail(bool deferred) :
115 DPL::TaskDecl<InstallerTaskFail>(this),
118 AddStep(&InstallerTaskFail::StepFail);
122 const std::string XML_EXTENSION = ".xml";
124 bool hasExtension(const std::string& filename, const std::string& extension) {
125 LogDebug("Looking for extension " << extension << " in: " << filename);
126 size_t fileLen = filename.length();
127 size_t extLen = extension.length();
128 if (fileLen < extLen) {
129 LogError("Filename " << filename << " is shorter than extension "
133 return (0 == filename.compare(fileLen-extLen, extLen, extension));
136 bool checkTizenIdExist(const std::string& tizenId) {
137 std::string installPath =
138 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
140 std::string preinstallPath =
141 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
145 if ((stat(installPath.c_str(), &dirStat) == 0) &&
146 (stat(preinstallPath.c_str(), &dirStat) == 0)) {
151 } // namespace anonymous
154 namespace WidgetInstall {
155 JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
156 const WidgetInstallationStruct &installerStruct) :
158 JobContextBase<WidgetInstallationStruct>(installerStruct),
159 m_exceptionCaught(Exceptions::Success)
162 gettimeofday(&tv, NULL);
163 srand(time(NULL) + tv.tv_usec);
165 m_installerContext.m_quiet = m_jobStruct.m_quiet;
167 ConfigureResult result = PrePareInstallation(widgetPath);
169 if (result == ConfigureResult::Ok) {
170 LogInfo("Configure installation succeeded");
172 AddTask(new TaskRecovery(m_installerContext));
174 // Create installation tasks
175 if (m_installerContext.widgetConfig.packagingType !=
176 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
177 m_installerContext.widgetConfig.packagingType !=
178 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
181 AddTask(new TaskUnzip(m_installerContext));
184 AddTask(new TaskWidgetConfig(m_installerContext));
185 if (m_installerContext.widgetConfig.packagingType ==
186 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
188 AddTask(new TaskPrepareFiles(m_installerContext));
190 AddTask(new TaskCertify(m_installerContext));
191 if (m_needEncryption) {
192 AddTask(new TaskEncryptResource(m_installerContext));
195 AddTask(new TaskFileManipulation(m_installerContext));
196 // TODO: Update progress information for this task
198 //This is sort of quick solution, because ACE verdicts are based upon
199 //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
201 AddTask(new TaskSmack(m_installerContext));
203 AddTask(new TaskManifestFile(m_installerContext));
204 AddTask(new TaskCertificates(m_installerContext));
205 if (m_installerContext.widgetConfig.packagingType ==
206 PKG_TYPE_HYBRID_WEB_APP) {
207 AddTask(new TaskInstallOspsvc(m_installerContext));
209 AddTask(new TaskPluginsCopy(m_installerContext));
210 AddTask(new TaskDatabase(m_installerContext));
211 AddTask(new TaskAceCheck(m_installerContext));
212 } else if (result == ConfigureResult::Updated) {
213 LogInfo("Configure installation updated");
214 LogInfo("Widget Update");
215 if (m_installerContext.widgetConfig.packagingType !=
216 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
217 m_installerContext.widgetConfig.packagingType !=
218 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
221 AddTask(new TaskUnzip(m_installerContext));
224 AddTask(new TaskWidgetConfig(m_installerContext));
226 if (m_installerContext.widgetConfig.packagingType ==
227 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
229 AddTask(new TaskPrepareFiles(m_installerContext));
232 AddTask(new TaskCertify(m_installerContext));
233 if (m_installerContext.widgetConfig.packagingType !=
234 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
236 AddTask(new TaskUpdateFiles(m_installerContext));
239 /* TODO : To backup file, save md5 values */
240 AddTask(new TaskSmack(m_installerContext));
242 AddTask(new TaskManifestFile(m_installerContext));
243 if (m_installerContext.widgetConfig.packagingType ==
244 PKG_TYPE_HYBRID_WEB_APP) {
245 AddTask(new TaskInstallOspsvc(m_installerContext));
247 if (m_installerContext.widgetConfig.packagingType !=
248 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
250 AddTask(new TaskRemoveBackupFiles(m_installerContext));
252 AddTask(new TaskPluginsCopy(m_installerContext));
253 AddTask(new TaskDatabase(m_installerContext));
254 AddTask(new TaskAceCheck(m_installerContext));
255 //TODO: remove widgetHandle from this task and move before database task
256 // by now widget handle is needed in ace check
257 // Any error in acecheck while update will break widget
259 } else if (result == ConfigureResult::Deferred) {
260 // Installation is deferred
261 LogInfo("Configure installation deferred");
263 AddTask(new InstallerTaskFail(true));
264 } else if (result == ConfigureResult::Failed) {
265 // Installation is not allowed to proceed due to widget update policy
266 LogWarning("Configure installation failed!");
268 AddTask(new InstallerTaskFail(false));
270 Assert(false && "Invalid configure result!");
274 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
275 const std::string &widgetPath)
277 ConfigureResult result;
278 m_needEncryption = false;
282 std::string tempDir =
283 Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
285 m_isDRM = isDRMWidget(widgetPath);
286 if (true == m_isDRM) {
287 LogDebug("decrypt DRM widget");
288 if(DecryptDRMWidget(widgetPath, tempDir)) {
289 LogDebug("Failed decrypt DRM widget");
290 return ConfigureResult::Failed;
294 LogDebug("widgetPath:" << widgetPath);
296 m_installerContext.widgetConfig.packagingType =
297 checkPackageType(widgetPath, tempDir);
298 ConfigParserData configData = getWidgetDataFromXML(
301 m_installerContext.widgetConfig.packagingType,
303 LogDebug("widget packaging type : " <<
304 m_installerContext.widgetConfig.packagingType.pkgType);
305 WidgetUpdateInfo update = detectWidgetUpdate(configData);
306 m_needEncryption = detectResourceEncryption(configData);
307 setInstallLocationType(configData);
309 // Configure installation
310 result = ConfigureInstallation(widgetPath, configData, update, tempDir);
312 Catch(Exceptions::ExtractFileFailed)
314 LogError("Failed to create temporary path for widget");
315 result = ConfigureResult::Failed;
321 bool JobWidgetInstall::setTizenId(
322 const WrtDB::ConfigParserData &configInfo,
323 const WidgetUpdateInfo &update,
326 using namespace PackageManager;
328 if(regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
329 LogDebug("Regcomp failed");
332 ConfigureResult result = checkWidgetUpdate(update);
333 if(!!configInfo.tizenId) {
334 LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId);
335 // send start signal of pkgmgr
336 getInstallerStruct().pkgmgrInterface->setPkgname(
337 DPL::ToUTF8String(*(configInfo.tizenId)));
338 getInstallerStruct().pkgmgrInterface->sendSignal(
340 PKGMGR_START_INSTALL);
342 if (result == ConfigureResult::Failed) {
346 if ((regexec(®, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
347 static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
348 (checkTizenIdExist(DPL::ToUTF8String(*(configInfo.tizenId))) &&
349 result != ConfigureResult::Updated))
351 //it is true when tizenId does not fit REG_TIZENID_PATTERN
352 LogError("tizen_id provided but not proper.");
356 m_installerContext.widgetConfig.pkgname = configInfo.tizenId;
359 WidgetPkgName tizenId = WidgetDAOReadOnly::generateTizenId();
361 // only for installation, not for update
362 if (result == ConfigureResult::Ok) {
363 //check if there is package with same name and if generate different name
365 LogDebug("Checking if tizen id is unique");
367 if (checkTizenIdExist(DPL::ToUTF8String(tizenId))) {
368 //path exist, chose another one
369 tizenId = WidgetDAOReadOnly::generateTizenId();
375 m_installerContext.widgetConfig.pkgname = tizenId;
377 LogInfo("tizen_id name was generated by WRT: " << tizenId);
378 // send start signal of pkgmgr
379 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
380 *m_installerContext.widgetConfig.pkgname));
381 getInstallerStruct().pkgmgrInterface->sendSignal(
383 PKGMGR_START_INSTALL);
387 LogInfo("Tizen Id : " << m_installerContext.widgetConfig.pkgname);
388 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
392 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
393 const std::string& tempPath)
395 m_installerContext.locations =
396 WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
397 widgetPath, tempPath,
398 m_installerContext.widgetConfig.packagingType,
399 m_installerContext.locationType);
401 LogInfo("widgetSource " << widgetPath);
404 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
405 const std::string &widgetSource,
406 const WrtDB::ConfigParserData &configData,
407 const WidgetUpdateInfo &update,
408 const std::string &tempPath)
411 if (!setTizenId(configData, update, m_jobStruct.m_preload)) {
412 return ConfigureResult::Failed;
414 LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
416 configureWidgetLocation(widgetSource, tempPath);
419 // Init installer context
420 m_installerContext.installStep = InstallerContext::INSTALL_START;
421 m_installerContext.job = this;
422 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
423 m_installerContext.widgetConfig.shareHref = std::string();
425 return ConfigureResult::Ok;
428 JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
429 const WidgetUpdateInfo &update)
432 "Widget install/update: incoming guid = '" <<
433 update.incomingGUID << "'");
435 "Widget install/update: incoming version = '" <<
436 update.incomingVersion << "'");
439 WidgetUpdateMode::Type updateTypeCheckBit;
441 if (update.existingWidgetInfo.isExist == false) {
442 LogInfo("Widget info does not exist");
443 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
445 LogInfo("Widget info exists. PkgName: " <<
446 update.existingWidgetInfo.pkgname);
448 DPL::OptionalString pkgname = update.existingWidgetInfo.pkgname;
450 if(pkgname.IsNull()) {
451 LogInfo("But package name doesn't exist");
452 return ConfigureResult::Failed;
455 LogInfo("Widget model exists. package name: " << pkgname);
457 // Check running state
458 int retval = APP_MANAGER_ERROR_NONE;
459 bool isRunning = false;
460 retval = app_manager_is_running(DPL::ToUTF8String(*pkgname).c_str(), &isRunning);
461 if (APP_MANAGER_ERROR_NONE != retval) {
462 LogError("Fail to get running state");
463 return ConfigureResult::Failed;
466 if (true == isRunning) {
467 // Must be deferred when update in progress
468 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
470 "Widget is already running. Policy is update according to WAC");
472 return ConfigureResult::Deferred;
475 "Widget is already running. Policy is not update according to WAC");
477 return ConfigureResult::Failed;
481 m_installerContext.widgetConfig.pkgname = pkgname;
482 OptionalWidgetVersion existingVersion;
483 existingVersion = update.existingWidgetInfo.existingVersion;
484 OptionalWidgetVersion incomingVersion = update.incomingVersion;
486 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
489 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
490 m_jobStruct.updateMode ==
491 WidgetUpdateMode::PolicyDirectoryForceInstall)
493 LogInfo("Whether widget policy allow proceed ok");
494 return ConfigureResult::Updated;
497 return ConfigureResult::Failed;
499 return ConfigureResult::Ok;
502 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
503 const OptionalWidgetVersion &existingVersion,
504 const OptionalWidgetVersion &incomingVersion) const
506 // Widget is installed, check versions
507 if (!existingVersion && !incomingVersion) {
508 return WidgetUpdateMode::ExistingVersionEqual;
509 } else if (!existingVersion && !!incomingVersion) {
510 return WidgetUpdateMode::ExistingVersionNewer;
511 } else if (!!existingVersion && !incomingVersion) {
512 return WidgetUpdateMode::ExistingVersionOlder;
514 LogInfo("Existing widget: version = '" << *existingVersion << "'");
516 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
517 return WidgetUpdateMode::BothVersionsNotStd;
518 } else if (!existingVersion->IsWac()) {
519 return WidgetUpdateMode::ExistingVersionNotStd;
520 } else if (!incomingVersion->IsWac()) {
521 return WidgetUpdateMode::IncomingVersionNotStd;
523 // Both versions are WAC-comparable. Do compare.
524 if (*incomingVersion == *existingVersion) {
525 return WidgetUpdateMode::ExistingVersionEqual;
526 } else if (*incomingVersion > *existingVersion) {
527 return WidgetUpdateMode::ExistingVersionOlder;
529 return WidgetUpdateMode::ExistingVersionNewer;
535 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
536 const std::string &widgetSource,
537 const std::string &tempPath,
538 WrtDB::PackagingType pkgType,
543 ConfigParserData configInfo;
547 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
548 parser.Parse(widgetSource,
550 new RootParser<WidgetParser>(configInfo,
551 DPL::FromUTF32String(
553 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
554 parser.Parse(widgetSource + '/' + WITH_OSP_XML,
556 new RootParser<WidgetParser>(
558 DPL::FromUTF32String(L"widget"))));
561 std::unique_ptr<DPL::ZipInput> zipFile(
562 new DPL::ZipInput(widgetSource));
564 std::unique_ptr<DPL::ZipInput::File> configFile;
566 // Open config.xml file
567 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
568 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
570 configFile.reset(zipFile->OpenFile(CONFIG_XML));
574 DPL::BinaryQueue buffer;
575 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
576 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
577 DPL::Copy(&inputAdapter, &outputAdapter);
578 parser.Parse(&buffer,
580 new RootParser<WidgetParser>(configInfo,
581 DPL::FromUTF32String(
585 std::string configFile;
586 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
587 configFile = tempPath + "/" + WITH_OSP_XML;
589 configFile = tempPath + "/" + CONFIG_XML;
592 parser.Parse(configFile,
594 new RootParser<WidgetParser>(configInfo,
595 DPL::FromUTF32String(
600 Catch(DPL::ZipInput::Exception::OpenFailed)
602 LogError("Failed to open widget package");
603 return ConfigParserData();
605 Catch(DPL::ZipInput::Exception::OpenFileFailed)
607 LogError("Failed to open config.xml file");
608 return ConfigParserData();
610 Catch(DPL::CopyFailed)
612 LogError("Failed to extract config.xml file");
613 return ConfigParserData();
615 Catch(DPL::FileInput::Exception::OpenFailed)
617 LogError("Failed to open config.xml file");
618 return ConfigParserData();
620 Catch(ElementParser::Exception::ParseError)
622 LogError("Failed to parse config.xml file");
623 return ConfigParserData();
625 Catch(DPL::ZipInput::Exception::SeekFileFailed)
627 LogError("Failed to seek widget archive - corrupted package?");
628 return ConfigParserData();
633 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
634 const ConfigParserData &configInfo)
636 LogInfo("Checking up widget package for config.xml...");
638 DPL::OptionalString widgetGUID;
639 OptionalWidgetVersion widgetVersion;
642 widgetGUID = configInfo.widget_id;
644 if (widgetGUID.IsNull()) {
645 LogWarning("Installed widget has no GUID");
646 return WidgetUpdateInfo();
649 LogDebug("Installed widget GUID: " << *widgetGUID);
651 // Locate widget ID with this GUID
652 // Incoming widget version
653 if (!configInfo.version.IsNull()) {
655 DPL::Optional<WidgetVersion>(
656 WidgetVersion(*configInfo.version));
661 // Search widget handle by GUID
662 WidgetDAOReadOnly dao(widgetGUID);
663 return WidgetUpdateInfo(
666 WidgetUpdateInfo::ExistingWidgetInfo(
667 *dao.getPkgname(), dao.getVersion()));
669 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
671 // GUID isn't installed
672 return WidgetUpdateInfo(
675 WidgetUpdateInfo::ExistingWidgetInfo());
679 void JobWidgetInstall::SendProgress()
681 using namespace PackageManager;
682 if (GetProgressFlag() != false) {
683 if (getInstallerStruct().progressCallback != NULL) {
684 // send progress signal of pkgmgr
685 std::ostringstream percent;
686 percent << static_cast<int>(GetProgressPercent());
687 getInstallerStruct().pkgmgrInterface->sendSignal(
691 LogDebug("Call widget install progressCallbak");
692 getInstallerStruct().progressCallback(getInstallerStruct().userParam,
693 GetProgressPercent(),GetProgressDescription());
698 void JobWidgetInstall::SendFinishedSuccess()
700 using namespace PackageManager;
701 // TODO : sync should move to separate task.
705 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
706 if (false == m_installerContext.existingWidgetInfo.isExist) {
707 WidgetInstallToExtSingleton::Instance().postInstallation(true);
709 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
711 WidgetInstallToExtSingleton::Instance().deinitialize();
714 // remove widget install information file
715 unlink(m_installerContext.installInfo.c_str());
718 JobWidgetInstall::displayWidgetInfo();
720 DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
722 // send signal of pkgmgr
723 getInstallerStruct().pkgmgrInterface->sendSignal(
727 LogDebug("Call widget install successfinishedCallback");
728 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
729 tizenId.IsNull() ? "" : DPL::ToUTF8String(*tizenId), Exceptions::Success);
732 void JobWidgetInstall::SendFinishedFailure()
734 using namespace PackageManager;
735 // remove widget install information file
736 unlink(m_installerContext.installInfo.c_str());
738 LogError("Error in installation step: " << m_exceptionCaught);
739 LogError("Message: " << m_exceptionMessage);
740 DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
742 LogDebug("Call widget install failure finishedCallback");
744 // send signal of pkgmgr
745 getInstallerStruct().pkgmgrInterface->sendSignal(
749 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
750 tizenId.IsNull() ? "" : DPL::ToUTF8String(*tizenId), m_exceptionCaught);
753 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
755 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
756 m_exceptionMessage = e.GetMessage();
759 void JobWidgetInstall::displayWidgetInfo()
761 WidgetDAOReadOnly dao(m_installerContext.locations->getPkgname());
763 std::ostringstream out;
764 WidgetLocalizedInfo localizedInfo =
765 W3CFileLocalization::getLocalizedInfo(*dao.getPkgname());
768 "===================================== INSTALLED WIDGET INFO ========="\
769 "============================";
770 out << std::endl << "Name: " << localizedInfo.name;
771 out << std::endl << "PkgName: " << dao.getPkgname();
772 WidgetSize size = dao.getPreferredSize();
773 out << std::endl << "Width: " << size.width;
774 out << std::endl << "Height: " << size.height;
775 out << std::endl << "Start File: " <<
776 W3CFileLocalization::getStartFile(*dao.getPkgname());
777 out << std::endl << "Version: " << dao.getVersion();
778 out << std::endl << "Licence: " <<
779 localizedInfo.license;
780 out << std::endl << "Licence Href: " <<
781 localizedInfo.licenseHref;
782 out << std::endl << "Description: " <<
783 localizedInfo.description;
784 out << std::endl << "Widget Id: " << dao.getGUID();
785 out << std::endl << "Widget recognized: " << dao.isRecognized();
786 out << std::endl << "Widget wac signed: " << dao.isWacSigned();
787 out << std::endl << "Widget distributor signed: " <<
788 dao.isDistributorSigned();
789 out << std::endl << "Widget trusted: " << dao.isTrusted();
791 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(*dao.getPkgname());
792 DPL::OptionalString iconSrc =
793 !!icon ? icon->src : DPL::OptionalString::Null;
794 out << std::endl << "Icon: " << iconSrc;
796 out << std::endl << "Preferences:";
798 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
801 out << std::endl << " Key: " <<
803 out << std::endl << " Readonly: " <<
808 out << std::endl << "Features:";
810 WidgetFeatureSet list = dao.getFeaturesList();
813 out << std::endl << " Name: " << it->name;
814 out << std::endl << " Required: " << it->required;
815 out << std::endl << " Params:";
824 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
825 const std::string &widgetSource,
826 const std::string &tempPath)
828 // Check installation type (direcotory/ or config.xml or widget.wgt)
829 if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
831 LogDebug("Install directly from directory");
832 return PKG_TYPE_DIRECTORY_WEB_APP;
834 if (hasExtension(widgetSource, XML_EXTENSION)) {
835 LogInfo("Hosted app installation");
836 return PKG_TYPE_HOSTED_WEB_APP;
840 std::string configFile = tempPath + "/" + CONFIG_XML;
841 if (WrtUtilFileExists(configFile)) {
842 return PKG_TYPE_NOMAL_WEB_APP;
845 configFile = tempPath + "/" + WITH_OSP_XML;
846 if (WrtUtilFileExists(configFile)) {
847 return PKG_TYPE_HYBRID_WEB_APP;
850 std::unique_ptr<DPL::ZipInput> zipFile;
855 zipFile.reset(new DPL::ZipInput(widgetSource));
858 Catch(DPL::ZipInput::Exception::OpenFailed)
860 LogDebug("Failed to open widget package");
861 return PKG_TYPE_UNKNOWN;
863 Catch(DPL::ZipInput::Exception::SeekFileFailed)
865 LogError("Failed to seek widget package file");
866 return PKG_TYPE_UNKNOWN;
871 // Open config.xml file in package root
872 std::unique_ptr<DPL::ZipInput::File> configFile(
873 zipFile->OpenFile(CONFIG_XML));
874 return PKG_TYPE_NOMAL_WEB_APP;
876 Catch(DPL::ZipInput::Exception::OpenFileFailed)
878 LogDebug("Could not find config.xml");
883 // Open config.xml file in package root
884 std::unique_ptr<DPL::ZipInput::File> configFile(
885 zipFile->OpenFile(WITH_OSP_XML));
887 return PKG_TYPE_HYBRID_WEB_APP;
889 Catch(DPL::ZipInput::Exception::OpenFileFailed)
891 LogDebug("Could not find wgt/config.xml");
892 return PKG_TYPE_UNKNOWN;
896 return PKG_TYPE_UNKNOWN;
899 bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
901 FOREACH(it, configData.settingsList)
903 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
904 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
905 LogDebug("resource need encryption");
912 void JobWidgetInstall::setInstallLocationType(const
913 WrtDB::ConfigParserData &configData)
915 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
917 if (true == m_jobStruct.m_preload) {
918 m_installerContext.locationType =
919 INSTALL_LOCATION_TYPE_PRELOAD;
921 FOREACH(it, configData.settingsList)
923 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
925 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
926 LogDebug("This widget will be installed to sd card");
927 m_installerContext.locationType =
928 INSTALL_LOCATION_TYPE_EXTERNAL;
934 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
937 drm_bool_type_e is_drm_file = DRM_UNKNOWN;
940 ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
941 if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
944 /* blow code temporary code for drm. */
945 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
953 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
954 std::string destPath)
957 drm_trusted_sapps_decrypt_package_info_s package_info;
959 strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
960 sizeof(package_info.sadcf_filepath));
961 strncpy(package_info.decrypt_filepath, destPath.c_str(),
962 sizeof(package_info.decrypt_filepath));
964 drm_trusted_request_type_e requestType =
965 DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
967 int ret = drm_trusted_handle_request(requestType,
968 (void *)&package_info, NULL);
969 if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
975 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
976 const_cast<char*>(destPath.c_str())) != 0) {
983 } //namespace WidgetInstall