Search in sources :

Example 11 with AccessPointPreference

use of com.android.settingslib.wifi.AccessPointPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiNetworkListFragment method updateAccessPointPreferences.

private void updateAccessPointPreferences() {
    // in case state has changed
    if (!mWifiManager.isWifiEnabled()) {
        return;
    }
    List<AccessPoint> savedAccessPoints = WifiSavedConfigUtils.getAllConfigs(getContext(), mWifiManager);
    savedAccessPoints = savedAccessPoints.stream().filter(accessPoint -> isValidForDppConfiguration(accessPoint)).map(accessPoint -> getScannedAccessPointIfAvailable(accessPoint)).sorted((ap1, ap2) -> {
        // orders reachable Wi-Fi networks on top
        if (ap1.isReachable() && !ap2.isReachable()) {
            return -1;
        } else if (!ap1.isReachable() && ap2.isReachable()) {
            return 1;
        }
        String ap1Title = nullToEmpty(ap1.getTitle());
        String ap2Title = nullToEmpty(ap2.getTitle());
        return ap1Title.compareToIgnoreCase(ap2Title);
    }).collect(Collectors.toList());
    int index = 0;
    mAccessPointsPreferenceCategory.removeAll();
    for (AccessPoint savedAccessPoint : savedAccessPoints) {
        final AccessPointPreference preference = createAccessPointPreference(savedAccessPoint);
        preference.setOrder(index++);
        preference.setEnabled(savedAccessPoint.isReachable());
        savedAccessPoint.setListener(this);
        preference.refresh();
        mAccessPointsPreferenceCategory.addPreference(preference);
    }
    mAddPreference.setOrder(index);
    mAccessPointsPreferenceCategory.addPreference(mAddPreference);
    if (mIsTest) {
        mAccessPointsPreferenceCategory.addPreference(mFakeNetworkPreference);
    }
}
Also used : SettingsPreferenceFragment(com.android.settings.SettingsPreferenceFragment) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) AddNetworkFragment(com.android.settings.wifi.AddNetworkFragment) Context(android.content.Context) Bundle(android.os.Bundle) WifiTrackerFactory(com.android.settingslib.wifi.WifiTrackerFactory) PreferenceCategory(androidx.preference.PreferenceCategory) SettingsEnums(android.app.settings.SettingsEnums) Intent(android.content.Intent) AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) Preference(androidx.preference.Preference) Collectors(java.util.stream.Collectors) WifiSavedConfigUtils(com.android.settingslib.wifi.WifiSavedConfigUtils) WifiManager(android.net.wifi.WifiManager) List(java.util.List) Toast(android.widget.Toast) View(android.view.View) WifiTracker(com.android.settingslib.wifi.WifiTracker) Activity(android.app.Activity) Collections(java.util.Collections) Log(android.util.Log) AccessPoint(com.android.settingslib.wifi.AccessPoint) WifiConfiguration(android.net.wifi.WifiConfiguration) R(com.android.settings.R) AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) AccessPoint(com.android.settingslib.wifi.AccessPoint) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 12 with AccessPointPreference

use of com.android.settingslib.wifi.AccessPointPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiNetworkListFragment method onAccessPointChanged.

@Override
public void onAccessPointChanged(final AccessPoint accessPoint) {
    Log.d(TAG, "onAccessPointChanged (singular) callback initiated");
    View view = getView();
    if (view != null) {
        view.post(() -> {
            final Object tag = accessPoint.getTag();
            if (tag != null) {
                ((AccessPointPreference) tag).refresh();
            }
        });
    }
}
Also used : AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) View(android.view.View)

Example 13 with AccessPointPreference

use of com.android.settingslib.wifi.AccessPointPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiNetworkListFragment method onPreferenceTreeClick.

