Merge "Apply model-config.xml" into tizen_2.2
[platform/framework/native/appfw.git] / src / system / FSys_SystemInfoImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file                FSys_SystemInfoImpl.cpp
19  * @brief               This is the implementation file for _SystemInfoImpl class.
20  */
21 #include <unique_ptr.h>
22 #include <unistd.h>
23
24 #include <system_info.h>
25 #include <ITapiModem.h>
26
27 #include <FBaseBoolean.h>
28 #include <FBaseInteger.h>
29 #include <FBaseColHashMap.h>
30 #include <FBaseUtilStringUtil.h>
31
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
493                         ClearLastResult();
494                         unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
495                         r = GetLastResult();
496                         SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
497                         int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
498
499                         SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
500
501                         r = StringUtil::Utf8ToString(pStringValue, value);
502                         free(pStringValue);
503                         r = E_SUCCESS;
504                 }
505         }
506         if( r == E_SUCCESS)
507         {
508                 stringList.Add(new String(tizenKey), new String(value));
509         }
510         return r;
511 }
512
513 result
514 _SystemInfoImpl::GetSysInfo(const String& key, int& value)
515 {
516         result r = E_SUCCESS;
517         String tizenKey = ConvertToTizen(key);
518
519         SysLog(NID_SYS, "Request Key is %ls.", key.GetPointer());
520
521         if (firstRequest == false)
522         {
523                 PrepareCache();
524         }
525
526         Integer* pValue = (Integer*)integerList.GetValue(tizenKey);
527
528         if(pValue != null)
529         {
530                 value = pValue->value;
531                 return E_SUCCESS;
532         }
533
534         if (key == _CAMERA_COUNT)
535         {
536                 bool supported = false;
537                 int cameraCount = 0;
538
539                 GetSysInfo(_CAMERA_FRONT, supported);
540                 if(supported == true)
541                         cameraCount++;
542
543                 GetSysInfo(_CAMERA_BACK, supported);
544                 if(supported == true)
545                         cameraCount++;
546
547                 value = cameraCount;
548         }
549         else
550         {
551                 r = GetFromRegistry(tizenKey, value);
552                 if(r != E_SUCCESS)
553                 {
554                         int ret = 0;
555                         String tKey;
556
557                         tizenKey.SubString(7, tKey);
558
559                         ClearLastResult();
560                         unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
561                         r = GetLastResult(); 
562                         SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
563                         ret = system_info_get_platform_int(systemKey.get(), &value);
564
565                         SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
566                         r = E_SUCCESS;
567                 }
568         }
569
570         if(r == E_SUCCESS)
571         {
572                 integerList.Add(new String(tizenKey), new Integer(value));
573         }
574
575         return r;
576 }
577
578 result
579 _SystemInfoImpl::GetSysInfo(const String& key, long long& value)
580 {
581         return E_OBJ_NOT_FOUND;
582 }
583
584 result
585 _SystemInfoImpl::GetSysInfo(const String& key, double& value)
586 {
587         return E_OBJ_NOT_FOUND;
588 }
589
590 result
591 _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
592 {
593         result r = E_SUCCESS;
594         String tizenKey = ConvertToTizen(key);
595
596         SysLog(NID_SYS, "Request Key is %ls.", key.GetPointer());
597
598         if (firstRequest == false)
599         {
600                 PrepareCache();
601         }
602
603         Boolean* pValue = (Boolean*)boolList.GetValue(tizenKey);
604
605         if(pValue != null)
606         {
607                 value = pValue->value;
608                 return E_SUCCESS;
609         }
610
611         r = GetFromRegistry(tizenKey, value);
612         if(r != E_SUCCESS)
613         {
614                 String tKey;
615                 tizenKey.SubString(7, tKey);
616
617                 ClearLastResult();
618                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
619                 r = GetLastResult();
620                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
621
622                 bool supported = false;
623                 int ret = system_info_get_platform_bool(systemKey.get(), &supported);
624                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
625                 value = supported;
626                 r = E_SUCCESS;
627         }
628
629         if(r == E_SUCCESS)
630         {
631                 boolList.Add(new String(tizenKey), new Boolean(value));
632         }
633
634         return r;
635 }
636
637 result
638 _SystemInfoImpl::GetSysInfo(const String& key, UuId& value)
639 {
640         return E_OBJ_NOT_FOUND;
641 }
642
643 Collection::IList*
644 _SystemInfoImpl::GetSysInfoValuesN(const String& key, SystemInfoValueType type)
645 {
646         SetLastResult(E_OBJ_NOT_FOUND);
647         return null;
648 }
649
650 result
651 _SystemInfoImpl::GetPlatformVersion(String& platformVersion)
652 {
653         result r = E_SUCCESS;
654         String tizenKey(_PLATFORM_VERSION);
655
656         r = GetFromRegistry(tizenKey, platformVersion);
657
658         if(r != E_SUCCESS)
659         {
660                 char* pStringValue = null;
661                 String tKey;
662                 tizenKey.SubString(7, tKey);
663
664                 ClearLastResult();
665                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
666                 r = GetLastResult();
667                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
668                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
669
670                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
671
672                 r = StringUtil::Utf8ToString(pStringValue, platformVersion);
673                 free(pStringValue);
674                 r = E_SUCCESS;
675         }
676 }
677
678 result
679 _SystemInfoImpl::GetBuildInfo(String& buildInfo)
680 {
681         result r = E_SUCCESS;
682         String tizenKey(_BUILD_STRING);
683
684         r = GetFromRegistry(tizenKey, buildInfo);
685
686         if(r != E_SUCCESS)
687         {
688                 char* pStringValue = null;
689                 String tKey;
690                 tizenKey.SubString(7, tKey);
691
692                 ClearLastResult();
693                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
694                 r = GetLastResult();
695                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
696                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
697
698                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
699
700                 r = StringUtil::Utf8ToString(pStringValue, buildInfo);
701                 free(pStringValue);
702                 r = E_SUCCESS;
703         }
704 }
705
706 result
707 _SystemInfoImpl::GetNativeApiVersion(String& nativeApiVersion)
708 {
709         result r = E_SUCCESS;
710         String tizenKey(_PLATFORM_NATIVE_API_VERSION);
711
712         r = GetFromRegistry(tizenKey, nativeApiVersion);
713
714         if(r != E_SUCCESS)
715         {
716                 char* pStringValue = null;
717                 String tKey;
718                 tizenKey.SubString(7, tKey);
719
720                 ClearLastResult();
721                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
722                 r = GetLastResult();
723                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
724                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
725
726                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
727
728                 r = StringUtil::Utf8ToString(pStringValue, nativeApiVersion);
729                 free(pStringValue);
730                 r = E_SUCCESS;
731         }
732 }
733
734 result
735 _SystemInfoImpl::GetWebApiVersion(String& webApiVersion)
736 {
737         result r = E_SUCCESS;
738         String tizenKey(_PLATFORM_WEB_API_VERSION);
739
740         r = GetFromRegistry(tizenKey, webApiVersion);
741
742         if(r != E_SUCCESS)
743         {
744                 char* pStringValue = null;
745                 String tKey;
746                 tizenKey.SubString(7, tKey);
747
748                 ClearLastResult();
749                 unique_ptr< char[] > systemKey(_StringConverter::CopyToCharArrayN(tKey));
750                 r = GetLastResult();
751                 SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "[%s] StringUtil::StringToUtf8N It is failed", GetErrorMessage(r));
752                 int ret = system_info_get_platform_string(systemKey.get(), &pStringValue);
753
754                 SysTryReturnResult(NID_SYS, ret == 0, E_OBJ_NOT_FOUND, "It is failed to get system information %ls from configration file.", tizenKey.GetPointer());
755
756                 r = StringUtil::Utf8ToString(pStringValue, webApiVersion);
757                 free(pStringValue);
758                 r = E_SUCCESS;
759         }
760 }
761
762 result
763 _SystemInfoImpl::GetImei(String& imei)
764 {
765         result r = E_SUCCESS;
766
767         int ret = 0;
768         TapiHandle* handle = null;
769         int time_count = 0;
770         int status = 0;
771
772         handle = tel_init(null);
773         SysTryReturnResult(NID_SYS, handle != null, E_SYSTEM, "It is failed to get handle of telephony.");
774         while(time_count < 30) //Wait 30 second.
775         {
776                 ret = tel_check_modem_power_status(handle, &status);
777                 SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
778                 if(ret != TAPI_API_SUCCESS)
779                 {
780                         SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
781                         tel_deinit(handle);
782                         return E_SYSTEM;
783                 }
784
785                 if(status == 0)
786                 {
787                         break;
788                 }
789
790                 usleep(1000000);
791                 time_count++;
792         }
793         tel_deinit(handle);
794
795         ArrayList requestMessage;
796         ArrayList responseMessage;
797
798         _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
799
800         _IpcClient* pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
801         SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
802
803         requestMessage.Construct();
804         responseMessage.Construct();
805
806         String serviceId(_SYSTEM_SERVICE_ID);
807         String commandId(L"osp.system.command.get.imei.internal");
808
809         requestMessage.Add(serviceId);
810         requestMessage.Add(commandId);
811
812         unique_ptr<IoService_Request> pMsg(new (std::nothrow) IoService_Request(requestMessage, &responseMessage));
813         SysTryReturnResult(NID_SYS, pMsg != null, E_OUT_OF_MEMORY, "It is failed to create Ipc message");
814
815         r = pIpcClient->SendRequest(pMsg.get());
816         SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to send ipc message. [%s]", GetErrorMessage(r));
817
818         unique_ptr<String> pResult((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA));
819         unique_ptr<String> pImei((String*)responseMessage.GetAt(_SYSTEM_RESPONSE_DATA+1));
820
821         SysTryReturnResult(NID_SYS, pResult != null, E_SYSTEM, "It is failed to receive result on IPC response message.");
822         SysTryReturnResult(NID_SYS, pImei != null, E_SYSTEM, "It is failed to receive IMEI value on IPC response message.");
823
824         SysTryReturnResult(NID_SYS, *pResult != _SYSTEM_RESULT_PRIVILEGED, E_PRIVILEGE_DENIED, "It is failed to get privilege.");
825         SysTryReturnResult(NID_SYS, *pResult == _SYSTEM_RESULT_OK, E_SYSTEM, "It is failed to get IMEI value.");
826
827         imei = *pImei;
828         return r;
829 }
830
831 result
832 _SystemInfoImpl::GetFromRegistry(const String& key, String& value)
833 {
834         result r = E_SUCCESS;
835         _RegistryImpl _reg;
836         String valStr;
837
838         r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
839         SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " RegistryImpl construct is failed");
840
841         r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
842         SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " Registry GetValue is failed");
843
844         if(valStr == L"true" || valStr == L"false")
845         {
846                 return E_OBJ_NOT_FOUND;
847         }
848         else
849         {
850                 value = valStr;
851         }
852
853         return E_SUCCESS;
854 }
855
856 result
857 _SystemInfoImpl::GetFromRegistry(const String& key, int& value)
858 {
859         result r = E_SUCCESS;
860         _RegistryImpl _reg;
861         String valStr;
862
863         r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
864         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct is failed");
865
866         r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
867         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue is failed");
868         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue is failed");
869         r = Integer::Parse(valStr, value);
870         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, " Integer::Parse() is failed");
871         return E_SUCCESS;
872 }
873
874 result
875 _SystemInfoImpl::GetFromRegistry(const String& key, bool& value)
876 {
877         result r = E_SUCCESS;
878         _RegistryImpl _reg;
879         String valStr;
880
881         r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
882         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct is failed");
883
884         r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
885         SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue is failed");
886         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue is failed");
887         if(valStr == L"true")
888         {
889                 value = true;
890         }
891         else if(valStr == L"false")
892         {
893                 value = false;
894         }
895         else
896         {
897                 return E_OBJ_NOT_FOUND;
898         }
899         return E_SUCCESS;
900 }
901
902 _SystemInfoImpl*
903 _SystemInfoImpl::GetInstance(SystemInfo& systeminfo)
904 {
905         return systeminfo.__pSystemInfoImpl;
906 }
907 const _SystemInfoImpl*
908 _SystemInfoImpl::GetInstance(const SystemInfo& systeminfo)
909 {
910         return systeminfo.__pSystemInfoImpl;
911 }
912 } } // Tizen::System