be2d8dfc00ddc9b0cbc55ec9abe1dde30508509a
[platform/framework/native/installer.git] / src / Context / InstallationContext.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        InstallationContext.cpp
19  * @brief       This is the implementation for the InstallerContext class.
20  */
21
22 #include "InstallationContext.h"
23 #include "SystemCheckStep.h"
24 #include "PackageCheckStep.h"
25 #include "ManifestXmlStep.h"
26 #include "LicenseStep.h"
27 #include "SignatureStep.h"
28 #include "DrmStep.h"
29 #include "UninstallStep.h"
30 #include "UnpackStep.h"
31 #include "RdsStep.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Io;
36 using namespace Tizen::Security::Cert;
37 using namespace Tizen::App;
38
39 InstallationContext::InstallationContext(void)
40 :__pStep(null)
41 ,__pDrmLicense(null)
42 ,__error(INSTALLER_ERROR_NONE)
43 ,__step(INSTALLER_STEP_NONE)
44 ,__attributeType(0)
45 ,__state(INSTALLER_STATE_RUNNING)
46 ,__stepChanged(true)
47 ,__continue(true)
48 ,__pAppDataList(null)
49 ,__isOspCompat(false)
50 ,__isPreloaded(false)
51 ,__isHybridService(false)
52 ,__isVerificationMode(false)
53 ,__isUpdated(false)
54 ,__isAppSetting(false)
55 ,__operation(INSTALLER_OPERATION_INSTALL)
56 ,__storage(INSTALLATION_STORAGE_INTERNAL)
57 ,__rootCertType(ROOT_CERTIFICATE_NONE)
58 ,__pApp2ExtHandle(null)
59 ,__pPrivilegeList(null)
60 ,__pStringPrivilegeList(null)
61 ,__pContentDataList(null)
62 ,__pAuthorCertPath(null)
63 ,__pDistributorCertPath(null)
64 ,__pAuthorCertList(null)
65 ,__pDistributorCertList(null)
66 ,__certType(0)
67 {
68 }
69
70 InstallationContext::~InstallationContext(void)
71 {
72         delete __pStep;
73         __pStep = null;
74
75         delete __pDrmLicense;
76         __pDrmLicense = null;
77
78         delete __pAuthorCertPath;
79         __pAuthorCertPath = null;
80
81         delete __pDistributorCertPath;
82         __pDistributorCertPath = null;
83
84         if (__pPrivilegeList)
85         {
86                 __pPrivilegeList->RemoveAll();
87                 delete __pPrivilegeList;
88                 __pPrivilegeList = null;
89         }
90
91         if (__pStringPrivilegeList)
92         {
93                 __pStringPrivilegeList->RemoveAll(true);
94                 delete __pStringPrivilegeList;
95                 __pStringPrivilegeList = null;
96         }
97
98         if (__pAppDataList)
99         {
100                 __pAppDataList->RemoveAll();
101                 delete __pAppDataList;
102         }
103
104         if (__pAuthorCertList)
105         {
106                 __pAuthorCertList->RemoveAll();
107                 delete __pAuthorCertList;
108                 __pAuthorCertList = null;
109         }
110
111         if (__pDistributorCertList)
112         {
113                 __pDistributorCertList->RemoveAll();
114                 delete __pDistributorCertList;
115                 __pDistributorCertList = null;
116         }
117 }
118
119 InstallerError
120 InstallationContext::Construct(void)
121 {
122         __pAppDataList = new (std::nothrow) ArrayListT<AppData*>;
123         TryReturn(__pAppDataList, INSTALLER_ERROR_OUT_OF_MEMORY, "__pAppDataList is null");
124
125         __pAuthorCertList = new (std::nothrow) ArrayListT<String*>;
126         TryReturn(__pAuthorCertList, INSTALLER_ERROR_OUT_OF_MEMORY, "__pAuthorCertList is null.");
127
128         __pDistributorCertList = new (std::nothrow) ArrayListT<String*>;
129         TryReturn(__pDistributorCertList, INSTALLER_ERROR_OUT_OF_MEMORY, "__pDistributorCertList is null.");
130
131         return INSTALLER_ERROR_NONE;
132 }
133
134 bool
135 InstallationContext::ChangeStep(InstallationStep step)
136 {
137         delete __pStep;
138         __pStep = null;
139
140         switch (step)
141         {
142         case INSTALLER_STEP_NONE:
143                 break;
144
145         case INSTALLER_STEP_INIT:
146                 break;
147
148         case INSTALLER_STEP_CHECK_SYSTEM:
149                 __pStep = new (std::nothrow) SystemCheckStep();
150                 TryReturn(__pStep, false, "SystemCheckStep is failed.");
151                 break;
152
153         case INSTALLER_STEP_CHECK_PACKAGE:
154                 __pStep = new (std::nothrow) PackageCheckStep();
155                 TryReturn(__pStep, false, "PackageCheckStep is failed.");
156                 break;
157
158         case INSTALLER_STEP_UNPACK:
159                 __pStep = new (std::nothrow) UnpackStep();
160                 TryReturn(__pStep, false, "UnpackStep is failed.");
161                 break;
162
163         case INSTALLER_STEP_PARSE_MANIFEST:
164                 __pStep = new (std::nothrow) ManifestXmlStep();
165                 TryReturn(__pStep, false, "ManifestXmlStep is failed.");
166                 break;
167
168         case INSTALLER_STEP_PARSE_SIGNATURE:
169                 __pStep = new (std::nothrow) SignatureStep();
170                 TryReturn(__pStep, false, "SignatureStep is failed.");
171                 break;
172
173         case INSTALLER_STEP_UNINSTALL:
174                 __pStep = new (std::nothrow) UninstallStep();
175                 TryReturn(__pStep, false, "UninstallStep is failed.");
176                 break;
177
178         case INSTALLER_STEP_LICENSE:
179                 __pStep = new (std::nothrow) LicenseStep();
180                 TryReturn(__pStep, false, "LicenseStep is failed.");
181                 break;
182
183         case INSTALLER_STEP_DRM:
184                 __pStep = new (std::nothrow) DrmStep();
185                 TryReturn(__pStep, false, "DrmStep is failed.");
186                 break;
187
188         case INSTALLER_STEP_RDS:
189                 __pStep = new (std::nothrow) RdsStep();
190                 TryReturn(__pStep, false, "DrmStep is failed.");
191                 break;
192
193         case INSTALLER_STEP_END:
194                 break;
195
196         default:
197                 break;
198         }
199
200         __step = step;
201         return true;
202 }
203
204 InstallerError
205 InstallationContext::Run(void)
206 {
207         InstallerError error = INSTALLER_ERROR_NONE;
208         AppLog("InstallationContext::Run()");
209         return error;
210 }
211
212 InstallationStep
213 InstallationContext::GetCurrentInstallationStep(void)
214 {
215         return __step;
216 }
217
218 void
219 InstallationContext::SetCurrentInstallationStep(InstallationStep step)
220 {
221         __step = step;
222 }
223
224 InstallerError
225 InstallationContext::GetError(void)
226 {
227         return __error;
228 }
229
230 void
231 InstallationContext::SetError(InstallerError installerError)
232 {
233         __error = installerError;
234 }
235
236 InstallationState
237 InstallationContext::GetState(void)
238 {
239         return __state;
240 }
241
242 void
243 InstallationContext::SetState(InstallationState installationState)
244 {
245         __state = installationState;
246 }
247
248 IInstallationStep*
249 InstallationContext::GetStep(void)
250 {
251         return __pStep;
252 }
253
254 void
255 InstallationContext::SetInstallerOperation(InstallerOperation op)
256 {
257         __operation = op;
258 }
259
260 InstallerOperation
261 InstallationContext::GetInstallerOperation(void) const
262 {
263         return __operation;
264 }
265
266 bool
267 InstallationContext::IsContinue(void)
268 {
269         return __continue;
270 }
271
272 void
273 InstallationContext::SetContinue(bool cont)
274 {
275         __continue = cont;
276 }
277
278 String
279 InstallationContext::GetSignatureXmlPath(void)
280 {
281         String  path;
282
283         path = __installDir + SIGNATURE1_XML_FILE;
284
285         return path;
286 }
287
288 String
289 InstallationContext::GetAuthorSignatureXmlPath(void)
290 {
291         String  path;
292
293         path = __installDir + AUTHOR_SIGNATURE_XML_FILE;
294
295         return path;
296 }
297
298 const ArrayList*
299 InstallationContext::GetPrivilegeList(void) const
300 {
301         return __pPrivilegeList;
302 }
303
304 void
305 InstallationContext::SetPrivilegeList(ArrayList* privilegeList)
306 {
307         __pPrivilegeList = privilegeList;
308 }
309
310 ArrayList*
311 InstallationContext::GetContentDataList(void) const
312 {
313         return __pContentDataList;
314 }
315
316 void
317 InstallationContext::SetContentDataList(ArrayList* pContentDataList)
318 {
319         __pContentDataList = pContentDataList;
320 }
321