100bf349ac3be8cb79030886dbe2cd8d6c3524ec
[framework/osp/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
32 #include <FAppPkg_PackageInfoImpl.h>
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Io;
37 using namespace Tizen::Security::Cert;
38 using namespace Tizen::App;
39 using namespace Tizen::App::Package;
40
41 InstallationContext::InstallationContext(void)
42 :__pAppDataList(null)
43 ,__isSubMode(false)
44 ,__pStep(null)
45 ,__pDrmLicense(null)
46 ,__error(INSTALLER_ERROR_NONE)
47 ,__step(INSTALLER_STEP_NONE)
48 ,__attributeType(0)
49 ,__state(INSTALLER_STATE_RUNNING)
50 ,__stepChanged(true)
51 ,__continue(true)
52 ,__preloaded(false)
53 ,__hybridService(false)
54 ,__verificationMode(false)
55 ,__operation(INSTALLER_OPERATION_INSTALL)
56 ,__storage(INSTALLATION_STORAGE_INTERNAL)
57 ,__pPrivilegeList(null)
58 ,__pLiveboxDataList(null)
59 ,__pContentDataList(null)
60 ,__pAuthorCertPath(null)
61 ,__pDistributorCertPath(null)
62 ,__rootCertType(ROOT_CERTIFICATE_NONE)
63 ,__packageNameType(INSTALLER_PREFIX_TYPE_NONE)
64 ,__pApp2ExtHandle(null)
65 ,__pPackageInfoImpl(null)
66 {
67 }
68
69 InstallationContext::~InstallationContext(void)
70 {
71         delete __pStep;
72         __pStep = null;
73
74         delete __pDrmLicense;
75         __pDrmLicense = null;
76
77         delete __pAuthorCertPath;
78         __pAuthorCertPath = null;
79
80         delete __pDistributorCertPath;
81         __pDistributorCertPath = null;
82
83         if (__pPrivilegeList)
84         {
85                 __pPrivilegeList->RemoveAll();
86                 delete __pPrivilegeList;
87                 __pPrivilegeList = null;
88         }
89
90         if (__pLiveboxDataList)
91         {
92                 __pLiveboxDataList->RemoveAll();
93                 delete __pLiveboxDataList;
94                 __pLiveboxDataList = null;
95         }
96
97         if (__pAppDataList)
98         {
99                 __pAppDataList->RemoveAll();
100                 delete __pAppDataList;
101         }
102 }
103
104 InstallerError
105 InstallationContext::Construct(void)
106 {
107         __pPackageInfoImpl = new (std::nothrow) _PackageInfoImpl();
108         TryReturn(__pPackageInfoImpl, INSTALLER_ERROR_MEMORY, "[osp-installer] __pPackageInfoImpl is null.");
109
110         __pAppDataList = new (std::nothrow) ArrayListT<AppData*>;
111         TryReturn(__pAppDataList, INSTALLER_ERROR_MEMORY, "[osp-installer] __pAppDataList is null");
112
113         return INSTALLER_ERROR_NONE;
114 }
115
116 bool
117 InstallationContext::ChangeStep(InstallationStep step)
118 {
119         delete __pStep;
120         __pStep = null;
121
122         switch (step)
123         {
124         case INSTALLER_STEP_NONE:
125                 break;
126
127         case INSTALLER_STEP_INIT:
128                 break;
129
130         case INSTALLER_STEP_CHECK_SYSTEM:
131                 __pStep = new (std::nothrow) SystemCheckStep();
132                 TryReturn(__pStep, false, "[osp-installer] SystemCheckStep is failed.");
133                 break;
134
135         case INSTALLER_STEP_CHECK_PACKAGE:
136                 __pStep = new (std::nothrow) PackageCheckStep();
137                 TryReturn(__pStep, false, "[osp-installer] PackageCheckStep is failed.");
138                 break;
139
140         case INSTALLER_STEP_UNPACK:
141                 __pStep = new (std::nothrow) UnpackStep();
142                 TryReturn(__pStep, false, "[osp-installer] UnpackStep is failed.");
143                 break;
144
145         case INSTALLER_STEP_PARSE_MANIFEST:
146                 __pStep = new (std::nothrow) ManifestXmlStep();
147                 TryReturn(__pStep, false, "[osp-installer] ManifestXmlStep is failed.");
148                 break;
149
150         case INSTALLER_STEP_PARSE_SIGNATURE:
151                 __pStep = new (std::nothrow) SignatureStep();
152                 TryReturn(__pStep, false, "[osp-installer] SignatureStep is failed.");
153                 break;
154
155         case INSTALLER_STEP_UNINSTALL:
156                 __pStep = new (std::nothrow) UninstallStep();
157                 TryReturn(__pStep, false, "[osp-installer] UninstallStep is failed.");
158                 break;
159
160         case INSTALLER_STEP_LICENSE:
161                 __pStep = new (std::nothrow) LicenseStep();
162                 TryReturn(__pStep, false, "[osp-installer] LicenseStep is failed.");
163                 break;
164
165         case INSTALLER_STEP_DRM:
166                 __pStep = new (std::nothrow) DrmStep();
167                 TryReturn(__pStep, false, "[osp-installer] DrmStep is failed.");
168                 break;
169
170         case INSTALLER_STEP_END:
171                 break;
172
173         default:
174                 break;
175         }
176
177         __step = step;
178         return true;
179 }
180
181 InstallerError
182 InstallationContext::Run(void)
183 {
184         InstallerError error = INSTALLER_ERROR_NONE;
185         AppLogTag(OSP_INSTALLER, "InstallationContext::Run()");
186         return error;
187 }
188
189 InstallationStep
190 InstallationContext::GetCurrentInstallationStep(void)
191 {
192         return __step;
193 }
194
195 void
196 InstallationContext::SetCurrentInstallationStep(InstallationStep step)
197 {
198         __step = step;
199 }
200
201 InstallerError
202 InstallationContext::GetError(void)
203 {
204         return __error;
205 }
206
207 void
208 InstallationContext::SetError(InstallerError installerError)
209 {
210         __error = installerError;
211 }
212
213 InstallationState
214 InstallationContext::GetState(void)
215 {
216         return __state;
217 }
218
219 void
220 InstallationContext::SetState(InstallationState installationState)
221 {
222         __state = installationState;
223 }
224
225 IInstallationStep*
226 InstallationContext::GetStep(void)
227 {
228         return __pStep;
229 }
230
231 void
232 InstallationContext::SetInputPath(const Tizen::Base::String& path)
233 {
234         __inputPath = path;
235 }
236
237 const String&
238 InstallationContext::GetInputPath(void) const
239 {
240         return __inputPath;
241 }
242
243 void
244 InstallationContext::SetInstallerOperation(InstallerOperation op)
245 {
246         __operation = op;
247 }
248
249 InstallerOperation
250 InstallationContext::GetInstallerOperation(void) const
251 {
252         return __operation;
253 }
254
255 bool
256 InstallationContext::IsContinue(void)
257 {
258         return __continue;
259 }
260
261 void
262 InstallationContext::SetContinue(bool cont)
263 {
264         __continue = cont;
265 }
266
267 bool
268 InstallationContext::IsPreloaded(void)
269 {
270         return __preloaded;
271 }
272
273 void
274 InstallationContext::SetPreloaded(bool preloaded)
275 {
276         __preloaded = preloaded;
277 }
278
279 bool
280 InstallationContext::IsHybridService(void)
281 {
282         return __hybridService;
283 }
284
285 void
286 InstallationContext::SetHybridService(bool hybridService)
287 {
288         __hybridService = hybridService;
289 }
290
291 bool
292 InstallationContext::IsVerificationMode(void)
293 {
294         return __verificationMode;
295 }
296
297 void
298 InstallationContext::SetVerificationMode(bool verificationMode)
299 {
300         __verificationMode = verificationMode;
301 }
302
303 const String&
304 InstallationContext::GetPackagePath(void) const
305 {
306         return __packagePath;
307 }
308
309 void
310 InstallationContext::SetPackagePath(const String& packagePath)
311 {
312         __packagePath = packagePath;
313 }
314
315 const String&
316 InstallationContext::GetLicensePath(void) const
317 {
318         return __licensePath;
319 }
320
321 void
322 InstallationContext::SetLicensePath(const String& licensePath)
323 {
324         __licensePath = licensePath;
325 }
326
327 const String&
328 InstallationContext::GetTemporaryDir(void) const
329 {
330         return __temporaryDir;
331 }
332
333 void
334 InstallationContext::SetTemporaryDir(const String& temporaryDir)
335 {
336         __temporaryDir = temporaryDir;
337 }
338
339 const String&
340 InstallationContext::GetInstallDir(void) const
341 {
342         return __installDir;
343 }
344
345 void
346 InstallationContext::SetInstallDir(const String& installDir)
347 {
348         __installDir = installDir;
349 }
350
351 const String&
352 InstallationContext::GetWorkingDir(void) const
353 {
354         return __workingDir;
355 }
356
357 void
358 InstallationContext::SetWorkingDir(const String& workingDir)
359 {
360         __workingDir = workingDir;
361 }
362
363 void
364 InstallationContext::SetInstallationStorage(InstallationStorage storage)
365 {
366         __storage = storage;
367 }
368
369 InstallationContext::InstallationStorage
370 InstallationContext::GetInstallationStorage(void) const
371 {
372         return __storage;
373 }
374
375 const PackageId&
376 InstallationContext::GetId(void) const
377 {
378         return __packageId;
379 }
380
381 void
382 InstallationContext::SetId(const PackageId& packageId)
383 {
384         __packageId = packageId;
385 }
386
387 const String&
388 InstallationContext::GetAppVersion(void) const
389 {
390         return __appVersion;
391 }
392
393 void
394 InstallationContext::SetAppVersion(const String& appVersion)
395 {
396         __appVersion = appVersion;
397 }
398
399 String
400 InstallationContext::GetManifestXmlPath(void)
401 {
402         String  path;
403
404         path = GetInstallDir() + PACKAGE_XML_FILE;
405
406         return path;
407 }
408
409 String
410 InstallationContext::GetSignatureXmlPath(void)
411 {
412         String  path;
413
414         path = GetInstallDir() + SIGNATURE1_XML_FILE;
415
416         return path;
417 }
418
419 String
420 InstallationContext::GetAuthorSignatureXmlPath(void)
421 {
422         String  path;
423
424         path = GetInstallDir() + AUTHOR_SIGNATURE_XML_FILE;
425
426         return path;
427 }
428
429 const ArrayList*
430 InstallationContext::GetPrivilegeList(void) const
431 {
432         return __pPrivilegeList;
433 }
434
435 void
436 InstallationContext::SetPrivilegeList(ArrayList* privilegeList)
437 {
438         __pPrivilegeList = privilegeList;
439 }
440
441 ArrayList*
442 InstallationContext::GetLiveboxDataList(void) const
443 {
444         return __pLiveboxDataList;
445 }
446
447 void
448 InstallationContext::SetLiveboxDataList(ArrayList* pLiveboxDataList)
449 {
450         __pLiveboxDataList = pLiveboxDataList;
451 }
452
453 ArrayList*
454 InstallationContext::GetContentDataList(void) const
455 {
456         return __pContentDataList;
457 }
458
459 void
460 InstallationContext::SetContentDataList(ArrayList* pContentDataList)
461 {
462         __pContentDataList = pContentDataList;
463 }
464
465 X509CertificatePath*
466 InstallationContext::GetAuthorCertPath(void) const
467 {
468         return __pAuthorCertPath;
469 }
470
471 void
472 InstallationContext::SetAuthorCertPath(X509CertificatePath* pAuthorCertPath)
473 {
474         __pAuthorCertPath = pAuthorCertPath;
475 }
476
477 X509CertificatePath*
478 InstallationContext::GetDistributorCertPath(void) const
479 {
480         return __pDistributorCertPath;
481 }
482
483 void
484 InstallationContext::SetDistributorCertPath(X509CertificatePath* pDistributorCertPath)
485 {
486         __pDistributorCertPath = pDistributorCertPath;
487 }
488
489 RootCertificateType
490 InstallationContext::GetRootCertType(void) const
491 {
492         return __rootCertType;
493 }
494
495 void
496 InstallationContext::SetRootCertType(RootCertificateType certType)
497 {
498         __rootCertType = certType;
499 }
500
501 int
502 InstallationContext::GetPackageNameType(void) const
503 {
504         return __packageNameType;
505 }
506
507 void
508 InstallationContext::SetPackageNameType(int type)
509 {
510         __packageNameType = type;
511 }
512
513 app2ext_handle*
514 InstallationContext::GetApp2ExtHandle(void) const
515 {
516         return __pApp2ExtHandle;
517 }
518
519 void
520 InstallationContext::SetApp2ExtHandle(app2ext_handle* pHandle)
521 {
522         __pApp2ExtHandle = pHandle;
523 }
524
525 _PackageInfoImpl*
526 InstallationContext::GetPackageInfoImpl(void) const
527 {
528         return __pPackageInfoImpl;
529 }