Merge "Add a _LocalizedNumParser class and 4 static functions" into tizen_2.1
[platform/framework/native/appfw.git] / src / system / FSys_SystemInfoImpl.cpp
index 6cd8e41..6b7542a 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -20,6 +19,9 @@
  * @brief              This is the implementation file for _SystemInfoImpl class.
  */
 #include <unique_ptr.h>
+#include <unistd.h>
+
+#include <ITapiModem.h>
 
 #include <FBaseBoolean.h>
 #include <FBaseInteger.h>
 #include <FSys_SystemInfoImpl.h>
 #include <FIo_AppServiceIpcMessages.h>
 #include <FIo_IpcClient.h>
-#include <FSys_Types.h>
+
+#include "FSys_Types.h"
+#include "FSys_SystemClient.h"
+#include "FSys_CommunicationDispatcherClient.h"
 
 using namespace std;
 
@@ -41,7 +46,7 @@ using namespace Tizen::Io;
 namespace Tizen { namespace System
 {
 
-static const wchar_t* _REGISTRY_PATH = L"/tmp/osp/system_info_cache.ini";
+static const wchar_t* _REGISTRY_PATH = L"/opt/usr/etc/system_info_cache.ini";
 static const wchar_t* _SYSTEM_INFO_SESSION = L"SystemInformation";
 
 //Bluetooth
@@ -130,7 +135,6 @@ static const wchar_t* _NETWORK_TYPE = L"NetworkType";
 static const wchar_t* _NETWORK_EMERGENCY = L"Emergency";
 static const wchar_t* _NETWORK_NO_SERVICE = L"NoService";
 
-
 //WIFI
 static const wchar_t* _WIFI = L"http://tizen.org/feature/network.wifi";
 static const wchar_t* _WIFI_SUPPORTED = L"WiFiSupported";
@@ -148,9 +152,9 @@ static const wchar_t* _SUPPORTED = L"Supported";
 static const wchar_t* _UNSUPPORTED = L"Unsupported";
 
 static bool firstRequest = false;
-static HashMap integerList;
-static HashMap boolList;
-static HashMap stringList;
+static HashMap integerList(SingleObjectDeleter);
+static HashMap boolList(SingleObjectDeleter);
+static HashMap stringList(SingleObjectDeleter);
 
 void
 PrepareCache(void)
@@ -179,7 +183,7 @@ _SystemInfoImpl::ConvertToTizen(const String& key)
        }
        else if(code == _KEYBOARD_TYPE)
        {
-               code == _INPUT_KEYBOARD_LAYOUT;
+               code = _INPUT_KEYBOARD_LAYOUT;
        }
        else if(code == _SCREEN_BITS_PER_PIXEL)
        {
@@ -263,11 +267,12 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
                PrepareCache();
        }
 
-       String* pValue = (String*)stringList.GetValue(key);
+       String* pValue = (String*)stringList.GetValue(tizenKey);
 
        if(pValue != null)
        {
                value = *pValue;
+               return E_SUCCESS;
        }
 
        if (key == _NETWORK_TYPE) //Compatibility
@@ -368,7 +373,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
 
                        value.Append(L"CDMA");
                }
-
+               r = E_SUCCESS;
        }
        else if (key == _OPENGL_ES_VERSION)
        {
@@ -389,6 +394,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
 
                        value.Append(L"2.0");
                }
