Merge "wifi: managed Passpoint configurations in "Saved Networks" page" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
82e2239c54
@@ -20,7 +20,9 @@ import android.app.Dialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.icu.text.Collator;
|
import android.icu.text.Collator;
|
||||||
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.net.wifi.hotspot2.PasspointConfiguration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -110,8 +112,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||||
final Context context = getPrefContext();
|
final Context context = getPrefContext();
|
||||||
|
|
||||||
final List<AccessPoint> accessPoints = WifiTracker.getCurrentAccessPoints(context, true,
|
final List<AccessPoint> accessPoints = getSavedConfigs(context, mWifiManager);
|
||||||
false, true);
|
|
||||||
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
|
Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
|
||||||
preferenceScreen.removeAll();
|
preferenceScreen.removeAll();
|
||||||
|
|
||||||
@@ -129,6 +130,39 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieved the list of saved network configurations from {@link WifiManager}.
|
||||||
|
* Each configuration is represented by {@link AccessPoint}.
|
||||||
|
*
|
||||||
|
* @param context The application context
|
||||||
|
* @param wifiManager An instance of {@link WifiManager}
|
||||||
|
* @return List of {@link AccessPoint}
|
||||||
|
*/
|
||||||
|
private static List<AccessPoint> getSavedConfigs(Context context, WifiManager wifiManager) {
|
||||||
|
List<AccessPoint> savedConfigs = new ArrayList<>();
|
||||||
|
List<WifiConfiguration> savedNetworks = wifiManager.getConfiguredNetworks();
|
||||||
|
for (WifiConfiguration network : savedNetworks) {
|
||||||
|
// Configuration for Passpoint network is configured temporary by WifiService for
|
||||||
|
// connection attempt only. The underlying configuration is saved as Passpoint
|
||||||
|
// configuration, which will be retrieved with WifiManager#getPasspointConfiguration
|
||||||
|
// call below.
|
||||||
|
if (network.isPasspoint()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
savedConfigs.add(new AccessPoint(context, network));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
List<PasspointConfiguration> savedPasspointConfigs =
|
||||||
|
wifiManager.getPasspointConfigurations();
|
||||||
|
for (PasspointConfiguration config : savedPasspointConfigs) {
|
||||||
|
savedConfigs.add(new AccessPoint(context, config));
|
||||||
|
}
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
|
// Passpoint not supported.
|
||||||
|
}
|
||||||
|
return savedConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
private void showDialog(LongPressAccessPointPreference accessPoint, boolean edit) {
|
private void showDialog(LongPressAccessPointPreference accessPoint, boolean edit) {
|
||||||
if (mDialog != null) {
|
if (mDialog != null) {
|
||||||
removeDialog(WifiSettings.WIFI_DIALOG_ID);
|
removeDialog(WifiSettings.WIFI_DIALOG_ID);
|
||||||
@@ -187,7 +221,17 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onForget(WifiDialog dialog) {
|
public void onForget(WifiDialog dialog) {
|
||||||
if (mSelectedAccessPoint != null) {
|
if (mSelectedAccessPoint != null) {
|
||||||
mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId, null);
|
if (mSelectedAccessPoint.isPasspointConfig()) {
|
||||||
|
try {
|
||||||
|
mWifiManager.removePasspointConfiguration(
|
||||||
|
mSelectedAccessPoint.getPasspointFqdn());
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
Log.e(TAG, "Failed to remove Passpoint configuration for "
|
||||||
|
+ mSelectedAccessPoint.getConfigName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mWifiManager.forget(mSelectedAccessPoint.getConfig().networkId, null);
|
||||||
|
}
|
||||||
mSelectedAccessPoint = null;
|
mSelectedAccessPoint = null;
|
||||||
initPreferences();
|
initPreferences();
|
||||||
}
|
}
|
||||||
@@ -235,8 +279,8 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
|
|||||||
result.add(data);
|
result.add(data);
|
||||||
|
|
||||||
// Add available Wi-Fi access points
|
// Add available Wi-Fi access points
|
||||||
final List<AccessPoint> accessPoints = WifiTracker.getCurrentAccessPoints(context,
|
final List<AccessPoint> accessPoints =
|
||||||
true, false, true);
|
getSavedConfigs(context, context.getSystemService(WifiManager.class));
|
||||||
|
|
||||||
final int accessPointsSize = accessPoints.size();
|
final int accessPointsSize = accessPoints.size();
|
||||||
for (int i = 0; i < accessPointsSize; ++i){
|
for (int i = 0; i < accessPointsSize; ++i){
|
||||||
|
@@ -217,7 +217,11 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
|
|
||||||
mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
|
mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
|
||||||
} else {
|
} else {
|
||||||
mConfigUi.setTitle(mAccessPoint.getSsid());
|
if (!mAccessPoint.isPasspointConfig()) {
|
||||||
|
mConfigUi.setTitle(mAccessPoint.getSsid());
|
||||||
|
} else {
|
||||||
|
mConfigUi.setTitle(mAccessPoint.getConfigName());
|
||||||
|
}
|
||||||
|
|
||||||
ViewGroup group = (ViewGroup) mView.findViewById(R.id.info);
|
ViewGroup group = (ViewGroup) mView.findViewById(R.id.info);
|
||||||
|
|
||||||
@@ -258,7 +262,8 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!mAccessPoint.isSaved() && !mAccessPoint.isActive())
|
if ((!mAccessPoint.isSaved() && !mAccessPoint.isActive()
|
||||||
|
&& !mAccessPoint.isPasspointConfig())
|
||||||
|| mMode != WifiConfigUiBase.MODE_VIEW) {
|
|| mMode != WifiConfigUiBase.MODE_VIEW) {
|
||||||
showSecurityFields();
|
showSecurityFields();
|
||||||
showIpConfigFields();
|
showIpConfigFields();
|
||||||
@@ -326,7 +331,8 @@ public class WifiConfigController implements TextWatcher,
|
|||||||
addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
|
addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
|
||||||
mView.findViewById(R.id.ip_fields).setVisibility(View.GONE);
|
mView.findViewById(R.id.ip_fields).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (mAccessPoint.isSaved() || mAccessPoint.isActive()) {
|
if (mAccessPoint.isSaved() || mAccessPoint.isActive()
|
||||||
|
|| mAccessPoint.isPasspointConfig()) {
|
||||||
mConfigUi.setForgetButton(res.getString(R.string.wifi_forget));
|
mConfigUi.setForgetButton(res.getString(R.string.wifi_forget));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user