Remove the trust zone service
[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
30 using namespace Tizen::System;
31 using namespace Tizen::App;
32 using namespace Tizen::Base::Collection;
33
34
35 static SecurityService* __pSecurityService = null;
36
37 SecurityService::SecurityService(void)
38         : __pPrivilegeService(null)
39         , __pCertificateService(null)
40 {
41
42 }
43
44 SecurityService::~SecurityService(void)
45 {
46
47 }
48
49 Service*
50 SecurityService::CreateInstance(void)
51 {
52         result r = E_SUCCESS;
53
54         ClearLastResult();
55
56         if (__pSecurityService == null)
57         {
58                 __pSecurityService = new (std::nothrow) SecurityService();
59                 if (__pSecurityService == null)
60                 {
61                         AppLogException("[E_OUT_OF_MEMORY] The memory is insufficient.");
62                         r = E_OUT_OF_MEMORY;
63                 }
64         }
65
66         SetLastResult(r);
67
68         return __pSecurityService;
69 }
70
71 bool
72 SecurityService::OnAppInitializing(AppRegistry& appRegistry)
73 {
74         result r = E_SUCCESS;
75         bool ret = true;
76
77         AppLog("Enter");
78
79         __pPrivilegeService = new (std::nothrow) PrivilegeService();
80         TryCatchTag(OSP_SECURITY_SERVICE, __pPrivilegeService != null, r = E_OUT_OF_MEMORY; ret = false, "[E_OUT_OF_MEMORY] The memory is insufficient.");
81
82         r = __pPrivilegeService->Construct();
83         TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = false, "[E_SYSTEM] An unexpected system error occurred.");
84
85         __pCertificateService = new (std::nothrow) CertificateService();        //return true even if error occured
86                                                                                                                                                 //because privilege must be running.
87         TryCatchTag(OSP_SECURITY_SERVICE, __pCertificateService != null, r = E_OUT_OF_MEMORY; ret = true, "[E_OUT_OF_MEMORY] The memory is insufficient.");
88
89         r = __pCertificateService->Construct();
90         TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = true, "[E_SYSTEM] An unexpected system error occurred.");
91
92         AppLog("Exit");
93
94         return ret;
95
96 CATCH:
97
98         SetLastResult(r);
99
100         AppLog("Exit");
101         return ret;
102 }
103
104 bool
105 SecurityService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
106 {
107         AppLog("Enter");
108
109         delete __pPrivilegeService;
110         delete __pCertificateService;
111
112         AppLog("Exit");
113         return true;
114 }
115
116 void
117 SecurityService::OnLowMemory(void)
118 {
119
120 }
121
122 void
123 SecurityService::OnBatteryLevelChanged(BatteryLevel batteryLevel)
124 {
125
126 }
127
128 void
129 SecurityService::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList *pArgs)
130 {
131
132 }
133
134