diff options
author | Prem Kumar <premk@google.com> | 2014-12-14 20:10:01 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2014-12-14 20:10:01 +0000 |
commit | 572ff423a75a1f19610b500645d9b14523abcde5 (patch) | |
tree | 6729de4296251a72b8ff5dfd13811fe6fc21666d /wifi/java/android | |
parent | c270a1c878d81a77bd4eafd9970860ff93d7b2a9 (diff) | |
parent | da6ebb4ee29fff8b5455cd8b779aaabc029cd3b5 (diff) | |
download | frameworks_base-572ff423a75a1f19610b500645d9b14523abcde5.zip frameworks_base-572ff423a75a1f19610b500645d9b14523abcde5.tar.gz frameworks_base-572ff423a75a1f19610b500645d9b14523abcde5.tar.bz2 |
am fa205fff: am 9ef07ad2: Merge "make sure wificonfiguration scan cache doesnt grow unbounded Bug:18703749" into lmp-mr1-dev
automerge: da6ebb4
* commit 'da6ebb4ee29fff8b5455cd8b779aaabc029cd3b5':
make sure wificonfiguration scan cache doesnt grow unbounded Bug:18703749
Diffstat (limited to 'wifi/java/android')
-rw-r--r-- | wifi/java/android/net/wifi/WifiConfiguration.java | 36 |
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 84da72c..e90e6ed 100644 --- a/wifi/java/android/net/wifi/WifiConfiguration.java +++ b/wifi/java/android/net/wifi/WifiConfiguration.java @@ -983,6 +983,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()); |