Search in sources :

Example 86 with WifiManager

use of android.net.wifi.WifiManager in project wigle-wifi-wardriving by wiglenet.

the class NetworkActivity method getExistingSsid.

private int getExistingSsid(final String ssid) {
    final WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    final String quotedSsid = "\"" + ssid + "\"";
    int netId = -2;
    for (final WifiConfiguration config : wifiManager.getConfiguredNetworks()) {
        MainActivity.info("bssid: " + config.BSSID + " ssid: " + config.SSID + " status: " + config.status + " id: " + config.networkId + " preSharedKey: " + config.preSharedKey + " priority: " + config.priority + " wepTxKeyIndex: " + config.wepTxKeyIndex + " allowedAuthAlgorithms: " + config.allowedAuthAlgorithms + " allowedGroupCiphers: " + config.allowedGroupCiphers + " allowedKeyManagement: " + config.allowedKeyManagement + " allowedPairwiseCiphers: " + config.allowedPairwiseCiphers + " allowedProtocols: " + config.allowedProtocols + " hiddenSSID: " + config.hiddenSSID + " wepKeys: " + Arrays.toString(config.wepKeys));
        if (quotedSsid.equals(config.SSID)) {
            netId = config.networkId;
            break;
        }
    }
    return netId;
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) SuppressLint(android.annotation.SuppressLint)

Example 87 with WifiManager

use of android.net.wifi.WifiManager in project wigle-wifi-wardriving by wiglenet.

the class NetworkActivity method connectToNetwork.

private void connectToNetwork(final String password) {
    final int preExistingNetId = getExistingSsid(network.getSsid());
    final WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    int netId = -2;
    if (preExistingNetId < 0) {
        final WifiConfiguration newConfig = new WifiConfiguration();
        newConfig.SSID = "\"" + network.getSsid() + "\"";
        newConfig.hiddenSSID = false;
        if (password != null) {
            if (Network.CRYPTO_WEP == network.getCrypto()) {
                newConfig.wepKeys = new String[] { "\"" + password + "\"" };
            } else {
                newConfig.preSharedKey = "\"" + password + "\"";
            }
        }
        netId = wifiManager.addNetwork(newConfig);
    }
    if (netId >= 0) {
        final boolean disableOthers = true;
        wifiManager.enableNetwork(netId, disableOthers);
    }
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) SuppressLint(android.annotation.SuppressLint)

Example 88 with WifiManager

use of android.net.wifi.WifiManager in project android_packages_apps_Settings by crdroidandroid.

the class WifiDialogActivity method onSubmit.

@Override
public void onSubmit(WifiDialog dialog) {
    final WifiConfiguration config = dialog.getController().getConfig();
    final AccessPoint accessPoint = dialog.getController().getAccessPoint();
    final WifiManager wifiManager = getSystemService(WifiManager.class);
    if (config == null) {
        if (accessPoint != null && accessPoint.isSaved()) {
            wifiManager.connect(accessPoint.getConfig(), null);
        }
    } else {
        wifiManager.save(config, null);
        if (accessPoint != null) {
            // accessPoint is null for "Add network"
            NetworkInfo networkInfo = accessPoint.getNetworkInfo();
            if (networkInfo == null || !networkInfo.isConnected()) {
                wifiManager.connect(config, null);
            }
        }
    }
    Intent resultData = new Intent();
    if (accessPoint != null) {
        Bundle accessPointState = new Bundle();
        accessPoint.saveWifiState(accessPointState);
        resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
    }
    if (config != null) {
        resultData.putExtra(KEY_WIFI_CONFIGURATION, config);
    }
    setResult(RESULT_CONNECTED, resultData);
    finish();
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) NetworkInfo(android.net.NetworkInfo) Bundle(android.os.Bundle) AccessPoint(com.android.settingslib.wifi.AccessPoint) Intent(android.content.Intent)

Example 89 with WifiManager

use of android.net.wifi.WifiManager in project android_packages_apps_Settings by crdroidandroid.

