diff options
author | Pankaj Kanwar <pkanwar@google.com> | 2018-01-24 23:02:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-01-24 23:02:22 +0000 |
commit | c551268ce17feba758a68fa9f24f7314bc1e6c1f (patch) | |
tree | 74bf90e83399f57e1e73fb038b319b9ce29212ae | |
parent | bb3272b409d725dc1aada2cb871f78423ac37c48 (diff) | |
parent | 929c521de00d91d269d2d4cad613904c76c366a1 (diff) |
Merge "Metrics for connected wifi score" into oc-mr1-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiMetrics.java | 34 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java | 32 |
2 files changed, 62 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 7254ad485..a8ad08c65 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -31,6 +31,7 @@ import android.util.Log; import android.util.Pair; import android.util.SparseIntArray; +import com.android.internal.annotations.VisibleForTesting; import com.android.server.wifi.aware.WifiAwareMetrics; import com.android.server.wifi.hotspot2.ANQPNetworkKey; import com.android.server.wifi.hotspot2.NetworkDetail; @@ -80,6 +81,8 @@ public class WifiMetrics { public static final long TIMEOUT_RSSI_DELTA_MILLIS = 3000; private static final int MIN_WIFI_SCORE = 0; private static final int MAX_WIFI_SCORE = NetworkAgent.WIFI_BASE_SCORE; + @VisibleForTesting + static final int LOW_WIFI_SCORE = 50; // Mobile data score private final Object mLock = new Object(); private static final int MAX_CONNECTION_EVENTS = 256; // Largest bucket in the NumConnectableNetworkCount histogram, @@ -1055,10 +1058,14 @@ public class WifiMetrics { } } + private boolean mWifiWins = false; // Based on scores, use wifi instead of mobile data? + /** * Increments occurence of a particular wifi score calculated * in WifiScoreReport by current connected network. Scores are bounded - * within [MIN_WIFI_SCORE, MAX_WIFI_SCORE] to limit size of SparseArray + * within [MIN_WIFI_SCORE, MAX_WIFI_SCORE] to limit size of SparseArray. + * + * Also records events when the current score breaches significant thresholds. */ public void incrementWifiScoreCount(int score) { if (score < MIN_WIFI_SCORE || score > MAX_WIFI_SCORE) { @@ -1067,6 +1074,20 @@ public class WifiMetrics { synchronized (mLock) { int count = mWifiScoreCounts.get(score); mWifiScoreCounts.put(score, count + 1); + + boolean wifiWins = mWifiWins; + if (mWifiWins && score < LOW_WIFI_SCORE) { + wifiWins = false; + } else if (!mWifiWins && score > LOW_WIFI_SCORE) { + wifiWins = true; + } + mLastScore = score; + if (wifiWins != mWifiWins) { + mWifiWins = wifiWins; + StaEvent event = new StaEvent(); + event.type = StaEvent.TYPE_SCORE_BREACH; + addStaEvent(event); + } } } @@ -1984,6 +2005,7 @@ public class WifiMetrics { public void setWifiState(int wifiState) { synchronized (mLock) { mWifiState = wifiState; + mWifiWins = (wifiState == WifiMetricsProto.WifiLog.WIFI_ASSOCIATED); } } @@ -2089,6 +2111,7 @@ public class WifiMetrics { case StaEvent.TYPE_CONNECT_NETWORK: case StaEvent.TYPE_NETWORK_AGENT_VALID_NETWORK: case StaEvent.TYPE_FRAMEWORK_DISCONNECT: + case StaEvent.TYPE_SCORE_BREACH: break; default: Log.e(TAG, "Unknown StaEvent:" + type); @@ -2109,10 +2132,12 @@ public class WifiMetrics { staEvent.lastFreq = mLastPollFreq; staEvent.lastLinkSpeed = mLastPollLinkSpeed; staEvent.supplicantStateChangesBitmask = mSupplicantStateChangeBitmask; + staEvent.lastScore = mLastScore; mSupplicantStateChangeBitmask = 0; mLastPollRssi = -127; mLastPollFreq = -1; mLastPollLinkSpeed = -1; + mLastScore = -1; mStaEventList.add(new StaEventWithTime(staEvent, mClock.getWallClockMillis())); // Prune StaEventList if it gets too long if (mStaEventList.size() > MAX_STA_EVENTS) mStaEventList.remove(); @@ -2268,6 +2293,9 @@ public class WifiMetrics { .append(" reason=") .append(frameworkDisconnectReasonToString(event.frameworkDisconnectReason)); break; + case StaEvent.TYPE_SCORE_BREACH: + sb.append("SCORE_BREACH"); + break; default: sb.append("UNKNOWN " + event.type + ":"); break; @@ -2275,6 +2303,7 @@ public class WifiMetrics { if (event.lastRssi != -127) sb.append(" lastRssi=").append(event.lastRssi); if (event.lastFreq != -1) sb.append(" lastFreq=").append(event.lastFreq); if (event.lastLinkSpeed != -1) sb.append(" lastLinkSpeed=").append(event.lastLinkSpeed); + if (event.lastScore != -1) sb.append(" lastScore=").append(event.lastScore); if (event.supplicantStateChangesBitmask != 0) { sb.append(", ").append(supplicantStateChangesBitmaskToString( event.supplicantStateChangesBitmask)); @@ -2337,11 +2366,12 @@ public class WifiMetrics { return sb.toString(); } - public static final int MAX_STA_EVENTS = 512; + public static final int MAX_STA_EVENTS = 768; private LinkedList<StaEventWithTime> mStaEventList = new LinkedList<StaEventWithTime>(); private int mLastPollRssi = -127; private int mLastPollLinkSpeed = -1; private int mLastPollFreq = -1; + private int mLastScore = -1; /** * Converts the first 31 bits of a BitSet to a little endian int diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index a07054abc..c6a06e882 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -782,6 +782,31 @@ public class WifiMetricsTest { // pending their implementation</TODO> } + /** + * Test that score breach events are properly generated + */ + @Test + public void testScoreBeachEvents() throws Exception { + int upper = WifiMetrics.LOW_WIFI_SCORE + 7; + int mid = WifiMetrics.LOW_WIFI_SCORE; + int lower = WifiMetrics.LOW_WIFI_SCORE - 8; + mWifiMetrics.setWifiState(WifiMetricsProto.WifiLog.WIFI_ASSOCIATED); + for (int score = upper; score >= mid; score--) mWifiMetrics.incrementWifiScoreCount(score); + mWifiMetrics.incrementWifiScoreCount(mid + 1); + mWifiMetrics.incrementWifiScoreCount(lower); // First breach + for (int score = lower; score <= mid; score++) mWifiMetrics.incrementWifiScoreCount(score); + mWifiMetrics.incrementWifiScoreCount(mid - 1); + mWifiMetrics.incrementWifiScoreCount(upper); // Second breach + + dumpProtoAndDeserialize(); + + assertEquals(2, mDecodedProto.staEventList.length); + assertEquals(StaEvent.TYPE_SCORE_BREACH, mDecodedProto.staEventList[0].type); + assertEquals(lower, mDecodedProto.staEventList[0].lastScore); + assertEquals(StaEvent.TYPE_SCORE_BREACH, mDecodedProto.staEventList[1].type); + assertEquals(upper, mDecodedProto.staEventList[1].lastScore); + } + private static final String SSID = "red"; private static final int CONFIG_DTIM = 3; private static final int NETWORK_DETAIL_WIFIMODE = 5; @@ -1060,7 +1085,7 @@ public class WifiMetricsTest { private static final int ASSOC_TIMEOUT = 1; private static final int LOCAL_GEN = 1; private static final int AUTH_FAILURE_REASON = WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD; - private static final int NUM_TEST_STA_EVENTS = 14; + private static final int NUM_TEST_STA_EVENTS = 15; private static final String sSSID = "\"SomeTestSsid\""; private static final WifiSsid sWifiSsid = WifiSsid.createFromAsciiEncoded(sSSID); private static final String sBSSID = "01:02:03:04:05:06"; @@ -1108,7 +1133,8 @@ public class WifiMetricsTest { {StaEvent.TYPE_CMD_START_ROAM, 0, 1}, {StaEvent.TYPE_CONNECT_NETWORK, 0, 1}, {StaEvent.TYPE_NETWORK_AGENT_VALID_NETWORK, 0, 0}, - {StaEvent.TYPE_FRAMEWORK_DISCONNECT, StaEvent.DISCONNECT_API, 0} + {StaEvent.TYPE_FRAMEWORK_DISCONNECT, StaEvent.DISCONNECT_API, 0}, + {StaEvent.TYPE_SCORE_BREACH, 0, 0} }; // Values used to generate the StaEvent log calls from WifiMonitor // <type>, <reason>, <status>, <local_gen>, @@ -1141,6 +1167,8 @@ public class WifiMetricsTest { {StaEvent.TYPE_NETWORK_AGENT_VALID_NETWORK, -1, -1, 0, /**/ 0, 0, 0, 0}, /**/ {StaEvent.TYPE_FRAMEWORK_DISCONNECT, -1, -1, 0, + /**/ 0, 0, 0, 0}, /**/ + {StaEvent.TYPE_SCORE_BREACH, -1, -1, 0, /**/ 0, 0, 0, 0} /**/ }; |