Merge "[2.2.1] Change FBase_String.h to FBaseUtil_AtomicOperations.h" into tizen_2.2
[platform/framework/native/appfw.git] / src / system / FSys_SystemInfoImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FSys_SystemInfoImpl.cpp
19  * @brief               This is the implementation file for _SystemInfoImpl class.
20  */
21 #include <unique_ptr.h>
22 #include <unistd.h>
23
24 #include <system_info.h>
25 #include <ITapiModem.h>
26
27 #include <FBaseBoolean.h>
28 #include <FBaseInteger.h>
29 #include <FBaseColHashMap.h>
30 #include <FBaseUtilStringUtil.h>
31 #include <FIoRegistry.h>
32
33 #include <FBase_NativeError.h>
34 #include <FBase_StringConverter.h>
35 #include <FIo_RegistryImpl.h>
36 #include <FSys_SystemInfoImpl.h>
37 #include <FIo_AppServiceIpcMessages.h>
38 #include <FIo_IpcClient.h>
39
40 #include "FSys_Types.h"
41 #include "FSys_SystemClient.h"
42 #include "FSys_CommunicationDispatcherClient.h"
43
44 using namespace std;
45
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Io;
49 using namespace Tizen::Base::Utility;
50
51 namespace Tizen { namespace System
52 {
53
54 static const wchar_t* _REGISTRY_PATH = L"/opt/usr/etc/system_info_cache.ini";
55 static const wchar_t* _SYSTEM_INFO_SESSION = L"SystemInformation";
56
57 //Bluetooth
58 static const wchar_t* _BLUETOOTH = L"http://tizen.org/feature/network.bluetooth";
59 static const wchar_t* _BLUETOOTH_SUPPORTED = L"BluetoothSupported";
60
61 //Camera
62
63 static const wchar_t* _CAMERA_FRONT = L"http://tizen.org/feature/camera.front";
64
65 static const wchar_t* _CAMERA_BACK = L"http://tizen.org/feature/camera.back";
66
67 static const wchar_t* _CAMERA_COUNT = L"CameraCount";
68
69 //DUID
70 static const wchar_t* _DUID = L"http://tizen.org/system/duid";
71 static const wchar_t* _DEVICE_ID = L"DUID";
72
73 //FM Radio
74 static const wchar_t* _FMRADIO = L"http://tizen.org/feature/fmradio";
75 static const wchar_t* _FM_RADIO_SUPPORTED = L"FmRadioSupported";
76
77 //Keyboard
78 static const wchar_t* _KEYBOARD_TYPE = L"KeyboardType";
79 static const wchar_t* _INPUT_KEYBOARD_LAYOUT = L"http://tizen.org/feature/input.keyboard.layout";
80
81 //Location
82 static const wchar_t* _GPS_SUPPORTED = L"GPSSupported";
83 static const wchar_t* _LOCATION_GPS = L"http://tizen.org/feature/location.gps";
84 static const wchar_t* _WPS_SUPPORTED = L"WPSSupported";
85 static const wchar_t* _LOCATION_WPS = L"http://tizen.org/feature/location.wps";
86
87 //Model name
88 static const wchar_t* _MODELNAME = L"http://tizen.org/system/model_name";
89 static const wchar_t* _MODEL_NAME = L"ModelName";
90
91 //Multi point
92 static const wchar_t* _MULTIPOINTTOUCH_POINTCOUNT = L"http://tizen.org/feature/multi_point_touch.point_count";
93 static const wchar_t* _MULTIPOINT_TOUCH_COUNT = L"MultiPointTouchCount";
94
95 //NFC
96 static const wchar_t* _NETWORK_NFC = L"http://tizen.org/feature/network.nfc";
97 static const wchar_t* _NFC_SUPPORTED = L"NFCSupported";
98
99 //Opengles
100 static const wchar_t* _OPENGLES_VERSION_1_1 = L"http://tizen.org/feature/opengles.version.1_1";
101 static const wchar_t* _OPENGLES_VERSION_2_0 = L"http://tizen.org/feature/opengles.version.2_0";
102 static const wchar_t* _OPENGL_ES_VERSION = L"OpenGLESVersion";
103
104 // Screen
105 static const wchar_t* _SCREEN_BPP = L"http://tizen.org/feature/screen.bpp";
106 static const wchar_t* _SCREEN_BITS_PER_PIXEL = L"ScreenBitsPerPixel";
107 static const wchar_t* _SCREEN_DPI = L"http://tizen.org/feature/screen.dpi";
108 static const wchar_t* _SCREEN_HEIGHT = L"http://tizen.org/feature/screen.height";
109 static const wchar_t* _SCREENHEIGHT = L"ScreenHeight";
110 static const wchar_t* _SCREEN_WIDTH = L"http://tizen.org/feature/screen.width";
111 static const wchar_t* _SCREENWIDTH = L"ScreenWidth";
112 static const wchar_t* _SCREENDPI = L"ScreenDPI";
113
114 //HDMI RCA
115 static const wchar_t* _SCREEN_OUTPUT_RCA = L"http://tizen.org/feature/screen.output.rca";
116 static const wchar_t* _TV_OUT_SUPPORTED = L"TvOutSupported";
117
118 //Sound
119 static const wchar_t* _SOUND_MEDIA_VOLUME_MAX = L"http://tizen.org/system/sound.media.volume.resolution.max";
120 static const wchar_t* _MAX_MEDIA_SOUND_VOLUME = L"MaxMediaSoundVolume";
121 static const wchar_t* _SOUND_NOTIFICATION_VOLUME_MAX = L"http://tizen.org/system/sound.notification.volume.resolution.max";
122 static const wchar_t* _MAX_NOTIFICATION_SOUND_VOLUME = L"MaxNotificationSoundVolume";
123 static const wchar_t* _SOUND_RINGTONE_VOLUME_MAX = L"http://tizen.org/system/sound.ringtone.volume.resolution.max";
124 static const wchar_t* _MAX_RINGTONE_SOUND_VOLUME = L"MaxRingtoneSoundVolume";
125 static const wchar_t* _SOUND_SYSTEM_VOLUME_MAX = L"http://tizen.org/system/sound.system.volume.resolution.max";
126 static const wchar_t* _MAX_SYSTEM_SOUND_VOLUME = L"MaxSystemSoundVolume";
127
128 //Telephony
129 static const wchar_t* _TELEPHONY = L"http://tizen.org/feature/network.telephony";
130 static const wchar_t* _TELEPHONY_SERVICE_GSM = L"http://tizen.org/feature/network.telephony.service.gsm";
131 static const wchar_t* _TELEPHONY_SERVICE_GPRS = L"http://tizen.org/feature/network.telephony.service.gprs";
132 static const wchar_t* _TELEPHONY_SERVICE_EDGE = L"http://tizen.org/feature/network.telephony.service.edge";
133 static const wchar_t* _TELEPHONY_SERVICE_UMTS = L"http://tizen.org/feature/network.telephony.service.umts";
134 static const wchar_t* _TELEPHONY_SERVICE_HSDPA = L"http://tizen.org/feature/network.telephony.service.hsdpa";
135 static const wchar_t* _TELEPHONY_SERVICE_HSUPA = L"http://tizen.org/feature/network.telephony.service.hsupa";
136 static const wchar_t* _TELEPHONY_SERVICE_HSPA = L"http://tizen.org/feature/network.telephony.service.hspa";
137 static const wchar_t* _TELEPHONY_SERVICE_LTE = L"http://tizen.org/feature/network.telephony.service.lte";
138 static const wchar_t* _TELEPHONY_SERVICE_CDMA = L"http://tizen.org/feature/network.telephony.service.cdma";
139 static const wchar_t* _NETWORK_TYPE = L"NetworkType";
140 static const wchar_t* _NETWORK_EMERGENCY = L"Emergency";
141 static const wchar_t* _NETWORK_NO_SERVICE = L"NoService";
142
143 //WIFI
144 static const wchar_t* _WIFI = L"http://tizen.org/feature/network.wifi";
145 static const wchar_t* _WIFI_SUPPORTED = L"WiFiSupported";
146 static const wchar_t* _WIFI_DIRECT = L"http://tizen.org/feature/network.wifi.direct";
147 static const wchar_t* _WIFI_DIRECT_SUPPORTED = L"WiFiDirectSupported";
148
149 //Version
150 static const wchar_t* _PLATFORM_VERSION = L"http://tizen.org/feature/platform.version";
151 static const wchar_t* _PLATFORM_NATIVE_API_VERSION = L"http://tizen.org/feature/platform.native.api.version";
152 static const wchar_t* _PLATFORM_WEB_API_VERSION = L"http://tizen.org/feature/platform.web.api.version";
153 static const wchar_t* _BUILD_STRING = L"http://tizen.org/system/build.string";
154
155 static const wchar_t* _WAC_VERSION = L"WACVersion";
156 static const wchar_t* _SUPPORTED = L"Supported";
157 static const wchar_t* _UNSUPPORTED = L"Unsupported";
158
159 static bool firstRequest = false;
160 static HashMap integerList(SingleObjectDeleter);
161 static HashMap boolList(SingleObjectDeleter);
162 static HashMap stringList(SingleObjectDeleter);
163
164 void
165 PrepareCache(void)
166 {
167         if(firstRequest == false)
168         {
169                 integerList.Construct();
170                 boolList.Construct();
171                 stringList.Construct();
172                 firstRequest = true;
173         }
174 }
175
176 String
177 _SystemInfoImpl::ConvertToTizen(const String& key)
178 {
179         String code(key);
180
181         if(code == _DEVICE_ID)
182         {
183                 code = _DUID;
184         }
185         else if(code == _MODEL_NAME)
186         {
187                 code = _MODELNAME;
188         }
189         else if(code == _KEYBOARD_TYPE)
190         {
191                 code = _INPUT_KEYBOARD_LAYOUT;
192         }
193         else if(code == _SCREEN_BITS_PER_PIXEL)
194         {
195                 code = _SCREEN_BPP;
196         }
197         else if(code == _SCREENHEIGHT)
198         {
199                 code = _SCREEN_HEIGHT;
200         }
201         else if(code == _SCREENWIDTH)
202         {
203                 code = _SCREEN_WIDTH;
204         }
205         else if(code == _SCREENDPI)
206         {
207                 code = _SCREEN_DPI;
208         }
209         else if(code == _MAX_SYSTEM_SOUND_VOLUME)
210         {
211                 code = _SOUND_SYSTEM_VOLUME_MAX;
212         }
213         else if(code == _MAX_MEDIA_SOUND_VOLUME)
214         {
215                 code = _SOUND_MEDIA_VOLUME_MAX;
216         }
217         else if(code == _MAX_RINGTONE_SOUND_VOLUME)
218         {
219                 code = _SOUND_RINGTONE_VOLUME_MAX;
220         }
221         else if(code == _MAX_NOTIFICATION_SOUND_VOLUME)
222         {
223                 code = _SOUND_NOTIFICATION_VOLUME_MAX;
224         }
225         else if(code == _MULTIPOINT_TOUCH_COUNT)
226         {
227                 code = _MULTIPOINTTOUCH_POINTCOUNT;
228         }
229         else if(code == _BLUETOOTH_SUPPORTED)
230         {
231                 code = _BLUETOOTH;
232         }
233         else if(code == _GPS_SUPPORTED)
234         {
235                 code = _LOCATION_GPS;
236         }
237         else if(code == _WPS_SUPPORTED)
238         {
239                 code = _LOCATION_WPS;
240         }
241         else if(code == _WIFI_SUPPORTED)
242         {
243                 code = _WIFI;
244         }
245         else if(code == _WIFI_DIRECT_SUPPORTED)
246         {
247                 code = _WIFI_DIRECT;
248         }
249         else if(code == _FM_RADIO_SUPPORTED)
250         {
251                 code = _FMRADIO;
252         }
253         else if(code == _TV_OUT_SUPPORTED)
254         {
255                 code = _SCREEN_OUTPUT_RCA;
256         }
257         else if(code == _NFC_SUPPORTED)
258         {
259                 code = _NETWORK_NFC;
260         }
261         return code;
262 }
263
264 result
265 _SystemInfoImpl::GetSysInfo(const String& key, String& value)
266 {
267         result r = E_OBJ_NOT_FOUND;
268         String tizenKey = ConvertToTizen(key);
269
270         SysLog(NID_SYS, "Request Key is %ls.", key.GetPointer());
271
272         if (firstRequest == false)
273         {
274                 PrepareCache();
275         }
276
277         String* pValue = (String*)stringList.GetValue(tizenKey);
278
279         if(pValue != null)
280         {
281                 value = *pValue;
282                 return E_SUCCESS;
283         }
284
285         if (key == _NETWORK_TYPE) //Compatibility
286         {
287                 bool supported = false;
288                 GetSysInfo(_TELEPHONY, supported);
289                 if(supported == false)
290                 {
291                         value = _NETWORK_EMERGENCY;
292                 }
293
294                 bool supportedGsm = false;
295                 bool supportedGprs = false;
296                 bool supportedEdge = false;
297                 bool supportedUmts = false;
298                 bool supportedHsdpa = false;
299                 bool supportedHsupa = false;
300                 bool supportedHspa = false;
301                 bool supportedLte = false;
302                 bool supportedCdma = false;
303
304                 GetSysInfo(_TELEPHONY_SERVICE_GSM, supportedGsm);
305                 GetSysInfo(_TELEPHONY_SERVICE_GPRS, supportedGprs);
306                 GetSysInfo(_TELEPHONY_SERVICE_EDGE, supportedEdge);
307                 GetSysInfo(_TELEPHONY_SERVICE_UMTS, supportedUmts);
308                 GetSysInfo(_TELEPHONY_SERVICE_HSDPA, supportedHsdpa);
309                 GetSysInfo(_TELEPHONY_SERVICE_HSUPA, supportedHsupa);
310                 GetSysInfo(_TELEPHONY_SERVICE_HSPA, supportedHspa);
311                 GetSysInfo(_TELEPHONY_SERVICE_LTE, supportedLte);
312                 GetSysInfo(_TELEPHONY_SERVICE_CDMA, supportedCdma);
313
314                 value.Clear();
315                 if(supportedGsm == false && supportedGprs == false
316                         && supportedEdge == false && supportedUmts == false
317                         && supportedHsdpa == false && supportedHsupa == false
318                         && supportedHspa == false && supportedLte == false
319                         && supportedCdma == false)
320                 {
321                         value = _NETWORK_NO_SERVICE;
322                 }
323                 else if(supportedGsm == true)
324                 {
325                         value.Append(L"GSM");
326                 }
327                 else if(supportedGprs == true)
328                 {
329                         if(value.GetLength() > 0)
330                                 value.Append(L" | ");
331
332                         value.Append(L"GPRS");
333                 }
334                 else if(supportedEdge == true)
335                 {
336                         if(value.GetLength() > 0)
337                                 value.Append(L" | ");
338
339                         value.Append(L"EDGE");
340                 }
341                 else if(supportedUmts == true)
342                 {
343                         if(value.GetLength() > 0)
344                                 value.Append(L" | ");
345
346                         value.Append(L"UMTS");
347                 }
348                 else if(supportedHsdpa == true)
349                 {
350                         if(value.GetLength() > 0)
351                                 value.Append(L" | ");
352
353                         value.Append(L"HSDPA");
354                 }
355                 else if(supportedHsupa == true)
356                 {
357                         if(value.GetLength() > 0)
358                                 value.Append(L" | ");
359
360                         value.Append(L"HSUPA");
361                 }
362                 else if(supportedHspa == true)
363                 {
364                         if(value.GetLength() > 0)
365                                 value.Append(L" | ");
366
367                         value.Append(L"HSPA");
368                 }
369                 else if(supportedLte == true)
370                 {
371                         if(value.GetLength() > 0)
372                                 value.Append(L" | ");
373
374                         value.Append(L"LTE");
375                 }
376                 else if(supportedCdma == true)
377                 {
378                         if(value.GetLength() > 0)
379                                 value.Append(L" | ");
380
381                         value.Append(L"CDMA");
382                 }
383                 r = E_SUCCESS;
384         }
385         else if (key == _OPENGL_ES_VERSION)
386         {
387                 bool opengles_11 = false;
388                 bool opengles_20 = false;
389
390                 GetSysInfo(_OPENGLES_VERSION_1_1, opengles_11);
391                 GetSysInfo(_OPENGLES_VERSION_2_0, opengles_20);
392
393                 if(opengles_11 == true)
394                 {
395                         value.Append(L"1.1");
396                 }
397                 else if(opengles_20 == true)
398                 {
399                         if(value.GetLength() > 0)
400                                 value.Append(L" | ");
401
402                         value.Append(L"2.0");
403                 }
404                 r = E_SUCCESS;
405         }
406         else if(key == _BLUETOOTH_SUPPORTED)
407         {
408                 bool supported = false;
409                 GetSysInfo(_BLUETOOTH, supported);
410                 if(supported == false)
411                         value = _SUPPORTED;
412                 else
413                         value = _UNSUPPORTED;
414                 r = E_SUCCESS;
415         }
416         else if (key == _GPS_SUPPORTED)
417         {
418                 bool supported = false;
419                 GetSysInfo(_LOCATION_GPS, supported);
420                 if(supported == false)
421                         value = _SUPPORTED;
422                 else
423                         value = _UNSUPPORTED;
424                 r = E_SUCCESS;
425         }
426         else if (key == _WIFI_SUPPORTED)
427         {
428                 bool supported = false;
429                 GetSysInfo(_WIFI, supported);
430                 if(supported == false)
431                         value = _SUPPORTED;
432                 else
433                         value = _UNSUPPORTED;
434                 r = E_SUCCESS;
435         }
436         else if (key == _WAC_VERSION)
437         {
438                 value.Clear();
439                 r = E_SUCCESS;
440         }
441         else if (key == _PLATFORM_NATIVE_API_VERSION || key == _PLATFORM_WEB_API_VERSION || key == _PLATFORM_VERSION || key == _BUILD_STRING)
442         {
443                 r = E_OBJ_NOT_FOUND;
444         }
445         else if (tizenKey == _DUID)
446         {
447                 r = GetFromRegistry(tizenKey, value);
448
449                 if(r != E_SUCCESS)
450                 {
451                         int ret = 0;
452                         TapiHandle* handle = null;
453                         int time_count = 0;
454                         int status = 0;
455
456                         handle = tel_init(null);
457                         if(handle != null)
458                         {
459                                 while(time_count < 30) //Wait 30 second.
460                                 {
461                                         ret = tel_check_modem_power_status(handle, &status);
462                                         SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
463                                         if(ret != TAPI_API_SUCCESS)
464                                         {
465                                                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
466                                                 tel_deinit(handle);
467                                                 return E_SYSTEM;
468                                         }
469
470                                         if(status == 0)
471                                         {
472                                                 break;
473                                         }
474
475                                         usleep(1000000);
476                                         time_count++;
477                                 }
478                                 tel_deinit(handle);
479                         }
480                         _SystemClient* pSystemClient = _SystemClient::GetInstance();
481                         r = pSystemClient->GetValue(tizenKey, value);
482                 }
483         }
484         else
485         {
486                 r = GetFromRegistry(tizenKey, value);
487
488                 if(r != E_SUCCESS)
489                 {
490                         char* pStringValue = null;
491                         String tKey;
492                         tizenKey.SubString(7, tKey);
493                         SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_OBJ_NOT_FOUND, "Required key should be longer than 0.");
494
495                         ClearLastResult();
496                         unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
497                         r = GetLastResult();
498                         SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
499                         int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
500
501                         SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
502
503                         r = StringUtil::Utf8ToString(pStringValue, value);
504                         free(pStringValue);
505                         r = E_SUCCESS;
506                 }
507         }
508         if( r == E_SUCCESS)
509         {
510                 stringList.Add(new String(tizenKey), new String(value));
511         }
512         return r;
513 }
514
515 result
516 _SystemInfoImpl::GetSysInfo(const String& key, int& value)
517 {
518         result r = E_SUCCESS;
519         String tizenKey = ConvertToTizen(key);
520
521         SysLog(NID_SYS, "Request Key is %ls.", key.GetPointer());
522
523         if (firstRequest == false)
524         {
525                 PrepareCache();
526         }
527
528         Integer* pValue = (Integer*)integerList.GetValue(tizenKey);
529
530         if(pValue != null)
531         {
532                 value = pValue->value;
533                 return E_SUCCESS;
534         }
535
536         if (key == _CAMERA_COUNT)
537         {
538                 bool supported = false;
539                 int cameraCount = 0;
540
541                 GetSysInfo(_CAMERA_FRONT, supported);
542                 if(supported == true)
543                         cameraCount++;
544
545                 GetSysInfo(_CAMERA_BACK, supported);
546                 if(supported == true)
547                         cameraCount++;
548
549                 value = cameraCount;
550         }
551         else
552         {
553                 r = GetFromRegistry(tizenKey, value);
554                 if(r != E_SUCCESS)
555                 {
556                         int ret = 0;
557                         String tKey;
558
559                         tizenKey.SubString(7, tKey);
560                         SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_OBJ_NOT_FOUND, "Required key should be longer than 0.");
561
562                         ClearLastResult();
563                         unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
564                         r = GetLastResult(); 
565                         SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
566                         ret = system_info_get_platform_int(systemKey.get(), &value);
567
568                         SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
569                         r = E_SUCCESS;
570                 }
571         }
572
573         if(r == E_SUCCESS)
574         {
575                 integerList.Add(new String(tizenKey), new Integer(value));
576         }
577
578         return r;
579 }
580
581 result
582 _SystemInfoImpl::GetSysInfo(const String& key, long long& value)
583 {
584         return E_OBJ_NOT_FOUND;
585 }
586
587 result
588 _SystemInfoImpl::GetSysInfo(const String& key, double& value)
589 {
590         return E_OBJ_NOT_FOUND;
591 }
592
593 result
594 _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
595 {
596         result r = E_SUCCESS;
597         String tizenKey = ConvertToTizen(key);
598
599         SysLog(NID_SYS, "Request Key is %ls.", key.GetPointer());
600
601         if (firstRequest == false)
602         {
603                 PrepareCache();
604         }
605
606         Boolean* pValue = (Boolean*)boolList.GetValue(tizenKey);
607
608         if(pValue != null)
609         {
610                 value = pValue->value;
611                 return E_SUCCESS;
612         }
613
614         r = GetFromRegistry(tizenKey, value);
615         if(r != E_SUCCESS)
616         {
617                 String tKey;
618                 tizenKey.SubString(7, tKey);
619                 SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_OBJ_NOT_FOUND, "Required key should be longer than 0.");
620
621                 ClearLastResult();
622                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
623                 r = GetLastResult();
624                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
625
626                 bool supported = false;
627                 int ret = system_info_get_platform_bool(systemKey.get(), &supported);
628                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
629                 value = supported;
630                 r = E_SUCCESS;
631         }
632
633         if(r == E_SUCCESS)
634         {
635                 boolList.Add(new String(tizenKey), new Boolean(value));
636         }
637
638         return r;
639 }
640
641 result
642 _SystemInfoImpl::GetSysInfo(const String& key, UuId& value)
643 {
644         return E_OBJ_NOT_FOUND;
645 }
646
647 Collection::IList*
648 _SystemInfoImpl::GetSysInfoValuesN(const String& key, SystemInfoValueType type)
649 {
650         SetLastResult(E_OBJ_NOT_FOUND);
651         return null;
652 }
653
654 result
655 _SystemInfoImpl::GetPlatformVersion(String& platformVersion)
656 {
657         result r = E_SUCCESS;
658         String tizenKey(_PLATFORM_VERSION);
659
660         r = GetFromRegistry(tizenKey, platformVersion);
661
662         if(r != E_SUCCESS)
663         {
664                 char* pStringValue = null;
665                 String tKey;
666                 tizenKey.SubString(7, tKey);
667                 SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_SYSTEM, "Required key should be longer than 0.");
668
669                 ClearLastResult();
670                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
671                 r = GetLastResult();
672                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
673                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
674
675                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
676
677                 r = StringUtil::Utf8ToString(pStringValue, platformVersion);
678                 free(pStringValue);
679                 r = E_SUCCESS;
680         }
681         return r;
682 }
683
684 result
685 _SystemInfoImpl::GetBuildInfo(String& buildInfo)
686 {
687         result r = E_SUCCESS;
688         String tizenKey(_BUILD_STRING);
689
690         r = GetFromRegistry(tizenKey, buildInfo);
691
692         if(r != E_SUCCESS)
693         {
694                 char* pStringValue = null;
695                 String tKey;
696                 tizenKey.SubString(7, tKey);
697                 SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_SYSTEM, "Required key should be longer than 0.");
698
699                 ClearLastResult();
700                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
701                 r = GetLastResult();
702                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
703                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
704
705                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
706
707                 r = StringUtil::Utf8ToString(pStringValue, buildInfo);
708                 free(pStringValue);
709                 r = E_SUCCESS;
710         }
711         return r;
712 }
713
714 result
715 _SystemInfoImpl::GetNativeApiVersion(String& nativeApiVersion)
716 {
717         result r = E_SUCCESS;
718         String tizenKey(_PLATFORM_NATIVE_API_VERSION);
719
720         r = GetFromRegistry(tizenKey, nativeApiVersion);
721
722         if(r != E_SUCCESS)
723         {
724                 char* pStringValue = null;
725                 String tKey;
726                 tizenKey.SubString(7, tKey);
727                 SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_SYSTEM, "Required key should be longer than 0.");
728
729                 ClearLastResult();
730                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
731                 r = GetLastResult();
732                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
733                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
734
735                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
736
737                 r = StringUtil::Utf8ToString(pStringValue, nativeApiVersion);
738                 free(pStringValue);
739                 r = E_SUCCESS;
740         }
741         return r;
742 }
743
744 result
745 _SystemInfoImpl::GetWebApiVersion(String& webApiVersion)
746 {
747         result r = E_SUCCESS;
748         String tizenKey(_PLATFORM_WEB_API_VERSION);
749
750         r = GetFromRegistry(tizenKey, webApiVersion);
751
752         if(r != E_SUCCESS)
753         {
754                 char* pStringValue = null;
755                 String tKey;
756                 tizenKey.SubString(7, tKey);
757                 SysTryReturnResult(NID_SYS, tKey.GetLength() > 0, E_SYSTEM, "Required key should be longer than 0.");
758
759                 ClearLastResult();
760                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
761                 r = GetLastResult();
762                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
763                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
764
765                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
766
767                 r = StringUtil::Utf8ToString(pStringValue, webApiVersion);
768                 free(pStringValue);
769                 r = E_SUCCESS;
770         }
771         return r;
772 }
773
774 result
775 _SystemInfoImpl::GetImei(String& imei)
776 {
777         result r = E_SUCCESS;
778
779         int ret = 0;
780         TapiHandle* handle = null;
781         int time_count = 0;
782         int status = 0;
783
784         handle = tel_init(null);
785         SysTryReturnResult(NID_SYS, handle != null, E_SYSTEM, "It is failed to get handle of telephony.");
786         while(time_count < 30) //Wait 30 second.
787         {
788                 ret = tel_check_modem_power_status(handle, &status);
789                 SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
790                 if(ret != TAPI_API_SUCCESS)
791                 {
792                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
793                         tel_deinit(handle);
794                         return E_SYSTEM;
795                 }
796
797                 if(status == 0)
798                 {
799                         break;
800                 }
801
802                 usleep(1000000);
803                 time_count++;
804         }
805         tel_deinit(handle);
806
807         ArrayList requestMessage;
808         ArrayList responseMessage;
809
810         _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
811
812         _IpcClient* pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
813         SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
814
815         requestMessage.Construct();
816         responseMessage.Construct();
817
818         String serviceId(_SYSTEM_SERVICE_ID);
819         String commandId(L"osp.system.command.get.imei.internal");
820
821         requestMessage.Add(serviceId);
822         requestMessage.Add(commandId);
823
824         unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
825         SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
826
827         r = pIpcClient->SendRequest(pMsg.get());
828         SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to send ipc message. [%s]", GetErrorMessage(r));
829
830         String* pResult = (String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA);
831         String* pImei = (String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA+1);
832
833         SysTryReturn(NID_SYS, pResult != null, r = E_SYSTEM, r, "It is failed to receive result on IPC response message.");
834         SysTryReturn(NID_SYS, pImei != null, r = E_SYSTEM, r, "It is failed to receive IMEI value on IPC response message.");
835
836         SysTryReturn(NID_SYS, *pResult != _SYSTEM_RESULT_PRIVILEGED, r = E_PRIVILEGE_DENIED, r, "It is failed to get privilege.");
837         SysTryReturn(NID_SYS, *pResult == _SYSTEM_RESULT_OK, r = E_SYSTEM, r, "It is failed to get IMEI value.");
838
839         imei = *pImei;
840
841 CATCH:
842         responseMessage.RemoveAll(true);
843
844         return r;
845 }
846
847 result
848 _SystemInfoImpl::GetFromRegistry(const String& key, String& value)
849 {
850         result r = E_SUCCESS;
851         _RegistryImpl _reg;
852         String valStr;
853
854         r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
855         SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " RegistryImpl construct is failed");
856
857         r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
858         SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " Registry GetValue is failed");
859
860         if(valStr == L"true" || valStr == L"false")
861         {
862                 return E_OBJ_NOT_FOUND;
863         }
864         else
865         {
866                 value = valStr;
867         }
868
869         return E_SUCCESS;
870 }
871
872 result
873 _SystemInfoImpl::GetFromRegistry(const String& key, int& value)
874 {
875         result r = E_SUCCESS;
876         _RegistryImpl _reg;
877         String valStr;
878
879         r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
880         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct is failed");
881
882         r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
883         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue is failed");
884         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue is failed");
885         r = Integer::Parse(valStr, value);
886         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, " Integer::Parse() is failed");
887         return E_SUCCESS;
888 }
889
890 result
891 _SystemInfoImpl::GetFromRegistry(const String& key, bool& value)
892 {
893         result r = E_SUCCESS;
894         _RegistryImpl _reg;
895         String valStr;
896
897         r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
898         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct is failed");
899
900         r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
901         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue is failed");
902         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue is failed");
903         if(valStr == L"true")
904         {
905                 value = true;
906         }
907         else if(valStr == L"false")
908         {
909                 value = false;
910         }
911         else
912         {
913                 return E_OBJ_NOT_FOUND;
914         }
915         return E_SUCCESS;
916 }
917
918 _SystemInfoImpl*
919 _SystemInfoImpl::GetInstance(SystemInfo& systeminfo)
920 {
921         return systeminfo.__pSystemInfoImpl;
922 }
923 const _SystemInfoImpl*
924 _SystemInfoImpl::GetInstance(const SystemInfo& systeminfo)
925 {
926         return systeminfo.__pSystemInfoImpl;
927 }
928 } } // Tizen::System