summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src
diff options
context:
space:
mode:
author Sundeep Ghuman <sghuman@google.com> 2017-08-28 17:04:16 -0700
committer Sundeep Ghuman <sghuman@google.com> 2017-09-13 13:23:55 -0700
commit1e98151104022d7dbc1f3d49501f46fe8090d265 (patch)
treecf7715825f7bbf4da6eea073ddd9cb258d6af3dc /packages/SettingsLib/src
parentc6e9bb9da094862eac5206e860df1a1487043deb (diff)
Change score cache eviction time to settings value.
Reduce default eviction time from intended 24 hours (erroneously input as 24 days) to 20 minutes. Bug: b/63073866 Test: runtest --path frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java Change-Id: I89eae2483b9a65a65d7cf5b1151952609b6b7fd7 Merged-In: I89eae2483b9a65a65d7cf5b1151952609b6b7fd7
Diffstat (limited to 'packages/SettingsLib/src')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java31
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java45
2 files changed, 40 insertions, 36 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index 0129c668ae6c..3fd7c392d77c 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -51,7 +51,6 @@ import android.support.annotation.NonNull;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
-import android.text.format.DateUtils;
import android.text.style.TtsSpan;
import android.util.Log;
@@ -133,10 +132,6 @@ public class AccessPoint implements Comparable<AccessPoint> {
*/
private final Map<String, TimestampedScoredNetwork> mScoredNetworkCache = new HashMap<>();
- /** Maximum age in millis of cached scored networks in {@link #mScoredNetworkCache}. */
- @VisibleForTesting static final long MAX_CACHED_SCORE_AGE_MILLIS =
- 24 * DateUtils.DAY_IN_MILLIS;
-
/** Maximum age of scan results to hold onto while actively scanning. **/
private static final long MAX_SCAN_RESULT_AGE_MILLIS = 15000;
@@ -438,13 +433,18 @@ public class AccessPoint implements Comparable<AccessPoint> {
* Updates the AccessPoint rankingScore, metering, and speed, returning true if the data has
* changed.
*
- * @param scoreCache The score cache to use to retrieve scores.
- * @param scoringUiEnabled Whether to show scoring and badging UI.
+ * @param scoreCache The score cache to use to retrieve scores
+ * @param scoringUiEnabled Whether to show scoring and badging UI
+ * @param maxScoreCacheAgeMillis the maximum age in milliseconds of scores to consider when
+ * generating speed labels
*/
- boolean update(WifiNetworkScoreCache scoreCache, boolean scoringUiEnabled) {
+ boolean update(
+ WifiNetworkScoreCache scoreCache,
+ boolean scoringUiEnabled,
+ long maxScoreCacheAgeMillis) {
boolean scoreChanged = false;
if (scoringUiEnabled) {
- scoreChanged = updateScores(scoreCache);
+ scoreChanged = updateScores(scoreCache, maxScoreCacheAgeMillis);
}
return updateMetered(scoreCache) || scoreChanged;
}
@@ -452,15 +452,18 @@ public class AccessPoint implements Comparable<AccessPoint> {
/**
* Updates the AccessPoint rankingScore and speed, returning true if the data has changed.
*
- * <p>Any cached {@link TimestampedScoredNetwork} objects older than
- * {@link #MAX_CACHED_SCORE_AGE_MILLIS} will be removed when this method is invoked.
+ * <p>Any cached {@link TimestampedScoredNetwork} objects older than the given max age in millis
+ * will be removed when this method is invoked.
*
* <p>Precondition: {@link #mRssi} is up to date before invoking this method.
*
- * @param scoreCache The score cache to use to retrieve scores.
+ * @param scoreCache The score cache to use to retrieve scores
+ * @param maxScoreCacheAgeMillis the maximum age in milliseconds of scores to consider when
+ * generating speed labels
+ *
* @return true if the set speed has changed
*/
- private boolean updateScores(WifiNetworkScoreCache scoreCache) {
+ private boolean updateScores(WifiNetworkScoreCache scoreCache, long maxScoreCacheAgeMillis) {
long nowMillis = SystemClock.elapsedRealtime();
for (ScanResult result : mScanResultCache.values()) {
ScoredNetwork score = scoreCache.getScoredNetwork(result);
@@ -478,7 +481,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
}
// Remove old cached networks
- long evictionCutoff = nowMillis - MAX_CACHED_SCORE_AGE_MILLIS;
+ long evictionCutoff = nowMillis - maxScoreCacheAgeMillis;
Iterator<TimestampedScoredNetwork> iterator = mScoredNetworkCache.values().iterator();
iterator.forEachRemaining(timestampedScoredNetwork -> {
if (timestampedScoredNetwork.getUpdatedTimestampMillis() < evictionCutoff) {
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
index a242570d6930..6895550e5108 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
@@ -20,7 +20,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkCapabilities;
@@ -41,6 +40,7 @@ import android.os.Looper;
import android.os.Message;
import android.provider.Settings;
import android.support.annotation.GuardedBy;
+import android.text.format.DateUtils;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
@@ -65,7 +65,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
* Tracks saved or available wifi networks and their state.
*/
public class WifiTracker {
- // TODO(b/36733768): Remove flag includeSaved and includePasspoints.
+ /**
+ * Default maximum age in millis of cached scored networks in
+ * {@link AccessPoint#mScoredNetworkCache} to be used for speed label generation.
+ */
+ private static final long DEFAULT_MAX_CACHED_SCORE_AGE_MILLIS = 20 * DateUtils.MINUTE_IN_MILLIS;
private static final String TAG = "WifiTracker";
private static final boolean DBG() {
@@ -76,6 +80,8 @@ public class WifiTracker {
* and used so as to assist with in-the-field WiFi connectivity debugging */
public static boolean sVerboseLogging;
+ // TODO(b/36733768): Remove flag includeSaved and includePasspoints.
+
// TODO: Allow control of this?
// Combo scans can take 5-6s to complete - set to 10s.
private static final int WIFI_RESCAN_INTERVAL_MS = 10 * 1000;
@@ -138,7 +144,7 @@ public class WifiTracker {
private final NetworkScoreManager mNetworkScoreManager;
private final WifiNetworkScoreCache mScoreCache;
private boolean mNetworkScoringUiEnabled;
- private final ContentObserver mObserver;
+ private long mMaxSpeedLabelScoreCacheAge;
@GuardedBy("mLock")
private final Set<NetworkKey> mRequestedScores = new ArraySet<>();
@@ -229,16 +235,6 @@ public class WifiTracker {
updateNetworkScores();
}
});
-
- mObserver = new ContentObserver(mWorkHandler) {
- @Override
- public void onChange(boolean selfChange) {
- mNetworkScoringUiEnabled =
- Settings.Global.getInt(
- mContext.getContentResolver(),
- Settings.Global.NETWORK_SCORING_UI_ENABLED, 0) == 1;
- }
- };
}
/** Synchronously update the list of access points with the latest information. */
@@ -314,11 +310,16 @@ public class WifiTracker {
synchronized (mLock) {
registerScoreCache();
- mContext.getContentResolver().registerContentObserver(
- Settings.Global.getUriFor(Settings.Global.NETWORK_SCORING_UI_ENABLED),
- false /* notifyForDescendants */,
- mObserver);
- mObserver.onChange(false /* selfChange */); // Set mScoringUiEnabled
+ mNetworkScoringUiEnabled =
+ Settings.Global.getInt(
+ mContext.getContentResolver(),
+ Settings.Global.NETWORK_SCORING_UI_ENABLED, 0) == 1;
+
+ mMaxSpeedLabelScoreCacheAge =
+ Settings.Global.getLong(
+ mContext.getContentResolver(),
+ Settings.Global.SPEED_LABEL_CACHE_EVICTION_AGE_MILLIS,
+ DEFAULT_MAX_CACHED_SCORE_AGE_MILLIS);
resumeScanning();
if (!mRegistered) {
@@ -370,7 +371,6 @@ public class WifiTracker {
}
unregisterScoreCache();
pauseScanning();
- mContext.getContentResolver().unregisterContentObserver(mObserver);
mWorkHandler.removePendingMessages();
mMainHandler.removePendingMessages();
@@ -609,7 +609,7 @@ public class WifiTracker {
requestScoresForNetworkKeys(scoresToRequest);
for (AccessPoint ap : accessPoints) {
- ap.update(mScoreCache, mNetworkScoringUiEnabled);
+ ap.update(mScoreCache, mNetworkScoringUiEnabled, mMaxSpeedLabelScoreCacheAge);
}
// Pre-sort accessPoints to speed preference insertion
@@ -710,7 +710,7 @@ public class WifiTracker {
updated = true;
if (previouslyConnected != ap.isActive()) reorder = true;
}
- if (ap.update(mScoreCache, mNetworkScoringUiEnabled)) {
+ if (ap.update(mScoreCache, mNetworkScoringUiEnabled, mMaxSpeedLabelScoreCacheAge)) {
reorder = true;
updated = true;
}
@@ -744,7 +744,8 @@ public class WifiTracker {
synchronized (mLock) {
boolean updated = false;
for (int i = 0; i < mInternalAccessPoints.size(); i++) {
- if (mInternalAccessPoints.get(i).update(mScoreCache, mNetworkScoringUiEnabled)) {
+ if (mInternalAccessPoints.get(i).update(
+ mScoreCache, mNetworkScoringUiEnabled, mMaxSpeedLabelScoreCacheAge)) {
updated = true;
}
}