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);
}
}
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();
}
});
}
}
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;
}
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);
}
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);
}
Aggregations