55bfe362547530e575b70a4e2c400c4696b95beb
[framework/osp/security-service.git] / src / SecurityService.cpp
1 //
2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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 /**
18  * @file                SecurityService.cpp
19  * @brief               This is the implementation file for SecurityService class.
20  */
21
22 #include <FAppAppRegistry.h>
23 #include <FSysBattery.h>
24 #include <FBaseLog.h>
25
26 #include "SecurityService.h"
27 #include "PrivilegeService.h"
28 #include "CertificateService.h"
29 #include "TrustZoneService.h"
30
31 using namespace Tizen::System;
32 using namespace Tizen::App;
33 using namespace Tizen::Base::Collection;
34
35
36 static SecurityService* __pSecurityService = null;
37
38 SecurityService::SecurityService(void)
39         : __pPrivilegeService(null)
40         , __pCertificateService(null)
41 {
42
43 }
44
45 SecurityService::~SecurityService(void)
46 {
47
48 }
49
50 Service*
51 SecurityService::CreateInstance(void)
52 {
53         result r = E_SUCCESS;
54
55         ClearLastResult();
56
57         if (__pSecurityService == null)
58         {
59                 __pSecurityService = new (std::nothrow) SecurityService();
60                 if (__pSecurityService == null)
61                 {
62                         AppLogException("[E_OUT_OF_MEMORY] The memory is insufficient.");
63                         r = E_OUT_OF_MEMORY;
64                 }
65         }
66
67         SetLastResult(r);
68
69         return __pSecurityService;
70 }
71
72 bool
73 SecurityService::OnAppInitializing(AppRegistry& appRegistry)
74 {
75         result r = E_SUCCESS;
76         bool ret = true;
77
78         AppLog("Enter");
79
80         __pPrivilegeService = new (std::nothrow) PrivilegeService();
81         TryCatchTag(OSP_SECURITY_SERVICE, __pPrivilegeService != null, r = E_OUT_OF_MEMORY; ret = false, "[E_OUT_OF_MEMORY] The memory is insufficient.");
82
83         r = __pPrivilegeService->Construct();
84         TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = false, "[E_SYSTEM] An unexpected system error occurred.");
85
86         __pCertificateService = new (std::nothrow) CertificateService();        //return true even if error occured
87                                                                                                                                                 //because privilege must be running.
88         TryCatchTag(OSP_SECURITY_SERVICE, __pCertificateService != null, r = E_OUT_OF_MEMORY; ret = true, "[E_OUT_OF_MEMORY] The memory is insufficient.");
89
90         r = __pCertificateService->Construct();
91         TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = true, "[E_SYSTEM] An unexpected system error occurred.");
92
93         __pTrustZoneService = new (std::nothrow) TrustZoneService();
94         r = __pTrustZoneService->Construct();
95         TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = true, "[E_SYSTEM] An unexpected system error occurred.");
96
97         AppLog("Exit");
98
99         return ret;
100
101 CATCH:
102
103         SetLastResult(r);
104
105         AppLog("Exit");
106         return ret;
107 }
108
109 bool
110 SecurityService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
111 {
112         AppLog("Enter");
113
114         delete __pPrivilegeService;
115         delete __pCertificateService;
116
117         AppLog("Exit");
118         return true;
119 }
120
121 void
122 SecurityService::OnLowMemory(void)
123 {
124
125 }
126
127 void
128 SecurityService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
129 {
130
131 }
132
133 void
134 SecurityService::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList *pArgs)
135 {
136
137 }
138
139