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