Search in sources :

Example 1 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android by cSploit.

the class NetworkManager method shiftPriorityAndSave.

public static int shiftPriorityAndSave(final WifiManager wifiMgr) {
    final List<WifiConfiguration> configurations = wifiMgr.getConfiguredNetworks();
    sortByPriority(configurations);
    final int size = configurations.size();
    for (int i = 0; i < size; i++) {
        final WifiConfiguration config = configurations.get(i);
        config.priority = i;
        wifiMgr.updateNetwork(config);
    }
    wifiMgr.saveConfiguration();
    return size;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 2 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project zxingfragmentlib by mitoyarzun.

the class WifiConfigManager method changeNetworkWPA.

// Adding a WPA or WPA2 network
private static void changeNetworkWPA(WifiManager wifiManager, WifiParsedResult wifiResult) {
    WifiConfiguration config = changeNetworkCommon(wifiResult);
    // Hex passwords that are 64 bits long are not to be quoted.
    config.preSharedKey = quoteNonHex(wifiResult.getPassword(), 64);
    config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
    // For WPA
    config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
    // For WPA2
    config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    updateNetwork(wifiManager, config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 3 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project zxingfragmentlib by mitoyarzun.

the class WifiConfigManager method changeNetworkWEP.

// Adding a WEP network
private static void changeNetworkWEP(WifiManager wifiManager, WifiParsedResult wifiResult) {
    WifiConfiguration config = changeNetworkCommon(wifiResult);
    config.wepKeys[0] = quoteNonHex(wifiResult.getPassword(), 10, 26, 58);
    config.wepTxKeyIndex = 0;
    config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
    updateNetwork(wifiManager, config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 4 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project zxingfragmentlib by mitoyarzun.

the class WifiConfigManager method changeNetworkUnEncrypted.

// Adding an open, unsecured network
private static void changeNetworkUnEncrypted(WifiManager wifiManager, WifiParsedResult wifiResult) {
    WifiConfiguration config = changeNetworkCommon(wifiResult);
    config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
    updateNetwork(wifiManager, config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 5 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project XPrivacy by M66B.

the class XWifiManager method after.

@Override
@SuppressWarnings("rawtypes")
protected void after(XParam param) throws Throwable {
    switch(mMethod) {
        case Srv_getBatchedScanResults:
            if (param.getResult() != null)
                if (isRestricted(param))
                    param.setResult(new ArrayList());
            break;
        case getConfiguredNetworks:
        case Srv_getConfiguredNetworks:
            if (param.getResult() != null)
                if (isRestricted(param))
                    param.setResult(new ArrayList<WifiConfiguration>());
            break;
        case getConnectionInfo:
        case Srv_getConnectionInfo:
            if (param.getResult() != null)
                if (isRestricted(param)) {
                    WifiInfo result = (WifiInfo) param.getResult();
                    WifiInfo wInfo = WifiInfo.class.getConstructor(WifiInfo.class).newInstance(result);
                    if (getRestrictionName().equals(PrivacyManager.cInternet)) {
                        // Supplicant state
                        try {
                            Field fieldState = WifiInfo.class.getDeclaredField("mSupplicantState");
                            fieldState.setAccessible(true);
                            fieldState.set(wInfo, SupplicantState.DISCONNECTED);
                        } catch (Throwable ex) {
                            Util.bug(this, ex);
                        }
                    } else {
                        // BSSID
                        try {
                            Field fieldBSSID = WifiInfo.class.getDeclaredField("mBSSID");
                            fieldBSSID.setAccessible(true);
                            fieldBSSID.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "MAC"));
                        } catch (Throwable ex) {
                            Util.bug(this, ex);
                        }
                        // IP address
                        try {
                            Field fieldIp = WifiInfo.class.getDeclaredField("mIpAddress");
                            fieldIp.setAccessible(true);
                            fieldIp.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "InetAddress"));
                        } catch (Throwable ex) {
                            Util.bug(this, ex);
                        }
                        // MAC address
                        try {
                            Field fieldMAC = WifiInfo.class.getDeclaredField("mMacAddress");
                            fieldMAC.setAccessible(true);
                            fieldMAC.set(wInfo, PrivacyManager.getDefacedProp(Binder.getCallingUid(), "MAC"));
                        } catch (Throwable ex) {
                            Util.bug(this, ex);
                        }
                        // SSID
                        String ssid = (String) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "SSID");
                        try {
                            Field fieldSSID = WifiInfo.class.getDeclaredField("mSSID");
                            fieldSSID.setAccessible(true);
                            fieldSSID.set(wInfo, ssid);
                        } catch (Throwable ex) {
                            try {
                                Field fieldWifiSsid = WifiInfo.class.getDeclaredField("mWifiSsid");
                                fieldWifiSsid.setAccessible(true);
                                Object mWifiSsid = fieldWifiSsid.get(wInfo);
                                if (mWifiSsid != null) {
                                    // public static WifiSsid
                                    // createFromAsciiEncoded(String
                                    // asciiEncoded)
                                    Method methodCreateFromAsciiEncoded = mWifiSsid.getClass().getDeclaredMethod("createFromAsciiEncoded", String.class);
                                    fieldWifiSsid.set(wInfo, methodCreateFromAsciiEncoded.invoke(null, ssid));
                                }
                            } catch (Throwable exex) {
                                Util.bug(this, exex);
                            }
                        }
                    }
                    param.setResult(wInfo);
                }
            break;
        case getDhcpInfo:
        case Srv_getDhcpInfo:
            if (param.getResult() != null)
                if (isRestricted(param)) {
                    DhcpInfo result = (DhcpInfo) param.getResult();
                    DhcpInfo dInfo = DhcpInfo.class.getConstructor(DhcpInfo.class).newInstance(result);
                    dInfo.ipAddress = (Integer) PrivacyManager.getDefacedProp(Binder.getCallingUid(), "IPInt");
                    dInfo.gateway = dInfo.ipAddress;
                    dInfo.dns1 = dInfo.ipAddress;
                    dInfo.dns2 = dInfo.ipAddress;
                    dInfo.serverAddress = dInfo.ipAddress;
                    param.setResult(dInfo);
                }
            break;
        case getScanResults:
        case Srv_getScanResults:
            if (param.getResult() != null)
                if (isRestricted(param))
                    param.setResult(new ArrayList<ScanResult>());
            break;
        case getWifiApConfiguration:
        case Srv_getWifiApConfiguration:
            if (param.getResult() != null)
                if (isRestricted(param))
                    param.setResult(null);
            break;
    }
}
Also used : ScanResult(android.net.wifi.ScanResult) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DhcpInfo(android.net.DhcpInfo) WifiInfo(android.net.wifi.WifiInfo) Field(java.lang.reflect.Field)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)569 WifiManager (android.net.wifi.WifiManager)88 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)47 AccessPoint (com.android.settingslib.wifi.AccessPoint)46 Test (org.junit.Test)45 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)40 WifiInfo (android.net.wifi.WifiInfo)36 ScanResult (android.net.wifi.ScanResult)27 NetworkInfo (android.net.NetworkInfo)22 StaticIpConfiguration (android.net.StaticIpConfiguration)20 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 Intent (android.content.Intent)19 Bundle (android.os.Bundle)19 ValidatedEditTextPreference (com.android.settings.widget.ValidatedEditTextPreference)16 Before (org.junit.Before)13 VisibleForTesting (android.support.annotation.VisibleForTesting)12 Preference (android.support.v7.preference.Preference)12