diff options
-rw-r--r-- | service/java/com/android/server/wifi/VelocityBasedConnectedScore.java | 4 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/VelocityBasedConnectedScoreTest.java | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java b/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java index e7d61f733..71f18fc7e 100644 --- a/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java +++ b/service/java/com/android/server/wifi/VelocityBasedConnectedScore.java @@ -63,6 +63,7 @@ public class VelocityBasedConnectedScore extends ConnectedScore { public void reset() { mLastMillis = 0; mThresholdAdjustment = 0; + mFilter.mx = null; } /** @@ -78,7 +79,7 @@ public class VelocityBasedConnectedScore extends ConnectedScore { @Override public void updateUsingRssi(int rssi, long millis, double standardDeviation) { if (millis <= 0) return; - if (mLastMillis <= 0 || millis < mLastMillis) { + if (mLastMillis <= 0 || millis < mLastMillis || mFilter.mx == null) { double initialVariance = 9.0 * standardDeviation * standardDeviation; mFilter.mx = new Matrix(1, new double[]{rssi, 0.0}); mFilter.mP = new Matrix(2, new double[]{initialVariance, 0.0, 0.0, 0.0}); @@ -167,6 +168,7 @@ public class VelocityBasedConnectedScore extends ConnectedScore { */ @Override public int generateScore() { + if (mFilter.mx == null) return WIFI_TRANSITION_SCORE + 1; double badRssi = getAdjustedRssiThreshold(); double horizonSeconds = mScoringParams.getHorizonSeconds(); Matrix x = new Matrix(mFilter.mx); diff --git a/tests/wifitests/src/com/android/server/wifi/VelocityBasedConnectedScoreTest.java b/tests/wifitests/src/com/android/server/wifi/VelocityBasedConnectedScoreTest.java index 0d5f5efa6..f4fa2b8b0 100644 --- a/tests/wifitests/src/com/android/server/wifi/VelocityBasedConnectedScoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/VelocityBasedConnectedScoreTest.java @@ -91,6 +91,17 @@ public class VelocityBasedConnectedScoreTest { } /** + * Generate a score with no updates + * + * Expect no crash, passing score + */ + @Test + public void noCrashWhenNoData() throws Exception { + int score = mVelocityBasedConnectedScore.generateScore(); + assertTrue(score > ConnectedScore.WIFI_TRANSITION_SCORE); + } + + /** * * Low RSSI, but some data is moving and error rate is low. * |