the class WifiDialogActivity method onForget.

@Override
public void onForget(WifiDialog dialog) {
    final WifiManager wifiManager = getSystemService(WifiManager.class);
    final AccessPoint accessPoint = dialog.getController().getAccessPoint();
    if (accessPoint != null) {
        if (!accessPoint.isSaved()) {
            if (accessPoint.getNetworkInfo() != null && accessPoint.getNetworkInfo().getState() != NetworkInfo.State.DISCONNECTED) {
                // Network is active but has no network ID - must be ephemeral.
                wifiManager.disableEphemeralNetwork(AccessPoint.convertToQuotedString(accessPoint.getSsidStr()));
            } else {
                // Should not happen, but a monkey seems to trigger it
                Log.e(TAG, "Failed to forget invalid network " + accessPoint.getConfig());
            }
        } else {
            wifiManager.forget(accessPoint.getConfig().networkId, null);
        }
    }
    Intent resultData = new Intent();
    if (accessPoint != null) {
        Bundle accessPointState = new Bundle();
        accessPoint.saveWifiState(accessPointState);
        resultData.putExtra(KEY_ACCESS_POINT_STATE, accessPointState);
    }
    setResult(RESULT_FORGET);
    finish();
}
Also used : WifiManager(android.net.wifi.WifiManager) Bundle(android.os.Bundle) AccessPoint(com.android.settingslib.wifi.AccessPoint) Intent(android.content.Intent)

Example 90 with WifiManager

use of android.net.wifi.WifiManager in project BlogSource by TeachCourse.

the class UniqueDevId method getDevId.

public String getDevId(int id) {
    String devId = null;
    switch(id) {
        /**
         *设备第一次启动时产生和存储的64bit的一个数
         */
        case ANDROID_ID:
            devId = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ANDROID_ID);
            break;
        /**
         * 根据不同的手机设备返回IMEI,MEID或者ESN码
         */
        case DEVICE_ID:
            devId = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
            break;
        /**
         *通过手机的Wifi或者蓝牙设备获取MAC ADDRESS作为DEVICE ID
         */
        case MAC_ADDRESS_ID:
            WifiManager wm = (WifiManager) mContext.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
            devId = wm.getConnectionInfo().getMacAddress();
            break;
        /**
         *获取SIM卡的设备编号
         */
        case SERIAL_NUMBER_ID:
            devId = ((TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE)).getSimSerialNumber();
            break;
        /**
         * 通过在程序安装后第一次运行生成一个ID实现的
         */
        case INSTALLTION_ID:
            devId = Installation.getId(mContext);
            break;
        /**
         * 这个在任何Android手机中都有效
         */
        case PSEUDO_UNIQUE_ID:
            devId = "35" + Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + Build.USER.length() % 10;
            break;
    }
    if (devId != null) {
        return devId;
    }
    return null;
}
Also used : WifiManager(android.net.wifi.WifiManager)

Aggregations

WifiManager (android.net.wifi.WifiManager)329 WifiInfo (android.net.wifi.WifiInfo)80 WifiConfiguration (android.net.wifi.WifiConfiguration)76 IOException (java.io.IOException)38 Intent (android.content.Intent)27 SuppressLint (android.annotation.SuppressLint)26 ConnectivityManager (android.net.ConnectivityManager)23 Context (android.content.Context)22 NetworkInfo (android.net.NetworkInfo)21 Test (org.junit.Test)20 AccessPoint (com.android.settingslib.wifi.AccessPoint)17 IntentFilter (android.content.IntentFilter)16 Bundle (android.os.Bundle)16 ArrayList (java.util.ArrayList)16 NetworkPolicyEditor (com.android.settingslib.NetworkPolicyEditor)12 PowerManager (android.os.PowerManager)11 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)10 SocketException (java.net.SocketException)10 SharedPreferences (android.content.SharedPreferences)9 Method (java.lang.reflect.Method)9