use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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 (isVerboseLoggingEnabled()) {
Log.i(TAG, "updateAccessPoints called for: " + accessPoints);
}
boolean hasAvailableAccessPoints = false;
mStatusMessagePreference.setVisible(false);
mConnectedAccessPointPreferenceCategory.setVisible(true);
mAccessPointsPreferenceCategory.setVisible(true);
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 = accessPoint.getKey();
hasAvailableAccessPoints = true;
LongPressAccessPointPreference pref = (LongPressAccessPointPreference) getCachedPreference(key);
if (pref != null) {
pref.setOrder(index);
continue;
}
LongPressAccessPointPreference preference = createLongPressAccessPointPreference(accessPoint);
preference.setKey(key);
preference.setOrder(index);
if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr()) && (accessPoint.getSecurity() != AccessPoint.SECURITY_NONE && accessPoint.getSecurity() != AccessPoint.SECURITY_OWE)) {
if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
onPreferenceTreeClick(preference);
mOpenSsid = null;
}
}
mAccessPointsPreferenceCategory.addPreference(preference);
accessPoint.setListener(WifiSettings.this);
preference.refresh();
}
}
removeCachedPrefs(mAccessPointsPreferenceCategory);
mAddWifiNetworkPreference.setOrder(index);
mAccessPointsPreferenceCategory.addPreference(mAddWifiNetworkPreference);
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);
}
}
use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiSettings method launchNetworkDetailsFragment.
private void launchNetworkDetailsFragment(ConnectedAccessPointPreference pref) {
final AccessPoint accessPoint = pref.getAccessPoint();
final Context context = getContext();
final CharSequence title = FeatureFlagUtils.isEnabled(context, FeatureFlags.WIFI_DETAILS_DATAUSAGE_HEADER) ? accessPoint.getTitle() : context.getText(R.string.pref_title_network_details);
new SubSettingLauncher(getContext()).setTitleText(title).setDestination(WifiNetworkDetailsFragment.class.getName()).setArguments(pref.getExtras()).setSourceMetricsCategory(getMetricsCategory()).launch();
}
use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiUtils method getWifiConfig.
/**
* Provides a simple way to generate a new {@link WifiConfiguration} obj from
* {@link ScanResult} or {@link AccessPoint}. Either {@code accessPoint} or {@code scanResult
* } input should be not null for retrieving information, otherwise will throw
* IllegalArgumentException.
* This method prefers to take {@link AccessPoint} input in priority. Therefore this method
* will take {@link AccessPoint} input as preferred data extraction source when you input
* both {@link AccessPoint} and {@link ScanResult}, and ignore {@link ScanResult} input.
*
* Duplicated and simplified method from {@link WifiConfigController#getConfig()}.
* TODO(b/120827021): Should be removed if the there is have a common one in shared place (e.g.
* SettingsLib).
*
* @param accessPoint Input data for retrieving WifiConfiguration.
* @param scanResult Input data for retrieving WifiConfiguration.
* @return WifiConfiguration obj based on input.
*/
public static WifiConfiguration getWifiConfig(AccessPoint accessPoint, ScanResult scanResult, String password) {
if (accessPoint == null && scanResult == null) {
throw new IllegalArgumentException("At least one of AccessPoint and ScanResult input is required.");
}
final WifiConfiguration config = new WifiConfiguration();
final int security;
if (accessPoint == null) {
config.SSID = AccessPoint.convertToQuotedString(scanResult.SSID);
security = getAccessPointSecurity(scanResult);
} else {
if (!accessPoint.isSaved()) {
config.SSID = AccessPoint.convertToQuotedString(accessPoint.getSsidStr());
} else {
config.networkId = accessPoint.getConfig().networkId;
config.hiddenSSID = accessPoint.getConfig().hiddenSSID;
}
security = accessPoint.getSecurity();
}
switch(security) {
case AccessPoint.SECURITY_NONE:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
break;
case AccessPoint.SECURITY_WEP:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
if (!TextUtils.isEmpty(password)) {
int length = password.length();
// WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
if ((length == 10 || length == 26 || length == 58) && password.matches("[0-9A-Fa-f]*")) {
config.wepKeys[0] = password;
} else {
config.wepKeys[0] = '"' + password + '"';
}
}
break;
case AccessPoint.SECURITY_PSK:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
if (!TextUtils.isEmpty(password)) {
if (password.matches("[0-9A-Fa-f]{64}")) {
config.preSharedKey = password;
} else {
config.preSharedKey = '"' + password + '"';
}
}
break;
case AccessPoint.SECURITY_EAP:
case AccessPoint.SECURITY_EAP_SUITE_B:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_EAP);
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.IEEE8021X);
if (security == AccessPoint.SECURITY_EAP_SUITE_B) {
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SUITE_B_192);
config.requirePMF = true;
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
config.allowedGroupManagementCiphers.set(WifiConfiguration.GroupMgmtCipher.BIP_GMAC_256);
// allowedSuiteBCiphers will be set according to certificate type
}
if (!TextUtils.isEmpty(password)) {
config.enterpriseConfig.setPassword(password);
}
break;
case AccessPoint.SECURITY_SAE:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.SAE);
config.requirePMF = true;
if (!TextUtils.isEmpty(password)) {
config.preSharedKey = '"' + password + '"';
}
break;
case AccessPoint.SECURITY_OWE:
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.OWE);
config.requirePMF = true;
break;
default:
break;
}
return config;
}
use of com.android.settingslib.wifi.AccessPoint in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SavedAccessPointsWifiSettings method initPreferences.
private void initPreferences() {
PreferenceScreen preferenceScreen = getPreferenceScreen();
final Context context = getPrefContext();
final List<AccessPoint> accessPoints = WifiTracker.getCurrentAccessPoints(context, true, false, true);
Collections.sort(accessPoints, new Comparator<AccessPoint>() {
public int compare(AccessPoint ap1, AccessPoint ap2) {
if (ap1.getConfigName() != null) {
return ap1.getConfigName().compareTo(ap2.getConfigName());
} else {
return -1;
}
}
});
preferenceScreen.removeAll();
final int accessPointsSize = accessPoints.size();
for (int i = 0; i < accessPointsSize; ++i) {
LongPressAccessPointPreference preference = new LongPressAccessPointPreference(accessPoints.get(i), context, mUserBadgeCache, true, this);
preference.setIcon(null);
preferenceScreen.addPreference(preference);
}
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 LineageOS.
the class WifiSettings method configureConnectedAccessPointPreferenceCategory.
/**
* Configure the ConnectedAccessPointPreferenceCategory and return true if the Category was
* shown.
*/
private boolean configureConnectedAccessPointPreferenceCategory(List<AccessPoint> accessPoints) {
if (accessPoints.size() == 0) {
removeConnectedAccessPointPreference();
return false;
}
AccessPoint connectedAp = accessPoints.get(0);
if (!connectedAp.isActive()) {
removeConnectedAccessPointPreference();
return false;
}
// Is the preference category empty?
if (mConnectedAccessPointPreferenceCategory.getPreferenceCount() == 0) {
addConnectedAccessPointPreference(connectedAp);
return true;
}
// Is the previous currently connected SSID different from the new one?
AccessPointPreference preference = (AccessPointPreference) (mConnectedAccessPointPreferenceCategory.getPreference(0));
// in the UI.
if (preference.getAccessPoint() != connectedAp) {
removeConnectedAccessPointPreference();
addConnectedAccessPointPreference(connectedAp);
return true;
}
// Else same AP is connected, simply refresh the connected access point preference
// (first and only access point in this category).
((LongPressAccessPointPreference) mConnectedAccessPointPreferenceCategory.getPreference(0)).refresh();
return true;
}
Aggregations