Search in sources :

Example 36 with WifiEntry

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

the class WifiNetworkListFragment method onSavedWifiEntriesChanged.

/**
 * Called when the state of Wifi has changed.
 */
@Override
public void onSavedWifiEntriesChanged() {
    final List<WifiEntry> savedWifiEntries = mSavedNetworkTracker.getSavedWifiEntries().stream().filter(entry -> isValidForDppConfiguration(entry)).collect(Collectors.toList());
    int index = 0;
    mPreferenceGroup.removeAll();
    for (WifiEntry savedEntry : savedWifiEntries) {
        final DisableUnreachableWifiEntryPreference preference = new DisableUnreachableWifiEntryPreference(getContext(), savedEntry);
        preference.setOnPreferenceClickListener(this);
        preference.setEnabled(savedEntry.getLevel() != WifiEntry.WIFI_LEVEL_UNREACHABLE);
        preference.setOrder(index++);
        mPreferenceGroup.addPreference(preference);
    }
    mAddPreference.setOrder(index);
    mPreferenceGroup.addPreference(mAddPreference);
}
Also used : SettingsPreferenceFragment(com.android.settings.SettingsPreferenceFragment) Context(android.content.Context) Bundle(android.os.Bundle) PreferenceCategory(androidx.preference.PreferenceCategory) Intent(android.content.Intent) SystemClock(android.os.SystemClock) Process(android.os.Process) Handler(android.os.Handler) Looper(android.os.Looper) Toast(android.widget.Toast) ZoneOffset(java.time.ZoneOffset) WifiConfiguration(android.net.wifi.WifiConfiguration) R(com.android.settings.R) ConnectivityManager(android.net.ConnectivityManager) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) AddNetworkFragment(com.android.settings.wifi.AddNetworkFragment) SavedNetworkTracker(com.android.wifitrackerlib.SavedNetworkTracker) WifiEntry(com.android.wifitrackerlib.WifiEntry) SettingsEnums(android.app.settings.SettingsEnums) NetworkScoreManager(android.net.NetworkScoreManager) Preference(androidx.preference.Preference) Collectors(java.util.stream.Collectors) WifiManager(android.net.wifi.WifiManager) List(java.util.List) HandlerThread(android.os.HandlerThread) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference) Clock(java.time.Clock) SimpleClock(android.os.SimpleClock) Activity(android.app.Activity) VisibleForTesting(androidx.annotation.VisibleForTesting) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 37 with WifiEntry

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

the class WifiNetworkListFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(Preference preference) {
    if (preference instanceof WifiEntryPreference) {
        final WifiEntry selectedWifiEntry = ((WifiEntryPreference) preference).getWifiEntry();
        // Launch WifiDppAddDeviceFragment to start DPP in Configurator-Initiator role.
        final WifiConfiguration wifiConfig = selectedWifiEntry.getWifiConfiguration();
        if (wifiConfig == null) {
            throw new IllegalArgumentException("Invalid access point");
        }
        final WifiNetworkConfig networkConfig = WifiNetworkConfig.getValidConfigOrNull(WifiDppUtils.getSecurityString(selectedWifiEntry), wifiConfig.getPrintableSsid(), wifiConfig.preSharedKey, wifiConfig.hiddenSSID, wifiConfig.networkId, /* isHotspot */
        false);
        if (mOnChooseNetworkListener != null) {
            mOnChooseNetworkListener.onChooseNetwork(networkConfig);
        }
    } else if (preference == mAddPreference) {
        new SubSettingLauncher(getContext()).setTitleRes(R.string.wifi_add_network).setDestination(AddNetworkFragment.class.getName()).setSourceMetricsCategory(getMetricsCategory()).setResultListener(this, ADD_NETWORK_REQUEST).launch();
    } else {
        return super.onPreferenceTreeClick(preference);
    }
    return true;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) WifiEntry(com.android.wifitrackerlib.WifiEntry) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference) AddNetworkFragment(com.android.settings.wifi.AddNetworkFragment)

Example 38 with WifiEntry

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

the class WifiNetworkDetailsFragment method clearWifiEntryCallback.

private void clearWifiEntryCallback() {
    if (mNetworkDetailsTracker == null) {
        return;
    }
    final WifiEntry wifiEntry = mNetworkDetailsTracker.getWifiEntry();
    if (wifiEntry == null) {
        return;
    }
    wifiEntry.setListener(null);
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 39 with WifiEntry

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

the class WifiSettings method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    // If the preference has a fragment set, open that
    if (preference.getFragment() != null) {
        preference.setOnPreferenceClickListener(null);
        return super.onPreferenceTreeClick(preference);
    }
    if (preference instanceof LongPressWifiEntryPreference) {
        final WifiEntry selectedEntry = ((LongPressWifiEntryPreference) preference).getWifiEntry();
        if (selectedEntry.shouldEditBeforeConnect()) {
            launchConfigNewNetworkFragment(selectedEntry);
            return true;
        }
        connect(selectedEntry, true, /* editIfNoConfig */
        true);
    } else if (preference == mAddWifiNetworkPreference) {
        onAddNetworkPressed();
    } else {
        return super.onPreferenceTreeClick(preference);
    }
    return true;
}
Also used : LongPressWifiEntryPreference(com.android.settingslib.wifi.LongPressWifiEntryPreference) WifiEntry(com.android.wifitrackerlib.WifiEntry)

Example 40 with WifiEntry

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

the class WifiSettings method onSubmit.

@Override
public void onSubmit(WifiDialog2 dialog) {
    final int dialogMode = dialog.getMode();
    final WifiConfiguration config = dialog.getController().getConfig();
    final WifiEntry wifiEntry = dialog.getWifiEntry();
    if (dialogMode == WifiConfigUiBase2.MODE_MODIFY) {
        if (config == null) {
            Toast.makeText(getContext(), R.string.wifi_failed_save_message, Toast.LENGTH_SHORT).show();
        } else {
            mWifiManager.save(config, mSaveListener);
        }
    } else if (dialogMode == WifiConfigUiBase2.MODE_CONNECT || (dialogMode == WifiConfigUiBase2.MODE_VIEW && wifiEntry.canConnect())) {
        if (config == null) {
            connect(wifiEntry, false, /* editIfNoConfig */
            false);
        } else {
            mWifiManager.connect(config, new WifiConnectActionListener());
        }
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) 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