Search in sources :

Example 1 with WifiEntryPreference

use of com.android.settingslib.wifi.WifiEntryPreference in project android_packages_apps_Settings by omnirom.

the class WifiConnectionPreferenceControllerTest method onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced.

@Test
public void onAccessPointsChanged_wifiBecameConnectedToDifferentAP_preferenceReplaced() {
    final WifiEntry wifiEntry1 = mock(WifiEntry.class);
    when(wifiEntry1.getKey()).thenReturn("KEY_1");
    when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry1);
    mController.displayPreference(mScreen);
    final ArgumentCaptor<WifiEntryPreference> captor = ArgumentCaptor.forClass(WifiEntryPreference.class);
    final WifiEntry wifiEntry2 = mock(WifiEntry.class);
    when(wifiEntry1.getKey()).thenReturn("KEY_2");
    when(mWifiPickerTracker.getConnectedWifiEntry()).thenReturn(wifiEntry2);
    final int onUpdatedCountBefore = mOnChildUpdatedCount;
    mController.onWifiEntriesChanged();
    verify(mPreferenceCategory, times(2)).addPreference(captor.capture());
    final WifiEntryPreference pref1 = captor.getAllValues().get(0);
    final WifiEntryPreference pref2 = captor.getAllValues().get(1);
    assertThat(pref1.getWifiEntry()).isEqualTo(wifiEntry1);
    assertThat(pref2.getWifiEntry()).isEqualTo(wifiEntry2);
    verify(mPreferenceCategory).removePreference(eq(pref1));
    assertThat(mOnChildUpdatedCount).isEqualTo(onUpdatedCountBefore + 1);
}
Also used : WifiEntry(com.android.wifitrackerlib.WifiEntry) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference) Test(org.junit.Test)

Example 2 with WifiEntryPreference

use of com.android.settingslib.wifi.WifiEntryPreference in project android_packages_apps_Settings by omnirom.

the class WifiNetworkListFragmentTest method onPreferenceClick_validWifiEntryPreference_onChooseNetwork.

@Test
public void onPreferenceClick_validWifiEntryPreference_onChooseNetwork() {
    final WifiEntry wifiEntry = mock(WifiEntry.class);
    when(wifiEntry.getSecurityString(true)).thenReturn("WPA3");
    final WifiConfiguration wifiConfig = mock(WifiConfiguration.class);
    when(wifiConfig.getPrintableSsid()).thenReturn("ssid");
    when(wifiEntry.getWifiConfiguration()).thenReturn(wifiConfig);
    final WifiEntryPreference preference = new WifiEntryPreference(mContext, wifiEntry);
    mWifiNetworkListFragment.onPreferenceClick(preference);
    verify(mWifiNetworkListFragment.mOnChooseNetworkListener).onChooseNetwork(any());
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) WifiEntry(com.android.wifitrackerlib.WifiEntry) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference) Test(org.junit.Test)

Example 3 with WifiEntryPreference

use of com.android.settingslib.wifi.WifiEntryPreference 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 4 with WifiEntryPreference

use of com.android.settingslib.wifi.WifiEntryPreference 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 5 with WifiEntryPreference

use of com.android.settingslib.wifi.WifiEntryPreference in project android_packages_apps_Settings by omnirom.

the class WifiConnectionPreferenceController method updatePreference.

private void updatePreference(WifiEntry wifiEntry) {
    if (mPreference != null) {
        mPreferenceGroup.removePreference(mPreference);
        mPreference = null;
    }
    if (wifiEntry == null || mPrefContext == null) {
        return;
    }
    mPreference = new WifiEntryPreference(mPrefContext, wifiEntry);
    mPreference.setKey(KEY);
    mPreference.refresh();
    mPreference.setOrder(order);
    mPreference.setOnPreferenceClickListener(pref -> {
        final Bundle args = new Bundle();
        args.putString(WifiNetworkDetailsFragment.KEY_CHOSEN_WIFIENTRY_KEY, wifiEntry.getKey());
        new SubSettingLauncher(mPrefContext).setTitleRes(R.string.pref_title_network_details).setDestination(WifiNetworkDetailsFragment.class.getName()).setArguments(args).setSourceMetricsCategory(mMetricsCategory).launch();
        return true;
    });
    mPreferenceGroup.addPreference(mPreference);
}
Also used : SubSettingLauncher(com.android.settings.core.SubSettingLauncher) Bundle(android.os.Bundle) WifiEntryPreference(com.android.settingslib.wifi.WifiEntryPreference)

Aggregations

WifiEntryPreference (com.android.settingslib.wifi.WifiEntryPreference)9 WifiEntry (com.android.wifitrackerlib.WifiEntry)8 Test (org.junit.Test)6 WifiConfiguration (android.net.wifi.WifiConfiguration)2 SubSettingLauncher (com.android.settings.core.SubSettingLauncher)2 Bundle (android.os.Bundle)1 AddNetworkFragment (com.android.settings.wifi.AddNetworkFragment)1 ArrayList (java.util.ArrayList)1