2 // Copyright (c) 2012 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 FSysSystemInfo.cpp
19 * @brief This is the implementation file for SystemInfo class.
22 #include <unique_ptr.h>
23 #include <FSysSystemInfo.h>
25 #include <FBaseSysLog.h>
26 #include <FIo_AppServiceIpcMessages.h>
27 #include <FIo_IpcClient.h>
28 #include <FSys_SystemInfoImpl.h>
29 #include <FSec_AccessController.h>
30 #include <FSys_Types.h>
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Io;
37 using namespace Tizen::Security;
39 namespace Tizen { namespace System
42 SystemInfo::SystemInfo(void)
43 :__pSystemInfoImpl(null)
47 SystemInfo::~SystemInfo(void)
52 SystemInfo::GetValue(const Tizen::Base::String& key, bool& value)
54 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
56 return _SystemInfoImpl::GetSysInfo(key, value);
60 SystemInfo::GetValue(const String& key, String& value)
62 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
64 return _SystemInfoImpl::GetSysInfo(key, value);
68 SystemInfo::GetValue(const String& key, int& value)
70 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
72 return _SystemInfoImpl::GetSysInfo(key, value);
76 SystemInfo::GetValue(const String& key, double& value)
78 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
80 return _SystemInfoImpl::GetSysInfo(key, value);
84 SystemInfo::GetValue(const String& key, UuId& value)
86 SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
88 return _SystemInfoImpl::GetSysInfo(key, value);
92 SystemInfo::GetValuesN(const String& key, SystemInfoValueType type)
95 IList* pValues = null;
96 SysTryCatch(NID_SYS, key.GetLength() > 0, r = E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
98 pValues = _SystemInfoImpl::GetSysInfoValuesN(key, type);
109 SystemInfo::GetPlatformVersion(String& platformVersion)
111 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
112 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."));
113 return _SystemInfoImpl::GetPlatformVersion(platformVersion);
117 SystemInfo::GetBuildInfo(String& buildInfo)
119 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
120 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."));
121 return _SystemInfoImpl::GetBuildInfo(buildInfo);
125 SystemInfo::GetNativeApiVersion(String& nativeApiVersion)
127 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
128 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."));
129 return _SystemInfoImpl::GetNativeApiVersion(nativeApiVersion);
133 SystemInfo::GetWebApiVersion(String& webApiVersion)
135 result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO, _PRV_SYSTEM);
136 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."));
137 return _SystemInfoImpl::GetWebApiVersion(webApiVersion);
141 SystemInfo::GetImei(String& imei)
143 result r = E_SUCCESS;
145 ArrayList requestMessage;
146 ArrayList responseMessage;
148 unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient());
149 SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
151 r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID);
152 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to create IpcClient. [%s]", GetErrorMessage(r));
154 requestMessage.Construct();
155 responseMessage.Construct();
157 String serviceId = _SYSTEM_SERVICE_ID;
158 String commandId = _SYSTEM_COMMAND_GET_IMEI;
160 requestMessage.Add(serviceId);
161 requestMessage.Add(commandId);
163 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
164 SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
166 r = pIpcClient->SendRequest(pMsg.get());
167 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to send ipc message. [%s]", GetErrorMessage(r));
169 String* pResult = (String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA);
170 String* pImei = (String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA+1);
172 SysTryCatch(NID_SYS, pResult != null, r = E_SYSTEM, r, "It is failed to receive result on IPC response message.");
173 SysTryCatch(NID_SYS, pImei != null, r = E_SYSTEM, r, "It is failed to receive IMEI value on IPC response message.");
175 SysTryCatch(NID_SYS, *pResult != _SYSTEM_RESULT_PRIVILEGED, r = E_PRIVILEGE_DENIED, r, "It is failed to get privilege.");
176 SysTryCatch(NID_SYS, *pResult == _SYSTEM_RESULT_OK, r = E_SYSTEM, r, "It is failed to get IMEI value.");
184 responseMessage.RemoveAll(true);