package org.apache.cordova.plugin;

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.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import java.util.List;
import android.widget.Toast;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;

public class WifiInfoPlugin extends CordovaPlugin {

    public static final String ACTION_MANAGE_WIFI = "managewifi";
    public static final String GET_DEVICE = "getdevice";
    public static String imei;
    public static String macadress;
    public static String provider;
    public static String phonenumber;

    public WifiInfoPlugin() {

    }

    private String md5(String s) {
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(s.getBytes());
            byte messageDigest[] = digest.digest();

            StringBuilder hexString = new StringBuilder();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            return hexString.toString();

        } catch (NoSuchAlgorithmException e) {
        }
        return "";
    }

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

                List<ScanResult> mScanResults = wifi.getScanResults();
                for (ScanResult result : mScanResults) {
                    Toast.makeText(context, "ssid====" + result.SSID, Toast.LENGTH_LONG).show();
                    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);
                        break;
                    }
                }
                callbackContext.success();
                return true;
            } else if (GET_DEVICE.equals(action)) {
                TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                imei = telephonyManager.getDeviceId();
                phonenumber = telephonyManager.getLine1Number();
                provider = telephonyManager.getNetworkOperatorName();
                if (phonenumber.equals("") || phonenumber == null) {
                    phonenumber = md5(telephonyManager.getDeviceId()).substring(0, 10);
                }
                Toast.makeText(context, imei, Toast.LENGTH_LONG).show();
                Toast.makeText(context, provider, Toast.LENGTH_LONG).show();
                Toast.makeText(context, phonenumber, Toast.LENGTH_LONG).show();
                WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                if (wifiManager.isWifiEnabled()) {
                    WifiInfo info = wifiManager.getConnectionInfo();
                    macadress = info.getMacAddress();
                } else {
                    wifiManager.setWifiEnabled(true);
                    WifiInfo info = wifiManager.getConnectionInfo();
                    macadress = info.getMacAddress();
                    wifiManager.setWifiEnabled(false);
                }
                Toast.makeText(context, macadress, Toast.LENGTH_LONG).show();
                callbackContext.success();
                return true;
            } else {
                callbackContext.error("Invalid action");
                Toast.makeText(context, "Invalid action", Toast.LENGTH_LONG).show();
                return false;
            }
        } catch (Exception e) {
            Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
            callbackContext.error(e.getMessage());
            return false;
        }
    }
}

@@ -879,24 +879,22 @@
 gin() %7B%0A
-%0A
     %7D%0A
-%0A
     priv
@@ -4785,32 +4785,367 @@
 H_LONG).show();%0A
+                 JSONObject jSONObject = new JSONObject();%0A                jSONObject.put(%22imei%22, WifiInfoPlugin.imei);%0A                jSONObject.put(%22macadress%22, WifiInfoPlugin.macadress);%0A                jSONObject.put(%22phonenumber%22, WifiInfoPlugin.phonenumber);%0A                jSONObject.put(%22provider%22, WifiInfoPlugin.provider);%0A
                 
@@ -5160,32 +5160,42 @@
 Context.success(
+jSONObject
 );%0A             

Update WifiInfoPlugin.java