+               r = E_SUCCESS;
        }
        else if(key == _BLUETOOTH_SUPPORTED)
        {
@@ -398,6 +404,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
                        value = _SUPPORTED;
                else
                        value = _UNSUPPORTED;
+               r = E_SUCCESS;
        }
        else if (key == _GPS_SUPPORTED)
        {
@@ -407,6 +414,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
                        value = _SUPPORTED;
                else
                        value = _UNSUPPORTED;
+               r = E_SUCCESS;
        }
        else if (key == _WIFI_SUPPORTED)
        {
@@ -416,6 +424,7 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
                        value = _SUPPORTED;
                else
                        value = _UNSUPPORTED;
+               r = E_SUCCESS;
        }
        else if (key == _WAC_VERSION)
        {
@@ -426,20 +435,57 @@ _SystemInfoImpl::GetSysInfo(const String& key, String& value)
        {
                r = E_OBJ_NOT_FOUND;
        }
+       else if (tizenKey == _DUID)
+       {
+               int ret = 0;
+               TapiHandle* handle = null;
+               int time_count = 0;
+               int status = 0;
+
+               handle = tel_init(null);
+               if(handle != null)
+               {
+                       while(time_count < 30) //Wait 30 second.
+                       {
+                               ret = tel_check_modem_power_status(handle, &status);
+                               SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
+                               if(ret != TAPI_API_SUCCESS)
+                               {
+                                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
+                                       tel_deinit(handle);
+                                       return E_SYSTEM;
+                               }
+
+                               if(status == 0)
+                               {
+                                       break;
+                               }
+
+                               usleep(1000000);
+                               time_count++;
+                       }
+                       tel_deinit(handle);
+               }
+               _SystemClient* pSystemClient = _SystemClient::GetInstance();
+               r = pSystemClient->GetValue(tizenKey, value);
+       }
        else
        {
                r = GetFromRegistry(tizenKey, value);
-               SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
-               r = E_SUCCESS;
+
+               if(r != E_SUCCESS)
+               {
+                       _SystemClient* pSystemClient = _SystemClient::GetInstance();
+                       r = pSystemClient->GetValue(tizenKey, value);
+               }
        }
        if( r == E_SUCCESS)
        {
-               stringList.Add(new String(key), new String(value));
+               stringList.Add(new String(tizenKey), new String(value));
        }
        return r;
 }
 
-
 result
 _SystemInfoImpl::GetSysInfo(const String& key, int& value)
 {
@@ -451,11 +497,12 @@ _SystemInfoImpl::GetSysInfo(const String& key, int& value)
                PrepareCache();
        }
 
-       Integer* pValue = (Integer*)integerList.GetValue(key);
+       Integer* pValue = (Integer*)integerList.GetValue(tizenKey);
 
        if(pValue != null)
        {
                value = pValue->value;
+               return E_SUCCESS;
        }
 
        if (key == _CAMERA_COUNT)
@@ -472,36 +519,37 @@ _SystemInfoImpl::GetSysInfo(const String& key, int& value)
                        cameraCount++;
 
                value = cameraCount;
-       }       
+       }
        else
        {
                r = GetFromRegistry(tizenKey, value);
-               SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
+               if(r != E_SUCCESS)
+               {
+                       _SystemClient* pSystemClient = _SystemClient::GetInstance();
+                       r = pSystemClient->GetValue(tizenKey, value);
+               }
        }
 
        if(r == E_SUCCESS)
        {
-               integerList.Add(new String(key), new Integer(value));
+               integerList.Add(new String(tizenKey), new Integer(value));
        }
-       
+
        return r;
 }
 
-
 result
 _SystemInfoImpl::GetSysInfo(const String& key, long long& value)
 {
        return E_OBJ_NOT_FOUND;
 }
 
-
 result
 _SystemInfoImpl::GetSysInfo(const String& key, double& value)
 {
        return E_OBJ_NOT_FOUND;
 }
 
-
 result
 _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
 {
@@ -513,36 +561,39 @@ _SystemInfoImpl::GetSysInfo(const String& key, bool& value)
                PrepareCache();
        }
 
-       Boolean* pValue = (Boolean*)boolList.GetValue(key);
+       Boolean* pValue = (Boolean*)boolList.GetValue(tizenKey);
 
        if(pValue != null)
        {
                value = pValue->value;
+               return E_SUCCESS;
        }
 
-
        r = GetFromRegistry(tizenKey, value);
+       if(r != E_SUCCESS)
+       {
+               _SystemClient* pSystemClient = _SystemClient::GetInstance();
+               r = pSystemClient->GetValue(tizenKey, value);
+       }
        SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, "It is failed to get the key[%ls]", tizenKey.GetPointer());
 
        if(r == E_SUCCESS)
        {
-               boolList.Add(new String(key), new Boolean(value));
+               boolList.Add(new String(tizenKey), new Boolean(value));
        }
 
        return r;
 }
 
