Merge "Flow control for DataControl" into tizen_2.1
[platform/framework/native/appfw.git] / src / system / FSysSystemInfo.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FSysSystemInfo.cpp
20  * @brief               This is the implementation file for SystemInfo class.
21  */
22
23 #include <unique_ptr.h>
24 #include <FSysSystemInfo.h>
25
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>
32
33 using namespace std;
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
38 using namespace Tizen::Security;
39
40 namespace Tizen { namespace System
41 {
42
43 SystemInfo::SystemInfo(void)
44         :__pSystemInfoImpl(null)
45 {
46 }
47
48 SystemInfo::~SystemInfo(void)
49 {
50 }
51
52 result
53 SystemInfo::GetValue(const Tizen::Base::String& key, bool& value)
54 {
55         SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
56
57         return _SystemInfoImpl::GetSysInfo(key, value);
58 }
59
60 result
61 SystemInfo::GetValue(const String& key, String& value)
62 {
63         SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
64
65         return _SystemInfoImpl::GetSysInfo(key, value);
66 }
67
68 result
69 SystemInfo::GetValue(const String& key, int& value)
70 {
71         SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
72
73         return _SystemInfoImpl::GetSysInfo(key, value);
74 }
75
76 result
77 SystemInfo::GetValue(const String& key, double& value)
78 {
79         SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
80
81         return _SystemInfoImpl::GetSysInfo(key, value);
82 }
83
84 result
85 SystemInfo::GetValue(const String& key, UuId& value)
86 {
87         SysTryReturn(NID_SYS, key.GetLength() > 0, E_INVALID_ARG, E_INVALID_ARG, ("Key length should be greater than 0."));
88
89         return _SystemInfoImpl::GetSysInfo(key, value);
90 }
91
92 IList*
93 SystemInfo::GetValuesN(const String& key, SystemInfoValueType type)
94 {
95         result r = E_SUCCESS;
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."));
98
99         pValues = _SystemInfoImpl::GetSysInfoValuesN(key, type);
100         if(pValues == null)
101         {
102                 r = E_OBJ_NOT_FOUND;
103         }
104 CATCH:
105         SetLastResult(r);
106         return pValues;
107 }
108
109 result
110 SystemInfo::GetPlatformVersion(String& platformVersion)
111 {
112         result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO);
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);
115 }
116
117 result
118 SystemInfo::GetBuildInfo(String& buildInfo)
119 {
120         result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO);
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);
123 }
124
125 result
126 SystemInfo::GetNativeApiVersion(String& nativeApiVersion)
127 {
128         result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO);
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);
131 }
132
133 result
134 SystemInfo::GetWebApiVersion(String& webApiVersion)
135 {
136         result r = _AccessController::CheckUserPrivilege(_PRV_PLATFORMINFO);
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);
139 }
140
141 result
142 SystemInfo::GetImei(String& imei)
143 {
144         result r = E_SUCCESS;
145
146         ArrayList requestMessage;
147         ArrayList responseMessage;
148
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.");
151
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));
154
155         requestMessage.Construct();
156         responseMessage.Construct();
157
158         String serviceId = _SYSTEM_SERVICE_ID;
159         String commandId = _SYSTEM_COMMAND_GET_IMEI;
160
161         requestMessage.Add(serviceId);
162         requestMessage.Add(commandId);
163
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");
166
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));
169
170         unique_ptr<String> pResult((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA));
171         unique_ptr<String> pImei((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA+1));
172
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.");
175
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.");
178
179         imei = *pImei;
180         return r;
181 }
182
183 }}  // Tizen::System