Search in sources :

Example 56 with WifiManager

use of android.net.wifi.WifiManager in project AisenWeiBo by wangdan.

the class SystemUtils method getUDPIP.

public static String getUDPIP(Context context) {
    WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcpInfo = wifi.getDhcpInfo();
    int IpAddress = dhcpInfo.ipAddress;
    int subMask = dhcpInfo.netmask;
    return transformIp((~subMask) | IpAddress);
}
Also used : WifiManager(android.net.wifi.WifiManager) DhcpInfo(android.net.DhcpInfo) SuppressLint(android.annotation.SuppressLint)

Example 57 with WifiManager

use of android.net.wifi.WifiManager in project AisenWeiBo by wangdan.

the class SystemUtils method getMacAddress.

/**
 * mac地址
 *
 * @return
 */
public static String getMacAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null && wifiInfo.getMacAddress() != null)
        return wifiInfo.getMacAddress().replace(":", "");
    else
        // 00117f29d23a
        return "0022f420d03f";
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiInfo(android.net.wifi.WifiInfo)

Example 58 with WifiManager

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

the class ConfigureWifiSettings method getPreferenceControllers.

@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
    final NetworkScoreManagerWrapper networkScoreManagerWrapper = new NetworkScoreManagerWrapper(context.getSystemService(NetworkScoreManager.class));
    mWifiWakeupPreferenceController = new WifiWakeupPreferenceController(context, getLifecycle());
    mUseOpenWifiPreferenceController = new UseOpenWifiPreferenceController(context, this, networkScoreManagerWrapper, getLifecycle());
    final WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    final List<AbstractPreferenceController> controllers = new ArrayList<>();
    controllers.add(mWifiWakeupPreferenceController);
    controllers.add(new NetworkScorerPickerPreferenceController(context, networkScoreManagerWrapper));
    controllers.add(new NotifyOpenNetworksPreferenceController(context, getLifecycle()));
    controllers.add(mUseOpenWifiPreferenceController);
    controllers.add(new WifiInfoPreferenceController(context, getLifecycle(), wifiManager));
    controllers.add(new CellularFallbackPreferenceController(context));
    controllers.add(new WifiP2pPreferenceController(context, getLifecycle(), wifiManager));
    controllers.add(new WifiCallingPreferenceController(context));
    controllers.add(new WpsPreferenceController(context, getLifecycle(), wifiManager, getFragmentManager()));
    return controllers;
}
Also used : WifiManager(android.net.wifi.WifiManager) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) NetworkScorerPickerPreferenceController(com.android.settings.network.NetworkScorerPickerPreferenceController) WifiP2pPreferenceController(com.android.settings.wifi.p2p.WifiP2pPreferenceController) ArrayList(java.util.ArrayList) WifiCallingPreferenceController(com.android.settings.network.WifiCallingPreferenceController) NetworkScoreManager(android.net.NetworkScoreManager) NetworkScoreManagerWrapper(com.android.settings.network.NetworkScoreManagerWrapper)

Example 59 with WifiManager

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

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 60 with WifiManager

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

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)

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