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