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_private_storage.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>
74 #include <widget_install/task_plugins_copy.h>
76 #include <widget_install/widget_install_errors.h>
77 #include <widget_install/widget_install_context.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";
92 class InstallerTaskFail :
93 public DPL::TaskDecl<InstallerTaskFail>
101 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
102 "Widget installation or update deferred!");
104 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
105 "Widget installation or update not allowed!");
110 InstallerTaskFail(bool deferred) :
111 DPL::TaskDecl<InstallerTaskFail>(this),
114 AddStep(&InstallerTaskFail::StepFail);
118 const std::string XML_EXTENSION = ".xml";
120 bool hasExtension(const std::string& filename, const std::string& extension) {
121 LogDebug("Looking for extension " << extension << " in: " << filename);
122 size_t fileLen = filename.length();
123 size_t extLen = extension.length();
124 if (fileLen < extLen) {
125 LogError("Filename " << filename << " is shorter than extension "
129 return (0 == filename.compare(fileLen-extLen, extLen, extension));
131 } // namespace anonymous
134 namespace WidgetInstall {
135 JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
136 const WidgetInstallationStruct &installerStruct) :
138 JobContextBase<WidgetInstallationStruct>(installerStruct),
139 m_exceptionCaught(Exceptions::Success)
142 gettimeofday(&tv, NULL);
143 srand(time(NULL) + tv.tv_usec);
145 m_installerContext.m_quiet = m_jobStruct.m_quiet;
147 ConfigureResult result = PrePareInstallation(widgetPath);
149 if (result == ConfigureResult::Ok) {
150 LogInfo("Configure installation succeeded");
152 AddTask(new TaskRecovery(m_installerContext));
154 // Create installation tasks
155 if (m_installerContext.widgetConfig.packagingType !=
156 WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) {
157 AddTask(new TaskUnzip(m_installerContext));
160 AddTask(new TaskWidgetConfig(m_installerContext));
161 if (m_installerContext.widgetConfig.packagingType ==
162 WrtDB::PKG_TYPE_HOSTED_WEB_APP ) {
163 AddTask(new TaskPrepareFiles(m_installerContext));
165 AddTask(new TaskCertify(m_installerContext));
166 if (m_needEncryption) {
167 AddTask(new TaskEncryptResource(m_installerContext));
169 AddTask(new TaskFileManipulation(m_installerContext));
170 // TODO: Update progress information for this task
172 AddTask(new TaskPrivateStorage(m_installerContext));
174 //This is sort of quick solution, because ACE verdicts are based upon
175 //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
177 AddTask(new TaskSmack(m_installerContext));
179 AddTask(new TaskManifestFile(m_installerContext));
180 AddTask(new TaskCertificates(m_installerContext));
181 if (m_installerContext.widgetConfig.packagingType ==
182 PKG_TYPE_HYBRID_WEB_APP) {
183 AddTask(new TaskInstallOspsvc(m_installerContext));
185 AddTask(new TaskPluginsCopy(m_installerContext));
186 AddTask(new TaskDatabase(m_installerContext));
187 AddTask(new TaskAceCheck(m_installerContext));
188 } else if (result == ConfigureResult::Updated) {
189 LogInfo("Configure installation updated");
190 LogInfo("Widget Update");
191 if (m_installerContext.widgetConfig.packagingType !=
192 WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) {
193 AddTask(new TaskUnzip(m_installerContext));
196 AddTask(new TaskWidgetConfig(m_installerContext));
198 if (m_installerContext.widgetConfig.packagingType ==
199 WrtDB::PKG_TYPE_HOSTED_WEB_APP ) {
200 AddTask(new TaskPrepareFiles(m_installerContext));
203 AddTask(new TaskCertify(m_installerContext));
204 AddTask(new TaskUpdateFiles(m_installerContext));
206 /* TODO : To backup file, save md5 values */
207 AddTask(new TaskSmack(m_installerContext));
209 AddTask(new TaskManifestFile(m_installerContext));
210 if (m_installerContext.widgetConfig.packagingType ==
211 PKG_TYPE_HYBRID_WEB_APP) {
212 AddTask(new TaskInstallOspsvc(m_installerContext));
214 AddTask(new TaskRemoveBackupFiles(m_installerContext));
215 AddTask(new TaskPluginsCopy(m_installerContext));
216 AddTask(new TaskDatabase(m_installerContext));
217 AddTask(new TaskAceCheck(m_installerContext));
218 //TODO: remove widgetHandle from this task and move before database task
219 // by now widget handle is needed in ace check
220 // Any error in acecheck while update will break widget
222 } else if (result == ConfigureResult::Deferred) {
223 // Installation is deferred
224 LogInfo("Configure installation deferred");
226 AddTask(new InstallerTaskFail(true));
227 } else if (result == ConfigureResult::Failed) {
228 // Installation is not allowed to proceed due to widget update policy
229 LogWarning("Configure installation failed!");
231 AddTask(new InstallerTaskFail(false));
233 Assert(false && "Invalid configure result!");
237 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
238 const std::string &widgetPath)
240 ConfigureResult result;
241 m_needEncryption = false;
245 std::string tempDir = Jobs::WidgetInstall::createTempPath();
247 bool m_isDRM = isDRMWidget(widgetPath);
248 if (true == m_isDRM) {
249 LogDebug("decrypt DRM widget");
250 if(DecryptDRMWidget(widgetPath, tempDir)) {
251 LogDebug("Failed decrypt DRM widget");
252 return ConfigureResult::Failed;
256 LogDebug("widgetPath:" << widgetPath);
258 m_installerContext.widgetConfig.packagingType =
259 checkPackageType(widgetPath, tempDir);
260 ConfigParserData configData = getWidgetDataFromXML(widgetPath, tempDir,
261 m_installerContext.widgetConfig.packagingType, m_isDRM);
262 LogDebug("widget packaging type : " <<
263 m_installerContext.widgetConfig.packagingType.pkgType);
264 WidgetUpdateInfo update = detectWidgetUpdate(configData);
265 m_needEncryption = detectResourceEncryption(configData);
267 // Configure installation
268 result = ConfigureInstallation(widgetPath, configData, update, tempDir);
270 Catch(Exceptions::ExtractFileFailed)
272 LogError("Failed to create temporary path for widget");
273 result = ConfigureResult::Failed;
279 bool JobWidgetInstall::setTizenId(
280 const WrtDB::ConfigParserData &configInfo, ConfigureResult result)
283 regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED);
285 if(!!configInfo.tizenId) {
286 LogDebug("Setting tizenId provided in config.xml: " << configInfo.tizenId);
287 if ((regexec(®, DPL::ToUTF8String(*(configInfo.tizenId)).c_str(),
288 static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
289 ((stat((std::string(GlobalConfig::GetUserInstalledWidgetPath()) + "/"
290 + DPL::ToUTF8String(*(configInfo.tizenId))).c_str(), &dirStat) == 0)
291 && result != ConfigureResult::Updated))
293 //it is true when tizenId does not fit REG_TIZENID_PATTERN
294 LogError("tizen_id provided but not proper.");
298 m_installerContext.widgetConfig.pkgname = configInfo.tizenId;
301 WidgetPkgName tizenId = WidgetDAOReadOnly::generateTizenId();
303 // only for installation, not for update
304 if (result == ConfigureResult::Ok) {
305 //check if there is package with same name and if generate different name
306 std::string path = GlobalConfig::GetUserInstalledWidgetPath();
309 std::ostringstream newPath;
310 newPath << path << tizenId;
312 LogDebug("Checking if tizen id is unique");
314 if (stat(newPath.str().c_str(), &dirStat) == 0) {
315 //path exist, chose another one
316 tizenId = WidgetDAOReadOnly::generateTizenId();
318 newPath << path << tizenId;
324 m_installerContext.widgetConfig.pkgname = tizenId;
326 LogInfo("tizen_id name was generated by WRT: " << tizenId);
330 LogInfo("Tizen Id : " << m_installerContext.widgetConfig.pkgname);
331 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
335 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
336 const std::string& tempPath)
338 m_installerContext.locations =
339 WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
340 widgetPath, tempPath,
341 m_installerContext.widgetConfig.packagingType);
343 LogInfo("widgetSource " << widgetPath);
346 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
347 const std::string &widgetSource,
348 const WrtDB::ConfigParserData &configData,
349 const WidgetUpdateInfo &update,
350 const std::string &tempPath)
353 "Widget install/update: incoming guid = '" <<
354 update.incomingGUID << "'");
356 "Widget install/update: incoming version = '" <<
357 update.incomingVersion << "'");
360 WidgetUpdateMode::Type updateTypeCheckBit;
361 JobWidgetInstall::ConfigureResult ret = ConfigureResult::Ok;
363 if (update.existingWidgetInfo.isExist == false) {
364 LogInfo("Widget info does not exist");
365 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
367 LogInfo("Widget info exists. PkgName: " <<
368 update.existingWidgetInfo.pkgname);
370 DPL::OptionalString pkgname = update.existingWidgetInfo.pkgname;
372 if(pkgname.IsNull()) {
373 LogInfo("But package name doesn't exist");
374 return ConfigureResult::Failed;
377 LogInfo("Widget model exists. package name: " << pkgname);
379 // Check running state
380 int retval = APP_MANAGER_ERROR_NONE;
381 bool isRunning = false;
382 retval = app_manager_is_running(DPL::ToUTF8String(*pkgname).c_str(), &isRunning);
383 if (APP_MANAGER_ERROR_NONE != retval) {
384 LogError("Fail to get running state");
385 return ConfigureResult::Failed;
388 if (true == isRunning) {
389 // Must be deferred when update in progress
390 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
392 "Widget is already running. Policy is update according to WAC");
394 return ConfigureResult::Deferred;
397 "Widget is already running. Policy is not update according to WAC");
398 LogInfo("Installation aborted: " << widgetSource);
400 return ConfigureResult::Failed;
404 m_installerContext.widgetConfig.pkgname = pkgname;
405 OptionalWidgetVersion existingVersion;
406 existingVersion = update.existingWidgetInfo.existingVersion;
407 OptionalWidgetVersion incomingVersion = update.incomingVersion;
409 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
412 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0) {
413 LogInfo("Whether widget policy allow proceed ok");
414 ret = ConfigureResult::Updated;
417 return ConfigureResult::Failed;
420 if (!setTizenId(configData, ret)) {
421 return ConfigureResult::Failed;
423 using namespace PackageManager;
424 LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
426 configureWidgetLocation(widgetSource, tempPath);
428 // send start signal of pkgmgr
429 PkgmgrSignalSingleton::Instance().setPkgname(
431 *m_installerContext.widgetConfig.pkgname));
432 PkgmgrSignalSingleton::Instance().sendSignal(
434 PKGMGR_START_INSTALL);
437 // Init installer context
438 m_installerContext.installStep = InstallerContext::INSTALL_START;
439 m_installerContext.job = this;
440 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
441 m_installerContext.widgetConfig.shareHref = std::string();
447 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
448 const OptionalWidgetVersion &existingVersion,
449 const OptionalWidgetVersion &incomingVersion) const
451 // Widget is installed, check versions
452 if (!existingVersion && !incomingVersion) {
453 return WidgetUpdateMode::ExistingVersionEqual;
454 } else if (!existingVersion && !!incomingVersion) {
455 return WidgetUpdateMode::ExistingVersionNewer;
456 } else if (!!existingVersion && !incomingVersion) {
457 return WidgetUpdateMode::ExistingVersionOlder;
459 LogInfo("Existing widget: version = '" << *existingVersion << "'");
461 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
462 return WidgetUpdateMode::BothVersionsNotStd;
463 } else if (!existingVersion->IsWac()) {
464 return WidgetUpdateMode::ExistingVersionNotStd;
465 } else if (!incomingVersion->IsWac()) {
466 return WidgetUpdateMode::IncomingVersionNotStd;
468 // Both versions are WAC-comparable. Do compare.
469 if (*incomingVersion == *existingVersion) {
470 return WidgetUpdateMode::ExistingVersionEqual;
471 } else if (*incomingVersion > *existingVersion) {
472 return WidgetUpdateMode::ExistingVersionOlder;
474 return WidgetUpdateMode::ExistingVersionNewer;
480 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
481 const std::string &widgetSource,
482 const std::string &tempPath,
483 WrtDB::PackagingType pkgType,
488 ConfigParserData configInfo;
492 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
493 parser.Parse(widgetSource,
495 new RootParser<WidgetParser>(configInfo,
496 DPL::FromUTF32String(
500 std::unique_ptr<DPL::ZipInput> zipFile(
501 new DPL::ZipInput(widgetSource));
503 std::unique_ptr<DPL::ZipInput::File> configFile;
505 // Open config.xml file
506 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
507 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
509 configFile.reset(zipFile->OpenFile(CONFIG_XML));
513 DPL::BinaryQueue buffer;
514 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
515 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
516 DPL::Copy(&inputAdapter, &outputAdapter);
517 parser.Parse(&buffer,
519 new RootParser<WidgetParser>(configInfo,
520 DPL::FromUTF32String(
524 std::string configFile;
525 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
526 configFile = tempPath + "/" + WITH_OSP_XML;
528 configFile = tempPath + "/" + CONFIG_XML;
531 parser.Parse(configFile,
533 new RootParser<WidgetParser>(configInfo,
534 DPL::FromUTF32String(
539 Catch(DPL::ZipInput::Exception::OpenFailed)
541 LogError("Failed to open widget package");
542 return ConfigParserData();
544 Catch(DPL::ZipInput::Exception::OpenFileFailed)
546 LogError("Failed to open config.xml file");
547 return ConfigParserData();
549 Catch(DPL::CopyFailed)
551 LogError("Failed to extract config.xml file");
552 return ConfigParserData();
554 Catch(DPL::FileInput::Exception::OpenFailed)
556 LogError("Failed to open config.xml file");
557 return ConfigParserData();
559 Catch(ElementParser::Exception::ParseError)
561 LogError("Failed to parse config.xml file");
562 return ConfigParserData();
567 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
568 const ConfigParserData &configInfo)
570 LogInfo("Checking up widget package for config.xml...");
572 DPL::OptionalString widgetGUID;
573 OptionalWidgetVersion widgetVersion;
576 widgetGUID = configInfo.widget_id;
578 if (widgetGUID.IsNull()) {
579 LogWarning("Installed widget has no GUID");
580 return WidgetUpdateInfo();
583 LogDebug("Installed widget GUID: " << *widgetGUID);
585 // Locate widget ID with this GUID
586 // Incoming widget version
587 if (!configInfo.version.IsNull()) {
589 DPL::Optional<WidgetVersion>(
590 WidgetVersion(*configInfo.version));
595 // Search widget handle by GUID
596 WidgetDAOReadOnly dao(widgetGUID);
597 return WidgetUpdateInfo(
600 WidgetUpdateInfo::ExistingWidgetInfo(
601 *dao.getPkgname(), dao.getVersion()));
603 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
605 // GUID isn't installed
606 return WidgetUpdateInfo(
609 WidgetUpdateInfo::ExistingWidgetInfo());
613 void JobWidgetInstall::SendProgress()
615 using namespace PackageManager;
616 if (GetProgressFlag() != false) {
617 if (getInstallerStruct().progressCallback != NULL) {
618 // send progress signal of pkgmgr
619 std::ostringstream percent;
620 percent << static_cast<int>(GetProgressPercent());
621 PkgmgrSignalSingleton::Instance().sendSignal(
625 LogDebug("Call widget install progressCallbak");
626 getInstallerStruct().progressCallback(getInstallerStruct().userParam,
627 GetProgressPercent(),GetProgressDescription());
632 void JobWidgetInstall::SendFinishedSuccess()
634 using namespace PackageManager;
635 // TODO : sync should move to separate task.
638 // remove widget install information file
639 unlink(m_installerContext.installInfo.c_str());
642 JobWidgetInstall::displayWidgetInfo();
644 DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
646 // send signal of pkgmgr
647 PkgmgrSignalSingleton::Instance().sendSignal(
651 LogDebug("Call widget install successfinishedCallback");
652 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
653 tizenId.IsNull() ? "" : DPL::ToUTF8String(*tizenId), Exceptions::Success);
656 void JobWidgetInstall::SendFinishedFailure()
658 using namespace PackageManager;
659 // remove widget install information file
660 unlink(m_installerContext.installInfo.c_str());
662 LogError("Error in installation step: " << m_exceptionCaught);
663 LogError("Message: " << m_exceptionMessage);
664 DPL::OptionalString & tizenId = m_installerContext.widgetConfig.pkgname;
666 LogDebug("Call widget install failure finishedCallback");
668 // send signal of pkgmgr
669 PkgmgrSignalSingleton::Instance().sendSignal(
673 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
674 tizenId.IsNull() ? "" : DPL::ToUTF8String(*tizenId), m_exceptionCaught);
677 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
679 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
680 m_exceptionMessage = e.GetMessage();
683 void JobWidgetInstall::displayWidgetInfo()
685 WidgetDAOReadOnly dao(m_installerContext.locations->getPkgname());
687 std::ostringstream out;
688 WidgetLocalizedInfo localizedInfo =
689 W3CFileLocalization::getLocalizedInfo(*dao.getPkgname());
692 "===================================== INSTALLED WIDGET INFO ========="\
693 "============================";
694 out << std::endl << "Name: " << localizedInfo.name;
695 out << std::endl << "PkgName: " << dao.getPkgname();
696 WidgetSize size = dao.getPreferredSize();
697 out << std::endl << "Width: " << size.width;
698 out << std::endl << "Height: " << size.height;
699 out << std::endl << "Start File: " <<
700 W3CFileLocalization::getStartFile(*dao.getPkgname());
701 out << std::endl << "Version: " << dao.getVersion();
702 out << std::endl << "Licence: " <<
703 localizedInfo.license;
704 out << std::endl << "Licence Href: " <<
705 localizedInfo.licenseHref;
706 out << std::endl << "Description: " <<
707 localizedInfo.description;
708 out << std::endl << "Widget Id: " << dao.getGUID();
709 out << std::endl << "Widget recognized: " << dao.isRecognized();
710 out << std::endl << "Widget wac signed: " << dao.isWacSigned();
711 out << std::endl << "Widget distributor signed: " <<
712 dao.isDistributorSigned();
713 out << std::endl << "Widget trusted: " << dao.isTrusted();
715 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(*dao.getPkgname());
716 DPL::OptionalString iconSrc =
717 !!icon ? icon->src : DPL::OptionalString::Null;
718 out << std::endl << "Icon: " << iconSrc;
720 out << std::endl << "Preferences:";
722 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
725 out << std::endl << " Key: " <<
727 out << std::endl << " Readonly: " <<
732 out << std::endl << "Features:";
734 WidgetFeatureSet list = dao.getFeaturesList();
737 out << std::endl << " Name: " << it->name;
738 out << std::endl << " Required: " << it->required;
739 out << std::endl << " Params:";
748 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
749 const std::string &widgetSource,
750 const std::string &tempPath)
752 // Check installation type (config.xml or widget.wgt)
753 if (hasExtension(widgetSource, XML_EXTENSION)) {
754 LogInfo("Hosted app installation");
755 return PKG_TYPE_HOSTED_WEB_APP;
759 std::string configFile = tempPath + "/" + CONFIG_XML;
760 if (WrtUtilFileExists(configFile)) {
761 return PKG_TYPE_NOMAL_WEB_APP;
764 configFile = tempPath + "/" + WITH_OSP_XML;
765 if (WrtUtilFileExists(configFile)) {
766 return PKG_TYPE_HYBRID_WEB_APP;
769 std::unique_ptr<DPL::ZipInput> zipFile;
774 zipFile.reset(new DPL::ZipInput(widgetSource));
777 Catch(DPL::ZipInput::Exception::OpenFailed)
779 LogDebug("Failed to open widget package");
780 return PKG_TYPE_UNKNOWN;
785 // Open config.xml file in package root
786 std::unique_ptr<DPL::ZipInput::File> configFile(
787 zipFile->OpenFile(CONFIG_XML));
788 return PKG_TYPE_NOMAL_WEB_APP;
790 Catch(DPL::ZipInput::Exception::OpenFileFailed)
792 LogDebug("Could not find config.xml");
797 // Open config.xml file in package root
798 std::unique_ptr<DPL::ZipInput::File> configFile(
799 zipFile->OpenFile(WITH_OSP_XML));
801 return PKG_TYPE_HYBRID_WEB_APP;
803 Catch(DPL::ZipInput::Exception::OpenFileFailed)
805 LogDebug("Could not find wgt/config.xml");
806 return PKG_TYPE_UNKNOWN;
810 return PKG_TYPE_UNKNOWN;
813 bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
815 FOREACH(it, configData.settingsList)
817 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
818 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
819 LogDebug("resource need encryption");
826 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
829 drm_bool_type_e is_drm_file = DRM_UNKNOWN;
832 ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
833 if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
836 /* blow code temporary code for drm. */
837 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
845 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
846 std::string destPath)
849 drm_trusted_sapps_decrypt_package_info_s package_info;
851 strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
852 sizeof(package_info.sadcf_filepath));
853 strncpy(package_info.decrypt_filepath, destPath.c_str(),
854 sizeof(package_info.decrypt_filepath));
856 drm_trusted_request_type_e requestType =
857 DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
859 int ret = drm_trusted_handle_request(requestType,
860 (void *)&package_info, NULL);
861 if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
867 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
868 const_cast<char*>(destPath.c_str())) != 0) {
875 } //namespace WidgetInstall