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)
130 LogDebug("Looking for extension " << extension << " in: " << filename);
131 size_t fileLen = filename.length();
132 size_t extLen = extension.length();
133 if (fileLen < extLen) {
134 LogError("Filename " << filename << " is shorter than extension "
138 return (0 == filename.compare(fileLen - extLen, extLen, extension));
141 bool checkTizenPkgIdExist(const std::string& tizenPkgId)
143 std::string installPath =
144 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
146 std::string preinstallPath =
147 std::string(GlobalConfig::GetUserPreloadedWidgetPath()) +
151 if ((stat(installPath.c_str(), &dirStat) == 0) ||
152 (stat(preinstallPath.c_str(), &dirStat) == 0))
158 } // namespace anonymous
161 namespace WidgetInstall {
162 JobWidgetInstall::JobWidgetInstall(
163 std::string const &widgetPath,
164 const WidgetInstallationStruct &
167 JobContextBase<WidgetInstallationStruct>(installerStruct),
168 m_exceptionCaught(Exceptions::Success)
170 m_installerContext.m_quiet = m_jobStruct.m_quiet;
172 ConfigureResult result = PrePareInstallation(widgetPath);
174 if (result == ConfigureResult::Ok) {
175 LogInfo("Configure installation succeeded");
176 m_installerContext.job->SetProgressFlag(true);
178 AddTask(new TaskRecovery(m_installerContext));
180 // Create installation tasks
181 if (m_installerContext.widgetConfig.packagingType !=
182 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
183 m_installerContext.widgetConfig.packagingType !=
184 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
187 AddTask(new TaskUnzip(m_installerContext));
190 AddTask(new TaskWidgetConfig(m_installerContext));
191 if (m_installerContext.widgetConfig.packagingType ==
192 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
194 AddTask(new TaskPrepareFiles(m_installerContext));
196 AddTask(new TaskCertify(m_installerContext));
197 if (m_needEncryption) {
198 AddTask(new TaskEncryptResource(m_installerContext));
201 AddTask(new TaskFileManipulation(m_installerContext));
202 // TODO: Update progress information for this task
204 //This is sort of quick solution, because ACE verdicts are based upon
205 //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
207 AddTask(new TaskSmack(m_installerContext));
209 AddTask(new TaskManifestFile(m_installerContext));
210 AddTask(new TaskCertificates(m_installerContext));
211 if (m_installerContext.widgetConfig.packagingType ==
212 PKG_TYPE_HYBRID_WEB_APP)
214 AddTask(new TaskInstallOspsvc(m_installerContext));
216 AddTask(new TaskPluginsCopy(m_installerContext));
217 AddTask(new TaskDatabase(m_installerContext));
218 AddTask(new TaskAceCheck(m_installerContext));
219 } else if (result == ConfigureResult::Updated) {
220 LogInfo("Configure installation updated");
221 LogInfo("Widget Update");
222 m_installerContext.job->SetProgressFlag(true);
223 if (m_installerContext.widgetConfig.packagingType !=
224 WrtDB::PKG_TYPE_HOSTED_WEB_APP &&
225 m_installerContext.widgetConfig.packagingType !=
226 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP &&
229 AddTask(new TaskUnzip(m_installerContext));
232 AddTask(new TaskWidgetConfig(m_installerContext));
234 if (m_installerContext.widgetConfig.packagingType ==
235 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
237 AddTask(new TaskPrepareFiles(m_installerContext));
240 AddTask(new TaskCertify(m_installerContext));
241 if (m_installerContext.widgetConfig.packagingType !=
242 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
244 AddTask(new TaskUpdateFiles(m_installerContext));
247 /* TODO : To backup file, save md5 values */
248 AddTask(new TaskSmack(m_installerContext));
250 AddTask(new TaskManifestFile(m_installerContext));
251 if (m_installerContext.widgetConfig.packagingType ==
252 PKG_TYPE_HYBRID_WEB_APP)
254 AddTask(new TaskInstallOspsvc(m_installerContext));
256 if (m_installerContext.widgetConfig.packagingType !=
257 WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
259 AddTask(new TaskRemoveBackupFiles(m_installerContext));
261 AddTask(new TaskPluginsCopy(m_installerContext));
262 AddTask(new TaskDatabase(m_installerContext));
263 AddTask(new TaskAceCheck(m_installerContext));
264 //TODO: remove widgetHandle from this task and move before database task
265 // by now widget handle is needed in ace check
266 // Any error in acecheck while update will break widget
267 } else if (result == ConfigureResult::Deferred) {
268 // Installation is deferred
269 LogInfo("Configure installation deferred");
271 AddTask(new InstallerTaskFail(true));
272 } else if (result == ConfigureResult::Failed) {
273 // Installation is not allowed to proceed due to widget update policy
274 LogWarning("Configure installation failed!");
276 AddTask(new InstallerTaskFail(false));
278 Assert(false && "Invalid configure result!");
282 JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation(
283 const std::string &widgetPath)
285 ConfigureResult result;
286 m_needEncryption = false;
290 std::string tempDir =
291 Jobs::WidgetInstall::createTempPath(m_jobStruct.m_preload);
293 m_isDRM = isDRMWidget(widgetPath);
294 if (true == m_isDRM) {
295 LogDebug("decrypt DRM widget");
296 if (DecryptDRMWidget(widgetPath, tempDir)) {
297 LogDebug("Failed decrypt DRM widget");
298 return ConfigureResult::Failed;
302 LogDebug("widgetPath:" << widgetPath);
304 m_installerContext.widgetConfig.packagingType =
305 checkPackageType(widgetPath, tempDir);
306 ConfigParserData configData = getWidgetDataFromXML(
309 m_installerContext.widgetConfig.packagingType,
311 LogDebug("widget packaging type : " <<
312 m_installerContext.widgetConfig.packagingType.pkgType);
314 setTizenId(configData);
315 setApplicationType(configData);
316 m_needEncryption = detectResourceEncryption(configData);
317 setInstallLocationType(configData);
319 // Configure installation
320 result = ConfigureInstallation(widgetPath, configData, tempDir);
322 Catch(Exceptions::ExtractFileFailed)
324 LogError("Failed to create temporary path for widget");
325 result = ConfigureResult::Failed;
331 void JobWidgetInstall::setTizenId(
332 const WrtDB::ConfigParserData &configInfo)
334 bool shouldMakeAppid = false;
335 using namespace PackageManager;
336 if (!!configInfo.tizenAppId) {
337 LogDebug("Setting tizenAppId provided in config.xml: " <<
338 configInfo.tizenAppId);
340 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
342 if (!!configInfo.tizenPkgId) {
343 LogDebug("Setting tizenPkgId provided in config.xml: " <<
344 configInfo.tizenPkgId);
346 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
348 DPL::String appid = *configInfo.tizenAppId;
349 if (appid.length() > PACKAGE_ID_LENGTH) {
350 m_installerContext.widgetConfig.tzPkgid =
351 appid.substr(0, PACKAGE_ID_LENGTH);
353 //old version appid only has 10byte random character is able to install for a while.
354 //this case appid equal pkgid.
355 m_installerContext.widgetConfig.tzPkgid =
356 *configInfo.tizenAppId;
357 shouldMakeAppid = true;
361 shouldMakeAppid = true;
362 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
363 LogDebug("Checking if pkg id is unique");
365 if (checkTizenPkgIdExist(DPL::ToUTF8String(pkgId))) {
366 //path exist, chose another one
367 pkgId = WidgetDAOReadOnly::generatePkgId();
372 m_installerContext.widgetConfig.tzPkgid = pkgId;
373 LogInfo("tizen_id name was generated by WRT: " <<
374 m_installerContext.widgetConfig.tzPkgid);
377 if (shouldMakeAppid == true) {
378 DPL::OptionalString name;
379 DPL::OptionalString defaultLocale = configInfo.defaultlocale;
381 FOREACH(localizedData, configInfo.localizedDataSet)
383 Locale i = localizedData->first;
384 if (!!defaultLocale) {
385 if (defaultLocale == i) {
386 name = localizedData->second.name;
390 name = localizedData->second.name;
395 if (regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
396 LogDebug("Regcomp failed");
399 LogDebug("Name : " << name);
400 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
401 static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
403 // TODO : generate name move to wrt-commons
404 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
405 std::ostringstream genName;
407 gettimeofday(&tv, NULL);
408 unsigned int seed = time(NULL) + tv.tv_usec;
410 genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
411 name = DPL::FromUTF8String(genName.str());
412 LogDebug("name was generated by WRT");
415 LogDebug("Name : " << name);
416 std::ostringstream genid;
417 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
418 LogDebug("tizen appid was generated by WRT : " << genid.str());
420 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
421 NormalizeAndTrimSpaceString(appid);
422 m_installerContext.widgetConfig.tzAppid = *appid;
425 // send start signal of pkgmgr
426 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
430 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
431 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
432 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
435 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
436 const std::string& tempPath)
438 m_installerContext.locations =
439 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.
441 widgetPath, tempPath,
442 m_installerContext.widgetConfig.packagingType,
443 m_installerContext.locationType);
444 m_installerContext.locations->registerAppid(
445 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
447 LogInfo("widgetSource " << widgetPath);
450 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
451 const std::string &widgetSource,
452 const WrtDB::ConfigParserData &configData,
453 const std::string &tempPath)
455 WidgetUpdateInfo update = detectWidgetUpdate(
458 widgetConfig.webAppType,
460 widgetConfig.tzAppid);
461 ConfigureResult result = checkWidgetUpdate(update);
465 if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
466 LogDebug("Regcomp failed");
470 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid).
472 static_cast<size_t>(0), NULL, 0) == REG_NOMATCH) ||
473 (checkTizenPkgIdExist(DPL::ToUTF8String(m_installerContext.widgetConfig
475 result != ConfigureResult::Updated))
477 //it is true when tizenId does not fit REG_TIZENID_PATTERN
478 LogError("tizen_id provided but not proper or pkgId directory exists");
479 //TODO(t.iwanek): appId is unique, what about installation of
480 // abcdefghij.test1 and abcdefghij.test2?
482 return ConfigureResult::Failed;
486 configureWidgetLocation(widgetSource, tempPath);
488 // Init installer context
489 m_installerContext.installStep = InstallerContext::INSTALL_START;
490 m_installerContext.job = this;
491 m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
492 m_installerContext.widgetConfig.shareHref = std::string();
497 JobWidgetInstall::ConfigureResult JobWidgetInstall::checkWidgetUpdate(
498 const WidgetUpdateInfo &update)
501 "Widget install/update: incoming guid = '" <<
502 update.incomingGUID << "'");
504 "Widget install/update: incoming version = '" <<
505 update.incomingVersion << "'");
508 WidgetUpdateMode::Type updateTypeCheckBit;
510 if (update.existingWidgetInfo.isExist == false) {
511 LogInfo("Widget info does not exist");
512 updateTypeCheckBit = WidgetUpdateMode::NotInstalled;
514 getInstallerStruct().pkgmgrInterface->sendSignal(
516 PKGMGR_START_INSTALL);
519 LogInfo("Widget info exists. appid: " <<
520 update.existingWidgetInfo.tzAppid);
522 getInstallerStruct().pkgmgrInterface->sendSignal(
524 PKGMGR_START_UPDATE);
526 TizenAppId tzAppid = update.existingWidgetInfo.tzAppid;
528 LogInfo("Widget model exists. tizen app id: " << tzAppid);
530 // Check running state
531 bool isRunning = false;
532 int retval = app_manager_is_running(DPL::ToUTF8String(
533 tzAppid).c_str(), &isRunning);
534 if (APP_MANAGER_ERROR_NONE != retval) {
535 LogError("Fail to get running state");
536 return ConfigureResult::Failed;
539 if (true == isRunning) {
540 // Must be deferred when update in progress
541 if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
543 "Widget is already running. Policy is update according to WAC");
545 return ConfigureResult::Deferred;
548 "Widget is already running. Policy is not update according to WAC");
550 return ConfigureResult::Failed;
554 m_installerContext.widgetConfig.tzAppid = tzAppid;
555 OptionalWidgetVersion existingVersion;
556 existingVersion = update.existingWidgetInfo.existingVersion;
557 OptionalWidgetVersion incomingVersion = update.incomingVersion;
559 updateTypeCheckBit = CalcWidgetUpdatePolicy(existingVersion,
562 if ((m_jobStruct.updateMode & updateTypeCheckBit) > 0 ||
563 m_jobStruct.updateMode ==
564 WidgetUpdateMode::PolicyDirectoryForceInstall)
566 LogInfo("Whether widget policy allow proceed ok");
567 return ConfigureResult::Updated;
569 return ConfigureResult::Failed;
572 return ConfigureResult::Ok;
575 WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy(
576 const OptionalWidgetVersion &existingVersion,
577 const OptionalWidgetVersion &incomingVersion) const
579 // Widget is installed, check versions
580 if (!existingVersion && !incomingVersion) {
581 return WidgetUpdateMode::ExistingVersionEqual;
582 } else if (!existingVersion && !!incomingVersion) {
583 return WidgetUpdateMode::ExistingVersionNewer;
584 } else if (!!existingVersion && !incomingVersion) {
585 return WidgetUpdateMode::ExistingVersionOlder;
587 LogInfo("Existing widget: version = '" << *existingVersion << "'");
589 if (!existingVersion->IsWac() && !incomingVersion->IsWac()) {
590 return WidgetUpdateMode::BothVersionsNotStd;
591 } else if (!existingVersion->IsWac()) {
592 return WidgetUpdateMode::ExistingVersionNotStd;
593 } else if (!incomingVersion->IsWac()) {
594 return WidgetUpdateMode::IncomingVersionNotStd;
596 // Both versions are WAC-comparable. Do compare.
597 if (*incomingVersion == *existingVersion) {
598 return WidgetUpdateMode::ExistingVersionEqual;
599 } else if (*incomingVersion > *existingVersion) {
600 return WidgetUpdateMode::ExistingVersionOlder;
602 return WidgetUpdateMode::ExistingVersionNewer;
608 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
609 const std::string &widgetSource,
610 const std::string &tempPath,
611 WrtDB::PackagingType pkgType,
616 ConfigParserData configInfo;
620 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
621 parser.Parse(widgetSource,
623 new RootParser<WidgetParser>(configInfo,
624 DPL::FromUTF32String(
626 } else if (pkgType == PKG_TYPE_DIRECTORY_WEB_APP) {
627 parser.Parse(widgetSource + '/' + WITH_OSP_XML,
629 new RootParser<WidgetParser>(
631 DPL::FromUTF32String(L"widget"))));
634 std::unique_ptr<DPL::ZipInput> zipFile(
635 new DPL::ZipInput(widgetSource));
637 std::unique_ptr<DPL::ZipInput::File> configFile;
639 // Open config.xml file
640 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
641 configFile.reset(zipFile->OpenFile(WITH_OSP_XML));
643 configFile.reset(zipFile->OpenFile(CONFIG_XML));
647 DPL::BinaryQueue buffer;
648 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
649 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
650 DPL::Copy(&inputAdapter, &outputAdapter);
651 parser.Parse(&buffer,
653 new RootParser<WidgetParser>(configInfo,
659 std::string configFile;
660 if (pkgType == PKG_TYPE_HYBRID_WEB_APP) {
661 configFile = tempPath + "/" + WITH_OSP_XML;
663 configFile = tempPath + "/" + CONFIG_XML;
666 parser.Parse(configFile,
668 new RootParser<WidgetParser>(configInfo,
675 Catch(DPL::ZipInput::Exception::OpenFailed)
677 LogError("Failed to open widget package");
678 return ConfigParserData();
680 Catch(DPL::ZipInput::Exception::OpenFileFailed)
682 LogError("Failed to open config.xml file");
683 return ConfigParserData();
685 Catch(DPL::CopyFailed)
687 LogError("Failed to extract config.xml file");
688 return ConfigParserData();
690 Catch(DPL::FileInput::Exception::OpenFailed)
692 LogError("Failed to open config.xml file");
693 return ConfigParserData();
695 Catch(ElementParser::Exception::ParseError)
697 LogError("Failed to parse config.xml file");
698 return ConfigParserData();
700 Catch(DPL::ZipInput::Exception::SeekFileFailed)
702 LogError("Failed to seek widget archive - corrupted package?");
703 return ConfigParserData();
708 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
709 const ConfigParserData &configInfo,
710 const WrtDB::WidgetType appType,
711 const WrtDB::TizenAppId &tizenId)
713 LogInfo("Checking up widget package for config.xml...");
715 DPL::OptionalString widgetGUID;
716 OptionalWidgetVersion widgetVersion;
719 widgetGUID = configInfo.widget_id;
721 if (widgetGUID.IsNull()) {
722 LogWarning("Installed widget has no GUID");
723 return WidgetUpdateInfo();
726 LogDebug("Installed widget GUID: " << *widgetGUID);
728 // Locate widget ID with this GUID
729 // Incoming widget version
730 if (!configInfo.version.IsNull()) {
732 DPL::Optional<WidgetVersion>(
733 WidgetVersion(*configInfo.version));
736 if (appType == APP_TYPE_WAC20) {
739 // Search widget handle by GUID
740 WidgetDAOReadOnly dao(widgetGUID);
741 return WidgetUpdateInfo(
744 WidgetUpdateInfo::ExistingWidgetInfo(
745 dao.getTzAppId(), dao.getVersion()));
747 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
749 // GUID isn't installed
750 return WidgetUpdateInfo(
753 WidgetUpdateInfo::ExistingWidgetInfo());
758 // Search widget handle by appId
759 WidgetDAOReadOnly dao(tizenId);
760 return WidgetUpdateInfo(
763 WidgetUpdateInfo::ExistingWidgetInfo(
764 dao.getTzAppId(), dao.getVersion()));
766 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
768 // GUID isn't installed
769 return WidgetUpdateInfo(
772 WidgetUpdateInfo::ExistingWidgetInfo());
777 void JobWidgetInstall::SendProgress()
779 using namespace PackageManager;
780 if (GetProgressFlag() != false) {
781 if (getInstallerStruct().progressCallback != NULL) {
782 // send progress signal of pkgmgr
783 std::ostringstream percent;
784 percent << static_cast<int>(GetProgressPercent());
785 getInstallerStruct().pkgmgrInterface->sendSignal(
789 LogDebug("Call widget install progressCallbak");
790 getInstallerStruct().progressCallback(
791 getInstallerStruct().userParam,
792 GetProgressPercent(),
793 GetProgressDescription());
798 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
800 using namespace PackageManager;
801 if (GetProgressFlag() != false) {
802 if (getInstallerStruct().progressCallback != NULL) {
803 // send progress signal of pkgmgr
804 getInstallerStruct().pkgmgrInterface->sendSignal(
811 void JobWidgetInstall::SendFinishedSuccess()
813 using namespace PackageManager;
814 // TODO : sync should move to separate task.
817 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
818 if (false == m_installerContext.existingWidgetInfo.isExist) {
819 WidgetInstallToExtSingleton::Instance().postInstallation(true);
821 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
823 WidgetInstallToExtSingleton::Instance().deinitialize();
826 // remove widget install information file
827 unlink(m_installerContext.installInfo.c_str());
830 JobWidgetInstall::displayWidgetInfo();
832 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
834 // send signal of pkgmgr
835 getInstallerStruct().pkgmgrInterface->sendSignal(
839 LogDebug("Call widget install successfinishedCallback");
840 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
842 tizenId), Exceptions::Success);
845 void JobWidgetInstall::SendFinishedFailure()
847 using namespace PackageManager;
848 // remove widget install information file
849 unlink(m_installerContext.installInfo.c_str());
851 LogError("Error in installation step: " << m_exceptionCaught);
852 LogError("Message: " << m_exceptionMessage);
853 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
855 LogDebug("Call widget install failure finishedCallback");
857 // send signal of pkgmgr
858 getInstallerStruct().pkgmgrInterface->sendSignal(
862 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
864 tizenId), m_exceptionCaught);
867 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
869 m_exceptionCaught = static_cast<Exceptions::Type>(e.getParam());
870 m_exceptionMessage = e.GetMessage();
873 void JobWidgetInstall::displayWidgetInfo()
875 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
877 std::ostringstream out;
878 WidgetLocalizedInfo localizedInfo =
879 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
882 "===================================== INSTALLED WIDGET INFO =========" \
883 "============================";
884 out << std::endl << "Name: " << localizedInfo.name;
885 out << std::endl << "AppId: " << dao.getTzAppId();
886 WidgetSize size = dao.getPreferredSize();
887 out << std::endl << "Width: " << size.width;
888 out << std::endl << "Height: " << size.height;
889 out << std::endl << "Start File: " <<
890 W3CFileLocalization::getStartFile(dao.getTzAppId());
891 out << std::endl << "Version: " << dao.getVersion();
892 out << std::endl << "Licence: " <<
893 localizedInfo.license;
894 out << std::endl << "Licence Href: " <<
895 localizedInfo.licenseHref;
896 out << std::endl << "Description: " <<
897 localizedInfo.description;
898 out << std::endl << "Widget Id: " << dao.getGUID();
899 out << std::endl << "Widget recognized: " << dao.isRecognized();
900 out << std::endl << "Widget wac signed: " << dao.isWacSigned();
901 out << std::endl << "Widget distributor signed: " <<
902 dao.isDistributorSigned();
903 out << std::endl << "Widget trusted: " << dao.isTrusted();
905 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
906 DPL::OptionalString iconSrc =
907 !!icon ? icon->src : DPL::OptionalString::Null;
908 out << std::endl << "Icon: " << iconSrc;
910 out << std::endl << "Preferences:";
912 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
915 out << std::endl << " Key: " <<
917 out << std::endl << " Readonly: " <<
922 out << std::endl << "Features:";
924 WidgetFeatureSet list = dao.getFeaturesList();
927 out << std::endl << " Name: " << it->name;
928 out << std::endl << " Required: " << it->required;
929 out << std::endl << " Params:";
938 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
939 const std::string &widgetSource,
940 const std::string &tempPath)
942 // Check installation type (direcotory/ or config.xml or widget.wgt)
943 if (WidgetUpdateMode::PolicyDirectoryForceInstall ==
944 m_jobStruct.updateMode)
946 LogDebug("Install directly from directory");
947 return PKG_TYPE_DIRECTORY_WEB_APP;
949 if (hasExtension(widgetSource, XML_EXTENSION)) {
950 LogInfo("Hosted app installation");
951 return PKG_TYPE_HOSTED_WEB_APP;
955 std::string configFile = tempPath + "/" + CONFIG_XML;
956 if (WrtUtilFileExists(configFile)) {
957 return PKG_TYPE_NOMAL_WEB_APP;
960 configFile = tempPath + "/" + WITH_OSP_XML;
961 if (WrtUtilFileExists(configFile)) {
962 return PKG_TYPE_HYBRID_WEB_APP;
965 std::unique_ptr<DPL::ZipInput> zipFile;
970 zipFile.reset(new DPL::ZipInput(widgetSource));
972 Catch(DPL::ZipInput::Exception::OpenFailed)
974 LogDebug("Failed to open widget package");
975 return PKG_TYPE_UNKNOWN;
977 Catch(DPL::ZipInput::Exception::SeekFileFailed)
979 LogError("Failed to seek widget package file");
980 return PKG_TYPE_UNKNOWN;
985 // Open config.xml file in package root
986 std::unique_ptr<DPL::ZipInput::File> configFile(
987 zipFile->OpenFile(CONFIG_XML));
988 return PKG_TYPE_NOMAL_WEB_APP;
990 Catch(DPL::ZipInput::Exception::OpenFileFailed)
992 LogDebug("Could not find config.xml");
997 // Open config.xml file in package root
998 std::unique_ptr<DPL::ZipInput::File> configFile(
999 zipFile->OpenFile(WITH_OSP_XML));
1001 return PKG_TYPE_HYBRID_WEB_APP;
1003 Catch(DPL::ZipInput::Exception::OpenFileFailed)
1005 LogDebug("Could not find wgt/config.xml");
1006 return PKG_TYPE_UNKNOWN;
1010 return PKG_TYPE_UNKNOWN;
1013 void JobWidgetInstall::setApplicationType(
1014 const WrtDB::ConfigParserData &configInfo)
1016 FOREACH(iterator, configInfo.nameSpaces) {
1017 LogInfo("namespace = [" << *iterator << "]");
1018 AppType currentAppType = APP_TYPE_UNKNOWN;
1020 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
1024 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
1026 ConfigurationNamespace::WacWidgetNamespaceName)
1028 currentAppType = APP_TYPE_WAC20;
1029 } else if (*iterator ==
1030 ConfigurationNamespace::TizenWebAppNamespaceName)
1032 currentAppType = APP_TYPE_TIZENWEBAPP;
1035 if (m_installerContext.widgetConfig.webAppType ==
1038 m_installerContext.widgetConfig.webAppType = currentAppType;
1039 } else if (m_installerContext.widgetConfig.webAppType ==
1044 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
1045 "Config.xml has more than one namespace");
1049 // If there is no define, type set to WAC 2.0
1050 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
1051 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
1054 LogInfo("type = [" <<
1055 m_installerContext.widgetConfig.webAppType.getApptypeToString() <<
1059 bool JobWidgetInstall::detectResourceEncryption(
1060 const WrtDB::ConfigParserData &configData)
1062 FOREACH(it, configData.settingsList)
1064 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
1065 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
1067 LogDebug("resource need encryption");
1074 void JobWidgetInstall::setInstallLocationType(
1076 WrtDB::ConfigParserData &
1079 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
1081 if (true == m_jobStruct.m_preload) {
1082 m_installerContext.locationType =
1083 INSTALL_LOCATION_TYPE_PRELOAD;
1085 FOREACH(it, configData.settingsList)
1087 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
1089 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
1091 LogDebug("This widget will be installed to sd card");
1092 m_installerContext.locationType =
1093 INSTALL_LOCATION_TYPE_EXTERNAL;
1099 bool JobWidgetInstall::isDRMWidget(std::string widgetPath)
1102 * drm_bool_type_e is_drm_file = DRM_UNKNOWN;
1105 * ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file);
1106 * if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) {
1109 /* blow code temporary code for drm. */
1110 int ret = drm_oem_intel_isDrmFile(const_cast<char*>(widgetPath.c_str()));
1118 bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath,
1119 std::string destPath)
1122 * drm_trusted_sapps_decrypt_package_info_s package_info;
1124 * strncpy(package_info.sadcf_filepath, widgetPath.c_str(),
1125 * sizeof(package_info.sadcf_filepath));
1126 * strncpy(package_info.decrypt_filepath, destPath.c_str(),
1127 * sizeof(package_info.decrypt_filepath));
1129 * drm_trusted_request_type_e requestType =
1130 * DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE;
1132 * int ret = drm_trusted_handle_request(requestType,
1133 * (void *)&package_info, NULL);
1134 * if (DRM_TRUSTED_RETURN_SUCCESS == ret) {
1140 if (drm_oem_intel_decrypt_package(const_cast<char*>(widgetPath.c_str()),
1141 const_cast<char*>(destPath.c_str())) != 0)
1148 } //namespace WidgetInstall