OSDN Git Service

wifi: managed Passpoint configurations in "Saved Networks" page
authorPeter Qiu <zqiu@google.com>
Tue, 14 Mar 2017 22:53:20 +0000 (15:53 -0700)
committerPeter Qiu <zqiu@google.com>
Wed, 29 Mar 2017 20:57:32 +0000 (13:57 -0700)
Instead of going through WifiTracker to retrieve saved network
configurations (including both WiFi networks and Passpoint provider
configurations), use the WifiManager's APIs to retrieve the
configurations directly, to avoid any unnecessary complexities.

Also update to use the appropriate APIs for configuration removal
based on the configuration type.

Bug: 34207710
Test: manual test by removing a Passpoint configuration from
      "Saved Networks" page.

Change-Id: I549cc484d8825b6c38895428c1b7941390bb5f1f

src/com/android/settings/wifi/SavedAccessPointsWifiSettings.java
src/com/android/settings/wifi/WifiConfigController.java

index b9ffcaf..07495ee 100644 (file)
@@ -20,7 +20,9 @@ import android.app.Dialog;
 import android.content.Context;
 import android.content.res.Resources;
 import android.icu.text.Collator;
+import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiManager;
+import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.os.Bundle;
 import android.provider.SearchIndexableResource;
 import android.support.v7.preference.Preference;
@@ -110,8 +112,7 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
         PreferenceScreen preferenceScreen = getPreferenceScreen();
         final Context context = getPrefContext();
 
-        final List<AccessPoint> accessPoints = WifiTracker.getCurrentAccessPoints(context, true,
-                false, true);
+        final List<AccessPoint> accessPoints = getSavedConfigs(context, mWifiManager);
         Collections.sort(accessPoints, SAVED_NETWORK_COMPARATOR);
         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) {
         if (mDialog != null) {
             removeDialog(WifiSettings.WIFI_DIALOG_ID);
@@ -187,7 +221,17 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
     @Override
     public void onForget(WifiDialog dialog) {
         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;
             initPreferences();
         }
@@ -235,8 +279,8 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
                 result.add(data);
 
                 // Add available Wi-Fi access points
-                final List<AccessPoint> accessPoints = WifiTracker.getCurrentAccessPoints(context,
-                        true, false, true);
+                final List<AccessPoint> accessPoints =
+                        getSavedConfigs(context, context.getSystemService(WifiManager.class));
 
                 final int accessPointsSize = accessPoints.size();
                 for (int i = 0; i < accessPointsSize; ++i){
index 460d210..4380cbe 100644 (file)
@@ -217,7 +217,11 @@ public class WifiConfigController implements TextWatcher,
 
             mConfigUi.setSubmitButton(res.getString(R.string.wifi_save));
         } 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);
 
@@ -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) {
                 showSecurityFields();
                 showIpConfigFields();
@@ -326,7 +331,8 @@ public class WifiConfigController implements TextWatcher,
                     addRow(group, R.string.wifi_security, mAccessPoint.getSecurityString(false));
                     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));
                 }
             }