summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorvandwalle <vandwalle@google.com>2014-12-10 13:25:47 -0800
committervandwalle <vandwalle@google.com>2014-12-11 02:58:44 -0800
commit53d1f0707323428edf9ec00da4ca98eeb1b5c092 (patch)
tree991b62da908e17f4ba2c464af69f6468aa7782cb /wifi
parentb713a7686e0ed1e14318f82a03bc611ac0050516 (diff)
downloadframeworks_base-53d1f0707323428edf9ec00da4ca98eeb1b5c092.zip
frameworks_base-53d1f0707323428edf9ec00da4ca98eeb1b5c092.tar.gz
frameworks_base-53d1f0707323428edf9ec00da4ca98eeb1b5c092.tar.bz2
make sure wificonfiguration scan cache doesnt grow unbounded
Bug:18703749 Change-Id: I8e35d602a80b341668d9607db2da3ca6fdb970ae
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiConfiguration.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfiguration.java b/wifi/java/android/net/wifi/WifiConfiguration.java
index 0457dda..12902bd 100644
--- a/wifi/java/android/net/wifi/WifiConfiguration.java
+++ b/wifi/java/android/net/wifi/WifiConfiguration.java
@@ -927,6 +927,42 @@ public class WifiConfiguration implements Parcelable {
}
}
+ /** @hide
+ * trim the scan Result Cache
+ * @param: number of entries to keep in the cache
+ */
+ public void trimScanResultsCache(int num) {
+ if (this.scanResultCache == null) {
+ return;
+ }
+ int currenSize = this.scanResultCache.size();
+ if (currenSize <= num) {
+ return; // Nothing to trim
+ }
+ ArrayList<ScanResult> list = new ArrayList<ScanResult>(this.scanResultCache.values());
+ if (list.size() != 0) {
+ // Sort by descending timestamp
+ Collections.sort(list, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ ScanResult a = (ScanResult)o1;
+ ScanResult b = (ScanResult)o2;
+ if (a.seen > b.seen) {
+ return 1;
+ }
+ if (a.seen < b.seen) {
+ return -1;
+ }
+ return a.BSSID.compareTo(b.BSSID);
+ }
+ });
+ }
+ for (int i = 0; i < currenSize - num ; i++) {
+ // Remove oldest results from scan cache
+ ScanResult result = list.get(i);
+ this.scanResultCache.remove(result.BSSID);
+ }
+ }
+
/* @hide */
private ArrayList<ScanResult> sortScanResults() {
ArrayList<ScanResult> list = new ArrayList<ScanResult>(this.scanResultCache.values());