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);
172 m_installerContext.job->SetProgressFlag(true);
174 if (result == ConfigureResult::Ok) {
175 LogInfo("Configure installation succeeded");
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 if (m_installerContext.widgetConfig.packagingType !=
221 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
222 m_installerContext.widgetConfig.packagingType !=
223 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
226 AddTask(new TaskUnzip(m_installerContext));
229 AddTask(new TaskWidgetConfig(m_installerContext));
231 if (m_installerContext.widgetConfig.packagingType ==
232 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
234 AddTask(new TaskPrepareFiles(m_installerContext));
237 AddTask(new TaskCertify(m_installerContext));
238 if (m_installerContext.widgetConfig.packagingType !=
239 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
241 AddTask(new TaskUpdateFiles(m_installerContext));
244 /* TODO : To backup file, save md5 values */
245 AddTask(new TaskSmack(m_installerContext));
247 AddTask(new TaskManifestFile(m_installerContext));
248 if (m_installerContext.widgetConfig.packagingType ==
249 PKG_TYPE_HYBRID_WEB_APP) {
250 AddTask(new TaskInstallOspsvc(m_installerContext));
252 if (m_installerContext.widgetConfig.packagingType !=
253 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
255 AddTask(new TaskRemoveBackupFiles(m_installerContext));
257 AddTask(new TaskPluginsCopy(m_installerContext));
258 AddTask(new TaskDatabase(m_installerContext));
259 AddTask(new TaskAceCheck(m_installerContext));
260 //TODO: remove widgetHandle from this task and move before database task
261 // by now widget handle is needed in ace check
262 // Any error in acecheck while update will break widget
264 } else if (result == ConfigureResult::Deferred) {
265 // Installation is deferred
266 LogInfo("Configure installation deferred");
268 AddTask(new InstallerTaskFail(true));
269 } else if (result == ConfigureResult::Failed) {
270 // Installation is not allowed to proceed due to widget update policy
271 LogWarning("Configure installation failed!");
273 AddTask(new InstallerTaskFail(false));
275 Assert(false && "Invalid configure result!");
279 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
280 const std::string &widgetPath)
282 ConfigureResult result;
283 m_needEncryption = false;
287 std::string tempDir =
288 Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
290 m_isDRM = isDRMWidget(widgetPath);
291 if (true == m_isDRM) {
292 LogDebug("decrypt DRM widget");
293 if(DecryptDRMWidget(widgetPath, tempDir)) {
294 LogDebug("Failed decrypt DRM widget");
295 return ConfigureResult::Failed;
299 LogDebug("widgetPath:" << widgetPath);
301 m_installerContext.widgetConfig.packagingType =
302 checkPackageType(widgetPath, tempDir);
303 ConfigParserData configData = getWidgetDataFromXML(
306 m_installerContext.widgetConfig.packagingType,
308 LogDebug("widget packaging type : " <<
309 m_installerContext.widgetConfig.packagingType.pkgType);
311 setTizenId(configData);
312 setApplicationType(configData);
313 m_needEncryption = detectResourceEncryption(configData);
314 setInstallLocationType(configData);
316 // Configure installation
317 result = ConfigureInstallation(widgetPath, configData, tempDir);
319 Catch(Exceptions::ExtractFileFailed)
321 LogError("Failed to create temporary path for widget");
322 result = ConfigureResult::Failed;
328 void JobWidgetInstall::setTizenId(
329 const WrtDB::ConfigParserData &configInfo)
331 bool shouldMakeAppid = false;
332 using namespace PackageManager;
333 if(!!configInfo.tizenAppId) {
334 LogDebug("Setting tizenAppId provided in config.xml: " <<
335 configInfo.tizenAppId);
337 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
339 if(!!configInfo.tizenPkgId) {
340 LogDebug("Setting tizenPkgId provided in config.xml: " <<
341 configInfo.tizenPkgId);
343 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
345 std::string appid = DPL::ToUTF8String(*configInfo.tizenAppId);
346 if(appid.length() > PACKAGE_ID_LENGTH) {
347 m_installerContext.widgetConfig.tzPkgid =
348 DPL::FromUTF8String(appid.substr(PACKAGE_ID_LENGTH));
350 m_installerContext.widgetConfig.tzPkgid =
351 *configInfo.tizenAppId;
353 shouldMakeAppid = true;
356 shouldMakeAppid = true;
357 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
358 LogDebug("Checking if pkg id is unique");
360 if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) {
361 //path exist, chose another one
362 pkgId = WidgetDAOReadOnly::generatePkgId();
367 m_installerContext.widgetConfig.tzPkgid = pkgId;
368 LogInfo("tizen_id name was generated by WRT: " <<
369 m_installerContext.widgetConfig.tzPkgid);
373 if(shouldMakeAppid == true) {
374 DPL::OptionalString name;
375 DPL::OptionalString defaultLocale = configInfo.defaultlocale;
377 FOREACH(localizedData, configInfo.localizedDataSet)
379 Locale i = localizedData->first;
380 if (!!defaultLocale) {
381 if (defaultLocale == i) {
382 name = localizedData->second.name;
387 name = localizedData->second.name;
392 if(regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
393 LogDebug("Regcomp failed");
396 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
397 static_cast<size_t>(0), NULL, 0) != REG_NOERROR)) {
398 // TODO : generate name move to wrt-commons
399 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
400 std::ostringstream genName;
402 genName << "_" << allowedString[rand() % allowedString.length()];
403 name = DPL::FromUTF8String(genName.str());
404 LogDebug("name was generated by WRT" );
407 LogDebug("Name : " << name);
408 std::ostringstream genid;
409 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
410 LogDebug("tizen appid was generated by WRT : " << genid.str());
412 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
413 NormalizeAndTrimSpaceString(appid);
414 m_installerContext.widgetConfig.tzAppid = *appid;
417 // send start signal of pkgmgr
418 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
419 m_installerContext.widgetConfig.tzAppid));
420 getInstallerStruct().pkgmgrInterface->sendSignal(
422 PKGMGR_START_INSTALL);
424 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
425 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
426 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
429 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
430 const std::string& tempPath)
432 m_installerContext.locations =
433 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.tzPkgid),
434 widgetPath, tempPath,
435 m_installerContext.widgetConfig.packagingType,
436 m_installerContext.locationType);
437 m_installerContext.locations->registerAppid(
438 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
440 LogInfo("widgetSource " << widgetPath);
443 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
444 const std::string &widgetSource,
445 const WrtDB::ConfigParserData &configData,
446 const std::string &tempPath)
448 WidgetUpdateInfo update = detectWidgetUpdate(configData,
449 m_installerContext.widgetConfig.webAppType,
450 m_installerContext.widgetConfig.tzAppid);
451 ConfigureResult result = checkWidgetUpdate(update);
455 if(regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED)!=0){
456 LogDebug("Regcomp failed");
460 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid).c_str(),
461 static_cast<size_t>(0), NULL, 0) != REG_NOERROR) ||
462 (checkTizenPkgIdExist(DPL::ToUTF8String(m_installerContext.widgetConfig.tzPkgid)) &&
463 result != ConfigureResult::Updated))
465 //it is true when tizenId does not fit REG_TIZENID_PATTERN
466 LogError("tizen_id provided but not proper.");
468 return ConfigureResult::Failed;
472 configureWidgetLocation(widgetSource, tempPath);
474 // Init installer context
475 m_installerContext.installStep = InstallerContext::INSTALL_START;
476 m_installerContext.job = this;
477 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
478 m_installerContext.widgetConfig.shareHref = std::string();
483 JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
484 const WidgetUpdateInfo &update)
487 "Widget install/update: incoming guid = '" <<
488 update.incomingGUID << "'");
490 "Widget install/update: incoming version = '" <<
491 update.incomingVersion << "'");
494 WidgetUpdateMode::Type updateTypeCheckBit;
496 if (update.existingWidgetInfo.isExist == false) {
497 LogInfo("Widget info does not exist");
498 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
500 LogInfo("Widget info exists. appid: " <<
501 update.existingWidgetInfo.tzAppid);
503 TizenAppId tzAppid = update.existingWidgetInfo.tzAppid;
505 LogInfo("Widget model exists. tizen app id: " << tzAppid);
507 // Check running state
508 int retval = APP_MANAGER_ERROR_NONE;
509 bool isRunning = false;
510 retval = app_manager_is_running(DPL::ToUTF8String(tzAppid).c_str(), &isRunning);
511 if (APP_MANAGER_ERROR_NONE != retval) {
512 LogError("Fail to get running state");
513 return ConfigureResult::Failed;
516 if (true == isRunning) {
517 // Must be deferred when update in progress
518 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
520 "Widget is already running. Policy is update according to WAC");
522 return ConfigureResult::Deferred;
525 "Widget is already running. Policy is not update according to WAC");
527 return ConfigureResult::Failed;
531 m_installerContext.widgetConfig.tzAppid = tzAppid;
532 OptionalWidgetVersion existingVersion;
533 existingVersion = update.existingWidgetInfo.existingVersion;
534 OptionalWidgetVersion incomingVersion = update.incomingVersion;
536 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
539 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
540 m_jobStruct.updateMode ==
541 WidgetUpdateMode::PolicyDirectoryForceInstall)
543 LogInfo("Whether widget policy allow proceed ok");
544 return ConfigureResult::Updated;
547 return ConfigureResult::Failed;
549 return ConfigureResult::Ok;
552 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
553 const OptionalWidgetVersion &existingVersion,
554 const OptionalWidgetVersion &incomingVersion) const
556 // Widget is installed, check versions
557 if (!existingVersion && !incomingVersion) {
558 return WidgetUpdateMode::ExistingVersionEqual;
559 } else if (!existingVersion && !!incomingVersion) {
560 return WidgetUpdateMode::ExistingVersionNewer;
561 } else if (!!existingVersion && !incomingVersion) {
562 return WidgetUpdateMode::ExistingVersionOlder;
564 LogInfo("Existing widget: version = '" << *existingVersion << "'");
566 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
567 return WidgetUpdateMode::BothVersionsNotStd;
568 } else if (!existingVersion->IsWac()) {
569 return WidgetUpdateMode::ExistingVersionNotStd;
570 } else if (!incomingVersion->IsWac()) {
571 return WidgetUpdateMode::IncomingVersionNotStd;
573 // Both versions are WAC-comparable. Do compare.
574 if (*incomingVersion == *existingVersion) {
575 return WidgetUpdateMode::ExistingVersionEqual;
576 } else if (*incomingVersion > *existingVersion) {
577 return WidgetUpdateMode::ExistingVersionOlder;
579 return WidgetUpdateMode::ExistingVersionNewer;
585 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
586 const std::string &widgetSource,
587 const std::string &tempPath,
588 WrtDB::PackagingType pkgType,
593 ConfigParserData configInfo;
597 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
598 parser.Parse(widgetSource,
600 new RootParser<WidgetParser>(configInfo,
601 DPL::FromUTF32String(
603 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
604 parser.Parse(widgetSource + '/' + WITH_OSP_XML,
606 new RootParser<WidgetParser>(
608 DPL::FromUTF32String(L"widget"))));
611 std::unique_ptr<DPL::ZipInput> zipFile(
612 new DPL::ZipInput(widgetSource));
614 std::unique_ptr<DPL::ZipInput::File> configFile;
616 // Open config.xml file
617 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
618 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
620 configFile.reset(zipFile->OpenFile(CONFIG_XML));
624 DPL::BinaryQueue buffer;
625 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
626 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
627 DPL::Copy(&inputAdapter, &outputAdapter);
628 parser.Parse(&buffer,
630 new RootParser<WidgetParser>(configInfo,
631 DPL::FromUTF32String(
635 std::string configFile;
636 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
637 configFile = tempPath + "/" + WITH_OSP_XML;
639 configFile = tempPath + "/" + CONFIG_XML;
642 parser.Parse(configFile,
644 new RootParser<WidgetParser>(configInfo,
645 DPL::FromUTF32String(
650 Catch(DPL::ZipInput::Exception::OpenFailed)
652 LogError("Failed to open widget package");
653 return ConfigParserData();
655 Catch(DPL::ZipInput::Exception::OpenFileFailed)
657 LogError("Failed to open config.xml file");
658 return ConfigParserData();
660 Catch(DPL::CopyFailed)
662 LogError("Failed to extract config.xml file");
663 return ConfigParserData();
665 Catch(DPL::FileInput::Exception::OpenFailed)
667 LogError("Failed to open config.xml file");
668 return ConfigParserData();
670 Catch(ElementParser::Exception::ParseError)
672 LogError("Failed to parse config.xml file");
673 return ConfigParserData();
675 Catch(DPL::ZipInput::Exception::SeekFileFailed)
677 LogError("Failed to seek widget archive - corrupted package?");
678 return ConfigParserData();
683 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
684 const ConfigParserData &configInfo,
685 const WrtDB::WidgetType appType,
686 const WrtDB::TizenAppId &tizenId)
688 LogInfo("Checking up widget package for config.xml...");
690 DPL::OptionalString widgetGUID;
691 OptionalWidgetVersion widgetVersion;
694 widgetGUID = configInfo.widget_id;
696 if (widgetGUID.IsNull()) {
697 LogWarning("Installed widget has no GUID");
698 return WidgetUpdateInfo();
701 LogDebug("Installed widget GUID: " << *widgetGUID);
703 // Locate widget ID with this GUID
704 // Incoming widget version
705 if (!configInfo.version.IsNull()) {
707 DPL::Optional<WidgetVersion>(
708 WidgetVersion(*configInfo.version));
711 if (appType == APP_TYPE_WAC20) {
714 // Search widget handle by GUID
715 WidgetDAOReadOnly dao(widgetGUID);
716 return WidgetUpdateInfo(
719 WidgetUpdateInfo::ExistingWidgetInfo(
720 dao.getTzAppId(), dao.getVersion()));
722 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
724 // GUID isn't installed
725 return WidgetUpdateInfo(
728 WidgetUpdateInfo::ExistingWidgetInfo());
733 // Search widget handle by appId
734 WidgetDAOReadOnly dao(tizenId);
735 return WidgetUpdateInfo(
738 WidgetUpdateInfo::ExistingWidgetInfo(
739 dao.getTzAppId(), dao.getVersion()));
741 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
743 // GUID isn't installed
744 return WidgetUpdateInfo(
747 WidgetUpdateInfo::ExistingWidgetInfo());
753 void JobWidgetInstall::SendProgress()
755 using namespace PackageManager;
756 if (GetProgressFlag() != false) {
757 if (getInstallerStruct().progressCallback != NULL) {
758 // send progress signal of pkgmgr
759 std::ostringstream percent;
760 percent << static_cast<int>(GetProgressPercent());
761 getInstallerStruct().pkgmgrInterface->sendSignal(
765 LogDebug("Call widget install progressCallbak");
766 getInstallerStruct().progressCallback(getInstallerStruct().userParam,
767 GetProgressPercent(),GetProgressDescription());
772 void JobWidgetInstall::SendFinishedSuccess()
774 using namespace PackageManager;
775 // TODO : sync should move to separate task.
779 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
780 if (false == m_installerContext.existingWidgetInfo.isExist) {
781 WidgetInstallToExtSingleton::Instance().postInstallation(true);
783 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
785 WidgetInstallToExtSingleton::Instance().deinitialize();
788 // remove widget install information file
789 unlink(m_installerContext.installInfo.c_str());
792 JobWidgetInstall::displayWidgetInfo();
794 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
796 // send signal of pkgmgr
797 getInstallerStruct().pkgmgrInterface->sendSignal(
801 LogDebug("Call widget install successfinishedCallback");
802 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
803 DPL::ToUTF8String(tizenId), Exceptions::Success);
806 void JobWidgetInstall::SendFinishedFailure()
808 using namespace PackageManager;
809 // remove widget install information file
810 unlink(m_installerContext.installInfo.c_str());
812 LogError("Error in installation step: " << m_exceptionCaught);
813 LogError("Message: " << m_exceptionMessage);
814 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
816 LogDebug("Call widget install failure finishedCallback");
818 // send signal of pkgmgr
819 getInstallerStruct().pkgmgrInterface->sendSignal(
823 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
824 DPL::ToUTF8String(tizenId), m_exceptionCaught);
827 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
829 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
830 m_exceptionMessage = e.GetMessage();
833 void JobWidgetInstall::displayWidgetInfo()
835 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
837 std::ostringstream out;
838 WidgetLocalizedInfo localizedInfo =
839 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
842 "===================================== INSTALLED WIDGET INFO ========="\
843 "============================";
844 out << std::endl << "Name: " << localizedInfo.name;
845 out << std::endl << "AppId: " << dao.getTzAppId();
846 WidgetSize size = dao.getPreferredSize();
847 out << std::endl << "Width: " << size.width;
848 out << std::endl << "Height: " << size.height;
849 out << std::endl << "Start File: " <<
850 W3CFileLocalization::getStartFile(dao.getTzAppId());
851 out << std::endl << "Version: " << dao.getVersion();
852 out << std::endl << "Licence: " <<
853 localizedInfo.license;
854 out << std::endl << "Licence Href: " <<
855 localizedInfo.licenseHref;
856 out << std::endl << "Description: " <<
857 localizedInfo.description;
858 out << std::endl << "Widget Id: " << dao.getGUID();
859 out << std::endl << "Widget recognized: " << dao.isRecognized();
860 out << std::endl << "Widget wac signed: " << dao.isWacSigned();
861 out << std::endl << "Widget distributor signed: " <<
862 dao.isDistributorSigned();
863 out << std::endl << "Widget trusted: " << dao.isTrusted();
865 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
866 DPL::OptionalString iconSrc = !!icon ? icon->src : DPL::OptionalString::Null;
867 out << std::endl << "Icon: " << iconSrc;
869 out << std::endl << "Preferences:";
871 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
874 out << std::endl << " Key: " <<
876 out << std::endl << " Readonly: " <<
881 out << std::endl << "Features:";
883 WidgetFeatureSet list = dao.getFeaturesList();
886 out << std::endl << " Name: " << it->name;
887 out << std::endl << " Required: " << it->required;
888 out << std::endl << " Params:";
897 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
898 const std::string &widgetSource,
899 const std::string &tempPath)
901 // Check installation type (direcotory/ or config.xml or widget.wgt)
902 if (WidgetUpdateMode::PolicyDirectoryForceInstall == m_jobStruct.updateMode)
904 LogDebug("Install directly from directory");
905 return PKG_TYPE_DIRECTORY_WEB_APP;
907 if (hasExtension(widgetSource, XML_EXTENSION)) {
908 LogInfo("Hosted app installation");
909 return PKG_TYPE_HOSTED_WEB_APP;
913 std::string configFile = tempPath + "/" + CONFIG_XML;
914 if (WrtUtilFileExists(configFile)) {
915 return PKG_TYPE_NOMAL_WEB_APP;
918 configFile = tempPath + "/" + WITH_OSP_XML;
919 if (WrtUtilFileExists(configFile)) {
920 return PKG_TYPE_HYBRID_WEB_APP;
923 std::unique_ptr<DPL::ZipInput> zipFile;
928 zipFile.reset(new DPL::ZipInput(widgetSource));
931 Catch(DPL::ZipInput::Exception::OpenFailed)
933 LogDebug("Failed to open widget package");
934 return PKG_TYPE_UNKNOWN;
936 Catch(DPL::ZipInput::Exception::SeekFileFailed)
938 LogError("Failed to seek widget package file");
939 return PKG_TYPE_UNKNOWN;
944 // Open config.xml file in package root
945 std::unique_ptr<DPL::ZipInput::File> configFile(
946 zipFile->OpenFile(CONFIG_XML));
947 return PKG_TYPE_NOMAL_WEB_APP;
949 Catch(DPL::ZipInput::Exception::OpenFileFailed)
951 LogDebug("Could not find config.xml");
956 // Open config.xml file in package root
957 std::unique_ptr<DPL::ZipInput::File> configFile(
958 zipFile->OpenFile(WITH_OSP_XML));
960 return PKG_TYPE_HYBRID_WEB_APP;
962 Catch(DPL::ZipInput::Exception::OpenFileFailed)
964 LogDebug("Could not find wgt/config.xml");
965 return PKG_TYPE_UNKNOWN;
969 return PKG_TYPE_UNKNOWN;
972 void JobWidgetInstall::setApplicationType(
973 const WrtDB::ConfigParserData &configInfo)
976 FOREACH(iterator, configInfo.nameSpaces) {
977 LogInfo("namespace = [" << *iterator << "]");
978 AppType currentAppType = APP_TYPE_UNKNOWN;
980 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
984 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
986 ConfigurationNamespace::WacWidgetNamespaceName)
988 currentAppType = APP_TYPE_WAC20;
989 } else if (*iterator ==
990 ConfigurationNamespace::TizenWebAppNamespaceName) {
991 currentAppType = APP_TYPE_TIZENWEBAPP;
994 if (m_installerContext.widgetConfig.webAppType ==
996 m_installerContext.widgetConfig.webAppType = currentAppType;
997 } else if (m_installerContext.widgetConfig.webAppType ==
1001 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
1002 "Config.xml has more than one namespace");
1006 // If there is no define, type set to WAC 2.0
1007 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
1008 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
1011 LogInfo("type = [" <<
1012 m_installerContext.widgetConfig.webAppType.getApptypeToString() << "]");
1015 bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
1017 FOREACH(it, configData.settingsList)
1019 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
1020 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
1021 LogDebug("resource need encryption");
1028 void JobWidgetInstall::setInstallLocationType(const
1029 WrtDB::ConfigParserData &configData)
1031 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
1033 if (true == m_jobStruct.m_preload) {
1034 m_installerContext.locationType =
1035 INSTALL_LOCATION_TYPE_PRELOAD;
1037 FOREACH(it, configData.settingsList)
1039 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
1041 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT) {
1042 LogDebug("This widget will be installed to sd card");
1043 m_installerContext.locationType =
1044 INSTALL_LOCATION_TYPE_EXTERNAL;
1050 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
1053 drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1056 ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
1057 if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
1060 /* blow code temporary code for drm. */
1061 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
1069 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
1070 std::string destPath)
1073 drm_trusted_sapps_decrypt_package_info_s package_info;
1075 strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
1076 sizeof(package_info.sadcf_filepath));
1077 strncpy(package_info.decrypt_filepath, destPath.c_str(),
1078 sizeof(package_info.decrypt_filepath));
1080 drm_trusted_request_type_e requestType =
1081 DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
1083 int ret = drm_trusted_handle_request(requestType,
1084 (void *)&package_info, NULL);
1085 if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
1091 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
1092 const_cast<char*>(destPath.c_str())) != 0) {
1099 } //namespace WidgetInstall