d790b94b111d4fc10149745df57dfcac17c855e3
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_configuration.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    task_configuration.cpp
18  * @version 1.0
19  * @author  Tomasz Iwanek
20  * @brief   implementation file for configuration task
21  */
22 #include "task_configuration.h"
23
24 #include <string>
25 #include <sstream>
26 #include <memory>
27 #include <sys/time.h>
28 #include <ctime>
29 #include <cstdlib>
30 #include <limits.h>
31 #include <regex.h>
32
33 #include <dpl/utils/wrt_utility.h>
34 #include <dpl/utils/path.h>
35 #include <dpl/wrt-dao-ro/common_dao_types.h>
36 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
37 #include <dpl/wrt-dao-ro/global_config.h>
38 #include <dpl/wrt-dao-ro/config_parser_data.h>
39 #include <dpl/localization/w3c_file_localization.h>
40
41 #include <libiriwrapper.h>
42 #include <pkg-manager/pkgmgr_signal.h>
43 #include <app_manager.h>
44
45 #include "root_parser.h"
46 #include "widget_parser.h"
47 #include "parser_runner.h"
48
49 #include <widget_install/widget_install_errors.h>
50 #include <widget_install/widget_install_context.h>
51 #include <widget_install_to_external.h>
52 #include <widget_install/widget_unzip.h>
53 #include <widget_install/job_widget_install.h>
54 #include <widget_install/task_commons.h>
55
56 #include <installer_log.h>
57
58 using namespace WrtDB;
59
60 namespace {
61 const char* const CONFIG_XML = "config.xml";
62 const char* const WITH_OSP_XML = "res/wgt/config.xml";
63 const char* const OSP_MANIFEST_XML = "info/manifest.xml";
64
65 //allowed: a-z, A-Z, 0-9
66 const char* REG_TIZENID_PATTERN = "^[a-zA-Z0-9]{10}.{1,}$";
67 const char* REG_NAME_PATTERN = "^[a-zA-Z0-9._-]{1,}$";
68 const size_t PACKAGE_ID_LENGTH = 10;
69
70 static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
71 static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
72 static const DPL::String SETTING_VALUE_ENCRYPTION_DISABLE = L"disable";
73 const DPL::String SETTING_VALUE_INSTALLTOEXT_NAME =
74     L"install-location";
75 const DPL::String SETTING_VALUE_INSTALLTOEXT_PREPER_EXT =
76     L"prefer-external";
77
78 const std::string XML_EXTENSION = ".xml";
79
80 bool hasExtension(const std::string& filename, const std::string& extension)
81 {
82     _D("Looking for extension %s in %s", extension.c_str(), filename.c_str());
83     size_t fileLen = filename.length();
84     size_t extLen = extension.length();
85     if (fileLen < extLen) {
86         _E("Filename %s is shorter than extension %s", filename.c_str(), extension.c_str());
87         return false;
88     }
89     return (0 == filename.compare(fileLen - extLen, extLen, extension));
90 }
91 } // namespace anonymous
92
93 namespace Jobs {
94 namespace WidgetInstall {
95
96 TaskConfiguration::TaskConfiguration(InstallerContext& context) :
97     DPL::TaskDecl<TaskConfiguration>(this),
98     m_context(context),
99     m_result(ConfigureResult::Unknown)
100 {
101     AddStep(&TaskConfiguration::StartStep);
102     AddStep(&TaskConfiguration::PrepareInstallationStep);
103     AddStep(&TaskConfiguration::AppendTasklistStep);
104     AddStep(&TaskConfiguration::EndStep);
105 }
106
107 void TaskConfiguration::StartStep()
108 {
109     _D("--------- <TaskConfiguration> : START ----------");
110 }
111
112 void TaskConfiguration::EndStep()
113 {
114     _D("--------- <TaskConfiguration> : END ----------");
115 }
116
117 void TaskConfiguration::AppendTasklistStep()
118 {
119     // TODO: (job_install_refactoring) do not store config result anywhere
120     m_context.confResult = m_result;
121
122     if (m_result == ConfigureResult::Ok) {
123         _D("TaskConfiguration -> new installation task list");
124         m_context.job->appendNewInstallationTaskList();
125     } else if (m_result == ConfigureResult::Updated) {
126         _D("TaskConfiguration -> update installation task list");
127         m_context.job->appendUpdateInstallationTaskList();
128     } else {
129         _D("TaskConfiguration -> failure task list");
130         m_context.job->appendFailureTaskList();
131     }
132 }
133
134 void TaskConfiguration::PrepareInstallationStep()
135 {
136     // TODO: (job_install_refactoring) clean up this task
137     std::string widgetPath = m_context.requestedPath;
138     ConfigureResult result;
139     m_context.needEncryption = false;
140     Try
141     {
142         std::string tempDir;
143         if (m_context.mode.extension == InstallMode::ExtensionType::DIR) {
144             if (m_context.mode.command ==
145                     InstallMode::Command::REINSTALL) {
146                 std::ostringstream tempPathBuilder;
147                 tempPathBuilder << WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
148                 tempPathBuilder << WrtDB::GlobalConfig::GetTmpDirPath();
149                 tempPathBuilder << "/";
150                 tempPathBuilder << widgetPath;
151                 tempDir = tempPathBuilder.str();
152             } else {
153                 tempDir = widgetPath;
154             }
155         } else {
156             tempDir =
157                 Jobs::WidgetInstall::createTempPath(
158                         m_context.mode.rootPath ==
159                             InstallMode::RootPath::RO);
160             WidgetUnzip wgtUnzip;
161             wgtUnzip.unzipWgtFile(widgetPath, tempDir);
162         }
163
164         _D("widgetPath:%s", widgetPath.c_str());
165         _D("tempPath:%s", tempDir.c_str());
166
167         m_context.widgetConfig.packagingType =
168             checkPackageType(widgetPath, tempDir);
169         ConfigParserData configData = getWidgetDataFromXML(
170                 widgetPath,
171                 tempDir,
172                 m_context.widgetConfig.packagingType,
173                 m_context.mode.command == InstallMode::Command::REINSTALL);
174         _D("widget packaging type : %d", m_context.widgetConfig.packagingType.pkgType);
175
176         setTizenId(configData);
177         setApplicationType(configData);
178         m_context.needEncryption = detectResourceEncryption(configData);
179         setInstallLocationType(configData);
180         // TODO: (job_install_refactoring) hide this call
181         m_context.callerPkgId =
182             DPL::FromUTF8String(m_context.job->GetInstallerStruct().pkgmgrInterface->getCallerId());
183         _D("Caller Package Id : %ls", m_context.callerPkgId.c_str());
184
185         // Configure installation
186         result = ConfigureInstallation(widgetPath, configData, tempDir);
187         // TODO: (job_install_refactoring) hide this call
188         m_context.job->GetInstallerStruct().pkgmgrInterface->sendSignal(
189                 PKGMGR_PROGRESS_KEY,
190                 PKGMGR_START_VALUE);
191     }
192     Catch(Exceptions::OpenZipFailed)
193     {
194         _E("Failed to unzip for widget");
195         result = ConfigureResult::Failed_OpenZipError;
196     }
197     Catch(Exceptions::ExtractFileFailed)
198     {
199         _E("Failed to unzip for widget");
200         result = ConfigureResult::Failed_UnzipError;
201     }
202     Catch(Exceptions::DrmDecryptFailed)
203     {
204         _E("Failed to unzip for widget");
205         result = ConfigureResult::Failed_DrmError;
206     }
207     Catch(Exceptions::MissingConfig)
208     {
209         _E("Failed to localize config.xml");
210         result = ConfigureResult::Failed_InvalidConfig;
211     }
212     Catch(Exceptions::WidgetConfigFileInvalid)
213     {
214         _E("Invalid configuration file");
215         result = ConfigureResult::Failed_InvalidConfig;
216     }
217     Catch(DPL::Exception)
218     {
219         _E("Unknown exception");
220         result = ConfigureResult::Failed;
221     }
222
223     m_result = result;
224 }
225
226 void TaskConfiguration::setTizenId(
227     const WrtDB::ConfigParserData &configInfo)
228 {
229     bool shouldMakeAppid = false;
230     using namespace PackageManager;
231     if (!!configInfo.tizenAppId) {
232         _D("Setting tizenAppId provided in config.xml: %ls", (*configInfo.tizenAppId).c_str());
233         m_context.widgetConfig.tzAppid = *configInfo.tizenAppId;
234         //check package id.
235         if (!!configInfo.tizenPkgId) {
236             _D("Setting tizenPkgId provided in config.xml: %ls", (*configInfo.tizenPkgId).c_str());
237             m_context.widgetConfig.tzPkgid = *configInfo.tizenPkgId;
238         } else {
239             DPL::String appid = *configInfo.tizenAppId;
240             if (appid.length() > PACKAGE_ID_LENGTH) {
241                 m_context.widgetConfig.tzPkgid =
242                     appid.substr(0, PACKAGE_ID_LENGTH);
243             } else {
244                 //old version appid only has 10byte random character is able to install for a while.
245                 //this case appid equal pkgid.
246                 m_context.widgetConfig.tzPkgid =
247                     *configInfo.tizenAppId;
248                 shouldMakeAppid = true;
249             }
250         }
251     } else {
252         shouldMakeAppid = true;
253         TizenPkgId pkgId = WidgetDAOReadOnly::generatePkgId();
254         _D("Checking if pkg id is unique");
255         while (true) {
256             if (!validateTizenPackageID(pkgId)) {
257                 //path exist, chose another one
258                 pkgId = WidgetDAOReadOnly::generatePkgId();
259                 continue;
260             }
261             break;
262         }
263         m_context.widgetConfig.tzPkgid = pkgId;
264         _D("tizen_id name was generated by WRT: %ls", m_context.widgetConfig.tzPkgid.c_str());
265     }
266
267     if (shouldMakeAppid == true) {
268         DPL::OptionalString name;
269         DPL::OptionalString defaultLocale = configInfo.defaultlocale;
270
271         FOREACH(localizedData, configInfo.localizedDataSet)
272         {
273             Locale i = localizedData->first;
274             if (!!defaultLocale) {
275                 if (defaultLocale == i) {
276                     name = localizedData->second.name;
277                     break;
278                 }
279             } else {
280                 name = localizedData->second.name;
281                 break;
282             }
283         }
284         regex_t regx;
285         if (regcomp(&regx, REG_NAME_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
286             _D("Regcomp failed");
287         }
288
289         _D("Name : %ls", (*name).c_str());
290         if (!name || (regexec(&regx, DPL::ToUTF8String(*name).c_str(),
291                               static_cast<size_t>(0), NULL, 0) != REG_NOERROR))
292         {
293             // TODO : (job_install_refactoring) generate name move to wrt-commons
294             std::string allowedString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
295             std::ostringstream genName;
296             struct timeval tv;
297             gettimeofday(&tv, NULL);
298             unsigned int seed = time(NULL) + tv.tv_usec;
299
300             genName << "_" << allowedString[rand_r(&seed) % allowedString.length()];
301             name = DPL::FromUTF8String(genName.str());
302             _D("name was generated by WRT");
303         }
304         regfree(&regx);
305         _D("Name : %ls", (*name).c_str());
306         std::ostringstream genid;
307         genid << m_context.widgetConfig.tzPkgid << "." << name;
308         _D("tizen appid was generated by WRT : %s", genid.str().c_str());
309
310         DPL::OptionalString appid = DPL::FromUTF8String(genid.str());
311         NormalizeAndTrimSpaceString(appid);
312         m_context.widgetConfig.tzAppid = *appid;
313     }
314
315     // send start signal of pkgmgr
316     // TODO: (job_install_refactoring) hide this call
317     m_context.job->GetInstallerStruct().pkgmgrInterface->setPkgname(DPL::ToUTF8String(
318                                                          m_context.
319                                                              widgetConfig.
320                                                              tzPkgid));
321     _D("Tizen App Id : %ls", m_context.widgetConfig.tzAppid.c_str());
322     _D("Tizen Pkg Id : %ls", m_context.widgetConfig.tzPkgid.c_str());
323 }
324
325 void TaskConfiguration::configureWidgetLocation(const std::string & widgetPath,
326                                                const std::string& tempPath)
327 {
328     m_context.locations =
329         WidgetLocation(DPL::ToUTF8String(m_context.widgetConfig.
330                                              tzPkgid),
331                        widgetPath, tempPath,
332                        m_context.widgetConfig.packagingType,
333                        m_context.mode.rootPath ==
334                            InstallMode::RootPath::RO,
335                            m_context.mode.extension);
336     m_context.locations->registerAppid(
337         DPL::ToUTF8String(m_context.widgetConfig.tzAppid));
338
339     _D("widgetSource %s", widgetPath.c_str());
340 }
341
342 ConfigureResult TaskConfiguration::ConfigureInstallation(
343     const std::string &widgetSource,
344     const WrtDB::ConfigParserData &configData,
345     const std::string &tempPath)
346 {
347     ConfigureResult result = ConfigureResult::Failed;
348     WidgetUpdateInfo update;
349
350     // checking installed web application
351     Try {
352         // checking existing application is installed
353         WidgetDAOReadOnly dao(m_context.widgetConfig.tzAppid);
354         // no excpetion means, it isn't update mode
355         // TODO: (job_install_refactoring) hide this call/
356         m_context.job->GetInstallerStruct().pkgmgrInterface->sendSignal(
357                 PKGMGR_START_KEY,
358                 PKGMGR_START_UPDATE);
359
360         update = detectWidgetUpdate(configData,
361                                     m_context.widgetConfig.tzAppid);
362         result = checkWidgetUpdate(update);
363         if (result != ConfigureResult::Updated) {
364             // Already installed TizenAppId. return failed
365             return ConfigureResult::Failed_AlreadyInstalled;
366         }
367         if (!checkSupportRDSUpdate(configData)) {
368             return ConfigureResult::Failed_NotSupportRDSUpdate;
369         }
370         m_context.isUpdateMode = true;
371     }
372     Catch(WidgetDAOReadOnly::Exception::WidgetNotExist) {
373         // TODO: (job_install_refactoring) hide this call
374         m_context.job->GetInstallerStruct().pkgmgrInterface->sendSignal(
375                 PKGMGR_START_KEY,
376                 PKGMGR_START_INSTALL);
377         result = ConfigureResult::Ok;
378         m_context.isUpdateMode = false;
379
380         if (!validateTizenApplicationID(
381             m_context.widgetConfig.tzAppid))
382         {
383             _E("tizen application ID is already used");
384             return ConfigureResult::Failed_InvalidConfig;
385         }
386         if (!validateTizenPackageID(m_context.widgetConfig.tzPkgid)) {
387             _E("tizen package ID is already used");
388             return ConfigureResult::Failed_AlreadyInstalled;
389         }
390     }
391
392     configureWidgetLocation(widgetSource, tempPath);
393
394     return result;
395 }
396
397 bool TaskConfiguration::validateTizenApplicationID(
398     const WrtDB::TizenAppId &tizenAppId)
399 {
400     _D("tizen application ID = [%ls]", tizenAppId.c_str());
401
402     regex_t reg;
403     if (regcomp(&reg, REG_TIZENID_PATTERN, REG_NOSUB | REG_EXTENDED) != 0) {
404         _D("Regcomp failed");
405     }
406
407     if (regexec(&reg, DPL::ToUTF8String(tizenAppId).c_str(), 0, NULL, 0)
408         == REG_NOMATCH)
409     {
410         regfree(&reg);
411         return false;
412     }
413     regfree(&reg);
414     return true;
415 }
416
417 bool TaskConfiguration::validateTizenPackageID(
418     const WrtDB::TizenPkgId &tizenPkgId)
419 {
420     std::string pkgId = DPL::ToUTF8String(tizenPkgId);
421
422     std::string installPath =
423         std::string(GlobalConfig::GetUserInstalledWidgetPath()) +
424         "/" + pkgId;
425
426     struct stat dirStat;
427     if ((stat(installPath.c_str(), &dirStat) == 0))
428     {
429         return false;
430     }
431     return true;
432 }
433
434 ConfigureResult TaskConfiguration::checkWidgetUpdate(
435     const WidgetUpdateInfo &update)
436 {
437     if (update.existingVersion.IsNull() || update.incomingVersion.IsNull()) {
438         return ConfigureResult::Failed;
439     }
440
441     _D("existing version = '%ls", update.existingVersion->Raw().c_str());
442     _D("incoming version = '%ls", update.incomingVersion->Raw().c_str());
443     _D("Tizen AppID = %ls", update.tzAppId.c_str());
444
445     // Check running state
446     bool isRunning = false;
447     int ret =
448         app_manager_is_running(DPL::ToUTF8String(update.tzAppId).c_str(),
449                                &isRunning);
450     if (APP_MANAGER_ERROR_NONE != ret) {
451         _E("Fail to get running state");
452         return ConfigureResult::Failed_WidgetRunning;
453     }
454
455     if (true == isRunning) {
456         // get app_context for running application
457         // app_context must be released with app_context_destroy
458         app_context_h appCtx = NULL;
459         ret =
460             app_manager_get_app_context(
461                 DPL::ToUTF8String(update.tzAppId).c_str(),
462                 &appCtx);
463         if (APP_MANAGER_ERROR_NONE != ret) {
464             _E("Fail to get app_context");
465             return ConfigureResult::Failed_WidgetRunning;
466         }
467
468         // terminate app_context_h
469         ret = app_manager_terminate_app(appCtx);
470         if (APP_MANAGER_ERROR_NONE != ret) {
471             _E("Fail to terminate running application");
472             app_context_destroy(appCtx);
473             return ConfigureResult::Failed_WidgetRunning;
474         } else {
475             app_context_destroy(appCtx);
476             // app_manager_terminate_app isn't sync API
477             // wait until application isn't running (50ms * 100)
478             bool isStillRunning = true;
479             int checkingloop = 100;
480             struct timespec duration = { 0, 50 * 1000 * 1000 };
481             while (--checkingloop >= 0) {
482                 nanosleep(&duration, NULL);
483                 int ret =
484                     app_manager_is_running(
485                         DPL::ToUTF8String(update.tzAppId).c_str(),
486                         &isStillRunning);
487                 if (APP_MANAGER_ERROR_NONE != ret) {
488                     _E("Fail to get running state");
489                     return ConfigureResult::Failed_WidgetRunning;
490                 }
491                 if (!isStillRunning) {
492                     break;
493                 }
494             }
495             if (isStillRunning) {
496                 _E("Fail to terminate running application");
497                 return ConfigureResult::Failed_WidgetRunning;
498             }
499             _D("terminate application");
500         }
501     }
502
503     m_context.widgetConfig.tzAppid = update.tzAppId;
504
505     if (!!update.existingVersion ||
506             m_context.mode.extension ==
507             InstallMode::ExtensionType::DIR) {
508         return ConfigureResult::Updated;
509     }
510
511     return ConfigureResult::Failed;
512 }
513
514 ConfigParserData TaskConfiguration::getWidgetDataFromXML(
515     const std::string &widgetSource,
516     const std::string &tempPath,
517     WrtDB::PackagingType pkgType,
518     bool isReinstall)
519 {
520     // Parse config
521     ParserRunner parser;
522     ConfigParserData configInfo;
523     Try
524     {
525         if (pkgType == PKG_TYPE_HOSTED_WEB_APP) {
526             parser.Parse(widgetSource,
527                          ElementParserPtr(
528                              new RootParser<WidgetParser>(configInfo,
529                                                           DPL::FromUTF32String(
530                                                               L"widget"))));
531         } else {
532             std::string configFile;
533             configFile = tempPath + "/" + CONFIG_XML;
534             if (!WrtUtilFileExists(configFile)) {
535                 configFile = tempPath + "/" + WITH_OSP_XML;
536             }
537
538             if (isReinstall) {
539                 // checking RDS data directory
540                 if (access(configFile.c_str(), F_OK) != 0) {
541                     std::string tzAppId =
542                         widgetSource.substr(widgetSource.find_last_of("/")+1);
543                     WidgetDAOReadOnly dao(WidgetDAOReadOnly::getTzAppId(DPL::FromUTF8String(tzAppId)));
544                     configFile = DPL::ToUTF8String(*dao.getWidgetInstalledPath());
545                     configFile += "/";
546                     configFile += WITH_OSP_XML;
547                 }
548             }
549
550             if(!DPL::Utils::Path(configFile).Exists())
551             {
552                 ThrowMsg(Exceptions::MissingConfig, "Config file not exists");
553             }
554
555             parser.Parse(configFile,
556                     ElementParserPtr(
557                         new RootParser<WidgetParser>(configInfo,
558                             DPL::
559                             FromUTF32String(
560                                 L"widget"))));
561         }
562     }
563     Catch(ElementParser::Exception::ParseError)
564     {
565         _E("Failed to parse config.xml file");
566         return ConfigParserData();
567     }
568     Catch(WidgetDAOReadOnly::Exception::WidgetNotExist)
569     {
570         _E("Failed to find installed widget - give proper tizenId");
571         return ConfigParserData();
572     }
573     Catch(Exceptions::WidgetConfigFileNotFound){
574         _E("Failed to find config.xml");
575         return ConfigParserData();
576     }
577
578     return configInfo;
579 }
580
581 WidgetUpdateInfo TaskConfiguration::detectWidgetUpdate(
582     const ConfigParserData &configInfo,
583     const WrtDB::TizenAppId &tizenId)
584 {
585     _D("Checking up widget package for config.xml...");
586     OptionalWidgetVersion incomingVersion;
587
588     if (!configInfo.version.IsNull()) {
589         incomingVersion =
590             DPL::Optional<WidgetVersion>(
591                 WidgetVersion(*configInfo.version));
592     }
593
594     WidgetDAOReadOnly dao(tizenId);
595
596     OptionalWidgetVersion optVersion;
597     DPL::OptionalString version = dao.getVersion();
598     if (!version.IsNull()) {
599         optVersion = OptionalWidgetVersion(WidgetVersion(*version));
600     }
601
602     return WidgetUpdateInfo(
603         dao.getTzAppId(),
604         optVersion,
605         incomingVersion);
606 }
607
608
609 WrtDB::PackagingType TaskConfiguration::checkPackageType(
610     const std::string &widgetSource,
611     const std::string &tempPath)
612 {
613     if (hasExtension(widgetSource, XML_EXTENSION)) {
614         _D("Hosted app installation");
615         return PKG_TYPE_HOSTED_WEB_APP;
616     }
617
618     std::string configFile = tempPath + "/" + OSP_MANIFEST_XML;
619     if (WrtUtilFileExists(configFile)) {
620         return PKG_TYPE_HYBRID_WEB_APP;
621     }
622
623     return PKG_TYPE_NOMAL_WEB_APP;
624 }
625
626 void TaskConfiguration::setApplicationType(
627     const WrtDB::ConfigParserData &configInfo)
628 {
629     AppType widgetAppType = APP_TYPE_UNKNOWN;
630     FOREACH(iterator, configInfo.nameSpaces) {
631         _D("namespace = [%ls]", (*iterator).c_str());
632
633         if (*iterator == ConfigurationNamespace::TizenWebAppNamespaceName) {
634             widgetAppType = APP_TYPE_TIZENWEBAPP;
635             break;
636         }
637     }
638
639     m_context.widgetConfig.webAppType = widgetAppType;
640
641     _D("type = [%s]", m_context.widgetConfig.webAppType.getApptypeToString().c_str());
642 }
643
644 bool TaskConfiguration::detectResourceEncryption(
645     const WrtDB::ConfigParserData &configData)
646 {
647     FOREACH(it, configData.settingsList)
648     {
649         if (it->m_name == SETTING_VALUE_ENCRYPTION &&
650             it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE)
651         {
652             _D("resource need encryption");
653             return true;
654         }
655     }
656     return false;
657 }
658
659 void TaskConfiguration::setInstallLocationType(
660     const WrtDB::ConfigParserData & configData)
661 {
662     m_context.locationType = INSTALL_LOCATION_TYPE_NOMAL;
663     if (m_context.mode.installTime != InstallMode::InstallTime::PRELOAD) {
664         FOREACH(it, configData.settingsList) {
665             if (it->m_name == SETTING_VALUE_INSTALLTOEXT_NAME &&
666                 it->m_value ==
667                 SETTING_VALUE_INSTALLTOEXT_PREPER_EXT)
668             {
669                 _D("This widget will be installed to sd card");
670                 m_context.locationType =
671                     INSTALL_LOCATION_TYPE_EXTERNAL;
672             }
673         }
674     }
675 }
676
677 bool TaskConfiguration::checkSupportRDSUpdate(const WrtDB::ConfigParserData
678         &configInfo)
679 {
680     if (m_context.mode.command ==
681             InstallMode::Command::REINSTALL)
682     {
683         DPL::String configValue = SETTING_VALUE_ENCRYPTION_DISABLE;
684         DPL::String dbValue = SETTING_VALUE_ENCRYPTION_DISABLE;
685
686         WidgetDAOReadOnly dao(m_context.widgetConfig.tzAppid);
687         WrtDB::WidgetSettings widgetSettings;
688         dao.getWidgetSettings(widgetSettings);
689
690         FOREACH(it, widgetSettings) {
691             if (it->settingName == SETTING_VALUE_ENCRYPTION) {
692                 dbValue = it->settingValue;
693             }
694         }
695
696         FOREACH(data, configInfo.settingsList)
697         {
698             if (data->m_name == SETTING_VALUE_ENCRYPTION)
699             {
700                 configValue = data->m_value;
701             }
702         }
703         if (configValue != dbValue) {
704             _E("Not Support RDS mode because of encryption setting");
705             return false;
706         }
707     }
708
709     return true;
710 }
711
712 }
713 }