[Systeminfo] Added filtering of cellular network listeners calls
authorPiotr Kosko <p.kosko@samsung.com>
Fri, 11 Sep 2015 13:02:24 +0000 (15:02 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 11 Sep 2015 13:04:05 +0000 (15:04 +0200)
[Feature] When only single-property cellular network listener is registered,
  it should only react to changes of default (first) SIM card. Changes of others should be ignored.

[Verification] Code compiles without errors.
  Feature was checked in chrome console and changes of second sim are ignored.
  TCT passrate on web-tct_2.4_r41 is 100%.

Change-Id: I6134f84615986724488cba0ba13fc7fec84d1be9
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/systeminfo/systeminfo_api.js
src/systeminfo/systeminfo_manager.cc
src/systeminfo/systeminfo_manager.h

index babcfe0e307c2faf6fcdb66e24a1ea6a2bb18aa6..17ce10fa0b448b84c182c207f35a07938d8cb9ba 100644 (file)
@@ -21,6 +21,9 @@ var T_ = xwalk.utils.type;
 var Converter_ = xwalk.utils.converter;
 var native_ = new xwalk.utils.NativeManager(extension);
 
+// index of default property for sim-related callbacks
+var defaultListenerIndex = 0;
+
 //enumeration SystemInfoPropertyId ////////////////////////////////////////////////////
 var SystemInfoPropertyId = {
         BATTERY : 'BATTERY',
@@ -1000,6 +1003,11 @@ function _systeminfoCellularNetworkListenerCallback(eventObj) {
     for (var watchId in callbacks) {
         if (callbacks.hasOwnProperty(watchId)) {
             var listener = callbacks[watchId];
+            if (!listener.isArrayType && eventObj.changedPropertyIndex != defaultListenerIndex) {
+                // if this is not arrayListener, ignore events of non-default SIM
+                return;
+            }
+
             var propObj = !listener.isArrayType ?
                     _createProperty(property, eventObj.result.array[0]) :
                         _createPropertyArray(property, eventObj.result);
index 6da6e5adcd1b2cf9e3e068fa578c975683a7c6b7..cbee4d808faac702dde0c9ba2a81625302b5bd78 100644 (file)
@@ -47,9 +47,12 @@ namespace {
 const int kDefaultPropertyCount = 1;
 const int BASE_GATHERING_INTERVAL = 100;
 const double kPropertyWatcherTime = 1;
+// index of default property for sim-related callbacks
+const int kDefaultListenerIndex = 0;
 
 const std::string kPropertyIdString = "propertyId";
 const std::string kListenerIdString = "listenerId";
+const std::string kChangedPropertyIndexString = "changedPropertyIndex";
 const std::string kListenerConstValue = "SysteminfoCommonListenerLabel";
 
 const std::string kPropertyIdBattery = "BATTERY";
@@ -184,7 +187,7 @@ static void OnNetworkValueChangedCb(const char* ipv4_address,
 static void OnCellularNetworkValueChangedCb(keynode_t *node, void *event_ptr) {
   LoggerD("Enter");
   SysteminfoManager* manager = static_cast<SysteminfoManager*>(event_ptr);
-  manager->CallListenerCallback(kPropertyIdCellularNetwork);
+  manager->CallListenerCallback(kPropertyIdCellularNetwork, kDefaultListenerIndex);
 }
 
 static void OnTapiValueChangedCb(TapiHandle *handle, const char *noti_id,
@@ -192,7 +195,9 @@ static void OnTapiValueChangedCb(TapiHandle *handle, const char *noti_id,
   LoggerD("Enter");
   LoggerD("Changed key: %s", noti_id);
   SysteminfoManager* manager = static_cast<SysteminfoManager*>(user_data);
-  manager->CallListenerCallback(kPropertyIdCellularNetwork);
+  int index = manager->GetChangedTapiIndex(handle);
+  LoggerD("Changed SIM index is: %d", index);
+  manager->CallListenerCallback(kPropertyIdCellularNetwork, index);
 }
 
 static void OnPeripheralChangedCb(keynode_t* node, void* event_ptr) {
@@ -1244,6 +1249,17 @@ TapiHandle** SysteminfoManager::GetTapiHandles() {
   return tapi_handles_;
 }
 
+int SysteminfoManager::GetChangedTapiIndex(TapiHandle* tapi) {
+  LoggerD("Enter");
+  TapiHandle** handles = GetTapiHandles();
+  for (int i = 0; i < sim_count_; ++i) {
+    if (handles[i] == tapi) {
+      return i;
+    }
+  }
+  return -1;
+}
+
 void SysteminfoManager::InitCameraTypes() {
   LoggerD("Enter");
   bool supported = false;
@@ -1295,19 +1311,24 @@ bool SysteminfoManager::IsListenerRegistered(const std::string& property_id) {
 }
 
 void SysteminfoManager::PostListenerResponse(const std::string& property_id,
-                                     const picojson::value& result) {
+                                     const picojson::value& result,
+                                     int property_index) {
   LoggerD("Entered");
   const std::shared_ptr<picojson::value>& response =
       std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
   response->get<picojson::object>()[kPropertyIdString] = picojson::value(property_id);
   response->get<picojson::object>()[kListenerIdString] = picojson::value(kListenerConstValue);
+  // Added pushing index of property to handle only default for signle-property listeners in js
+  response->get<picojson::object>()[kChangedPropertyIndexString] =
+      picojson::value(static_cast<double>(property_index));
 
   ReportSuccess(result,response->get<picojson::object>());
   Instance::PostMessage(instance_, response->serialize().c_str());
 }
 
 
-void SysteminfoManager::CallListenerCallback(const std::string& property_id) {
+void SysteminfoManager::CallListenerCallback(const std::string& property_id,
+                                             int property_index) {
   LoggerD("Enter");
   if(IsListenerRegistered(property_id)) {
     LoggerD("listener for %s property is registered, calling it", property_id.c_str());
@@ -1316,7 +1337,7 @@ void SysteminfoManager::CallListenerCallback(const std::string& property_id) {
     PlatformResult ret = GetPropertiesManager().GetPropertyValue(
         property_id, true, &result);
     if (ret.IsSuccess()) {
-      PostListenerResponse(property_id, result);
+      PostListenerResponse(property_id, result, property_index);
     }
   } else {
     LoggerD("listener for %s property is not registered, ignoring", property_id.c_str());
index 4c85f698a76c206f7395ed36e140378cbf21523a..298f1e810818e659def36e30315e3b93a3fd9211 100644 (file)
@@ -57,6 +57,7 @@ class SysteminfoManager {
   int GetSensorHandle();
   TapiHandle* GetTapiHandle();
   TapiHandle** GetTapiHandles();
+  int GetChangedTapiIndex(TapiHandle* tapi);
   common::PlatformResult GetConnectionHandle(connection_h& handle);
 
   SysteminfoInstance* GetInstance() { return instance_;};
@@ -69,11 +70,12 @@ class SysteminfoManager {
   int GetCameraTypesCount();
 
   bool IsListenerRegistered(const std::string& property_id);
-  void CallListenerCallback(const std::string& property_id);
+  void CallListenerCallback(const std::string& property_id, int property_index = 0);
   void CallCpuListenerCallback();
   void CallStorageListenerCallback();
  private:
-  void PostListenerResponse(const std::string& property_id, const picojson::value& result);
+  void PostListenerResponse(const std::string& property_id, const picojson::value& result,
+                            int property_index = 0);
   common::PlatformResult ConnectSensor(int* result);
   void DisconnectSensor(int handle_orientation);
   void InitTapiHandles();