diff options
author | Michael Plass <mplass@google.com> | 2018-05-10 14:57:56 -0700 |
---|---|---|
committer | Michael Plass <mplass@google.com> | 2018-05-21 12:36:28 -0700 |
commit | a332e6d65efbee41e08b86d56394db4431ca6e86 (patch) | |
tree | a051fa41513e03bfa8b023b3d4b26349974cb9de | |
parent | 0e5fc47e8d6585855927fe8485c924cce2c5c4f7 (diff) |
WifiMetrics score experiment id
Bug: 79482323
Test: Unit tests
Test: adb shell dumpsys wifi | grep -10 scoreExperimentId
Test: adb shell settings put global wifi_score_params expid=99
Test: adb shell dumpsys wifi | grep -10 scoreExperimentId
Test: adb shell settings delete global wifi_score_params
Test: adb shell dumpsys wifi | grep -10 scoreExperimentId
Change-Id: Ib74de2dc23aa689e64662406738f0a24cf76366f
3 files changed, 50 insertions, 1 deletions
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/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; |