Search in sources :

Example 31 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class WifiDppQrCodeScannerFragment method isReachableWifiNetwork.

private boolean isReachableWifiNetwork(WifiConfiguration wifiConfiguration) {
    final List<WifiEntry> wifiEntries = mWifiPickerTracker.getWifiEntries();
    final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
    if (connectedWifiEntry != null) {
        // Add connected WifiEntry to prevent fail toast to users when it's connected.
        wifiEntries.add(connectedWifiEntry);
    }
    for (WifiEntry wifiEntry : wifiEntries) {
        if (!TextUtils.equals(wifiEntry.getSsid(), sanitizeSsid(wifiConfiguration.SSID))) {
            continue;
        }
        final int security = WifiDppUtils.getSecurityTypeFromWifiConfiguration(wifiConfiguration);
        if (security == wifiEntry.getSecurity()) {
            return true;
        }
        // there is no way to know if a WifiEntry is of transition mode. Give it a chance.
        if (security == WifiEntry.SECURITY_SAE && wifiEntry.getSecurity() == WifiEntry.SECURITY_PSK) {
            return true;
        }
    }
    return false;
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 32 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class NetworkRequestDialogFragment method onClick.

@Override
public void onClick(DialogInterface dialog, int which) {
    if (mFilteredWifiEntries.size() == 0 || which >= mFilteredWifiEntries.size()) {
        // Invalid values.
        return;
    }
    if (mUserSelectionCallback == null) {
        // Callback is missing or not ready.
        return;
    }
    final WifiEntry wifiEntry = mFilteredWifiEntries.get(which);
    WifiConfiguration config = wifiEntry.getWifiConfiguration();
    if (config == null) {
        config = WifiUtils.getWifiConfig(wifiEntry, null);
    }
    mUserSelectionCallback.select(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 33 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class SavedAccessPointsPreferenceController2 method updatePreference.

/**
 * mPreferenceGroup is not in a RecyclerView. To keep TalkBack focus, this method should not
 * mPreferenceGroup.removeAll() then mPreferenceGroup.addPreference for mWifiEntries.
 */
private void updatePreference() {
    // Remove the Preference of removed WifiEntry.
    final List<String> removedPreferenceKeys = new ArrayList<>();
    final int preferenceCount = mPreferenceGroup.getPreferenceCount();
    for (int i = 0; i < preferenceCount; i++) {
        final String key = mPreferenceGroup.getPreference(i).getKey();
        if (mWifiEntries.stream().filter(wifiEntry -> TextUtils.equals(key, wifiEntry.getKey())).count() == 0) {
            removedPreferenceKeys.add(key);
        }
    }
    for (String removedPreferenceKey : removedPreferenceKeys) {
        mPreferenceGroup.removePreference(mPreferenceGroup.findPreference(removedPreferenceKey));
    }
    // Add the Preference of new added WifiEntry.
    for (WifiEntry wifiEntry : mWifiEntries) {
        if (mPreferenceGroup.findPreference(wifiEntry.getKey()) == null) {
            final WifiEntryPreference preference = new WifiEntryPreference(mContext, wifiEntry);
            preference.setKey(wifiEntry.getKey());
            preference.setOnPreferenceClickListener(this);
            mPreferenceGroup.addPreference(preference);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) WifiEntry(com.android.wifitrackerlib.WifiEntry) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference)

Example 34 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class WifiScanWorker method getWifiEntry.

/**
 * To get the WifiEntry of key.
 */
public WifiEntry getWifiEntry(String key) {
    // Get specified WifiEntry.
    WifiEntry keyWifiEntry = null;
    final WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
    if (connectedWifiEntry != null && TextUtils.equals(key, connectedWifiEntry.getKey())) {
        keyWifiEntry = connectedWifiEntry;
    } else {
        for (WifiEntry wifiEntry : mWifiPickerTracker.getWifiEntries()) {
            if (TextUtils.equals(key, wifiEntry.getKey())) {
                keyWifiEntry = wifiEntry;
                break;
            }
        }
    }
    return keyWifiEntry;
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 35 with WifiEntry

use of com.android.wifitrackerlib.WifiEntry in project android_packages_apps_Settings by omnirom.

the class ConnectToWifiHandler method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if (context == null || intent == null) {
        return;
    }
    final String key = intent.getStringExtra(KEY_CHOSEN_WIFIENTRY_KEY);
    if (TextUtils.isEmpty(key)) {
        return;
    }
    if (intent.getParcelableExtra(KEY_WIFI_SLICE_URI) == null) {
        return;
    }
    final WifiScanWorker worker = getWifiScanWorker(intent);
    if (worker == null) {
        return;
    }
    final WifiEntry wifiEntry = worker.getWifiEntry(key);
    if (wifiEntry == null) {
        return;
    }
    wifiEntry.connect(new WifiEntryConnectCallback(context, wifiEntry));
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry)

Aggregations

WifiEntry (com.android.wifitrackerlib.WifiEntry)54 Test (org.junit.Test)28 WifiConfiguration (android.net.wifi.WifiConfiguration)10 WifiEntryPreference (com.android.settingslib.wifi.WifiEntryPreference)10 LongPressWifiEntryPreference (com.android.settingslib.wifi.LongPressWifiEntryPreference)8 Intent (android.content.Intent)7 Preference (androidx.preference.Preference)5 Context (android.content.Context)4 Bundle (android.os.Bundle)4 DataUsagePreference (com.android.settings.datausage.DataUsagePreference)4 WifiManager (android.net.wifi.WifiManager)3 Handler (android.os.Handler)3 View (android.view.View)3 FragmentActivity (androidx.fragment.app.FragmentActivity)3 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)3 AddWifiNetworkPreference (com.android.settings.wifi.AddWifiNetworkPreference)3 ConnectedWifiEntryPreference (com.android.settings.wifi.ConnectedWifiEntryPreference)3 FooterPreference (com.android.settingslib.widget.FooterPreference)3 LayoutPreference (com.android.settingslib.widget.LayoutPreference)3 ArrayList (java.util.ArrayList)3