summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIsaac Levy <ilevy@google.com>2011-08-24 16:48:27 -0700
committerIsaac Levy <ilevy@google.com>2011-08-25 19:31:20 -0700
commitfdac5bae251bd0b569c38aa8575b89ba0895911c (patch)
tree0a326e9da20a86a0be351067614a20db744fd178 /src
parent2aaf687aa6b92b193f6716ab9d057ea439804402 (diff)
downloadpackages_apps_Settings-fdac5bae251bd0b569c38aa8575b89ba0895911c.zip
packages_apps_Settings-fdac5bae251bd0b569c38aa8575b89ba0895911c.tar.gz
packages_apps_Settings-fdac5bae251bd0b569c38aa8575b89ba0895911c.tar.bz2
Speeding up WifiSettings AP list printout
Change-Id: Idc82ba7320469e05984ba6ac9f7d2cf927dfaa00
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/wifi/WifiSettings.java53
1 files changed, 41 insertions, 12 deletions
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 188765f..5eec6e3 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -49,12 +49,10 @@ import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity;
-import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.Switch;
import android.widget.TextView;
@@ -66,6 +64,8 @@ import com.android.settings.SettingsPreferenceFragment;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -92,6 +92,9 @@ public class WifiSettings extends SettingsPreferenceFragment
private static final int WIFI_DIALOG_ID = 1;
+ // Combo scans can take 5-6s to complete - set to 10s.
+ private static final int WIFI_RESCAN_INTERVAL_MS = 10 * 1000;
+
// Instance state keys
private static final String SAVE_DIALOG_EDIT_MODE = "edit_mode";
private static final String SAVE_DIALOG_ACCESS_POINT_STATE = "wifi_ap_state";
@@ -451,9 +454,9 @@ public class WifiSettings extends SettingsPreferenceFragment
switch (wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
- getPreferenceScreen().removeAll();
// AccessPoints are automatically sorted with TreeSet.
final Collection<AccessPoint> accessPoints = constructAccessPoints();
+ getPreferenceScreen().removeAll();
if (mInXlSetupWizard) {
((WifiSettingsForSetupWizardXL)getActivity()).onAccessPointsUpdated(
getPreferenceScreen(), accessPoints);
@@ -483,8 +486,12 @@ public class WifiSettings extends SettingsPreferenceFragment
getPreferenceScreen().removeAll();
}
- private Collection<AccessPoint> constructAccessPoints() {
- Collection<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
+ /** Returns sorted list of access points */
+ private List<AccessPoint> constructAccessPoints() {
+ ArrayList<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
+ /** Lookup table to more quickly update AccessPoints by only considering objects with the
+ * correct SSID. Maps SSID -> List of AccessPoints with the given SSID. */
+ Multimap<String, AccessPoint> apMap = new Multimap<String, AccessPoint>();
final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
if (configs != null) {
@@ -492,6 +499,7 @@ public class WifiSettings extends SettingsPreferenceFragment
AccessPoint accessPoint = new AccessPoint(getActivity(), config);
accessPoint.update(mLastInfo, mLastState);
accessPoints.add(accessPoint);
+ apMap.put(accessPoint.ssid, accessPoint);
}
}
@@ -505,21 +513,43 @@ public class WifiSettings extends SettingsPreferenceFragment
}
boolean found = false;
- for (AccessPoint accessPoint : accessPoints) {
- if (accessPoint.update(result)) {
- found = true;
- break;
+ if (apMap.getAll(result.SSID) != null) {
+ for (AccessPoint accessPoint : apMap.getAll(result.SSID)) {
+ if (accessPoint.update(result))
+ found = true;
}
}
if (!found) {
- accessPoints.add(new AccessPoint(getActivity(), result));
+ AccessPoint accessPoint = new AccessPoint(getActivity(), result);
+ accessPoints.add(accessPoint);
+ apMap.put(accessPoint.ssid, accessPoint);
}
}
}
+ //
+ Collections.sort(accessPoints);
return accessPoints;
}
+ /** A restricted multimap for use in constructAccessPoints */
+ private class Multimap<K,V> {
+ private HashMap<K,List<V>> store = new HashMap<K,List<V>>();
+ /** retrieve a possibly null list of values with key K */
+ List<V> getAll(K key) {
+ return store.get(key);
+ }
+
+ void put(K key, V val) {
+ List<V> curVals = store.get(key);
+ if (curVals == null) {
+ curVals = new ArrayList<V>(3);
+ store.put(key, curVals);
+ }
+ curVals.add(val);
+ }
+ }
+
private void handleEvent(Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
@@ -647,8 +677,7 @@ public class WifiSettings extends SettingsPreferenceFragment
Toast.LENGTH_LONG).show();
return;
}
- // Combo scans can take 5-6s to complete. Increase interval to 10s.
- sendEmptyMessageDelayed(0, 10000);
+ sendEmptyMessageDelayed(0, WIFI_RESCAN_INTERVAL_MS);
}
}