Search in sources :

Example 31 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 32 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 33 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)

Example 34 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by ParanoidAndroid.

the class ConnectionUtil method disconnectAP.

/*
     * Disconnect from the current AP and remove configured networks.
     */
public boolean disconnectAP() {
    // remove saved networks
    List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks();
    Log.v(LOG_TAG, "size of wifiConfigList: " + wifiConfigList.size());
    for (WifiConfiguration wifiConfig : wifiConfigList) {
        Log.v(LOG_TAG, "Remove wifi configuration: " + wifiConfig.networkId);
        int netId = wifiConfig.networkId;
        mWifiManager.forget(netId, new WifiManager.ActionListener() {

            public void onSuccess() {
            }

            public void onFailure(int reason) {
                Log.e(LOG_TAG, "forget failed " + reason);
            }
        });
    }
    return true;
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 35 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by ParanoidAndroid.

the class WifiAssociationTest method testWifiAssociation.

@LargeTest
public void testWifiAssociation() {
    assertNotNull("no test ssid", mSsid);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = mSsid;
    SECURITY_TYPE security = SECURITY_TYPE.valueOf(mSecurityType);
    log("Security type is " + security.toString());
    switch(security) {
        // set network configurations
        case OPEN:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            break;
        case WEP64:
            // always use hex pair for WEP-40
            assertTrue("not a WEP64 security type?", mPassword.length() == 10);
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            config.allowedGroupCiphers.set(GroupCipher.WEP40);
            if (mPassword != null) {
                int length = mPassword.length();
                // WEP-40
                if (mPassword.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = mPassword;
                } else {
                    fail("Please type hex pair for the password");
                }
            }
            break;
        case WEP128:
            assertNotNull("password is empty", mPassword);
            // always use hex pair for WEP-104
            assertTrue("not a WEP128 security type?", mPassword.length() == 26);
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            config.allowedGroupCiphers.set(GroupCipher.WEP104);
            if (mPassword != null) {
                int length = mPassword.length();
                // WEP-40
                if (mPassword.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = mPassword;
                } else {
                    fail("Please type hex pair for the password");
                }
            }
            break;
        case WPA_TKIP:
            assertNotNull("missing password", mPassword);
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedProtocols.set(Protocol.WPA);
            config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
            config.allowedGroupCiphers.set(GroupCipher.TKIP);
            if (mPassword.matches("[0-9A-Fa-f]{64}")) {
                config.preSharedKey = mPassword;
            } else {
                config.preSharedKey = '"' + mPassword + '"';
            }
            break;
        case WPA2_AES:
            assertNotNull("missing password", mPassword);
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedProtocols.set(Protocol.RSN);
            config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
            config.allowedGroupCiphers.set(GroupCipher.CCMP);
            config.allowedProtocols.set(Protocol.RSN);
            if (mPassword.matches("[0-9A-Fa-f]{64}")) {
                config.preSharedKey = mPassword;
            } else {
                config.preSharedKey = '"' + mPassword + '"';
            }
            break;
        default:
            fail("Not a valid security type: " + mSecurityType);
            break;
    }
    Log.v(TAG, "network config: " + config.toString());
    connectToWifi(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)316 WifiManager (android.net.wifi.WifiManager)54 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)44 ArrayList (java.util.ArrayList)38 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)32 ScanResult (android.net.wifi.ScanResult)27 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiInfo (android.net.wifi.WifiInfo)16 Bundle (android.os.Bundle)12 NetworkPolicy (android.net.NetworkPolicy)10 SpannableString (android.text.SpannableString)10 EAP (com.android.anqp.eap.EAP)10 X509Certificate (java.security.cert.X509Certificate)10 StaticIpConfiguration (android.net.StaticIpConfiguration)7 PackageManager (android.content.pm.PackageManager)6 NetworkInfo (android.net.NetworkInfo)6 PowerManager (android.os.PowerManager)6 RemoteException (android.os.RemoteException)6