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;
83 namespace // anonymous
85 const char * const CONFIG_XML = "config.xml";
86 const char * const WITH_OSP_XML = "res/wgt/config.xml";
88 //allowed: a-z, A-Z, 0-9
89 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
90 const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
91 const size_t PACKAGE_ID_LENGTH = 10;
93 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
94 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
95 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
96 L"install-location-type";
97 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
100 class InstallerTaskFail :
101 public DPL::TaskDecl<InstallerTaskFail>
109 ThrowMsg(Jobs::WidgetInstall::Exceptions::Deferred,
110 "Widget installation or update deferred!");
112 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
113 "Widget installation or update not allowed!");
118 InstallerTaskFail(bool deferred) :
119 DPL::TaskDecl<InstallerTaskFail>(this),
122 AddStep(&InstallerTaskFail::StepFail);
126 const std::string XML_EXTENSION = ".xml";
128 bool hasExtension(const std::string& filename, const std::string& extension) {
129 LogDebug("Looking for extension " << extension << " in: " << filename);
130 size_t fileLen = filename.length();
131 size_t extLen = extension.length();
132 if (fileLen < extLen) {
133 LogError("Filename " << filename << " is shorter than extension "
137 return (0 == filename.compare(fileLen-extLen, extLen, extension));
140 bool checkTizenPkgIdExist(const std::string& tizenPkgId) {
141 std::string installPath =
142 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
144 std::string preinstallPath =
145 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
149 if ((stat(installPath.c_str(), &dirStat) == 0) &&
150 (stat(preinstallPath.c_str(), &dirStat) == 0)) {
155 } // namespace anonymous
158 namespace WidgetInstall {
159 JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
160 const WidgetInstallationStruct &installerStruct) :
162 JobContextBase<WidgetInstallationStruct>(installerStruct),
163 m_exceptionCaught(Exceptions::Success)
166 gettimeofday(&tv, NULL);
167 srand(time(NULL) + tv.tv_usec);
169 m_installerContext.m_quiet = m_jobStruct.m_quiet;
171 ConfigureResult result = PrePareInstallation(widgetPath);
173 if (result == ConfigureResult::Ok) {
174 LogInfo("Configure installation succeeded");
175 m_installerContext.job->SetProgressFlag(true);
177 AddTask(new TaskRecovery(m_installerContext));
179 // Create installation tasks
180 if (m_installerContext.widgetConfig.packagingType !=
181 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
182 m_installerContext.widgetConfig.packagingType !=
183 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
186 AddTask(new TaskUnzip(m_installerContext));
189 AddTask(new TaskWidgetConfig(m_installerContext));
190 if (m_installerContext.widgetConfig.packagingType ==
191 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
193 AddTask(new TaskPrepareFiles(m_installerContext));
195 AddTask(new TaskCertify(m_installerContext));
196 if (m_needEncryption) {
197 AddTask(new TaskEncryptResource(m_installerContext));
200 AddTask(new TaskFileManipulation(m_installerContext));
201 // TODO: Update progress information for this task
203 //This is sort of quick solution, because ACE verdicts are based upon
204 //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
206 AddTask(new TaskSmack(m_installerContext));
208 AddTask(new TaskManifestFile(m_installerContext));
209 AddTask(new TaskCertificates(m_installerContext));
210 if (m_installerContext.widgetConfig.packagingType ==
211 PKG_TYPE_HYBRID_WEB_APP) {
212 AddTask(new TaskInstallOspsvc(m_installerContext));
214 AddTask(new TaskPluginsCopy(m_installerContext));
215 AddTask(new TaskDatabase(m_installerContext));
216 AddTask(new TaskAceCheck(m_installerContext));
217 } else if (result == ConfigureResult::Updated) {
218 LogInfo("Configure installation updated");
219 LogInfo("Widget Update");
220 m_installerContext.job->SetProgressFlag(true);
221 if (m_installerContext.widgetConfig.packagingType !=
222 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
223 m_installerContext.widgetConfig.packagingType !=
224 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
227 AddTask(new TaskUnzip(m_installerContext));
230 AddTask(new TaskWidgetConfig(m_installerContext));
232 if (m_installerContext.widgetConfig.packagingType ==
233 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
235 AddTask(new TaskPrepareFiles(m_installerContext));
238 AddTask(new TaskCertify(m_installerContext));
239 if (m_installerContext.widgetConfig.packagingType !=
240 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
242 AddTask(new TaskUpdateFiles(m_installerContext));
245 /* TODO : To backup file, save md5 values */
246 AddTask(new TaskSmack(m_installerContext));
248 AddTask(new TaskManifestFile(m_installerContext));
249 if (m_installerContext.widgetConfig.packagingType ==
250 PKG_TYPE_HYBRID_WEB_APP) {
251 AddTask(new TaskInstallOspsvc(m_installerContext));
253 if (m_installerContext.widgetConfig.packagingType !=
254 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
256 AddTask(new TaskRemoveBackupFiles(m_installerContext));
258 AddTask(new TaskPluginsCopy(m_installerContext));
259 AddTask(new TaskDatabase(m_installerContext));
260 AddTask(new TaskAceCheck(m_installerContext));
261 //TODO: remove widgetHandle from this task and move before database task
262 // by now widget handle is needed in ace check
263 // Any error in acecheck while update will break widget
265 } else if (result == ConfigureResult::Deferred) {
266 // Installation is deferred
267 LogInfo("Configure installation deferred");
269 AddTask(new InstallerTaskFail(true));
270 } else if (result == ConfigureResult::Failed) {
271 // Installation is not allowed to proceed due to widget update policy
272 LogWarning("Configure installation failed!");
274 AddTask(new InstallerTaskFail(false));
276 Assert(false && "Invalid configure result!");
280 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
281 const std::string &widgetPath)
283 ConfigureResult result;
284 m_needEncryption = false;
288 std::string tempDir =
289 Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
291 m_isDRM = isDRMWidget(widgetPath);
292 if (true == m_isDRM) {
293 LogDebug("decrypt DRM widget");
294 if(DecryptDRMWidget(widgetPath, tempDir)) {
295 LogDebug("Failed decrypt DRM widget");
296 return ConfigureResult::Failed;
300 LogDebug("widgetPath:" << widgetPath);
302 m_installerContext.widgetConfig.packagingType =
303 checkPackageType(widgetPath, tempDir);
304 ConfigParserData configData = getWidgetDataFromXML(
307 m_installerContext.widgetConfig.packagingType,
309 LogDebug("widget packaging type : " <<
310 m_installerContext.widgetConfig.packagingType.pkgType);
312 setTizenId(configData);
313 setApplicationType(configData);
314 m_needEncryption = detectResourceEncryption(configData);
315 setInstallLocationType(configData);
317 // Configure installation
318 result = ConfigureInstallation(widgetPath, configData, tempDir);
320 Catch(Exceptions::ExtractFileFailed)
322 LogError("Failed to create temporary path for widget");
323 result = ConfigureResult::Failed;
329 void JobWidgetInstall::setTizenId(
330 const WrtDB::ConfigParserData &configInfo)
332 bool shouldMakeAppid = false;
333 using namespace PackageManager;
334 if(!!configInfo.tizenAppId) {
335 LogDebug("Setting tizenAppId provided in config.xml: " <<
336 configInfo.tizenAppId);
338 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
340 if(!!configInfo.tizenPkgId) {
341 LogDebug("Setting tizenPkgId provided in config.xml: " <<
342 configInfo.tizenPkgId);
344 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
346 DPL::String appid = *configInfo.tizenAppId;
347 if(appid.length() > PACKAGE_ID_LENGTH) {
348 m_installerContext.widgetConfig.tzPkgid =
349 appid.substr(0, PACKAGE_ID_LENGTH);
350 } //else: this means appId is broken anyway
353 shouldMakeAppid = true;
354 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
355 LogDebug("Checking if pkg id is unique");
357 if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) {
358 //path exist, chose another one
359 pkgId = WidgetDAOReadOnly::generatePkgId();
364 m_installerContext.widgetConfig.tzPkgid = pkgId;
365 LogInfo("tizen_id name was generated by WRT: " <<
366 m_installerContext.widgetConfig.tzPkgid);
370 if(shouldMakeAppid == true) {
371 DPL::OptionalString name;
372 DPL::OptionalString defaultLocale = configInfo.defaultlocale;
374 FOREACH(localizedData, configInfo.localizedDataSet)
376 Locale i = localizedData->first;
377 if (!!defaultLocale) {
378 if (defaultLocale == i) {
379 name = localizedData->second.name;
384 name = localizedData->second.name;
389 if(regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
390 LogDebug("Regcomp failed");
393 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
394 static_cast<size_t>(0), NULL, 0) != REG_NOERROR)) {
395 // TODO : generate name move to wrt-commons
396 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
397 std::ostringstream genName;
399 genName << "_" << allowedString[rand() % allowedString.length()];
400 name = DPL::FromUTF8String(genName.str());
401 LogDebug("name was generated by WRT" );
404 LogDebug("Name : " << name);
405 std::ostringstream genid;
406 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
407 LogDebug("tizen appid was generated by WRT : " << genid.str());
409 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
410 NormalizeAndTrimSpaceString(appid);
411 m_installerContext.widgetConfig.tzAppid = *appid;
414 // send start signal of pkgmgr
415 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
416 m_installerContext.widgetConfig.tzAppid));
417 getInstallerStruct().pkgmgrInterface->sendSignal(
419 PKGMGR_START_INSTALL);
421 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
422 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
423 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
426 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
427 const std::string& tempPath)
429 m_installerContext.locations =
430 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.tzPkgid),
431 widgetPath, tempPath,
432 m_installerContext.widgetConfig.packagingType,
433 m_installerContext.locationType);
434 m_installerContext.locations->registerAppid(
435 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
437 LogInfo("widgetSource " << widgetPath);
440 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
441 const std::string &widgetSource,
442 const WrtDB::ConfigParserData &configData,
443 const std::string &tempPath)
445 WidgetUpdateInfo update = detectWidgetUpdate(configData,
446 m_installerContext.widgetConfig.webAppType,
447 m_installerContext.widgetConfig.tzAppid);
448 ConfigureResult result = checkWidgetUpdate(update);
452 if(regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
453 LogDebug("Regcomp failed");
457 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid).c_str(),
458 static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
459 (checkTizenPkgIdExist(DPL::ToUTF8String(m_installerContext.widgetConfig.tzPkgid)) &&
460 result != ConfigureResult::Updated))
462 //it is true when tizenId does not fit REG_TIZENID_PATTERN
463 LogError("tizen_id provided but not proper or pkgId directory exists");
464 //TODO(t.iwanek): appId is unique, what about installation of abcdefghij.test1 and abcdefghij.test2?
466 return ConfigureResult::Failed;
470 configureWidgetLocation(widgetSource, tempPath);
472 // Init installer context
473 m_installerContext.installStep = InstallerContext::INSTALL_START;
474 m_installerContext.job = this;
475 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
476 m_installerContext.widgetConfig.shareHref = std::string();
481 JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
482 const WidgetUpdateInfo &update)
485 "Widget install/update: incoming guid = '" <<
486 update.incomingGUID << "'");
488 "Widget install/update: incoming version = '" <<
489 update.incomingVersion << "'");
492 WidgetUpdateMode::Type updateTypeCheckBit;
494 if (update.existingWidgetInfo.isExist == false) {
495 LogInfo("Widget info does not exist");
496 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
498 LogInfo("Widget info exists. appid: " <<
499 update.existingWidgetInfo.tzAppid);
501 TizenAppId tzAppid = update.existingWidgetInfo.tzAppid;
503 LogInfo("Widget model exists. tizen app id: " << tzAppid);
505 // Check running state
506 int retval = APP_MANAGER_ERROR_NONE;
507 bool isRunning = false;
508 retval = app_manager_is_running(DPL::ToUTF8String(tzAppid).c_str(), &isRunning);
509 if (APP_MANAGER_ERROR_NONE != retval) {
510 LogError("Fail to get running state");
511 return ConfigureResult::Failed;
514 if (true == isRunning) {
515 // Must be deferred when update in progress
516 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
518 "Widget is already running. Policy is update according to WAC");
520 return ConfigureResult::Deferred;
523 "Widget is already running. Policy is not update according to WAC");
525 return ConfigureResult::Failed;
529 m_installerContext.widgetConfig.tzAppid = tzAppid;
530 OptionalWidgetVersion existingVersion;
531 existingVersion = update.existingWidgetInfo.existingVersion;
532 OptionalWidgetVersion incomingVersion = update.incomingVersion;
534 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
537 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
538 m_jobStruct.updateMode ==
539 WidgetUpdateMode::PolicyDirectoryForceInstall)
541 LogInfo("Whether widget policy allow proceed ok");
542 return ConfigureResult::Updated;
545 return ConfigureResult::Failed;
547 return ConfigureResult::Ok;
550 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
551 const OptionalWidgetVersion &existingVersion,
552 const OptionalWidgetVersion &incomingVersion) const
554 // Widget is installed, check versions
555 if (!existingVersion && !incomingVersion) {
556 return WidgetUpdateMode::ExistingVersionEqual;
557 } else if (!existingVersion && !!incomingVersion) {
558 return WidgetUpdateMode::ExistingVersionNewer;
559 } else if (!!existingVersion && !incomingVersion) {
560 return WidgetUpdateMode::ExistingVersionOlder;
562 LogInfo("Existing widget: version = '" << *existingVersion << "'");
564 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
565 return WidgetUpdateMode::BothVersionsNotStd;
566 } else if (!existingVersion->IsWac()) {
567 return WidgetUpdateMode::ExistingVersionNotStd;
568 } else if (!incomingVersion->IsWac()) {
569 return WidgetUpdateMode::IncomingVersionNotStd;
571 // Both versions are WAC-comparable. Do compare.
572 if (*incomingVersion == *existingVersion) {
573 return WidgetUpdateMode::ExistingVersionEqual;
574 } else if (*incomingVersion > *existingVersion) {
575 return WidgetUpdateMode::ExistingVersionOlder;
577 return WidgetUpdateMode::ExistingVersionNewer;
583 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
584 const std::string &widgetSource,
585 const std::string &tempPath,
586 WrtDB::PackagingType pkgType,
591 ConfigParserData configInfo;
595 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
596 parser.Parse(widgetSource,
598 new RootParser<WidgetParser>(configInfo,
599 DPL::FromUTF32String(
601 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
602 parser.Parse(widgetSource + '/' + WITH_OSP_XML,
604 new RootParser<WidgetParser>(
606 DPL::FromUTF32String(L"widget"))));
609 std::unique_ptr<DPL::ZipInput> zipFile(
610 new DPL::ZipInput(widgetSource));
612 std::unique_ptr<DPL::ZipInput::File> configFile;
614 // Open config.xml file
615 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
616 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
618 configFile.reset(zipFile->OpenFile(CONFIG_XML));
622 DPL::BinaryQueue buffer;
623 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
624 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
625 DPL::Copy(&inputAdapter, &outputAdapter);
626 parser.Parse(&buffer,
628 new RootParser<WidgetParser>(configInfo,
629 DPL::FromUTF32String(
633 std::string configFile;
634 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
635 configFile = tempPath + "/" + WITH_OSP_XML;
637 configFile = tempPath + "/" + CONFIG_XML;
640 parser.Parse(configFile,
642 new RootParser<WidgetParser>(configInfo,
643 DPL::FromUTF32String(
648 Catch(DPL::ZipInput::Exception::OpenFailed)
650 LogError("Failed to open widget package");
651 return ConfigParserData();
653 Catch(DPL::ZipInput::Exception::OpenFileFailed)
655 LogError("Failed to open config.xml file");
656 return ConfigParserData();
658 Catch(DPL::CopyFailed)
660 LogError("Failed to extract config.xml file");
661 return ConfigParserData();
663 Catch(DPL::FileInput::Exception::OpenFailed)
665 LogError("Failed to open config.xml file");
666 return ConfigParserData();
668 Catch(ElementParser::Exception::ParseError)
670 LogError("Failed to parse config.xml file");
671 return ConfigParserData();
673 Catch(DPL::ZipInput::Exception::SeekFileFailed)
675 LogError("Failed to seek widget archive - corrupted package?");
676 return ConfigParserData();
681 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
682 const ConfigParserData &configInfo,
683 const WrtDB::WidgetType appType,
684 const WrtDB::TizenAppId &tizenId)
686 LogInfo("Checking up widget package for config.xml...");
688 DPL::OptionalString widgetGUID;
689 OptionalWidgetVersion widgetVersion;
692 widgetGUID = configInfo.widget_id;
694 if (widgetGUID.IsNull()) {
695 LogWarning("Installed widget has no GUID");
696 return WidgetUpdateInfo();
699 LogDebug("Installed widget GUID: " << *widgetGUID);
701 // Locate widget ID with this GUID
702 // Incoming widget version
703 if (!configInfo.version.IsNull()) {
705 DPL::Optional<WidgetVersion>(
706 WidgetVersion(*configInfo.version));
709 if (appType == APP_TYPE_WAC20) {
712 // Search widget handle by GUID
713 WidgetDAOReadOnly dao(widgetGUID);
714 return WidgetUpdateInfo(
717 WidgetUpdateInfo::ExistingWidgetInfo(
718 dao.getTzAppId(), dao.getVersion()));
720 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
722 // GUID isn't installed
723 return WidgetUpdateInfo(
726 WidgetUpdateInfo::ExistingWidgetInfo());
731 // Search widget handle by appId
732 WidgetDAOReadOnly dao(tizenId);
733 return WidgetUpdateInfo(
736 WidgetUpdateInfo::ExistingWidgetInfo(
737 dao.getTzAppId(), dao.getVersion()));
739 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
741 // GUID isn't installed
742 return WidgetUpdateInfo(
745 WidgetUpdateInfo::ExistingWidgetInfo());
751 void JobWidgetInstall::SendProgress()
753 using namespace PackageManager;
754 if (GetProgressFlag() != false) {
755 if (getInstallerStruct().progressCallback != NULL) {
756 // send progress signal of pkgmgr
757 std::ostringstream percent;
758 percent << static_cast<int>(GetProgressPercent());
759 getInstallerStruct().pkgmgrInterface->sendSignal(
763 LogDebug("Call widget install progressCallbak");
764 getInstallerStruct().progressCallback(getInstallerStruct().userParam,
765 GetProgressPercent(),GetProgressDescription());
770 void JobWidgetInstall::SendFinishedSuccess()
772 using namespace PackageManager;
773 // TODO : sync should move to separate task.
777 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
778 if (false == m_installerContext.existingWidgetInfo.isExist) {
779 WidgetInstallToExtSingleton::Instance().postInstallation(true);
781 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
783 WidgetInstallToExtSingleton::Instance().deinitialize();
786 // remove widget install information file
787 unlink(m_installerContext.installInfo.c_str());
790 JobWidgetInstall::displayWidgetInfo();
792 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
794 // send signal of pkgmgr
795 getInstallerStruct().pkgmgrInterface->sendSignal(
799 LogDebug("Call widget install successfinishedCallback");
800 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
801 DPL::ToUTF8String(tizenId), Exceptions::Success);
804 void JobWidgetInstall::SendFinishedFailure()
806 using namespace PackageManager;
807 // remove widget install information file
808 unlink(m_installerContext.installInfo.c_str());
810 LogError("Error in installation step: " << m_exceptionCaught);
811 LogError("Message: " << m_exceptionMessage);
812 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
814 LogDebug("Call widget install failure finishedCallback");
816 // send signal of pkgmgr
817 getInstallerStruct().pkgmgrInterface->sendSignal(
821 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
822 DPL::ToUTF8String(tizenId), m_exceptionCaught);
825 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
827 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
828 m_exceptionMessage = e.GetMessage();
831 void JobWidgetInstall::displayWidgetInfo()
833 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
835 std::ostringstream out;
836 WidgetLocalizedInfo localizedInfo =
837 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
840 "===================================== INSTALLED WIDGET INFO ========="\
841 "============================";
842 out << std::endl << "Name: " << localizedInfo.name;
843 out << std::endl << "AppId: " << dao.getTzAppId();
844 WidgetSize size = dao.getPreferredSize();
845 out << std::endl << "Width: " << size.width;
846 out << std::endl << "Height: " << size.height;
847 out << std::endl << "Start File: " <<
848 W3CFileLocalization::getStartFile(dao.getTzAppId());
849 out << std::endl << "Version: " << dao.getVersion();
850 out << std::endl << "Licence: " <<
851 localizedInfo.license;
852 out << std::endl << "Licence Href: " <<
853 localizedInfo.licenseHref;
854 out << std::endl << "Description: " <<
855 localizedInfo.description;
856 out << std::endl << "Widget Id: " << dao.getGUID();
857 out << std::endl << "Widget recognized: " << dao.isRecognized();
858 out << std::endl << "Widget wac signed: " << dao.isWacSigned();
859 out << std::endl << "Widget distributor signed: " <<
860 dao.isDistributorSigned();
861 out << std::endl << "Widget trusted: " << dao.isTrusted();
863 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
864 DPL::OptionalString iconSrc = !!icon ? icon->src : DPL::OptionalString::Null;
865 out << std::endl << "Icon: " << iconSrc;
867 out << std::endl << "Preferences:";
869 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
872 out << std::endl << " Key: " <<
874 out << std::endl << " Readonly: " <<
879 out << std::endl << "Features:";
881 WidgetFeatureSet list = dao.getFeaturesList();
884 out << std::endl << " Name: " << it->name;
885 out << std::endl << " Required: " << it->required;
886 out << std::endl << " Params:";
895 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
896 const std::string &widgetSource,
897 const std::string &tempPath)
899 // Check installation type (direcotory/ or config.xml or widget.wgt)
900 if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
902 LogDebug("Install directly from directory");
903 return PKG_TYPE_DIRECTORY_WEB_APP;
905 if (hasExtension(widgetSource, XML_EXTENSION)) {
906 LogInfo("Hosted app installation");
907 return PKG_TYPE_HOSTED_WEB_APP;
911 std::string configFile = tempPath + "/" + CONFIG_XML;
912 if (WrtUtilFileExists(configFile)) {
913 return PKG_TYPE_NOMAL_WEB_APP;
916 configFile = tempPath + "/" + WITH_OSP_XML;
917 if (WrtUtilFileExists(configFile)) {
918 return PKG_TYPE_HYBRID_WEB_APP;
921 std::unique_ptr<DPL::ZipInput> zipFile;
926 zipFile.reset(new DPL::ZipInput(widgetSource));
929 Catch(DPL::ZipInput::Exception::OpenFailed)
931 LogDebug("Failed to open widget package");
932 return PKG_TYPE_UNKNOWN;
934 Catch(DPL::ZipInput::Exception::SeekFileFailed)
936 LogError("Failed to seek widget package file");
937 return PKG_TYPE_UNKNOWN;
942 // Open config.xml file in package root
943 std::unique_ptr<DPL::ZipInput::File> configFile(
944 zipFile->OpenFile(CONFIG_XML));
945 return PKG_TYPE_NOMAL_WEB_APP;
947 Catch(DPL::ZipInput::Exception::OpenFileFailed)
949 LogDebug("Could not find config.xml");
954 // Open config.xml file in package root
955 std::unique_ptr<DPL::ZipInput::File> configFile(
956 zipFile->OpenFile(WITH_OSP_XML));
958 return PKG_TYPE_HYBRID_WEB_APP;
960 Catch(DPL::ZipInput::Exception::OpenFileFailed)
962 LogDebug("Could not find wgt/config.xml");
963 return PKG_TYPE_UNKNOWN;
967 return PKG_TYPE_UNKNOWN;
970 void JobWidgetInstall::setApplicationType(
971 const WrtDB::ConfigParserData &configInfo)
974 FOREACH(iterator, configInfo.nameSpaces) {
975 LogInfo("namespace = [" << *iterator << "]");
976 AppType currentAppType = APP_TYPE_UNKNOWN;
978 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
982 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
984 ConfigurationNamespace::WacWidgetNamespaceName)
986 currentAppType = APP_TYPE_WAC20;
987 } else if (*iterator ==
988 ConfigurationNamespace::TizenWebAppNamespaceName) {
989 currentAppType = APP_TYPE_TIZENWEBAPP;
992 if (m_installerContext.widgetConfig.webAppType ==
994 m_installerContext.widgetConfig.webAppType = currentAppType;
995 } else if (m_installerContext.widgetConfig.webAppType ==
999 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
1000 "Config.xml has more than one namespace");
1004 // If there is no define, type set to WAC 2.0
1005 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
1006 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
1009 LogInfo("type = [" <<
1010 m_installerContext.widgetConfig.webAppType.getApptypeToString() << "]");
1013 bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
1015 FOREACH(it, configData.settingsList)
1017 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
1018 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
1019 LogDebug("resource need encryption");
1026 void JobWidgetInstall::setInstallLocationType(const
1027 WrtDB::ConfigParserData &configData)
1029 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
1031 if (true == m_jobStruct.m_preload) {
1032 m_installerContext.locationType =
1033 INSTALL_LOCATION_TYPE_PRELOAD;
1035 FOREACH(it, configData.settingsList)
1037 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
1039 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
1040 LogDebug("This widget will be installed to sd card");
1041 m_installerContext.locationType =
1042 INSTALL_LOCATION_TYPE_EXTERNAL;
1048 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
1051 drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1054 ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
1055 if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
1058 /* blow code temporary code for drm. */
1059 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
1067 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
1068 std::string destPath)
1071 drm_trusted_sapps_decrypt_package_info_s package_info;
1073 strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
1074 sizeof(package_info.sadcf_filepath));
1075 strncpy(package_info.decrypt_filepath, destPath.c_str(),
1076 sizeof(package_info.decrypt_filepath));
1078 drm_trusted_request_type_e requestType =
1079 DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
1081 int ret = drm_trusted_handle_request(requestType,
1082 (void *)&package_info, NULL);
1083 if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
1089 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
1090 const_cast<char*>(destPath.c_str())) != 0) {
1097 } //namespace WidgetInstall