use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by SudaMod.
the class SavedAccessPointsWifiSettings method initPreferences.
private void initPreferences() {
PreferenceScreen preferenceScreen = getPreferenceScreen();
final Context context = getPrefContext();
final List<AccessPoint> accessPoints = WifiSavedConfigUtils.getAllConfigs(context, mWifiManager);
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
cacheRemoveAllPrefs(preferenceScreen);
final int accessPointsSize = accessPoints.size();
for (int i = 0; i < accessPointsSize; ++i) {
AccessPoint ap = accessPoints.get(i);
String key = AccessPointPreference.generatePreferenceKey(ap);
LongPressAccessPointPreference preference = (LongPressAccessPointPreference) getCachedPreference(key);
if (preference == null) {
preference = new LongPressAccessPointPreference(ap, context, mUserBadgeCache, true, this);
preference.setKey(key);
preference.setIcon(null);
preferenceScreen.addPreference(preference);
}
preference.setOrder(i);
}
removeCachedPrefs(preferenceScreen);
if (mAddNetworkPreference == null) {
mAddNetworkPreference = new Preference(getPrefContext());
mAddNetworkPreference.setIcon(R.drawable.ic_menu_add_inset);
mAddNetworkPreference.setTitle(R.string.wifi_add_network);
}
mAddNetworkPreference.setOrder(accessPointsSize);
preferenceScreen.addPreference(mAddNetworkPreference);
if (getPreferenceScreen().getPreferenceCount() < 1) {
Log.w(TAG, "Saved networks activity loaded, but there are no saved networks!");
}
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by SudaMod.
the class WifiSettingsUiTest method changingSecurityStateOnApShouldNotCauseMultipleListItems.
@Test
public void changingSecurityStateOnApShouldNotCauseMultipleListItems() {
setWifiState(WifiManager.WIFI_STATE_ENABLED);
TestAccessPointBuilder builder = new TestAccessPointBuilder(mContext).setSsid(TEST_SSID).setSecurity(AccessPoint.SECURITY_NONE).setRssi(TEST_RSSI);
AccessPoint open = builder.build();
builder.setSecurity(AccessPoint.SECURITY_EAP);
AccessPoint eap = builder.build();
builder.setSecurity(AccessPoint.SECURITY_WEP);
AccessPoint wep = builder.build();
// Return a different security state each time getAccessPoints is invoked
when(mWifiTracker.getAccessPoints()).thenReturn(Lists.newArrayList(open)).thenReturn(Lists.newArrayList(eap)).thenReturn(Lists.newArrayList(wep));
launchActivity();
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
mWifiListener.onAccessPointsChanged();
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
mWifiListener.onAccessPointsChanged();
onView(withText(TEST_SSID)).check(matches(isDisplayed()));
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by SudaMod.
the class WifiSettingsUiTest method wrongPasswordSavedNetwork.
@Test
public void wrongPasswordSavedNetwork() {
setWifiState(WifiManager.WIFI_STATE_ENABLED);
// Set up an AccessPoint that is disabled due to incorrect password.
WifiConfiguration config = new WifiConfiguration();
config.SSID = TEST_SSID;
config.BSSID = TEST_BSSID;
config.networkId = TEST_NETWORK_ID;
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
WifiConfiguration.NetworkSelectionStatus selectionStatus = new WifiConfiguration.NetworkSelectionStatus();
selectionStatus.setNetworkSelectionDisableReason(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
selectionStatus.setNetworkSelectionStatus(WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED);
config.setNetworkSelectionStatus(selectionStatus);
WifiInfo wifiInfo = new WifiInfo();
wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_UNQUOTED_SSID));
wifiInfo.setBSSID(TEST_BSSID);
wifiInfo.setRssi(TEST_RSSI);
wifiInfo.setNetworkId(TEST_NETWORK_ID);
AccessPoint accessPoint = new AccessPoint(mContext, config);
accessPoint.update(config, wifiInfo, null);
// Make sure we've set up our access point correctly.
assertThat(accessPoint.getSsidStr()).isEqualTo(TEST_UNQUOTED_SSID);
assertThat(accessPoint.getBssid()).isEqualTo(TEST_BSSID);
assertThat(accessPoint.isActive()).isFalse();
assertThat(accessPoint.getConfig()).isNotNull();
WifiConfiguration.NetworkSelectionStatus networkStatus = accessPoint.getConfig().getNetworkSelectionStatus();
assertThat(networkStatus).isNotNull();
assertThat(networkStatus.isNetworkEnabled()).isFalse();
assertThat(networkStatus.getNetworkSelectionDisableReason()).isEqualTo(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD);
when(mWifiTracker.getAccessPoints()).thenReturn(Lists.newArrayList(accessPoint));
launchActivity(WifiSettings.EXTRA_START_CONNECT_SSID, accessPoint.getSsidStr());
// Make sure that the password dialog is visible.
onView(withText(resourceId(STRING, WIFI_PASSWORD))).check(matches(isDisplayed()));
onView(withText(resourceId(STRING, WIFI_SHOW_PASSWORD))).check(matches(isDisplayed()));
onView(withId(resourceId(ID, PASSWORD_LAYOUT))).check(matches(isDisplayed()));
onView(withId(resourceId(ID, PASSWORD))).check(matches(isDisplayed()));
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by SudaMod.
the class WifiSettingsUiTest method setupConnectedAccessPoint.
private void setupConnectedAccessPoint() {
WifiConfiguration config = new WifiConfiguration();
config.SSID = TEST_SSID;
config.BSSID = TEST_BSSID;
config.networkId = TEST_NETWORK_ID;
WifiInfo wifiInfo = new WifiInfo();
wifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_UNQUOTED_SSID));
wifiInfo.setBSSID(TEST_BSSID);
wifiInfo.setRssi(TEST_RSSI);
wifiInfo.setNetworkId(TEST_NETWORK_ID);
NetworkInfo networkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0, null, null);
networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, null, null);
AccessPoint accessPoint = new AccessPoint(mContext, config);
accessPoint.update(config, wifiInfo, networkInfo);
assertThat(accessPoint.getSsidStr()).isEqualTo(TEST_UNQUOTED_SSID);
assertThat(accessPoint.getBssid()).isEqualTo(TEST_BSSID);
assertThat(accessPoint.getNetworkInfo()).isNotNull();
assertThat(accessPoint.isActive()).isTrue();
assertThat(accessPoint.getSettingsSummary()).isEqualTo(resourceString(WIFI_DISPLAY_STATUS_CONNECTED));
when(mWifiTracker.getAccessPoints()).thenReturn(Lists.asList(accessPoint, new AccessPoint[] {}));
}
use of com.android.settingslib.wifi.AccessPoint in project android_packages_apps_Settings by DirtyUnicorns.
the class WifiSettings method updateAccessPointPreferences.
private void updateAccessPointPreferences() {
// in case state has changed
if (!mWifiManager.isWifiEnabled()) {
return;
}
// AccessPoints are sorted by the WifiTracker
final List<AccessPoint> accessPoints = mWifiTracker.getAccessPoints();
if (WifiTracker.sVerboseLogging) {
Log.i(TAG, "updateAccessPoints called for: " + accessPoints);
}
boolean hasAvailableAccessPoints = false;
mAccessPointsPreferenceCategory.removePreference(mStatusMessagePreference);
cacheRemoveAllPrefs(mAccessPointsPreferenceCategory);
int index = configureConnectedAccessPointPreferenceCategory(accessPoints) ? 1 : 0;
int numAccessPoints = accessPoints.size();
for (; index < numAccessPoints; index++) {
AccessPoint accessPoint = accessPoints.get(index);
// Ignore access points that are out of range.
if (accessPoint.isReachable()) {
String key = AccessPointPreference.generatePreferenceKey(accessPoint);
hasAvailableAccessPoints = true;
LongPressAccessPointPreference pref = (LongPressAccessPointPreference) getCachedPreference(key);
if (pref != null) {
pref.setOrder(index);
continue;
}
LongPressAccessPointPreference preference = createLongPressActionPointPreference(accessPoint);
preference.setKey(key);
preference.setOrder(index);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr()) && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
onPreferenceTreeClick(preference);
mOpenSsid = null;
}
}
mAccessPointsPreferenceCategory.addPreference(preference);
accessPoint.setListener(WifiSettings.this);
preference.refresh();
}
}
removeCachedPrefs(mAccessPointsPreferenceCategory);
mAddPreference.setOrder(index);
mAccessPointsPreferenceCategory.addPreference(mAddPreference);
setAdditionalSettingsSummaries();
if (!hasAvailableAccessPoints) {
setProgressBarVisible(true);
Preference pref = new Preference(getPrefContext());
pref.setSelectable(false);
pref.setSummary(R.string.wifi_empty_list_wifi_on);
pref.setOrder(index++);
pref.setKey(PREF_KEY_EMPTY_WIFI_LIST);
mAccessPointsPreferenceCategory.addPreference(pref);
} else {
// Continuing showing progress bar for an additional delay to overlap with animation
getView().postDelayed(mHideProgressBarRunnable, 1700);
}
}
Aggregations