[Systeminfo] vconf calls related to SIM replaced with tapi calls
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 10 Sep 2015 11:12:22 +0000 (13:12 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 10 Sep 2015 11:12:26 +0000 (13:12 +0200)
[Feature] fetching sim-related fields with vconf was replaced with proper
  calls of TAPI (in case of getters and change listeners)

[Verification] Code compiles without errors.
  TCT passrate is 100% on web-tct_2.4_r40.

Change-Id: I7f6ee8b23c301bb15b1d473b44b26bdc46267d0d
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/systeminfo/systeminfo-utils.cpp
src/systeminfo/systeminfo-utils.h
src/systeminfo/systeminfo_manager.cc
src/systeminfo/systeminfo_properties_manager.cc
src/systeminfo/systeminfo_properties_manager.h

index cf948d5647abd53196bd71bf8cad09d32888e00a..ab4c7c22a3b8f35395af55d59d8a9926b82fde84 100644 (file)
@@ -165,6 +165,25 @@ PlatformResult SysteminfoUtils::UnregisterVconfCallback(const char *in_key, vcon
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult SysteminfoUtils::RegisterTapiChangeCallback(TapiHandle *handle,
+                                                           const char *noti_id,
+                                                           tapi_notification_cb callback,
+                                                           void *user_data) {
+  if (TAPI_API_SUCCESS != tel_register_noti_event(handle, noti_id, callback, user_data)) {
+    LoggerE("Failed to register tapi callback with key: %s", noti_id);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to register tapi callback");
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SysteminfoUtils::UnregisterTapiChangeCallback(TapiHandle *handle,
+                                                             const char *noti_id) {
+  if (TAPI_API_SUCCESS != tel_deregister_noti_event(handle, noti_id)) {
+    LoggerE("Failed to unregister tapi callback with key: %s", noti_id);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to unregister tapi callback");
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
 
 } // namespace systeminfo
 } // namespace webapi
index 4ccdd36aa3c8063eba673d54f8e55dfe46c5fd31..818933daaae208977f11f18b63a43b19dcbfc464 100644 (file)
@@ -21,6 +21,8 @@
 #include <system_settings.h>
 #include <vconf.h>
 #include <vconf-internal-keys.h>
+#include <ITapiSim.h>
+#include <TelNetwork.h>
 #include "common/picojson.h"
 #include "common/platform_result.h"
 #include "systeminfo/systeminfo_device_capability.h"
@@ -49,6 +51,11 @@ class SysteminfoUtils {
   static common::PlatformResult RegisterVconfCallback(const char *in_key, vconf_callback_fn cb,
                                                             void* event_ptr);
   static common::PlatformResult UnregisterVconfCallback(const char *in_key, vconf_callback_fn cb);
+  static common::PlatformResult RegisterTapiChangeCallback(TapiHandle *handle, const char *noti_id,
+                                                           tapi_notification_cb callback,
+                                                           void *user_data);
+  static common::PlatformResult UnregisterTapiChangeCallback(TapiHandle *handle,
+                                                             const char *noti_id);
 };
 
 typedef unsigned char byte;
index 11487f00e1f81a7b122a6e154de74950343d707b..6da6e5adcd1b2cf9e3e068fa578c975683a7c6b7 100644 (file)
@@ -187,6 +187,14 @@ static void OnCellularNetworkValueChangedCb(keynode_t *node, void *event_ptr) {
   manager->CallListenerCallback(kPropertyIdCellularNetwork);
 }
 
+static void OnTapiValueChangedCb(TapiHandle *handle, const char *noti_id,
+                                 void *data, void *user_data) {
+  LoggerD("Enter");
+  LoggerD("Changed key: %s", noti_id);
+  SysteminfoManager* manager = static_cast<SysteminfoManager*>(user_data);
+  manager->CallListenerCallback(kPropertyIdCellularNetwork);
+}
+
 static void OnPeripheralChangedCb(keynode_t* node, void* event_ptr) {
   LoggerD("Enter");
   SysteminfoManager* manager = static_cast<SysteminfoManager*>(event_ptr);
@@ -926,14 +934,18 @@ PlatformResult SysteminfoManager::RegisterCellularNetworkListener() {
   }
 
   if (!IsListenerRegistered(kPropertyIdCellularNetwork)) {
-    CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterVconfCallback(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                          OnCellularNetworkValueChangedCb, this))
-    CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterVconfCallback(VCONFKEY_TELEPHONY_CELLID,
-                          OnCellularNetworkValueChangedCb, this))
-    CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterVconfCallback(VCONFKEY_TELEPHONY_LAC,
-                          OnCellularNetworkValueChangedCb, this))
-    CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterVconfCallback(VCONFKEY_TELEPHONY_SVC_ROAM,
-                          OnCellularNetworkValueChangedCb, this))
+    CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterVconfCallback(
+        VCONFKEY_TELEPHONY_FLIGHT_MODE, OnCellularNetworkValueChangedCb, this))
+    int sim_count = GetSimCount();
+    TapiHandle **tapis = GetTapiHandles();
+    for (int i = 0; i < sim_count; ++i) {
+      CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterTapiChangeCallback(
+          tapis[i], TAPI_PROP_NETWORK_CELLID, OnTapiValueChangedCb, this))
+      CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterTapiChangeCallback(
+          tapis[i], TAPI_PROP_NETWORK_LAC, OnTapiValueChangedCb, this))
+      CHECK_LISTENER_ERROR(SysteminfoUtils::RegisterTapiChangeCallback(
+          tapis[i], TAPI_PROP_NETWORK_ROAMING_STATUS, OnTapiValueChangedCb, this))
+    }
     LoggerD("Added callback for CELLULAR_NETWORK");
   }
   return PlatformResult(ErrorCode::NO_ERROR);
