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