@Override
public boolean onPreferenceTreeClick(Preference preference) {
    if (preference instanceof AccessPointPreference) {
        final AccessPoint selectedAccessPoint = ((AccessPointPreference) preference).getAccessPoint();
        if (selectedAccessPoint == null) {
            return false;
        }
        // Launch WifiDppAddDeviceFragment to start DPP in Configurator-Initiator role.
        final WifiConfiguration wifiConfig = selectedAccessPoint.getConfig();
        if (wifiConfig == null) {
            throw new IllegalArgumentException("Invalid access point");
        }
        final WifiNetworkConfig networkConfig = WifiNetworkConfig.getValidConfigOrNull(selectedAccessPoint.getSecurityString(/* concise */
        true), wifiConfig.getPrintableSsid(), wifiConfig.preSharedKey, wifiConfig.hiddenSSID, wifiConfig.networkId, /* isHotspot */
        false);
        if (mOnChooseNetworkListener != null) {
            mOnChooseNetworkListener.onChooseNetwork(networkConfig);
        }
    } else if (preference == mAddPreference) {
        launchAddNetworkFragment();
    } else if (preference == mFakeNetworkPreference) {
        if (mOnChooseNetworkListener != null) {
            mOnChooseNetworkListener.onChooseNetwork(new WifiNetworkConfig(WifiQrCode.SECURITY_WPA_PSK, /* ssid */
            WifiNetworkConfig.FAKE_SSID, /* preSharedKey */
            WifiNetworkConfig.FAKE_PASSWORD, /* hiddenSsid */
            true, /* networkId */
            WifiConfiguration.INVALID_NETWORK_ID, /* isHotspot*/
            false));
        }
    } else {
        return super.onPreferenceTreeClick(preference);
    }
    return true;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) AccessPoint(com.android.settingslib.wifi.AccessPoint)

Example 14 with AccessPointPreference

use of com.android.settingslib.wifi.AccessPointPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiConnectionPreferenceControllerTest method onConnectedChanged_wifiBecameDisconnected_preferenceRemoved.

@Test
public void onConnectedChanged_wifiBecameDisconnected_preferenceRemoved() {
    when(mWifiTracker.isConnected()).thenReturn(true);
    final AccessPoint accessPoint = mock(AccessPoint.class);
    when(accessPoint.isActive()).thenReturn(true);
    when(mWifiTracker.getAccessPoints()).thenReturn(Arrays.asList(accessPoint));
    mController.displayPreference(mScreen);
    final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(AccessPointPreference.class);
    verify(mPreferenceCategory).addPreference(captor.capture());
    final AccessPointPreference pref = captor.getValue();
    when(mWifiTracker.isConnected()).thenReturn(false);
    when(mWifiTracker.getAccessPoints()).thenReturn(new ArrayList<>());
    final int onUpdatedCountBefore = mOnChildUpdatedCount;
    mController.onConnectedChanged();
    verify(mPreferenceCategory).removePreference(pref);
    assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
}
Also used : AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) AccessPoint(com.android.settingslib.wifi.AccessPoint) AccessPoint(com.android.settingslib.wifi.AccessPoint) Test(org.junit.Test)

Example 15 with AccessPointPreference

use of com.android.settingslib.wifi.AccessPointPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SavedAccessPointsPreferenceControllerTest method refreshSavedAccessPoints_shouldListNonSubscribedAPs.

@Test
@Config(shadows = ShadowAccessPoint.class)
public void refreshSavedAccessPoints_shouldListNonSubscribedAPs() {
    final WifiConfiguration config = new WifiConfiguration();
    config.SSID = "SSID";
    config.BSSID = "BSSID";
    config.networkId = 2;
    mWifiManager.addNetwork(config);
    final ArgumentCaptor<AccessPointPreference> captor = ArgumentCaptor.forClass(AccessPointPreference.class);
    mController.displayPreference(mPreferenceScreen);
    mController.refreshSavedAccessPoints();
    verify(mPreferenceCategory).addPreference(captor.capture());
    final AccessPointPreference pref = captor.getValue();
    assertThat(pref.getTitle()).isEqualTo(config.SSID);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) AccessPointPreference(com.android.settingslib.wifi.AccessPointPreference) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

AccessPointPreference (com.android.settingslib.wifi.AccessPointPreference)16 AccessPoint (com.android.settingslib.wifi.AccessPoint)12 Test (org.junit.Test)4 Context (android.content.Context)3 WifiConfiguration (android.net.wifi.WifiConfiguration)3 Bundle (android.os.Bundle)2 View (android.view.View)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)2 Config (org.robolectric.annotation.Config)2 Activity (android.app.Activity)1 SettingsEnums (android.app.settings.SettingsEnums)1 Intent (android.content.Intent)1 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)1 WifiManager (android.net.wifi.WifiManager)1 Log (android.util.Log)1 Toast (android.widget.Toast)1 Preference (androidx.preference.Preference)1 PreferenceCategory (androidx.preference.PreferenceCategory)1 R (com.android.settings.R)1