2 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file SecurityService.cpp
19 * @brief This is the implementation file for SecurityService class.
22 #include <FAppAppRegistry.h>
25 #include "SecurityService.h"
26 #include "PrivilegeService.h"
27 #include "CertificateService.h"
28 #include "DrmService.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base::Collection;
33 #define VCONFKEY_APPSERVICE_STATUS "memory/appservice/status"
35 static SecurityService* __pSecurityService = null;
37 SecurityService::SecurityService(void)
38 : __pPrivilegeService(null)
39 , __pCertificateService(null)
44 SecurityService::~SecurityService(void)
50 SecurityService::CreateInstance(void)
56 if (__pSecurityService == null)
58 __pSecurityService = new (std::nothrow) SecurityService();
59 if (__pSecurityService == null)
61 AppLogException("[E_OUT_OF_MEMORY] The memory is insufficient.");
68 return __pSecurityService;
72 SecurityService::OnAppInitializing(AppRegistry& appRegistry)
78 int channelStatus = 0;
82 __pPrivilegeService = new (std::nothrow) PrivilegeService();
83 TryCatchTag(OSP_SECURITY_SERVICE, __pPrivilegeService != null, r = E_OUT_OF_MEMORY; ret = false, "[E_OUT_OF_MEMORY] The memory is insufficient.");
85 r = __pPrivilegeService->Construct();
86 TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = false, "[E_SYSTEM] An unexpected system error occurred.");
89 __pCertificateService = new (std::nothrow) CertificateService(); //return true even if error occured
90 //because privilege must be running.
91 TryCatchTag(OSP_SECURITY_SERVICE, __pCertificateService != null, r = E_OUT_OF_MEMORY; ret = true, "[E_OUT_OF_MEMORY] The memory is insufficient.");
93 r = __pCertificateService->Construct();
94 TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = true, "[E_SYSTEM] An unexpected system error occurred.");
97 errorCode = vconf_get_int(VCONFKEY_APPSERVICE_STATUS, &channelStatus);
98 TryCatchTag(OSP_SECURITY_SERVICE, errorCode == 0, r = E_SYSTEM; ret = true, "[E_SYSTEM] It is failed to get the VCONF_APPSERVICE_STATUS vconf.");
100 AppLog("Channel IPC Server init started... VCONF_APPSERVICE_STATUS = %d", errorCode);
102 if (channelStatus == 2)
104 AppLog("Channel Service already launched. DRM IPC Server started.");
105 DrmService* pDrmService = DrmService::GetInstance();
106 TryCatchTag(OSP_SECURITY_SERVICE, pDrmService != null, r = E_OUT_OF_MEMORY; ret = true, "[E_OUT_OF_MEMORY] DrmService::GetInstance() failed.");
108 errorCode = vconf_ignore_key_changed(VCONFKEY_APPSERVICE_STATUS, OnChannelServiceLaunched);
111 AppLogException("[E_SYSTEM] It is failed to unregister event listener for vconf change.");
116 AppLog("Channel Service has not been launched. Wait for launching channel service.");
117 errorCode = vconf_notify_key_changed(VCONFKEY_APPSERVICE_STATUS, OnChannelServiceLaunched, null);
118 TryCatchTag(OSP_SECURITY_SERVICE, errorCode == 0, r = E_SYSTEM; ret = true, "[E_SYSTEM] Failed to register event listener of VCONF_APPSERVICE_STATUS.");
134 SecurityService::OnAppInitialized(void)
136 result r = E_SUCCESS;
141 __pCertificateService = new (std::nothrow) CertificateService(); //return true even if error occured
142 //because privilege must be running.
143 TryCatchTag(OSP_SECURITY_SERVICE, __pCertificateService != null, r = E_OUT_OF_MEMORY; ret = true, "[E_OUT_OF_MEMORY] The memory is insufficient.");
145 r = __pCertificateService->Construct();
146 TryCatchTag(OSP_SECURITY_SERVICE, r == E_SUCCESS, r = E_SYSTEM; ret = true, "[E_SYSTEM] An unexpected system error occurred.");
159 SecurityService::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
163 delete __pPrivilegeService;
164 delete __pCertificateService;
165 DrmService::FreeInstance();
172 SecurityService::OnLowMemory(void)
178 SecurityService::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList *pArgs)
184 SecurityService::OnChannelServiceLaunched(keynode_t* node, void* userData)
186 result r = E_SUCCESS;
188 int channelStatus = 0;
191 AppLog("OnChannelServiceLaunched started. - vconf changed.");
193 if(strcmp(VCONFKEY_APPSERVICE_STATUS, vconf_keynode_get_name(node)) == 0)
195 errorCode = vconf_get_int(VCONFKEY_APPSERVICE_STATUS, &channelStatus);
196 TryCatchTag(OSP_SECURITY_SERVICE, errorCode == 0, r = E_SYSTEM, "[E_SYSTEM] Failed to get the VCONF_APPSERVICE_STATUS.");
198 if (channelStatus == 2)
200 AppLog("Channel Service launched. DRM IPC Server will be started.");
202 DrmService* pDrmService = DrmService::GetInstance();
203 TryCatchTag(OSP_SECURITY_SERVICE, pDrmService != null, r = E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] DrmService::GetInstance() failed.");
205 AppLog("DRM IPC Server succesfully launched.");
207 errorCode = vconf_ignore_key_changed(VCONFKEY_APPSERVICE_STATUS, OnChannelServiceLaunched);
210 AppLogException("[E_SYSTEM] It is failed to unregister event listener for vconf change.");