You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2014/06/03 23:08:38 UTC

git commit: Cached extra info to better detect changes.

Repository: cordova-plugin-network-information
Updated Branches:
  refs/heads/master f27b34c2a -> 1cec040b3


Cached extra info to better detect changes.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/commit/1cec040b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/tree/1cec040b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/diff/1cec040b

Branch: refs/heads/master
Commit: 1cec040b30084a02ce052278a13eda9c7d9d46d0
Parents: f27b34c
Author: Max Woghiren <ma...@gmail.com>
Authored: Tue Jun 3 17:08:16 2014 -0400
Committer: Max Woghiren <ma...@gmail.com>
Committed: Tue Jun 3 17:08:32 2014 -0400

----------------------------------------------------------------------
 src/android/NetworkManager.java | 43 +++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/1cec040b/src/android/NetworkManager.java
----------------------------------------------------------------------
diff --git a/src/android/NetworkManager.java b/src/android/NetworkManager.java
index e2ac500..4c54b81 100755
--- a/src/android/NetworkManager.java
+++ b/src/android/NetworkManager.java
@@ -24,6 +24,8 @@ import org.apache.cordova.CordovaPlugin;
 import org.apache.cordova.PluginResult;
 import org.apache.cordova.CordovaWebView;
 import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
 
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -75,7 +77,7 @@ public class NetworkManager extends CordovaPlugin {
 
     ConnectivityManager sockMan;
     BroadcastReceiver receiver;
-    private String lastStatus = "";
+    private JSONObject lastInfo = null;
 
     /**
      * Constructor.
@@ -104,7 +106,7 @@ public class NetworkManager extends CordovaPlugin {
                 @Override
                 public void onReceive(Context context, Intent intent) {
                     // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
-                    if(NetworkManager.this.webView != null)                        
+                    if(NetworkManager.this.webView != null)
                         updateConnectionInfo(sockMan.getActiveNetworkInfo());
                 }
             };
@@ -126,7 +128,12 @@ public class NetworkManager extends CordovaPlugin {
         if (action.equals("getConnectionInfo")) {
             this.connectionCallbackContext = callbackContext;
             NetworkInfo info = sockMan.getActiveNetworkInfo();
-            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, this.getConnectionInfo(info));
+            String connectionType = "";
+            try {
+                connectionType = this.getConnectionInfo(info).get("type").toString();
+            } catch (JSONException e) { }
+
+            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, connectionType);
             pluginResult.setKeepCallback(true);
             callbackContext.sendPluginResult(pluginResult);
             return true;
@@ -161,13 +168,17 @@ public class NetworkManager extends CordovaPlugin {
     private void updateConnectionInfo(NetworkInfo info) {
         // send update to javascript "navigator.network.connection"
         // Jellybean sends its own info
-        String thisStatus = this.getConnectionInfo(info);
-        if(!thisStatus.equals(lastStatus))
+        JSONObject thisInfo = this.getConnectionInfo(info);
+        if(!thisInfo.equals(lastInfo))
         {
-            sendUpdate(thisStatus);
-            lastStatus = thisStatus;
+            String connectionType = "";
+            try {
+                connectionType = thisInfo.get("type").toString();
+            } catch (JSONException e) { }
+
+            sendUpdate(connectionType);
+            lastInfo = thisInfo;
         }
-            
     }
 
     /**
@@ -176,7 +187,7 @@ public class NetworkManager extends CordovaPlugin {
      * @param info the current active network info
      * @return a JSONObject that represents the network info
      */
-    private String getConnectionInfo(NetworkInfo info) {
+    private JSONObject getConnectionInfo(NetworkInfo info) {
         String type = TYPE_NONE;
         if (info != null) {
             // If we are not connected to any network set type to none
@@ -187,8 +198,19 @@ public class NetworkManager extends CordovaPlugin {
                 type = getType(info);
             }
         }
+        String extraInfo = info.getExtraInfo();
+
         Log.d("CordovaNetworkManager", "Connection Type: " + type);
-        return type;
+        Log.d("CordovaNetworkManager", "Connection Extra Info: " + extraInfo);
+
+        JSONObject connectionInfo = new JSONObject();
+
+        try {
+            connectionInfo.put("type", type);
+            connectionInfo.put("extraInfo", extraInfo);
+        } catch (JSONException e) { }
+
+        return connectionInfo;
     }
 
     /**
@@ -247,3 +269,4 @@ public class NetworkManager extends CordovaPlugin {
         return TYPE_UNKNOWN;
     }
 }
+