Modify to check verification mode
[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 <FApp_PackageInfoImpl.h>
33
34 using namespace Osp::Base;
35 using namespace Osp::Base::Collection;
36 using namespace Osp::Io;
37 using namespace Osp::Security::Cert;
38 using namespace Osp::App;
39
40 InstallationContext::InstallationContext(void)
41 :__pStep(null)
42 ,__pDrmLicense(null)
43 ,__error(INSTALLER_ERROR_NONE)
44 ,__step(INSTALLER_STEP_NONE)
45 ,__attributeType(0)
46 ,__state(INSTALLER_STATE_RUNNING)
47 ,__stepChanged(true)
48 ,__continue(true)
49 ,__preloaded(false)
50 ,__hybridService(false)
51 ,__verificationMode(false)
52 ,__operation(INSTALLER_OPERATION_INSTALL)
53 ,__storage(INSTALLATION_STORAGE_INTERNAL)
54 ,__pPrivilegeList(null)
55 ,__pLiveBoxList(null)
56 ,__pContentInfoList(null)
57 ,__pAuthorCertPath(null)
58 ,__pDistributorCertPath(null)
59 ,__rootCertType(ROOT_CERTIFICATE_NONE)
60 ,__packageNameType(INSTALLER_PREFIX_TYPE_NONE)
61 ,__pApp2ExtHandle(null)
62 ,__pPackageInfoImpl(null)
63 {
64 }
65
66 InstallationContext::~InstallationContext(void)
67 {
68         delete __pStep;
69         __pStep = null;
70
71         delete __pDrmLicense;
72         __pDrmLicense = null;
73
74         delete __pAuthorCertPath;
75         __pAuthorCertPath = null;
76
77         delete __pDistributorCertPath;
78         __pDistributorCertPath = null;
79
80         if (__pPrivilegeList)
81         {
82                 __pPrivilegeList->RemoveAll();
83                 delete __pPrivilegeList;
84                 __pPrivilegeList = null;
85         }
86
87         if (__pLiveBoxList)
88         {
89                 __pLiveBoxList->RemoveAll();
90                 delete __pLiveBoxList;
91                 __pLiveBoxList = null;
92         }
93 }
94
95 InstallerError
96 InstallationContext::Construct(void)
97 {
98         __pPackageInfoImpl = new _PackageInfoImpl();
99         TryReturn(__pPackageInfoImpl, INSTALLER_ERROR_MEMORY, "[osp-installer] __pPackageInfoImpl is null.");
100
101         return INSTALLER_ERROR_NONE;
102 }
103
104 bool
105 InstallationContext::ChangeStep(InstallationStep step)
106 {
107         delete __pStep;
108         __pStep = null;
109
110         switch (step)
111         {
112         case INSTALLER_STEP_NONE:
113                 break;
114
115         case INSTALLER_STEP_INIT:
116                 break;
117
118         case INSTALLER_STEP_CHECK_SYSTEM:
119                 __pStep = new SystemCheckStep();
120                 TryReturn(__pStep, false, "[osp-installer] SystemCheckStep is failed.");
121                 break;
122
123         case INSTALLER_STEP_CHECK_PACKAGE:
124                 __pStep = new PackageCheckStep();
125                 TryReturn(__pStep, false, "[osp-installer] PackageCheckStep is failed.");
126                 break;
127
128         case INSTALLER_STEP_UNPACK:
129                 __pStep = new UnpackStep();
130                 TryReturn(__pStep, false, "[osp-installer] UnpackStep is failed.");
131                 break;
132
133         case INSTALLER_STEP_PARSE_MANIFEST:
134                 __pStep = new ManifestXmlStep();
135                 TryReturn(__pStep, false, "[osp-installer] ManifestXmlStep is failed.");
136                 break;
137
138         case INSTALLER_STEP_PARSE_SIGNATURE:
139                 __pStep = new SignatureStep();
140                 TryReturn(__pStep, false, "[osp-installer] SignatureStep is failed.");
141                 break;
142
143         case INSTALLER_STEP_UNINSTALL:
144                 __pStep = new UninstallStep();
145                 TryReturn(__pStep, false, "[osp-installer] UninstallStep is failed.");
146                 break;
147
148         case INSTALLER_STEP_LICENSE:
149                 __pStep = new LicenseStep();
150                 TryReturn(__pStep, false, "[osp-installer] LicenseStep is failed.");
151                 break;
152
153         case INSTALLER_STEP_DRM:
154                 __pStep = new DrmStep();
155                 TryReturn(__pStep, false, "[osp-installer] DrmStep is failed.");
156                 break;
157
158         case INSTALLER_STEP_END:
159                 break;
160
161         default:
162                 break;
163         }
164
165         __step = step;
166         return true;
167 }
168
169 InstallerError
170 InstallationContext::Run(void)
171 {
172         InstallerError error = INSTALLER_ERROR_NONE;
173         AppLogTag(OSP_INSTALLER, "InstallationContext::Run()");
174         return error;
175 }
176
177 InstallationStep
178 InstallationContext::GetCurrentInstallationStep(void)
179 {
180         return __step;
181 }
182
183 void
184 InstallationContext::SetCurrentInstallationStep(InstallationStep step)
185 {
186         __step = step;
187 }
188
189 InstallerError
190 InstallationContext::GetError(void)
191 {
192         return __error;
193 }
194
195 void
196 InstallationContext::SetError(InstallerError installerError)
197 {
198         __error = installerError;
199 }
200
201 InstallationState
202 InstallationContext::GetState(void)
203 {
204         return __state;
205 }
206
207 void
208 InstallationContext::SetState(InstallationState installationState)
209 {
210         __state = installationState;
211 }
212
213 IInstallationStep*
214 InstallationContext::GetStep(void)
215 {
216         return __pStep;
217 }
218
219 void
220 InstallationContext::SetInputPath(const Osp::Base::String& path)
221 {
222         __inputPath = path;
223 }
224
225 const String&
226 InstallationContext::GetInputPath(void) const
227 {
228         return __inputPath;
229 }
230
231 void
232 InstallationContext::SetInstallerOperation(InstallerOperation op)
233 {
234         __operation = op;
235 }
236
237 InstallerOperation
238 InstallationContext::GetInstallerOperation(void) const
239 {
240         return __operation;
241 }
242
243 bool
244 InstallationContext::IsContinue(void)
245 {
246         return __continue;
247 }
248
249 void
250 InstallationContext::SetContinue(bool cont)
251 {
252         __continue = cont;
253 }
254
255 bool
256 InstallationContext::IsPreloaded(void)
257 {
258         return __preloaded;
259 }
260
261 void
262 InstallationContext::SetPreloaded(bool preloaded)
263 {
264         __preloaded = preloaded;
265 }
266
267 bool
268 InstallationContext::IsHybridService(void)
269 {
270         return __hybridService;
271 }
272
273 void
274 InstallationContext::SetHybridService(bool hybridService)
275 {
276         __hybridService = hybridService;
277 }
278
279 bool
280 InstallationContext::IsVerificationMode(void)
281 {
282         return __verificationMode;
283 }
284
285 void
286 InstallationContext::SetVerificationMode(bool verificationMode)
287 {
288         __verificationMode = verificationMode;
289 }
290
291 const String&
292 InstallationContext::GetPackagePath(void) const
293 {
294         return __packagePath;
295 }
296
297 void
298 InstallationContext::SetPackagePath(const String& packagePath)
299 {
300         __packagePath = packagePath;
301 }
302
303 const String&
304 InstallationContext::GetLicensePath(void) const
305 {
306         return __licensePath;
307 }
308
309 void
310 InstallationContext::SetLicensePath(const String& licensePath)
311 {
312         __licensePath = licensePath;
313 }
314
315 const String&
316 InstallationContext::GetTemporaryDir(void) const
317 {
318         return __temporaryDir;
319 }
320
321 void
322 InstallationContext::SetTemporaryDir(const String& temporaryDir)
323 {
324         __temporaryDir = temporaryDir;
325 }
326
327 const String&
328 InstallationContext::GetInstallDir(void) const
329 {
330         return __installDir;
331 }
332
333 void
334 InstallationContext::SetInstallDir(const String& installDir)
335 {
336         __installDir = installDir;
337 }
338
339 const String&
340 InstallationContext::GetWorkingDir(void) const
341 {
342         return __workingDir;
343 }
344
345 void
346 InstallationContext::SetWorkingDir(const String& workingDir)
347 {
348         __workingDir = workingDir;
349 }
350
351 void
352 InstallationContext::SetInstallationStorage(InstallationStorage storage)
353 {
354         __storage = storage;
355 }
356
357 InstallationContext::InstallationStorage
358 InstallationContext::GetInstallationStorage(void) const
359 {
360         return __storage;
361 }
362
363 const String&
364 InstallationContext::GetAppId(void) const
365 {
366         return __appId;
367 }
368
369 void
370 InstallationContext::SetAppId(const String& appId)
371 {
372         __appId = appId;
373 }
374
375 const String&
376 InstallationContext::GetAppVersion(void) const
377 {
378         return __appVersion;
379 }
380
381 void
382 InstallationContext::SetAppVersion(const String& appVersion)
383 {
384         __appVersion = appVersion;
385 }
386
387 String
388 InstallationContext::GetManifestXmlPath(void)
389 {
390         String  path;
391
392         path = GetInstallDir() + PACKAGE_XML_FILE;
393
394         return path;
395 }
396
397 String
398 InstallationContext::GetSignatureXmlPath(void)
399 {
400         String  path;
401
402         path = GetInstallDir() + SIGNATURE1_XML_FILE;
403
404         return path;
405 }
406
407 String
408 InstallationContext::GetAuthorSignatureXmlPath(void)
409 {
410         String  path;
411
412         path = GetInstallDir() + AUTHOR_SIGNATURE_XML_FILE;
413
414         return path;
415 }
416
417 const ArrayList*
418 InstallationContext::GetPrivilegeList(void) const
419 {
420         return __pPrivilegeList;
421 }
422
423 void
424 InstallationContext::SetPrivilegeList(ArrayList* privilegeList)
425 {
426         __pPrivilegeList = privilegeList;
427 }
428
429 ArrayList*
430 InstallationContext::GetLiveBoxList(void) const
431 {
432         return __pLiveBoxList;
433 }
434
435 void
436 InstallationContext::SetLiveBoxList(ArrayList* pLiveBoxList)
437 {
438         __pLiveBoxList = pLiveBoxList;
439 }
440
441 ArrayList*
442 InstallationContext::GetContentInfoList(void) const
443 {
444         return __pContentInfoList;
445 }
446
447 void
448 InstallationContext::SetContentInfoList(ArrayList* pContentInfoList)
449 {
450         __pContentInfoList = pContentInfoList;
451 }
452
453 X509CertificatePath*
454 InstallationContext::GetAuthorCertPath(void) const
455 {
456         return __pAuthorCertPath;
457 }
458
459 void
460 InstallationContext::SetAuthorCertPath(X509CertificatePath* pAuthorCertPath)
461 {
462         __pAuthorCertPath = pAuthorCertPath;
463 }
464
465 X509CertificatePath*
466 InstallationContext::GetDistributorCertPath(void) const
467 {
468         return __pDistributorCertPath;
469 }
470
471 void
472 InstallationContext::SetDistributorCertPath(X509CertificatePath* pDistributorCertPath)
473 {
474         __pDistributorCertPath = pDistributorCertPath;
475 }
476
477 RootCertificateType
478 InstallationContext::GetRootCertType(void) const
479 {
480         return __rootCertType;
481 }
482
483 void
484 InstallationContext::SetRootCertType(RootCertificateType certType)
485 {
486         __rootCertType = certType;
487 }
488
489 int
490 InstallationContext::GetPackageNameType(void) const
491 {
492         return __packageNameType;
493 }
494
495 void
496 InstallationContext::SetPackageNameType(int type)
497 {
498         __packageNameType = type;
499 }
500
501 app2ext_handle*
502 InstallationContext::GetApp2ExtHandle(void) const
503 {
504         return __pApp2ExtHandle;
505 }
506
507 void
508 InstallationContext::SetApp2ExtHandle(app2ext_handle* pHandle)
509 {
510         __pApp2ExtHandle = pHandle;
511 }
512
513 _PackageInfoImpl*
514 InstallationContext::GetPackageInfoImpl(void) const
515 {
516         return __pPackageInfoImpl;
517 }
518
519 LiveboxInfo::LiveboxInfo(void)
520 :__updatePeriod(0)
521 ,__pNameList(null)
522 ,__pSizeList(null)
523 {
524         __pNameList = new (std::nothrow) HashMap;
525         TryReturn(__pNameList, , "[osp-installer] __pNameList is null.");
526         __pNameList->Construct();
527
528         __pSizeList = new (std::nothrow) ArrayList;
529         TryReturn(__pSizeList, , "[osp-installer] __pSizeList is null.");
530         __pSizeList->Construct();
531 }
532
533 LiveboxInfo::~LiveboxInfo(void)
534 {
535         __pNameList->RemoveAll(true);
536         delete __pNameList;
537
538         __pSizeList->RemoveAll(true);
539         delete __pSizeList;
540 }
541
542 result
543 LiveboxInfo::SetUpdatePeriod(long long period)
544 {
545         __updatePeriod = period;
546         return E_SUCCESS;
547 }
548
549 long long
550 LiveboxInfo::GetUpdatePeriod(void) const
551 {
552         return __updatePeriod;
553 }
554
555 result
556 LiveboxInfo::SetPopupEnabled(const String& value)
557 {
558         __popupEnabled = value;
559         return E_SUCCESS;
560 }
561
562 const String&
563 LiveboxInfo::GetPopupEnabled(void) const
564 {
565         return __popupEnabled;
566 }
567
568 result
569 LiveboxInfo::SetIcon(const String& icon)
570 {
571         __icon = icon;
572         return E_SUCCESS;
573 }
574
575 const String&
576 LiveboxInfo::GetIcon(void) const
577 {
578         return __icon;
579 }
580
581 result
582 LiveboxInfo::AddName(const String& language, const String& name)
583 {
584         result r = E_SUCCESS;
585
586         r = __pNameList->Add(language, name);
587
588         return r;
589 }
590
591 HashMap*
592 LiveboxInfo::GetNameList(void) const
593 {
594         return __pNameList;
595 }
596
597 result
598 LiveboxInfo::AddSize(const String& size)
599 {
600         result r = E_SUCCESS;
601
602         r = __pSizeList->Add(size);
603
604         return r;
605 }
606
607 ArrayList*
608 LiveboxInfo::GetSizeList(void) const
609 {
610         return __pSizeList;
611 }
612
613 ContentInfo::ContentInfo(void)
614 :__pNameList(null)
615 {
616         __pNameList = new (std::nothrow) HashMap;
617         TryReturn(__pNameList, , "[osp-installer] __pNameList is null.");
618         __pNameList->Construct();
619 }
620
621 ContentInfo::~ContentInfo(void)
622 {
623         __pNameList->RemoveAll(true);
624         delete __pNameList;
625 }
626
627 result
628 ContentInfo::SetContentId(const String& contentId)
629 {
630         __contentId = contentId;
631         return E_SUCCESS;
632 }
633
634 const String&
635 ContentInfo::GetContentId(void) const
636 {
637         return __contentId;
638 }
639
640 result
641 ContentInfo::SetIcon(const String& icon)
642 {
643         __icon = icon;
644         return E_SUCCESS;
645 }
646
647 const String&
648 ContentInfo::GetIcon(void) const
649 {
650         return __icon;
651 }
652
653 result
654 ContentInfo::AddName(const String& language, const String& name)
655 {
656         result r = E_SUCCESS;
657
658         r = __pNameList->Add(language, name);
659
660         return r;
661 }
662
663 HashMap*
664 ContentInfo::GetNameList(void) const
665 {
666         return __pNameList;
667 }
668