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 FSys_SystemInfoImpl.cpp
20 * @brief This is the implementation file for _SystemInfoImpl class.
22 #include <unique_ptr.h>
24 #include <FBaseInteger.h>
26 #include <FBase_NativeError.h>
27 #include <FIo_RegistryImpl.h>
28 #include <FSys_SystemInfoImpl.h>
29 #include <FIo_AppServiceIpcMessages.h>
30 #include <FIo_IpcClient.h>
31 #include <FSys_Types.h>
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Io;
39 namespace Tizen { namespace System
42 static const wchar_t* _REGISTRY_PATH = L"/tmp/osp/system_info_cache.ini";
43 static const wchar_t* _SYSTEM_INFO_SESSION = L"SystemInformation";
46 static const wchar_t* _BLUETOOTH = L"http://tizen.org/feature/network.bluetooth";
47 static const wchar_t* _BLUETOOTH_SUPPORTED = L"BluetoothSupported";
51 static const wchar_t* _CAMERA_FRONT = L"http://tizen.org/feature/camera.front";
53 static const wchar_t* _CAMERA_BACK = L"http://tizen.org/feature/camera.back";
55 static const wchar_t* _CAMERA_COUNT = L"CameraCount";
58 static const wchar_t* _DUID = L"http://tizen.org/system/duid";
59 static const wchar_t* _DEVICE_ID = L"DUID";
62 static const wchar_t* _FMRADIO = L"http://tizen.org/feature/fmradio";
63 static const wchar_t* _FM_RADIO_SUPPORTED = L"FmRadioSupported";
66 static const wchar_t* _KEYBOARD_TYPE = L"KeyboardType";
67 static const wchar_t* _INPUT_KEYBOARD_LAYOUT = L"http://tizen.org/feature/input.keyboard.layout";
70 static const wchar_t* _GPS_SUPPORTED = L"GPSSupported";
71 static const wchar_t* _LOCATION_GPS = L"http://tizen.org/feature/location.gps";
72 static const wchar_t* _WPS_SUPPORTED = L"WPSSupported";
73 static const wchar_t* _LOCATION_WPS = L"http://tizen.org/feature/location.wps";
76 static const wchar_t* _MODELNAME = L"http://tizen.org/system/model_name";
77 static const wchar_t* _MODEL_NAME = L"ModelName";
80 static const wchar_t* _MULTIPOINTTOUCH_POINTCOUNT = L"http://tizen.org/feature/multi_point_touch.point_count";
81 static const wchar_t* _MULTIPOINT_TOUCH_COUNT = L"MultiPointTouchCount";
84 static const wchar_t* _NETWORK_NFC = L"http://tizen.org/feature/network.nfc";
85 static const wchar_t* _NFC_SUPPORTED = L"NFCSupported";
88 static const wchar_t* _OPENGLES_VERSION_1_1 = L"http://tizen.org/feature/opengles.version.1_1";
89 static const wchar_t* _OPENGLES_VERSION_2_0 = L"http://tizen.org/feature/opengles.version.2_0";
90 static const wchar_t* _OPENGL_ES_VERSION = L"OpenGLESVersion";
93 static const wchar_t* _SCREEN_BPP = L"http://tizen.org/feature/screen.bpp";
94 static const wchar_t* _SCREEN_BITS_PER_PIXEL = L"ScreenBitsPerPixel";
95 static const wchar_t* _SCREEN_DPI = L"http://tizen.org/feature/screen.dpi";
96 static const wchar_t* _SCREEN_HEIGHT = L"http://tizen.org/feature/screen.height";
97 static const wchar_t* _SCREENHEIGHT = L"ScreenHeight";
98 static const wchar_t* _SCREEN_WIDTH = L"http://tizen.org/feature/screen.width";
99 static const wchar_t* _SCREENWIDTH = L"ScreenWidth";
100 static const wchar_t* _SCREENDPI = L"ScreenDPI";
103 static const wchar_t* _SCREEN_OUTPUT_RCA = L"http://tizen.org/feature/screen.output.rca";
104 static const wchar_t* _TV_OUT_SUPPORTED = L"TvOutSupported";
107 static const wchar_t* _SOUND_MEDIA_VOLUME_MAX = L"http://tizen.org/system/sound.media.volume.resolution.max";
108 static const wchar_t* _MAX_MEDIA_SOUND_VOLUME = L"MaxMediaSoundVolume";
109 static const wchar_t* _SOUND_NOTIFICATION_VOLUME_MAX = L"http://tizen.org/system/sound.notification.volume.resolution.max";
110 static const wchar_t* _MAX_NOTIFICATION_SOUND_VOLUME = L"MaxNotificationSoundVolume";
111 static const wchar_t* _SOUND_RINGTONE_VOLUME_MAX = L"http://tizen.org/system/sound.ringtone.volume.resolution.max";
112 static const wchar_t* _MAX_RINGTONE_SOUND_VOLUME = L"MaxRingtoneSoundVolume";
113 static const wchar_t* _SOUND_SYSTEM_VOLUME_MAX = L"http://tizen.org/system/sound.system.volume.resolution.max";
114 static const wchar_t* _MAX_SYSTEM_SOUND_VOLUME = L"MaxSystemSoundVolume";
117 static const wchar_t* _TELEPHONY = L"http://tizen.org/feature/network.telephony";
118 static const wchar_t* _TELEPHONY_SERVICE_GSM = L"http://tizen.org/feature/network.telephony.service.gsm";
119 static const wchar_t* _TELEPHONY_SERVICE_GPRS = L"http://tizen.org/feature/network.telephony.service.gprs";
120 static const wchar_t* _TELEPHONY_SERVICE_EDGE = L"http://tizen.org/feature/network.telephony.service.edge";
121 static const wchar_t* _TELEPHONY_SERVICE_UMTS = L"http://tizen.org/feature/network.telephony.service.umts";
122 static const wchar_t* _TELEPHONY_SERVICE_HSDPA = L"http://tizen.org/feature/network.telephony.service.hsdpa";
123 static const wchar_t* _TELEPHONY_SERVICE_HSUPA = L"http://tizen.org/feature/network.telephony.service.hsupa";
124 static const wchar_t* _TELEPHONY_SERVICE_HSPA = L"http://tizen.org/feature/network.telephony.service.hspa";
125 static const wchar_t* _TELEPHONY_SERVICE_LTE = L"http://tizen.org/feature/network.telephony.service.lte";
126 static const wchar_t* _TELEPHONY_SERVICE_CDMA = L"http://tizen.org/feature/network.telephony.service.cdma";
127 static const wchar_t* _NETWORK_TYPE = L"NetworkType";
128 static const wchar_t* _NETWORK_EMERGENCY = L"Emergency";
129 static const wchar_t* _NETWORK_NO_SERVICE = L"NoService";
133 static const wchar_t* _WIFI = L"http://tizen.org/feature/network.wifi";
134 static const wchar_t* _WIFI_SUPPORTED = L"WiFiSupported";
135 static const wchar_t* _WIFI_DIRECT = L"http://tizen.org/feature/network.wifi.direct";
136 static const wchar_t* _WIFI_DIRECT_SUPPORTED = L"WiFiDirectSupported";
139 static const wchar_t* _PLATFORM_VERSION = L"http://tizen.org/feature/platform.version";
140 static const wchar_t* _PLATFORM_NATIVE_API_VERSION = L"http://tizen.org/feature/platform.native.api.version";
141 static const wchar_t* _PLATFORM_WEB_API_VERSION = L"http://tizen.org/feature/platform.web.api.version";
142 static const wchar_t* _BUID_STRING = L"http://tizen.org/system/build.string";
144 static const wchar_t* _WAC_VERSION = L"WACVersion";
145 static const wchar_t* _SUPPORTED = L"Supported";
146 static const wchar_t* _UNSUPPORTED = L"Unsupported";
149 _SystemInfoImpl::ConvertToTizen(const String& key)
153 if(code == _DEVICE_ID)
157 else if(code == _MODEL_NAME)
161 else if(code == _KEYBOARD_TYPE)
163 code == _INPUT_KEYBOARD_LAYOUT;
165 else if(code == _SCREEN_BITS_PER_PIXEL)
169 else if(code == _SCREENHEIGHT)
171 code = _SCREEN_HEIGHT;
173 else if(code == _SCREENWIDTH)
175 code = _SCREEN_WIDTH;
177 else if(code == _SCREENDPI)
181 else if(code == _MAX_SYSTEM_SOUND_VOLUME)
183 code = _SOUND_SYSTEM_VOLUME_MAX;
185 else if(code == _MAX_MEDIA_SOUND_VOLUME)
187 code = _SOUND_MEDIA_VOLUME_MAX;
189 else if(code == _MAX_RINGTONE_SOUND_VOLUME)
191 code = _SOUND_RINGTONE_VOLUME_MAX;
193 else if(code == _MAX_NOTIFICATION_SOUND_VOLUME)
195 code = _SOUND_NOTIFICATION_VOLUME_MAX;
197 else if(code == _MULTIPOINT_TOUCH_COUNT)
199 code = _MULTIPOINTTOUCH_POINTCOUNT;
201 else if(code == _BLUETOOTH_SUPPORTED)
205 else if(code == _GPS_SUPPORTED)
207 code = _LOCATION_GPS;
209 else if(code == _WPS_SUPPORTED)
211 code = _LOCATION_WPS;
213 else if(code == _WIFI_SUPPORTED)
217 else if(code == _WIFI_DIRECT_SUPPORTED)
221 else if(code == _FM_RADIO_SUPPORTED)
225 else if(code == _TV_OUT_SUPPORTED)
227 code = _SCREEN_OUTPUT_RCA;
229 else if(code == _NFC_SUPPORTED)
237 _SystemInfoImpl::GetSysInfo(const String& key, String& value)
239 result r = E_OBJ_NOT_FOUND;
240 String tizenKey = ConvertToTizen(key);
242 if (key == _NETWORK_TYPE) //Compatibility
244 bool supported = false;
245 GetSysInfo(_TELEPHONY, supported);
246 if(supported == false)
248 value = _NETWORK_EMERGENCY;
251 bool supportedGsm = false;
252 bool supportedGprs = false;
253 bool supportedEdge = false;
254 bool supportedUmts = false;
255 bool supportedHsdpa = false;
256 bool supportedHsupa = false;
257 bool supportedHspa = false;
258 bool supportedLte = false;
259 bool supportedCdma = false;
261 GetSysInfo(_TELEPHONY_SERVICE_GSM, supportedGsm);
262 GetSysInfo(_TELEPHONY_SERVICE_GPRS, supportedGprs);
263 GetSysInfo(_TELEPHONY_SERVICE_EDGE, supportedEdge);
264 GetSysInfo(_TELEPHONY_SERVICE_UMTS, supportedUmts);
265 GetSysInfo(_TELEPHONY_SERVICE_HSDPA, supportedHsdpa);
266 GetSysInfo(_TELEPHONY_SERVICE_HSUPA, supportedHsupa);
267 GetSysInfo(_TELEPHONY_SERVICE_HSPA, supportedHspa);
268 GetSysInfo(_TELEPHONY_SERVICE_LTE, supportedLte);
269 GetSysInfo(_TELEPHONY_SERVICE_CDMA, supportedCdma);
272 if(supportedGsm == false && supportedGprs == false
273 && supportedEdge == false && supportedUmts == false
274 && supportedHsdpa == false && supportedHsupa == false
275 && supportedHspa == false && supportedLte == false
276 && supportedCdma == false)
278 value = _NETWORK_NO_SERVICE;
280 else if(supportedGsm == true)
282 value.Append(L"GSM");
284 else if(supportedGprs == true)
286 if(value.GetLength() > 0)
287 value.Append(L" | ");
289 value.Append(L"GPRS");
291 else if(supportedEdge == true)
293 if(value.GetLength() > 0)
294 value.Append(L" | ");
296 value.Append(L"EDGE");
298 else if(supportedUmts == true)
300 if(value.GetLength() > 0)
301 value.Append(L" | ");
303 value.Append(L"UMTS");
305 else if(supportedHsdpa == true)
307 if(value.GetLength() > 0)
308 value.Append(L" | ");
310 value.Append(L"HSDPA");
312 else if(supportedHsupa == true)
314 if(value.GetLength() > 0)
315 value.Append(L" | ");
317 value.Append(L"HSUPA");
319 else if(supportedHspa == true)
321 if(value.GetLength() > 0)
322 value.Append(L" | ");
324 value.Append(L"HSPA");
326 else if(supportedLte == true)
328 if(value.GetLength() > 0)
329 value.Append(L" | ");
331 value.Append(L"LTE");
333 else if(supportedCdma == true)
335 if(value.GetLength() > 0)
336 value.Append(L" | ");
338 value.Append(L"CDMA");
342 else if (key == _OPENGL_ES_VERSION)
344 bool opengles_11 = false;
345 bool opengles_20 = false;
347 GetSysInfo(_OPENGLES_VERSION_1_1, opengles_11);
348 GetSysInfo(_OPENGLES_VERSION_2_0, opengles_20);
350 if(opengles_11 == true)
352 value.Append(L"1.1");
354 else if(opengles_20 == true)
356 if(value.GetLength() > 0)
357 value.Append(L" | ");
359 value.Append(L"2.0");
362 else if(key == _BLUETOOTH_SUPPORTED)
364 bool supported = false;
365 GetSysInfo(_BLUETOOTH, supported);
366 if(supported == false)
369 value = _UNSUPPORTED;
371 else if (key == _GPS_SUPPORTED)
373 bool supported = false;
374 GetSysInfo(_LOCATION_GPS, supported);
375 if(supported == false)
378 value = _UNSUPPORTED;
380 else if (key == _WIFI_SUPPORTED)
382 bool supported = false;
383 GetSysInfo(_WIFI, supported);
384 if(supported == false)
387 value = _UNSUPPORTED;
389 else if (key == _WAC_VERSION)
394 else if (key == _PLATFORM_NATIVE_API_VERSION || key == _PLATFORM_WEB_API_VERSION || key == _PLATFORM_VERSION)
400 r = GetFromRegistry(tizenKey, value);
401 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
409 _SystemInfoImpl::GetSysInfo(const String& key, int& value)
411 result r = E_SUCCESS;
412 String tizenKey = ConvertToTizen(key);
414 if (key == _CAMERA_COUNT)
416 bool supported = false;
419 GetSysInfo(_CAMERA_FRONT, supported);
420 if(supported == true)
423 GetSysInfo(_CAMERA_BACK, supported);
424 if(supported == true)
431 r = GetFromRegistry(tizenKey, value);
432 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
440 _SystemInfoImpl::GetSysInfo(const String& key, long long& value)
442 return E_OBJ_NOT_FOUND;
447 _SystemInfoImpl::GetSysInfo(const String& key, double& value)
449 return E_OBJ_NOT_FOUND;
454 _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
456 result r = E_SUCCESS;
457 String tizenKey = ConvertToTizen(key);
459 r = GetFromRegistry(tizenKey, value);
460 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
467 _SystemInfoImpl::GetSysInfo(const String& key, UuId& value)
469 return E_OBJ_NOT_FOUND;
474 _SystemInfoImpl::GetSysInfoValuesN(const String& key, SystemInfoValueType type)
476 SetLastResult(E_OBJ_NOT_FOUND);
481 _SystemInfoImpl::GetPlatformVersion(String& platformVersion)
483 result r = E_SUCCESS;
484 String tizenKey(_PLATFORM_VERSION);
486 r = GetFromRegistry(tizenKey, platformVersion);
487 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the key[%ls]", tizenKey.GetPointer());
492 _SystemInfoImpl::GetBuildInfo(String& buildInfo)
494 result r = E_SUCCESS;
495 String tizenKey(_BUID_STRING);
497 r = GetFromRegistry(tizenKey, buildInfo);
498 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the key[%ls]", tizenKey.GetPointer());
503 _SystemInfoImpl::GetNativeApiVersion(String& nativeApiVersion)
505 result r = E_SUCCESS;
506 String tizenKey(_PLATFORM_NATIVE_API_VERSION);
508 r = GetFromRegistry(tizenKey, nativeApiVersion);
509 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the key[%ls]", tizenKey.GetPointer());
514 _SystemInfoImpl::GetWebApiVersion(String& webApiVersion)
516 result r = E_SUCCESS;
517 String tizenKey(_PLATFORM_WEB_API_VERSION);
519 r = GetFromRegistry(tizenKey, webApiVersion);
520 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get the key[%ls]", tizenKey.GetPointer());
525 _SystemInfoImpl::GetImei(String& imei)
527 result r = E_SUCCESS;
529 ArrayList requestMessage;
530 ArrayList responseMessage;
532 unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient());
533 SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
535 r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID);
536 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to create IpcClient. [%s]", GetErrorMessage(r));
538 requestMessage.Construct();
539 responseMessage.Construct();
541 String serviceId(_SYSTEM_SERVICE_ID);
542 String commandId(L"osp.system.command.get.imei.internal");
544 requestMessage.Add(serviceId);
545 requestMessage.Add(commandId);
547 unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
548 SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
550 r = pIpcClient->SendRequest(pMsg.get());
551 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to send ipc message. [%s]", GetErrorMessage(r));
553 unique_ptr<String> pResult((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA));
554 unique_ptr<String> pImei((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA+1));
556 SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "It is failed to receive result on IPC response message.");
557 SysTryReturnResult(NID_SYS, pImei != null, E_SYSTEM, "It is failed to receive IMEI value on IPC response message.");
559 SysTryReturnResult(NID_SYS, *pResult != _SYSTEM_RESULT_PRIVILEGED, E_PRIVILEGE_DENIED, "It is failed to get privilege.");
560 SysTryReturnResult(NID_SYS, *pResult == _SYSTEM_RESULT_OK, E_SYSTEM, "It is failed to get IMEI value.");
567 _SystemInfoImpl::GetFromRegistry(const String& key, String& value)
569 result r = E_SUCCESS;
573 r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
574 SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " RegistryImpl construct It is failed");
576 r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
577 SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " Registry GetValue It is failed");
579 if(valStr == L"true" || valStr == L"false")
581 return E_OBJ_NOT_FOUND;
592 _SystemInfoImpl::GetFromRegistry(const String& key, int& value)
594 result r = E_SUCCESS;
597 r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
598 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct It is failed");
600 r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
601 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue It is failed");
602 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue It is failed");
603 r = Integer::Parse(valStr, value);
604 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, " Integer::Parse() It is failed");
609 _SystemInfoImpl::GetFromRegistry(const String& key, bool& value)
611 result r = E_SUCCESS;
614 r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
615 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct It is failed");
617 r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
618 SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue It is failed");
619 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue It is failed");
620 if(valStr == L"true")
624 else if(valStr == L"false")
630 return E_OBJ_NOT_FOUND;
635 _SystemInfoImpl::GetInstance(SystemInfo& systeminfo)
637 return systeminfo.__pSystemInfoImpl;
639 const _SystemInfoImpl*
640 _SystemInfoImpl::GetInstance(const SystemInfo& systeminfo)
642 return systeminfo.__pSystemInfoImpl;