@@ -945,14 +957,18 @@ PlatformResult SysteminfoManager::UnregisterCellularNetworkListener() {
   // if there is no other ip-relateded listeners left, unregister
   if (!IsListenerRegistered(kPropertyIdCellularNetwork)) {
     PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
-    CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterVconfCallback(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                            OnCellularNetworkValueChangedCb))
-    CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterVconfCallback(VCONFKEY_TELEPHONY_CELLID,
-                            OnCellularNetworkValueChangedCb))
-    CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterVconfCallback(VCONFKEY_TELEPHONY_LAC,
-                            OnCellularNetworkValueChangedCb))
-    CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterVconfCallback(VCONFKEY_TELEPHONY_SVC_ROAM,
-                            OnCellularNetworkValueChangedCb))
+    CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterVconfCallback(
+        VCONFKEY_TELEPHONY_FLIGHT_MODE, OnCellularNetworkValueChangedCb))
+    int sim_count = GetSimCount();
+    TapiHandle **tapis = GetTapiHandles();
+    for (int i = 0; i < sim_count; ++i) {
+      CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterTapiChangeCallback(
+          tapis[i], TAPI_PROP_NETWORK_CELLID))
+      CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterTapiChangeCallback(
+          tapis[i], TAPI_PROP_NETWORK_LAC))
+      CHECK_LISTENER_ERROR(SysteminfoUtils::UnregisterTapiChangeCallback(
+          tapis[i], TAPI_PROP_NETWORK_ROAMING_STATUS))
+    }
   }
 
   if (IsIpChangeCallbackNotRegistered()) {
@@ -1091,18 +1107,10 @@ PlatformResult SysteminfoManager::GetPropertyCount(const std::string& property,
 
   if ("BATTERY" == property || "CPU" == property || "STORAGE" == property ||
       "DISPLAY" == property || "DEVICE_ORIENTATION" == property ||
-      "BUILD" == property || "LOCALE" == property || "NETWORK" == property ||
-      "WIFI_NETWORK" == property || "PERIPHERAL" == property ||
-      "MEMORY" == property) {
+      "BUILD" == property || "LOCALE" == property || "WIFI_NETWORK" == property ||
+      "PERIPHERAL" == property || "MEMORY" == property) {
     *count = kDefaultPropertyCount;
-  } else if ("CELLULAR_NETWORK" == property) {
-    PlatformResult ret = SysteminfoUtils::CheckTelephonySupport();
-    if (ret.IsError()) {
-      *count = 0;
-    } else {
-      *count = GetSimCount();
-    }
-  } else if ("SIM" == property) {
+  } else if ("CELLULAR_NETWORK" == property || "SIM" == property || "NETWORK" == property) {
     PlatformResult ret = SysteminfoUtils::CheckTelephonySupport();
     if (ret.IsError()) {
       *count = 0;
index d520b8b9bd098886eea0291e52da9dd41ba52db4..1d21729850e18bc778063245c79f45b87d9b174c 100644 (file)
@@ -159,7 +159,7 @@ PlatformResult SysteminfoPropertiesManager::ReportProperty(const std::string& pr
   } else if ("LOCALE" == property) {
     return ReportLocale(res_obj);
   } else if ("NETWORK" == property) {
-    return ReportNetwork(res_obj);
+    return ReportNetwork(res_obj, index);
   } else if ("WIFI_NETWORK" == property) {
     return ReportWifiNetwork(res_obj);
   } else if ("ETHERNET_NETWORK" == property) {
@@ -486,7 +486,7 @@ static PlatformResult GetNetworkTypeString(NetworkType type, std::string& type_s
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out) {
+PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out, unsigned long count) {
   connection_h connection_handle = nullptr;
   connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED;
   int networkType = 0;
@@ -518,18 +518,19 @@ PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out)
       type =  kWifi;
       break;
     case CONNECTION_TYPE_CELLULAR :
-      if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) {
-        if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) {
+      if (TAPI_API_SUCCESS == tel_get_property_int(manager_.GetTapiHandles()[count],
+                                                   TAPI_PROP_NETWORK_SERVICE_TYPE, &networkType)) {
+        if (networkType < TAPI_NETWORK_SERVICE_TYPE_2G) {
           type =  kNone;
-        } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) {
+        } else if (networkType == TAPI_NETWORK_SERVICE_TYPE_2G) {
           type =  kType2G;
-        } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G
-            || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) {
+        } else if (networkType == TAPI_NETWORK_SERVICE_TYPE_2_5G
+            || networkType == TAPI_NETWORK_SERVICE_TYPE_2_5G_EDGE) {
           type =  kType2_5G;
-        } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G
-            || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) {
+        } else if (networkType == TAPI_NETWORK_SERVICE_TYPE_3G
+            || networkType == TAPI_NETWORK_SERVICE_TYPE_HSDPA) {
           type =  kType3G;
-        } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) {
+        } else if (networkType == TAPI_NETWORK_SERVICE_TYPE_LTE) {
           type =  kType4G;
         } else {
           type =  kNone;
index cb966d881e8ba8549f82a24a46ce6eeada2a0bcc..7b7a030a3d49d98ad8cdbfbf04a5f16286f33625 100644 (file)
@@ -44,7 +44,7 @@ class SysteminfoPropertiesManager {
   common::PlatformResult ReportDeviceOrientation(picojson::object* out);
   common::PlatformResult ReportBuild(picojson::object* out);
   common::PlatformResult ReportLocale(picojson::object* out);
-  common::PlatformResult ReportNetwork(picojson::object* out);
+  common::PlatformResult ReportNetwork(picojson::object* out, unsigned long count);
   common::PlatformResult ReportWifiNetwork(picojson::object* out);
   common::PlatformResult ReportEthernetNetwork(picojson::object* out);
   common::PlatformResult ReportCellularNetwork(picojson::object* out, unsigned long count);