Implement reinstall mode
[framework/web/wrt-installer.git] / src / jobs / widget_install / job_widget_install.h
1 /*
2  * Copyright (c) 2011 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    job_widget_install.h
18  * @author  Radoslaw Wicik r.wicik@samsung.com
19  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20  * @version 1.0
21  * @brief   Implementation file for main installer task
22  */
23 #ifndef WRT_SRC_INSTALLER_CORE_JOB_JOB_WIDGET_INSTALL_H_
24 #define WRT_SRC_INSTALLER_CORE_JOB_JOB_WIDGET_INSTALL_H_
25
26 #include <dpl/optional.h>
27 #include <dpl/string.h>
28 #include <job.h>
29 #include <job_base.h>
30 #include <dpl/utils/widget_version.h>
31 #include <widget_install/widget_install_context.h>
32 #include <widget_install/widget_update_info.h>
33 #include <dpl/wrt-dao-ro/config_parser_data.h>
34 #include "widget_installer_struct.h"
35
36 using namespace Jobs::Exceptions;
37
38 namespace Jobs {
39 namespace WidgetInstall {
40 enum class ConfigureResult
41 {
42     Ok,
43     Deferred,
44     Updated,
45     Failed,
46     Failed_InvalidConfig,
47     Failed_LowerVersion,
48     Failed_AlreadyInstalled,
49     Failed_WidgetRunning,
50     Failed_DrmError,
51 };
52
53 class JobWidgetInstall :
54     public Job,
55     public JobProgressBase<InstallerContext::InstallStep,
56                            InstallerContext::INSTALL_END>,
57     public JobContextBase<WidgetInstallationStruct>   //TODO typedef
58 {
59   private:
60     InstallerContext m_installerContext;
61
62     //TODO move it to base class of all jobs -> make it base template class??
63     Jobs::Exceptions::Type m_exceptionCaught;
64     std::string m_exceptionMessage;
65     WidgetUpdateInfo m_widgetUpdateInfo;
66     bool m_needEncryption;
67     bool m_isDRM;
68
69     ConfigureResult ConfigureInstallation(const std::string &widgetSource,
70                                           const WrtDB::ConfigParserData
71                                           &configData,
72                                           const std::string &tempPath);
73     static WrtDB::ConfigParserData getWidgetDataFromXML(
74         const std::string &widgetSource,
75         const std::string &tempPath,
76         WrtDB::PackagingType pkgType,
77         bool isDRM,
78         bool isReinstall);
79     static WidgetUpdateInfo detectWidgetUpdate(
80         const WrtDB::ConfigParserData &configInfo,
81         const WrtDB::TizenAppId &tizenId);
82     bool isUpperVersion(
83         const OptionalWidgetVersion &existingVersion,
84         const OptionalWidgetVersion &incomingVersion);
85     void setTizenId(const WrtDB::ConfigParserData &configInfo);
86     void displayWidgetInfo();
87     void configureWidgetLocation(const std::string & widgetPath,
88                                  const std::string &tempPath);
89
90     WrtDB::PackagingType checkPackageType(
91         const std::string &widgetSource,
92         const std::string &tempPath);
93     bool detectResourceEncryption(const WrtDB::ConfigParserData &configData);
94     void setInstallLocationType(const WrtDB::ConfigParserData
95                                 &configData);
96     bool isDRMWidget(std::string widgetPath);
97     bool DecryptDRMWidget(std::string widgetPath, std::string destPath);
98     ConfigureResult PrePareInstallation(const std::string &widgetPath);
99     bool validateTizenApplicationID(const WrtDB::TizenAppId &tizenAppId);
100     bool validateTizenPackageID(const WrtDB::TizenPkgId &tizenPkgId);
101     ConfigureResult checkWidgetUpdate(const WidgetUpdateInfo &update);
102     void setApplicationType(const WrtDB::ConfigParserData &configInfo);
103
104   public:
105     /**
106      * @brief Automaticaly sets installation process
107      */
108     JobWidgetInstall(std::string const & widgetPath,
109                      const WidgetInstallationStruct &installerStruct);
110
111     //overrides
112     void SendProgress();
113     void SendFinishedSuccess();
114     void SendFinishedFailure();
115     void SendProgressIconPath(const std::string &path);
116     void SaveExceptionData(const Jobs::JobExceptionBase&);
117 };
118 } //namespace WidgetInstall
119 } //namespace Jobs
120
121 #endif // WRT_SRC_INSTALLER_CORE_JOB_JOB_WIDGET_INSTALL_H_