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/utils/path.h>
42 #include <dpl/wrt-dao-ro/common_dao_types.h>
43 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
44 #include <dpl/wrt-dao-ro/global_config.h>
45 #include <dpl/wrt-dao-ro/config_parser_data.h>
46 #include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
47 #include <dpl/localization/w3c_file_localization.h>
49 #include <libiriwrapper.h>
50 #include <pkg-manager/pkgmgr_signal.h>
51 #include <app_manager.h>
53 #include "root_parser.h"
54 #include "widget_parser.h"
55 #include "parser_runner.h"
56 #include <widget_install/job_widget_install.h>
57 #include <widget_install/task_certify.h>
58 #include <widget_install/task_widget_config.h>
59 #include <widget_install/task_file_manipulation.h>
60 #include <widget_install/task_ace_check.h>
61 #include <widget_install/task_smack.h>
62 #include <widget_install/task_manifest_file.h>
63 #include <widget_install/task_prepare_files.h>
64 #include <widget_install/task_recovery.h>
65 #include <widget_install/task_install_ospsvc.h>
66 #include <widget_install/task_update_files.h>
67 #include <widget_install/task_database.h>
68 #include <widget_install/task_remove_backup.h>
69 #include <widget_install/task_encrypt_resource.h>
70 #include <widget_install/task_certificates.h>
71 #include <widget_install/task_commons.h>
72 #include <widget_install/task_prepare_reinstall.h>
74 #include <widget_install/widget_install_errors.h>
75 #include <widget_install/widget_install_context.h>
76 #include <widget_install_to_external.h>
77 #include <widget_install/widget_unzip.h>
79 using namespace WrtDB;
80 using namespace Jobs::Exceptions;
82 namespace // anonymous
84 const char * const CONFIG_XML = "config.xml";
85 const char * const WITH_OSP_XML = "res/wgt/config.xml";
86 const char * const OSP_MANIFEST_XML = "info/manifest.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 static const DPL::String SETTING_VALUE_ENCRYPTION_DISABLE = L"disable";
96 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
98 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
101 const std::string XML_EXTENSION = ".xml";
103 bool hasExtension(const std::string& filename, const std::string& extension)
105 LogDebug("Looking for extension " << extension << " in: " << filename);
106 size_t fileLen = filename.length();
107 size_t extLen = extension.length();
108 if (fileLen < extLen) {
109 LogError("Filename " << filename << " is shorter than extension "
113 return (0 == filename.compare(fileLen - extLen, extLen, extension));
115 } // namespace anonymous
118 namespace WidgetInstall {
119 class InstallerTaskFail :
120 public DPL::TaskDecl<InstallerTaskFail>
123 ConfigureResult m_result;
127 if (m_result == ConfigureResult::Failed_InvalidConfig) {
128 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetConfigFileInvalid,
130 } else if (m_result == ConfigureResult::Failed_OpenZipError) {
131 ThrowMsg(Jobs::WidgetInstall::Exceptions::OpenZipFailed,
132 "can't open wgt file");
133 } else if (m_result == ConfigureResult::Failed_UnzipError) {
134 ThrowMsg(Jobs::WidgetInstall::Exceptions::ExtractFileFailed,
135 "can't extract wgt file");
136 } else if (m_result == ConfigureResult::Failed_LowerVersion) {
137 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageLowerVersion,
138 "package version is lower than installed version");
139 } else if (m_result == ConfigureResult::Failed_AlreadyInstalled) {
140 ThrowMsg(Jobs::WidgetInstall::Exceptions::PackageAlreadyInstalled,
141 "package is already installed");
142 } else if (m_result == ConfigureResult::Failed_WidgetRunning) {
143 ThrowMsg(Jobs::WidgetInstall::Exceptions::WidgetRunningError,
144 "widget is running");
145 } else if (m_result == ConfigureResult::Failed_DrmError) {
146 ThrowMsg(Jobs::WidgetInstall::Exceptions::DrmDecryptFailed,
148 } else if (m_result == ConfigureResult::Failed_NotSupportRDSUpdate) {
149 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotSupportRDSUpdate,
150 "RDS update failed");
152 ThrowMsg(Jobs::WidgetInstall::Exceptions::NotAllowed,
153 "widget installation or update not allowed!");
158 InstallerTaskFail(ConfigureResult result) :
159 DPL::TaskDecl<InstallerTaskFail>(this),
162 AddStep(&InstallerTaskFail::StepFail);
166 JobWidgetInstall::JobWidgetInstall(
167 std::string const &widgetPath,
168 const WidgetInstallationStruct &
171 JobContextBase<WidgetInstallationStruct>(installerStruct),
172 m_exceptionCaught(Jobs::Exceptions::Success)
174 m_installerContext.mode = m_jobStruct.m_installMode;
175 ConfigureResult result = prepareInstallation(widgetPath);
177 if (result == ConfigureResult::Ok) {
178 LogInfo("Configure installation succeeded");
179 m_installerContext.job->SetProgressFlag(true);
181 AddTask(new TaskRecovery(m_installerContext));
183 AddTask(new TaskWidgetConfig(m_installerContext));
184 if (m_installerContext.widgetConfig.packagingType ==
185 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
187 AddTask(new TaskPrepareFiles(m_installerContext));
189 AddTask(new TaskCertify(m_installerContext));
190 if (m_needEncryption) {
191 AddTask(new TaskEncryptResource(m_installerContext));
194 AddTask(new TaskFileManipulation(m_installerContext));
195 AddTask(new TaskManifestFile(m_installerContext));
196 if (m_installerContext.widgetConfig.packagingType ==
197 PKG_TYPE_HYBRID_WEB_APP)
199 AddTask(new TaskInstallOspsvc(m_installerContext));
201 AddTask(new TaskCertificates(m_installerContext));
202 AddTask(new TaskDatabase(m_installerContext));
203 AddTask(new TaskAceCheck(m_installerContext));
204 AddTask(new TaskSmack(m_installerContext));
205 } else if (result == ConfigureResult::Updated) {
206 LogInfo("Configure installation updated");
207 LogInfo("Widget Update");
208 m_installerContext.job->SetProgressFlag(true);
210 if (m_installerContext.mode.command ==
211 InstallMode::Command::REINSTALL)
213 AddTask(new TaskPrepareReinstall(m_installerContext));
216 AddTask(new TaskWidgetConfig(m_installerContext));
218 if (m_installerContext.widgetConfig.packagingType ==
219 WrtDB::PKG_TYPE_HOSTED_WEB_APP)
221 AddTask(new TaskPrepareFiles(m_installerContext));
224 AddTask(new TaskCertify(m_installerContext));
225 if (m_needEncryption) {
226 AddTask(new TaskEncryptResource(m_installerContext));
229 if (m_installerContext.mode.extension !=
230 InstallMode::ExtensionType::DIR) {
231 AddTask(new TaskUpdateFiles(m_installerContext));
232 AddTask(new TaskFileManipulation(m_installerContext));
235 AddTask(new TaskManifestFile(m_installerContext));
236 if (m_installerContext.widgetConfig.packagingType ==
237 PKG_TYPE_HYBRID_WEB_APP)
239 AddTask(new TaskInstallOspsvc(m_installerContext));
241 AddTask(new TaskCertificates(m_installerContext));
242 AddTask(new TaskDatabase(m_installerContext));
243 AddTask(new TaskAceCheck(m_installerContext));
244 //TODO: remove widgetHandle from this task and move before database task
245 // by now widget handle is needed in ace check
246 // Any error in acecheck while update will break widget
247 AddTask(new TaskSmack(m_installerContext));
248 AddTask(new TaskRemoveBackupFiles(m_installerContext));
250 // Installation is not allowed to proceed due to widget update policy
251 LogWarning("Configure installation failed!");
253 AddTask(new InstallerTaskFail(result));
257 ConfigureResult JobWidgetInstall::prepareInstallation(
258 const std::string &widgetPath)
260 ConfigureResult result;
261 m_needEncryption = false;
266 if (m_installerContext.mode.extension == InstallMode::ExtensionType::DIR) {
267 if (m_installerContext.mode.command ==
268 InstallMode::Command::REINSTALL) {
269 std::ostringstream tempPathBuilder;
270 tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
271 tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
272 tempPathBuilder << "/";
273 tempPathBuilder << widgetPath;
274 tempDir = tempPathBuilder.str();;
276 tempDir = widgetPath;
280 Jobs::WidgetInstall::createTempPath(
281 m_installerContext.mode.rootPath ==
282 InstallMode::RootPath::RO);
283 WidgetUnzip wgtUnzip;
284 wgtUnzip.unzipWgtFile(widgetPath, tempDir);
287 LogDebug("widgetPath:" << widgetPath);
288 LogDebug("tempPath:" << tempDir);
290 m_installerContext.widgetConfig.packagingType =
291 checkPackageType(widgetPath, tempDir);
292 ConfigParserData configData = getWidgetDataFromXML(
295 m_installerContext.widgetConfig.packagingType,
296 m_installerContext.mode.command == InstallMode::Command::REINSTALL);
297 LogDebug("widget packaging type : " <<
298 m_installerContext.widgetConfig.packagingType.pkgType);
300 setTizenId(configData);
301 setApplicationType(configData);
302 m_needEncryption = detectResourceEncryption(configData);
303 setInstallLocationType(configData);
305 // Configure installation
306 result = ConfigureInstallation(widgetPath, configData, tempDir);
308 Catch(Exceptions::OpenZipFailed)
310 LogError("Failed to unzip for widget");
311 result = ConfigureResult::Failed_OpenZipError;
313 Catch(Exceptions::ExtractFileFailed)
315 LogError("Failed to unzip for widget");
316 result = ConfigureResult::Failed_UnzipError;
318 Catch(Exceptions::DrmDecryptFailed)
320 LogError("Failed to unzip for widget");
321 result = ConfigureResult::Failed_DrmError;
327 void JobWidgetInstall::setTizenId(
328 const WrtDB::ConfigParserData &configInfo)
330 bool shouldMakeAppid = false;
331 using namespace PackageManager;
332 if (!!configInfo.tizenAppId) {
333 LogDebug("Setting tizenAppId provided in config.xml: " <<
334 configInfo.tizenAppId);
336 m_installerContext.widgetConfig.tzAppid = *configInfo.tizenAppId;
338 if (!!configInfo.tizenPkgId) {
339 LogDebug("Setting tizenPkgId provided in config.xml: " <<
340 configInfo.tizenPkgId);
342 m_installerContext.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
344 DPL::String appid = *configInfo.tizenAppId;
345 if (appid.length() > PACKAGE_ID_LENGTH) {
346 m_installerContext.widgetConfig.tzPkgid =
347 appid.substr(0, PACKAGE_ID_LENGTH);
349 //old version appid only has 10byte random character is able to install for a while.
350 //this case appid equal pkgid.
351 m_installerContext.widgetConfig.tzPkgid =
352 *configInfo.tizenAppId;
353 shouldMakeAppid = true;
357 shouldMakeAppid = true;
358 TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
359 LogDebug("Checking if pkg id is unique");
361 if (!validateTizenPackageID(pkgId)) {
362 //path exist, chose another one
363 pkgId = WidgetDAOReadOnly::generatePkgId();
368 m_installerContext.widgetConfig.tzPkgid = pkgId;
369 LogInfo("tizen_id name was generated by WRT: " <<
370 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;
386 name = localizedData->second.name;
391 if (regcomp(®x, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
392 LogDebug("Regcomp failed");
395 LogDebug("Name : " << name);
396 if (!name || (regexec(®x, DPL::ToUTF8String(*name).c_str(),
397 static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
399 // TODO : generate name move to wrt-commons
400 std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
401 std::ostringstream genName;
403 gettimeofday(&tv, NULL);
404 unsigned int seed = time(NULL) + tv.tv_usec;
406 genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
407 name = DPL::FromUTF8String(genName.str());
408 LogDebug("name was generated by WRT");
411 LogDebug("Name : " << name);
412 std::ostringstream genid;
413 genid << m_installerContext.widgetConfig.tzPkgid << "." << name;
414 LogDebug("tizen appid was generated by WRT : " << genid.str());
416 DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
417 NormalizeAndTrimSpaceString(appid);
418 m_installerContext.widgetConfig.tzAppid = *appid;
421 // send start signal of pkgmgr
422 getInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
426 LogInfo("Tizen App Id : " << m_installerContext.widgetConfig.tzAppid);
427 LogInfo("Tizen Pkg Id : " << m_installerContext.widgetConfig.tzPkgid);
428 LogInfo("W3C Widget GUID : " << m_installerContext.widgetConfig.guid);
431 void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath,
432 const std::string& tempPath)
434 m_installerContext.locations =
435 WidgetLocation(DPL::ToUTF8String(m_installerContext.widgetConfig.
437 widgetPath, tempPath,
438 m_installerContext.widgetConfig.packagingType,
439 m_installerContext.mode.rootPath ==
440 InstallMode::RootPath::RO,
441 m_installerContext.mode.extension);
442 m_installerContext.locations->registerAppid(
443 DPL::ToUTF8String(m_installerContext.widgetConfig.tzAppid));
445 LogInfo("widgetSource " << widgetPath);
448 ConfigureResult JobWidgetInstall::ConfigureInstallation(
449 const std::string &widgetSource,
450 const WrtDB::ConfigParserData &configData,
451 const std::string &tempPath)
453 ConfigureResult result = ConfigureResult::Failed;
454 WidgetUpdateInfo update;
456 // checking installed web application
458 // checking existing application is installed
459 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
460 // no excpetion means, it isn't update mode
461 getInstallerStruct().pkgmgrInterface->sendSignal(
463 PKGMGR_START_UPDATE);
465 update = detectWidgetUpdate(configData,
466 m_installerContext.widgetConfig.tzAppid);
467 result = checkWidgetUpdate(update);
468 if (result != ConfigureResult::Updated) {
469 // Already installed TizenAppId. return failed
470 return ConfigureResult::Failed_AlreadyInstalled;
472 if (!checkSupportRDSUpdate(configData)) {
473 return ConfigureResult::Failed_NotSupportRDSUpdate;
475 m_installerContext.isUpdateMode = true;
477 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
478 result = ConfigureResult::Ok;
479 getInstallerStruct().pkgmgrInterface->sendSignal(
481 PKGMGR_START_INSTALL);
482 m_installerContext.isUpdateMode = false;
484 if (!validateTizenApplicationID(
485 m_installerContext.widgetConfig.tzAppid))
487 LogError("tizen application ID is already used");
488 return ConfigureResult::Failed_InvalidConfig;
490 if (!validateTizenPackageID(m_installerContext.widgetConfig.tzPkgid)) {
491 LogError("tizen package ID is already used");
492 return ConfigureResult::Failed_AlreadyInstalled;
496 configureWidgetLocation(widgetSource, tempPath);
498 // Init installer context
499 m_installerContext.installStep = InstallerContext::INSTALL_START;
500 m_installerContext.job = this;
501 m_installerContext.widgetConfig.shareHref = std::string();
506 bool JobWidgetInstall::validateTizenApplicationID(
507 const WrtDB::TizenAppId &tizenAppId)
509 LogInfo("tizen application ID = [" << tizenAppId << "]");
512 if (regcomp(®, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
513 LogDebug("Regcomp failed");
516 if (regexec(®, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
526 bool JobWidgetInstall::validateTizenPackageID(
527 const WrtDB::TizenPkgId &tizenPkgId)
529 std::string pkgId = DPL::ToUTF8String(tizenPkgId);
531 std::string installPath =
532 std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
536 if ((stat(installPath.c_str(), &dirStat) == 0))
543 ConfigureResult JobWidgetInstall::checkWidgetUpdate(
544 const WidgetUpdateInfo &update)
546 if (update.existingVersion.IsNull() || update.incomingVersion.IsNull()) {
547 return ConfigureResult::Failed;
550 LogInfo("existing version = '" << update.existingVersion);
551 LogInfo("incoming version = '" << update.incomingVersion);
552 LogInfo("Tizen AppID = " << update.tzAppId);
554 // Check running state
555 bool isRunning = false;
557 app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
559 if (APP_MANAGER_ERROR_NONE != ret) {
560 LogError("Fail to get running state");
561 return ConfigureResult::Failed_WidgetRunning;
564 if (true == isRunning) {
565 // get app_context for running application
566 // app_context must be released with app_context_destroy
567 app_context_h appCtx = NULL;
569 app_manager_get_app_context(
570 DPL::ToUTF8String(update.tzAppId).c_str(),
572 if (APP_MANAGER_ERROR_NONE != ret) {
573 LogError("Fail to get app_context");
574 return ConfigureResult::Failed_WidgetRunning;
577 // terminate app_context_h
578 ret = app_manager_terminate_app(appCtx);
579 if (APP_MANAGER_ERROR_NONE != ret) {
580 LogError("Fail to terminate running application");
581 app_context_destroy(appCtx);
582 return ConfigureResult::Failed_WidgetRunning;
584 app_context_destroy(appCtx);
585 // app_manager_terminate_app isn't sync API
586 // wait until application isn't running (50ms * 100)
587 bool isStillRunning = true;
588 int checkingloop = 100;
589 struct timespec duration = { 0, 50 * 1000 * 1000 };
590 while (--checkingloop >= 0) {
591 nanosleep(&duration, NULL);
593 app_manager_is_running(
594 DPL::ToUTF8String(update.tzAppId).c_str(),
596 if (APP_MANAGER_ERROR_NONE != ret) {
597 LogError("Fail to get running state");
598 return ConfigureResult::Failed_WidgetRunning;
600 if (!isStillRunning) {
604 if (isStillRunning) {
605 LogError("Fail to terminate running application");
606 return ConfigureResult::Failed_WidgetRunning;
608 LogInfo("terminate application");
612 m_installerContext.widgetConfig.tzAppid = update.tzAppId;
614 if (!!update.existingVersion ||
615 m_installerContext.mode.extension ==
616 InstallMode::ExtensionType::DIR) {
617 return ConfigureResult::Updated;
620 return ConfigureResult::Failed;
623 ConfigParserData JobWidgetInstall::getWidgetDataFromXML(
624 const std::string &widgetSource,
625 const std::string &tempPath,
626 WrtDB::PackagingType pkgType,
631 ConfigParserData configInfo;
634 if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
635 parser.Parse(widgetSource,
637 new RootParser<WidgetParser>(configInfo,
638 DPL::FromUTF32String(
641 std::string configFile;
642 configFile = tempPath + "/" + CONFIG_XML;
643 if (!WrtUtilFileExists(configFile)) {
644 configFile = tempPath + "/" + WITH_OSP_XML;
648 // checking RDS data directory
649 if (access(configFile.c_str(), F_OK) != 0) {
650 std::string tzAppId =
651 widgetSource.substr(widgetSource.find_last_of("/")+1);
652 WidgetDAOReadOnly dao(WidgetDAOReadOnly::getTzAppId(DPL::FromUTF8String(tzAppId)));
653 configFile = DPL::ToUTF8String(*dao.getWidgetInstalledPath());
655 configFile += WITH_OSP_XML;
659 parser.Parse(configFile,
661 new RootParser<WidgetParser>(configInfo,
667 Catch(ElementParser::Exception::ParseError)
669 LogError("Failed to parse config.xml file");
670 return ConfigParserData();
672 Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
674 LogError("Failed to find installed widget - give proper tizenId");
675 return ConfigParserData();
677 Catch(Exceptions::WidgetConfigFileNotFound){
678 LogError("Failed to find config.xml");
679 return ConfigParserData();
685 WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
686 const ConfigParserData &configInfo,
687 const WrtDB::TizenAppId &tizenId)
689 LogInfo("Checking up widget package for config.xml...");
690 OptionalWidgetVersion incomingVersion;
692 if (!configInfo.version.IsNull()) {
694 DPL::Optional<WidgetVersion>(
695 WidgetVersion(*configInfo.version));
698 WidgetDAOReadOnly dao(tizenId);
700 OptionalWidgetVersion optVersion;
701 DPL::OptionalString version = dao.getVersion();
702 if (!version.IsNull()) {
703 optVersion = OptionalWidgetVersion(WidgetVersion(*version));
706 return WidgetUpdateInfo(
712 void JobWidgetInstall::SendProgress()
714 using namespace PackageManager;
715 if (GetProgressFlag() != false) {
716 if (getInstallerStruct().progressCallback != NULL) {
717 // send progress signal of pkgmgr
718 std::ostringstream percent;
719 percent << static_cast<int>(GetProgressPercent());
720 getInstallerStruct().pkgmgrInterface->sendSignal(
724 LogDebug("Call widget install progressCallbak");
725 getInstallerStruct().progressCallback(
726 getInstallerStruct().userParam,
727 GetProgressPercent(),
728 GetProgressDescription());
733 void JobWidgetInstall::SendProgressIconPath(const std::string &path)
735 using namespace PackageManager;
736 if (GetProgressFlag() != false) {
737 if (getInstallerStruct().progressCallback != NULL) {
738 // send progress signal of pkgmgr
739 getInstallerStruct().pkgmgrInterface->sendSignal(
746 void JobWidgetInstall::SendFinishedSuccess()
748 using namespace PackageManager;
749 // TODO : sync should move to separate task.
752 if (INSTALL_LOCATION_TYPE_EXTERNAL == m_installerContext.locationType) {
753 if (m_installerContext.isUpdateMode) {
754 WidgetInstallToExtSingleton::Instance().postUpgrade(true);
756 WidgetInstallToExtSingleton::Instance().postInstallation(true);
758 WidgetInstallToExtSingleton::Instance().deinitialize();
761 // remove widget install information file
762 unlink(m_installerContext.installInfo.c_str());
765 JobWidgetInstall::displayWidgetInfo();
767 TizenAppId& tizenId = m_installerContext.widgetConfig.tzAppid;
769 // send signal of pkgmgr
770 getInstallerStruct().pkgmgrInterface->sendSignal(
774 LogDebug("Call widget install successfinishedCallback");
775 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
777 tizenId), Jobs::Exceptions::Success);
780 void JobWidgetInstall::SendFinishedFailure()
782 using namespace PackageManager;
783 // remove widget install information file
784 unlink(m_installerContext.installInfo.c_str());
786 LogError("Error number: " << m_exceptionCaught);
787 LogError("Message: " << m_exceptionMessage);
788 TizenAppId & tizenId = m_installerContext.widgetConfig.tzAppid;
790 LogDebug("Call widget install failure finishedCallback");
791 std::stringstream errorNum;
792 errorNum << m_exceptionCaught;
794 // send signal of pkgmgr
795 getInstallerStruct().pkgmgrInterface->sendSignal(
799 getInstallerStruct().pkgmgrInterface->sendSignal(
803 getInstallerStruct().finishedCallback(getInstallerStruct().userParam,
805 tizenId), m_exceptionCaught);
808 void JobWidgetInstall::SaveExceptionData(const Jobs::JobExceptionBase &e)
810 m_exceptionCaught = static_cast<Jobs::Exceptions::Type>(e.getParam());
811 m_exceptionMessage = e.GetMessage();
814 void JobWidgetInstall::displayWidgetInfo()
816 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
818 std::ostringstream out;
819 WidgetLocalizedInfo localizedInfo =
820 W3CFileLocalization::getLocalizedInfo(dao.getTzAppId());
823 "===================================== INSTALLED WIDGET INFO =========" \
824 "============================";
825 out << std::endl << "Name: " << localizedInfo.name;
826 out << std::endl << "AppId: " << dao.getTzAppId();
827 WidgetSize size = dao.getPreferredSize();
828 out << std::endl << "Width: " << size.width;
829 out << std::endl << "Height: " << size.height;
830 out << std::endl << "Start File: " <<
831 W3CFileLocalization::getStartFile(dao.getTzAppId());
832 out << std::endl << "Version: " << dao.getVersion();
833 out << std::endl << "Licence: " <<
834 localizedInfo.license;
835 out << std::endl << "Licence Href: " <<
836 localizedInfo.licenseHref;
837 out << std::endl << "Description: " <<
838 localizedInfo.description;
839 out << std::endl << "Widget Id: " << dao.getGUID();
840 out << std::endl << "Widget recognized: " << dao.isRecognized();
841 out << std::endl << "Widget distributor signed: " <<
842 dao.isDistributorSigned();
843 out << std::endl << "Widget trusted: " << dao.isTrusted();
845 OptionalWidgetIcon icon = W3CFileLocalization::getIcon(dao.getTzAppId());
846 DPL::OptionalString iconSrc =
847 !!icon ? icon->src : DPL::OptionalString::Null;
848 out << std::endl << "Icon: " << iconSrc;
850 out << std::endl << "Preferences:";
852 PropertyDAOReadOnly::WidgetPreferenceList list = dao.getPropertyList();
855 out << std::endl << " Key: " <<
857 out << std::endl << " Readonly: " <<
862 out << std::endl << "Features:";
864 WidgetFeatureSet list = dao.getFeaturesList();
867 out << std::endl << " Name: " << it->name;
876 WrtDB::PackagingType JobWidgetInstall::checkPackageType(
877 const std::string &widgetSource,
878 const std::string &tempPath)
880 if (hasExtension(widgetSource, XML_EXTENSION)) {
881 LogInfo("Hosted app installation");
882 return PKG_TYPE_HOSTED_WEB_APP;
885 std::string configFile = tempPath + "/" + OSP_MANIFEST_XML;
886 if (WrtUtilFileExists(configFile)) {
887 return PKG_TYPE_HYBRID_WEB_APP;
890 return PKG_TYPE_NOMAL_WEB_APP;
893 void JobWidgetInstall::setApplicationType(
894 const WrtDB::ConfigParserData &configInfo)
896 FOREACH(iterator, configInfo.nameSpaces) {
897 LogInfo("namespace = [" << *iterator << "]");
898 AppType currentAppType = APP_TYPE_UNKNOWN;
900 if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
904 ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
906 ConfigurationNamespace::WacWidgetNamespaceName)
908 currentAppType = APP_TYPE_WAC20;
909 } else if (*iterator ==
910 ConfigurationNamespace::TizenWebAppNamespaceName)
912 currentAppType = APP_TYPE_TIZENWEBAPP;
915 if (m_installerContext.widgetConfig.webAppType ==
918 m_installerContext.widgetConfig.webAppType = currentAppType;
919 } else if (m_installerContext.widgetConfig.webAppType ==
924 ThrowMsg(Exceptions::WidgetConfigFileInvalid,
925 "Config.xml has more than one namespace");
929 // If there is no define, type set to WAC 2.0
930 if (m_installerContext.widgetConfig.webAppType == APP_TYPE_UNKNOWN) {
931 m_installerContext.widgetConfig.webAppType = APP_TYPE_WAC20;
934 LogInfo("type = [" <<
935 m_installerContext.widgetConfig.webAppType.getApptypeToString() <<
939 bool JobWidgetInstall::detectResourceEncryption(
940 const WrtDB::ConfigParserData &configData)
942 FOREACH(it, configData.settingsList)
944 if (it->m_name == SETTING_VALUE_ENCRYPTION &&
945 it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
947 LogDebug("resource need encryption");
954 void JobWidgetInstall::setInstallLocationType(
955 const WrtDB::ConfigParserData & configData)
957 m_installerContext.locationType = INSTALL_LOCATION_TYPE_NOMAL;
958 if (m_installerContext.mode.installTime != InstallMode::InstallTime::PRELOAD) {
959 FOREACH(it, configData.settingsList) {
960 if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
962 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
964 LogDebug("This widget will be installed to sd card");
965 m_installerContext.locationType =
966 INSTALL_LOCATION_TYPE_EXTERNAL;
972 bool JobWidgetInstall::checkSupportRDSUpdate(const WrtDB::ConfigParserData
975 if (m_installerContext.mode.command ==
976 InstallMode::Command::REINSTALL)
978 DPL::String configValue = SETTING_VALUE_ENCRYPTION_DISABLE;
979 DPL::String dbValue = SETTING_VALUE_ENCRYPTION_DISABLE;
981 WidgetDAOReadOnly dao(m_installerContext.widgetConfig.tzAppid);
982 WrtDB::WidgetSettings widgetSettings;
983 dao.getWidgetSettings(widgetSettings);
985 FOREACH(it, widgetSettings) {
986 if (it->settingName == SETTING_VALUE_ENCRYPTION) {
987 dbValue = it->settingValue;
991 FOREACH(data, configInfo.settingsList)
993 if (data->m_name == SETTING_VALUE_ENCRYPTION)
995 configValue = data->m_value;
998 if (configValue != dbValue) {
999 LogError("Not Support RDS mode because of encryption setting");
1006 } //namespace WidgetInstall