2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FSysSystemInfo.cpp
20 * @brief This is the implementation file for SystemInfo class.
23 #include <unique_ptr.h>
24 #include <FSysSystemInfo.h>
26 #include <FBaseSysLog.h>
27 #include <FIo_AppServiceIpcMessages.h>
28 #include <FIo_IpcClient.h>
29 #include <FSys_SystemInfoImpl.h>
30 #include <FSec_AccessController.h>
31 #include <FSys_Types.h>
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
38 using namespace Tizen::Security;
40 namespace Tizen { namespace System
43 SystemInfo::SystemInfo(void)
44 :__pSystemInfoImpl(null)
48 SystemInfo::~SystemInfo(void)
53 SystemInfo::GetValue(const Tizen::Base::String& key, bool& value)
55 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
57 return _SystemInfoImpl::GetSysInfo(key, value);
61 SystemInfo::GetValue(const String& key, String& value)
63 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
65 return _SystemInfoImpl::GetSysInfo(key, value);
69 SystemInfo::GetValue(const String& key, int& value)
71 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
73 return _SystemInfoImpl::GetSysInfo(key, value);
77 SystemInfo::GetValue(const String& key, double& value)
79 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
81 return _SystemInfoImpl::GetSysInfo(key, value);
85 SystemInfo::GetValue(const String& key, UuId& value)
87 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
89 return _SystemInfoImpl::GetSysInfo(key, value);
93 SystemInfo::GetValuesN(const String& key, SystemInfoValueType type)
96 IList* pValues = null;
97 SysTryCatch(NID_SYS, key.GetLength() > 0, r = E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
99 pValues = _SystemInfoImpl::GetSysInfoValuesN(key, type);
110 SystemInfo::GetPlatformVersion(String& platformVersion)
112 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
113 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
114 return _SystemInfoImpl::GetPlatformVersion(platformVersion);
118 SystemInfo::GetBuildInfo(String& buildInfo)
120 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
121 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
122 return _SystemInfoImpl::GetBuildInfo(buildInfo);
126 SystemInfo::GetNativeApiVersion(String& nativeApiVersion)
128 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
129 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
130 return _SystemInfoImpl::GetNativeApiVersion(nativeApiVersion);
134 SystemInfo::GetWebApiVersion(String& webApiVersion)
136 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
137 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
138 return _SystemInfoImpl::GetWebApiVersion(webApiVersion);
142 SystemInfo::GetImei(String& imei)
144 result r = E_SUCCESS;
146 ArrayList requestMessage;
147 ArrayList responseMessage;
149 unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient());
150 SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
152 r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID);
153 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to create IpcClient. [%s]", GetErrorMessage(r));
155 requestMessage.Construct();
156 responseMessage.Construct();
158 String serviceId = _SYSTEM_SERVICE_ID;
159 String commandId = _SYSTEM_COMMAND_GET_IMEI;
161 requestMessage.Add(serviceId);
162 requestMessage.Add(commandId);
164 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
165 SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
167 r = pIpcClient->SendRequest(pMsg.get());
168 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to send ipc message. [%s]", GetErrorMessage(r));
170 unique_ptr<String> pResult((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA));
171 unique_ptr<String> pImei((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA+1));
173 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "It is failed to receive result on IPC response message.");
174 SysTryReturnResult(NID_SYS, pImei != null, E_SYSTEM, "It is failed to receive IMEI value on IPC response message.");
176 SysTryReturnResult(NID_SYS, *pResult != _SYSTEM_RESULT_PRIVILEGED, E_PRIVILEGE_DENIED, "It is failed to get privilege.");
177 SysTryReturnResult(NID_SYS, *pResult == _SYSTEM_RESULT_OK, E_SYSTEM, "It is failed to get IMEI value.");