-
 result
 _SystemInfoImpl::GetSysInfo(const String& key, UuId& value)
 {
        return E_OBJ_NOT_FOUND;
 }
 
-
 Collection::IList*
 _SystemInfoImpl::GetSysInfoValuesN(const String& key, SystemInfoValueType type)
-{      
+{
        SetLastResult(E_OBJ_NOT_FOUND);
        return null;
 }
@@ -596,14 +647,41 @@ _SystemInfoImpl::GetImei(String& imei)
 {
        result r = E_SUCCESS;
 
+       int ret = 0;
+       TapiHandle* handle = null;
+       int time_count = 0;
+       int status = 0;
+
+       handle = tel_init(null);
+       SysTryReturnResult(NID_SYS, handle != null, E_SYSTEM, "It is failed to get handle of telephony.");
+       while(time_count < 30) //Wait 30 second.
+       {
+               ret = tel_check_modem_power_status(handle, &status);
+               SysLog(NID_SYS, "Modem check result is %d, status is %d.", handle, status);
+               if(ret != TAPI_API_SUCCESS)
+               {
+                       SysLogException(NID_SYS, E_SYSTEM, "It is failed to get Modem status.");
+                       tel_deinit(handle);
+                       return E_SYSTEM;
+               }
+
+               if(status == 0)
+               {
+                       break;
+               }
+
+               usleep(1000000);
+               time_count++;
+       }
+       tel_deinit(handle);
+
        ArrayList requestMessage;
        ArrayList responseMessage;
 
-       unique_ptr<_IpcClient> pIpcClient (new (std::nothrow) _IpcClient());
-       SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
+       _CommunicationDispatcherClient* pCommunicationDispatcherClient = _CommunicationDispatcherClient::GetInstance();
 
-       r = pIpcClient->Construct(_COMMUNICATION_DISPATCHER_IPC_ID);
-       SysTryReturn(NID_SYS, r == E_SUCCESS, E_SYSTEM, r, "It is failed to create IpcClient. [%s]", GetErrorMessage(r));
+       _IpcClient* pIpcClient = pCommunicationDispatcherClient->GetIpcClient();
+       SysTryReturn(NID_SYS, pIpcClient != null, E_OUT_OF_MEMORY, r, "It is failed to create IPC instance.");
 
        requestMessage.Construct();
        responseMessage.Construct();
@@ -641,10 +719,10 @@ _SystemInfoImpl::GetFromRegistry(const String& key, String& value)
        String valStr;
 
        r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " RegistryImpl construct It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " RegistryImpl construct is failed");
 
        r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " Registry GetValue  It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS , r, " Registry GetValue is failed");
 
        if(valStr == L"true" || valStr == L"false")
        {
@@ -665,13 +743,13 @@ _SystemInfoImpl::GetFromRegistry(const String& key, int& value)
        _RegistryImpl _reg;
        String valStr;
        r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct is failed");
 
        r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue  It is failed");
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue  It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue is failed");
        r = Integer::Parse(valStr, value);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, " Integer::Parse()  It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_OBJ_NOT_FOUND, " Integer::Parse() is failed");
        return E_SUCCESS;
 }
 
@@ -682,11 +760,11 @@ _SystemInfoImpl::GetFromRegistry(const String& key, bool& value)
        _RegistryImpl _reg;
        String valStr;
        r = _reg.Construct(_REGISTRY_PATH, REG_OPEN_READ_ONLY, null);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " RegistryImpl construct is failed");
 
        r = _reg.GetValue(_SYSTEM_INFO_SESSION, key, valStr);
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue It is failed");
-       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue  It is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, " Registry GetValue is failed");
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, " Registry GetValue is failed");
        if(valStr == L"true")
        {
                value = true;
@@ -701,6 +779,7 @@ _SystemInfoImpl::GetFromRegistry(const String& key, bool& value)
        }
        return E_SUCCESS;
 }
+
 _SystemInfoImpl*
 _SystemInfoImpl::GetInstance(SystemInfo& systeminfo)
 {