diff options
5 files changed, 88 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/ScoringParams.java b/service/java/com/android/server/wifi/ScoringParams.java index 5b9951ff8..8f68627b7 100644 --- a/service/java/com/android/server/wifi/ScoringParams.java +++ b/service/java/com/android/server/wifi/ScoringParams.java @@ -70,6 +70,12 @@ public class ScoringParams { public static final int MAX_NUD = 10; public int nud = 8; + /** Experiment identifier */ + public static final String KEY_EXPID = "expid"; + public static final int MIN_EXPID = 0; + public static final int MAX_EXPID = Integer.MAX_VALUE; + public int expid = 0; + Values() { } @@ -85,6 +91,7 @@ public class ScoringParams { } horizon = source.horizon; nud = source.nud; + expid = source.expid; } public void validate() throws IllegalArgumentException { @@ -93,6 +100,7 @@ public class ScoringParams { validateOrderedNonNegativeArray(pps); validateRange(horizon, MIN_HORIZON, MAX_HORIZON); validateRange(nud, MIN_NUD, MAX_NUD); + validateRange(expid, MIN_EXPID, MAX_EXPID); } private void validateRssiArray(int[] rssi) throws IllegalArgumentException { @@ -131,6 +139,7 @@ public class ScoringParams { updateIntArray(pps, parser, KEY_PPS); horizon = updateInt(parser, KEY_HORIZON, horizon); nud = updateInt(parser, KEY_NUD, nud); + expid = updateInt(parser, KEY_EXPID, expid); } private int updateInt(KeyValueListParser parser, String key, int defaultValue) @@ -168,6 +177,8 @@ public class ScoringParams { sb.append(horizon); appendKey(sb, KEY_NUD); sb.append(nud); + appendKey(sb, KEY_EXPID); + sb.append(expid); return sb.toString(); } @@ -352,6 +363,15 @@ public class ScoringParams { return mVal.nud; } + /** + * Returns the experiment identifier. + * + * This value may be used to tag a set of experimental settings. + */ + public int getExperimentIdentifier() { + return mVal.expid; + } + private static final int MINIMUM_5GHZ_BAND_FREQUENCY_IN_MEGAHERTZ = 5000; private int[] getRssiArray(int frequency) { diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index 358abd546..0e30af841 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -230,6 +230,7 @@ public class WifiInjector { mConnectivityLocalLog = new LocalLog(ActivityManager.isLowRamDeviceStatic() ? 256 : 512); mScoringParams = new ScoringParams(mContext, mFrameworkFacade, new Handler(wifiStateMachineLooper)); + mWifiMetrics.setScoringParams(mScoringParams); mWifiNetworkSelector = new WifiNetworkSelector(mContext, mScoringParams, mWifiConfigManager, mClock, mConnectivityLocalLog); diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 3097658d3..39266a638 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -109,6 +109,7 @@ public class WifiMetrics { private final PnoScanMetrics mPnoScanMetrics = new PnoScanMetrics(); private final WpsMetrics mWpsMetrics = new WpsMetrics(); private Handler mHandler; + private ScoringParams mScoringParams; private WifiConfigManager mWifiConfigManager; private WifiNetworkSelector mWifiNetworkSelector; private PasspointManager mPasspointManager; @@ -452,6 +453,11 @@ public class WifiMetrics { }; } + /** Sets internal ScoringParams member */ + public void setScoringParams(ScoringParams scoringParams) { + mScoringParams = scoringParams; + } + /** Sets internal WifiConfigManager member */ public void setWifiConfigManager(WifiConfigManager wifiConfigManager) { mWifiConfigManager = wifiConfigManager; @@ -1770,10 +1776,11 @@ public class WifiMetrics { * * @param fd unused * @param pw PrintWriter for writing dump to - * @param args unused + * @param args [wifiMetricsProto [clean]] */ public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { synchronized (mLock) { + consolidateScoringParams(); if (args != null && args.length > 0 && PROTO_DUMP_ARG.equals(args[0])) { // Dump serialized WifiLog proto consolidateProto(true); @@ -2116,6 +2123,7 @@ public class WifiMetrics { mWifiWakeMetrics.dump(pw); pw.println("mWifiLogProto.isMacRandomizationOn=" + mIsMacRandomizationOn); + pw.println("mWifiLogProto.scoreExperimentId=" + mWifiLogProto.scoreExperimentId); } } } @@ -2411,6 +2419,20 @@ public class WifiMetrics { } } + /** Sets the scoring experiment id to current value */ + private void consolidateScoringParams() { + synchronized (mLock) { + if (mScoringParams != null) { + int experimentIdentifier = mScoringParams.getExperimentIdentifier(); + if (experimentIdentifier == 0) { + mWifiLogProto.scoreExperimentId = ""; + } else { + mWifiLogProto.scoreExperimentId = "x" + experimentIdentifier; + } + } + } + } + private WifiMetricsProto.NumConnectableNetworksBucket[] makeNumConnectableNetworksBucketArray( SparseIntArray sia) { WifiMetricsProto.NumConnectableNetworksBucket[] array = diff --git a/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java b/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java index fc9b33ad2..56dca114a 100644 --- a/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ScoringParamsTest.java @@ -49,7 +49,10 @@ import org.mockito.Spy; @SmallTest public class ScoringParamsTest { - ScoringParams mScoringParams; + private static final String EXPECTED_DEFAULTS = + "rssi2=-83:-80:-73:-60,rssi5=-80:-77:-70:-57,pps=0:1:100,horizon=15,nud=8,expid=0"; + + private ScoringParams mScoringParams; /** * Sets up for unit test @@ -93,8 +96,7 @@ public class ScoringParamsTest { @Test public void testToString() throws Exception { mScoringParams = new ScoringParams(); - String expect = - "rssi2=-83:-80:-73:-60,rssi5=-80:-77:-70:-57,pps=0:1:100,horizon=15,nud=8"; + String expect = EXPECTED_DEFAULTS; String actual = mScoringParams.toString(); assertEquals(expect, actual); } @@ -105,8 +107,7 @@ public class ScoringParamsTest { @Test public void testUpdateEverything() throws Exception { mScoringParams = new ScoringParams(); - String params = - "rssi2=-86:-84:-77:-10,rssi5=-88:-77:-66:-55,pps=1:10:30,horizon=3,nud=3"; + String params = EXPECTED_DEFAULTS.replaceAll("8", "9"); assertTrue(mScoringParams.update(params)); assertEquals(params, mScoringParams.toString()); } @@ -200,6 +201,17 @@ public class ScoringParamsTest { } /** + * Test that expid is hooked up + */ + @Test + public void testExperimentIdentifier() throws Exception { + mScoringParams = new ScoringParams(); + assertEquals(0, mScoringParams.getExperimentIdentifier()); + assertTrue(mScoringParams.update("expid=99")); + assertEquals(99, mScoringParams.getExperimentIdentifier()); + } + + /** * Check character set */ @Test @@ -225,6 +237,7 @@ public class ScoringParamsTest { assertEquals(param100.substring(0, 90), mScoringParams.sanitize(param100 + "00000000000").substring(0, 90)); assertEquals("q?=???", mScoringParams.sanitize("q\b= ~[")); + assertEquals("", mScoringParams.sanitize(null)); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 3e267196e..9682750d2 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -72,6 +72,7 @@ public class WifiMetricsTest { WifiMetricsProto.WifiLog mDecodedProto; TestLooper mTestLooper; @Mock Clock mClock; + @Mock ScoringParams mScoringParams; @Mock WifiConfigManager mWcm; @Mock PasspointManager mPpm; @Mock WifiNetworkSelector mWns; @@ -86,6 +87,7 @@ public class WifiMetricsTest { new WifiAwareMetrics(mClock), new RttMetrics(mClock)); mWifiMetrics.setWifiConfigManager(mWcm); mWifiMetrics.setPasspointManager(mPpm); + mWifiMetrics.setScoringParams(mScoringParams); mWifiMetrics.setWifiNetworkSelector(mWns); } @@ -1737,6 +1739,30 @@ public class WifiMetricsTest { assertEquals(0, mDecodedProto.numOpenNetworkRecommendationUpdates); } + /** + * Check ScoringParams + */ + @Test + public void testExperimentId() throws Exception { + final int id = 42; + final String expectId = "x" + id; + when(mScoringParams.getExperimentIdentifier()).thenReturn(id); + dumpProtoAndDeserialize(); + assertEquals(expectId, mDecodedProto.scoreExperimentId); + } + + /** + * Check ScoringParams default case + */ + @Test + public void testDefaultExperimentId() throws Exception { + final int id = 0; + final String expectId = ""; + when(mScoringParams.getExperimentIdentifier()).thenReturn(id); + dumpProtoAndDeserialize(); + assertEquals(expectId, mDecodedProto.scoreExperimentId); + } + /** short hand for instantiating an anonymous int array, instead of 'new int[]{a1, a2, ...}' */ private int[] a(int... element) { return element; |