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