package org.apache.cordova.plugin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;

import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import java.util.List;

public class WifiInfoPlugin extends CordovaPlugin {
   public static final String ACTION_MANAGE_WIFI= "managewifi";
    @Override
    public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
        if (ACTION_MANAGE_WIFI.equals(action)) { 
          Context context = cordova.getActivity().getApplicationContext();
        final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (wifi.isWifiEnabled() == false) {
            wifi.setWifiEnabled(true);
        }

        List<ScanResult> mScanResults = wifi.getScanResults();
        for (ScanResult result : mScanResults) {

            if ("belkin_cloudlabz".equals(result.SSID)) {
                WifiConfiguration wc = new WifiConfiguration();
                wc.SSID = "\"belkin_cloudlabz\"";
                wc.preSharedKey = "\"84dcd64a\"";
                wc.hiddenSSID = true;
                wc.status = WifiConfiguration.Status.ENABLED;

                wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
                wc.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
                wc.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
                wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
                wc.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
                wc.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
                int res = wifi.addNetwork(wc);
                boolean es = wifi.saveConfiguration();
                boolean b = wifi.enableNetwork(res, true);
            }
        }  
        }
        return true;
    }
}

@@ -33,93 +33,8 @@
 n;%0A%0A
-import org.apache.cordova.CallbackContext;%0Aimport org.apache.cordova.CordovaPlugin;%0A%0A
 impo
@@ -257,16 +257,108 @@
 il.List;
+%0Aimport org.apache.cordova.api.CallbackContext;%0Aimport org.apache.cordova.api.CordovaPlugin;
 %0A%0Apublic
@@ -403,19 +403,21 @@
 lugin %7B%0A
+%0A
    
+ 
 public s
@@ -453,16 +453,17 @@
 AGE_WIFI
+ 
 = %22manag
@@ -470,16 +470,17 @@
 ewifi%22;%0A
+%0A
     @Ove
@@ -599,16 +599,34 @@
 ption %7B%0A
+        try %7B%0A    
         
@@ -665,18 +665,23 @@
 tion)) %7B
- 
 %0A
+      
         
@@ -755,16 +755,24 @@
         
+  
+      
 final Wi
@@ -850,16 +850,24 @@
 RVICE);%0A
+        
         
@@ -915,16 +915,24 @@
         
+      
+  
 wifi.set
@@ -962,11 +962,27 @@
     
-%7D%0A%0A
+        %7D%0A%0A        
     
@@ -1048,16 +1048,24 @@
         
+  
+      
 for (Sca
@@ -1106,24 +1106,32 @@
             
+     
+   
 if (%22belkin_
@@ -1180,16 +1180,24 @@
         
+       
+ 
 WifiConf
@@ -1252,16 +1252,24 @@
         
+        
 wc.SSID 
@@ -1310,16 +1310,24 @@
         
+ 
+       
 wc.preSh
@@ -1368,16 +1368,24 @@
         
+   
+     
 wc.hidde
@@ -1394,24 +1394,32 @@
 SID = true;%0A
+        
             
@@ -1477,32 +1477,40 @@
                 
+       
+ 
 wc.allowedGroupC
@@ -1549,32 +1549,40 @@
 upCipher.TKIP);%0A
+        
                 
@@ -1653,32 +1653,40 @@
                 
+ 
+       
 wc.allowedKeyMan
@@ -1741,32 +1741,40 @@
                 
+   
+     
 wc.allowedPairwi
@@ -1835,32 +1835,40 @@
                 
+      
+  
 wc.allowedPairwi
@@ -1913,32 +1913,40 @@
 seCipher.CCMP);%0A
+        
                 
@@ -2018,16 +2018,24 @@
         
+        
 int res 
@@ -2057,16 +2057,24 @@
 rk(wc);%0A
+        
         
@@ -2128,32 +2128,40 @@
                 
+    
+    
 boolean b = wifi
@@ -2191,32 +2191,40 @@
 e);%0A            
+        
 %7D%0A        %7D  %0A  
@@ -2221,42 +2221,394 @@
     
+ 
-%7D  %0A        %7D%0A        return true;
+       %7D%0A                callbackContext.success();%0A                return true;%0A            %7D else %7B%0A                callbackContext.error(%22Invalid action%22);%0A                return false;%0A            %7D%0A        %7D catch (Exception e) %7B%0A            System.err.println(%22Exception: %22 + e.getMessage());%0A            callbackContext.error(e.getMessage());%0A            return false;%0A        %7D
 %0A   

Update WifiInfoPlugin.java