Search in sources :

Example 6 with WifiApControl

use of cc.mvdan.accesspoint.WifiApControl in project fdroidclient by f-droid.

the class WifiStateChangeService method setSsid.

private void setSsid(WifiInfo wifiInfo) {
    Context context = getApplicationContext();
    if (wifiInfo != null && wifiInfo.getBSSID() != null) {
        String ssid = wifiInfo.getSSID();
        Utils.debugLog(TAG, "Have wifi info, connected to " + ssid);
        if (ssid == null) {
            FDroidApp.ssid = context.getString(R.string.swap_blank_wifi_ssid);
        } else {
            FDroidApp.ssid = ssid.replaceAll("^\"(.*)\"$", "$1");
        }
        FDroidApp.bssid = wifiInfo.getBSSID();
    } else {
        WifiApControl wifiApControl = null;
        try {
            wifiApControl = WifiApControl.getInstance(context);
            wifiApControl.isEnabled();
        } catch (NullPointerException e) {
            wifiApControl = null;
        }
        Utils.debugLog(TAG, "WifiApControl: " + wifiApControl);
        if (wifiApControl == null && FDroidApp.ipAddressString != null) {
            wifiInfo = wifiManager.getConnectionInfo();
            if (wifiInfo != null && wifiInfo.getBSSID() != null) {
                setSsid(wifiInfo);
            } else {
                FDroidApp.ssid = context.getString(R.string.swap_active_hotspot, "");
            }
        } else if (wifiApControl != null && wifiApControl.isEnabled()) {
            WifiConfiguration wifiConfiguration = wifiApControl.getConfiguration();
            Utils.debugLog(TAG, "WifiConfiguration: " + wifiConfiguration);
            if (wifiConfiguration == null) {
                FDroidApp.ssid = context.getString(R.string.swap_active_hotspot, "");
                FDroidApp.bssid = "";
                return;
            }
            if (wifiConfiguration.hiddenSSID) {
                FDroidApp.ssid = context.getString(R.string.swap_hidden_wifi_ssid);
            } else {
                FDroidApp.ssid = wifiConfiguration.SSID;
            }
            FDroidApp.bssid = wifiConfiguration.BSSID;
        }
    }
}
Also used : Context(android.content.Context) WifiConfiguration(android.net.wifi.WifiConfiguration) WifiApControl(cc.mvdan.accesspoint.WifiApControl)

Aggregations

WifiApControl (cc.mvdan.accesspoint.WifiApControl)6 WifiConfiguration (android.net.wifi.WifiConfiguration)3 Context (android.content.Context)2 WifiManager (android.net.wifi.WifiManager)2 IntentFilter (android.content.IntentFilter)1 TextView (android.widget.TextView)1