diff options
4 files changed, 100 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 6cd1ad3ce..86b881951 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -899,6 +899,15 @@ public class WifiMetrics { } /** + * Increment the count of oneshot scans that include DFS channels. + */ + public void incrementOneshotScanWithDfsCount() { + synchronized (mLock) { + mWifiLogProto.numOneshotHasDfsChannelScans++; + } + } + + /** * Increment connectivity oneshot scan count. */ public void incrementConnectivityOneshotScanCount() { @@ -926,6 +935,15 @@ public class WifiMetrics { } /** + * Get the count of oneshot scan requests that included DFS channels. + */ + public int getOneshotScanWithDfsCount() { + synchronized (mLock) { + return mWifiLogProto.numOneshotHasDfsChannelScans; + } + } + + /** * Increment oneshot scan count for external apps. */ public void incrementExternalAppOneshotScanRequestsCount() { @@ -1945,6 +1963,8 @@ public class WifiMetrics { + mWifiLogProto.numConnectivityOneshotScans); pw.println("mWifiLogProto.numOneshotScans=" + mWifiLogProto.numOneshotScans); + pw.println("mWifiLogProto.numOneshotHasDfsChannelScans=" + + mWifiLogProto.numOneshotHasDfsChannelScans); pw.println("mWifiLogProto.numBackgroundScans=" + mWifiLogProto.numBackgroundScans); pw.println("mWifiLogProto.numExternalAppOneshotScanRequests=" diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index d2c4d5af8..ce02ffd6c 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -601,7 +601,6 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { // Ignore if we're already in driver loaded state. return HANDLED; case WifiScanner.CMD_START_SINGLE_SCAN: - mWifiMetrics.incrementOneshotScanCount(); int handler = msg.arg2; Bundle scanParams = (Bundle) msg.obj; if (scanParams == null) { @@ -615,6 +614,12 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { WorkSource workSource = scanParams.getParcelable(WifiScanner.SCAN_PARAMS_WORK_SOURCE_KEY); if (validateScanRequest(ci, handler, scanSettings)) { + mWifiMetrics.incrementOneshotScanCount(); + if (scanSettings.band == WifiScanner.WIFI_BAND_5_GHZ_DFS_ONLY + || scanSettings.band == WifiScanner.WIFI_BAND_5_GHZ_WITH_DFS + || scanSettings.band == WifiScanner.WIFI_BAND_BOTH_WITH_DFS) { + mWifiMetrics.incrementOneshotScanWithDfsCount(); + } logScanRequest("addSingleScanRequest", ci, handler, workSource, scanSettings, null); replySucceeded(msg); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 579dca606..1077eafc6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -311,6 +311,7 @@ public class WifiMetricsTest { private static final int DATA_STALL_MIN_TX_BAD_SETTING = 5; private static final int DATA_STALL_MIN_TX_SUCCESS_WITHOUT_RX_SETTING = 75; private static final int NUM_SAR_SENSOR_LISTENER_REGISTRATION_FAILURES = 5; + private static final int NUM_ONESHOT_SCAN_REQUESTS_WITH_DFS_CHANNELS = 4; /** Number of notifications per "Connect to Network" notification type. */ private static final int[] NUM_CONNECT_TO_NETWORK_NOTIFICATIONS = {0, 10, 20, 30, 40}; @@ -706,6 +707,9 @@ public class WifiMetricsTest { for (int i = 0; i < NUM_SAR_SENSOR_LISTENER_REGISTRATION_FAILURES; i++) { mWifiMetrics.incrementNumSarSensorRegistrationFailures(); } + for (int i = 0; i < NUM_ONESHOT_SCAN_REQUESTS_WITH_DFS_CHANNELS; i++) { + mWifiMetrics.incrementOneshotScanWithDfsCount(); + } mWifiMetrics.setWatchdogSuccessTimeDurationMs(NUM_WATCHDOG_SUCCESS_DURATION_MS); mWifiMetrics.setIsMacRandomizationOn(IS_MAC_RANDOMIZATION_ON); @@ -1015,6 +1019,8 @@ public class WifiMetricsTest { assertEquals(NUM_SAR_SENSOR_LISTENER_REGISTRATION_FAILURES, mDecodedProto.numSarSensorRegistrationFailures); + assertEquals(NUM_ONESHOT_SCAN_REQUESTS_WITH_DFS_CHANNELS, + mDecodedProto.numOneshotHasDfsChannelScans); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index 58f2eb6a1..67b99f884 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -719,7 +719,7 @@ public class WifiScanningServiceTest { assertDumpContainsCallbackLog("singleScanInvalidRequest", requestId, "bad request"); - assertEquals(mWifiMetrics.getOneshotScanCount(), 1); + assertEquals(0, mWifiMetrics.getOneshotScanCount()); assertEquals(mWifiMetrics.getScanReturnEntry( WifiMetricsProto.WifiLog.SCAN_FAILURE_INVALID_CONFIGURATION), 1); @@ -771,7 +771,7 @@ public class WifiScanningServiceTest { assertDumpContainsCallbackLog("singleScanInvalidRequest", requestId, "bad request"); - assertEquals(mWifiMetrics.getOneshotScanCount(), 1); + assertEquals(0, mWifiMetrics.getOneshotScanCount()); assertEquals(mWifiMetrics.getScanReturnEntry( WifiMetricsProto.WifiLog.SCAN_FAILURE_INVALID_CONFIGURATION), 1); @@ -816,7 +816,7 @@ public class WifiScanningServiceTest { assertDumpContainsCallbackLog("singleScanInvalidRequest", requestId, "bad request"); - assertEquals(mWifiMetrics.getOneshotScanCount(), 1); + assertEquals(0, mWifiMetrics.getOneshotScanCount()); assertEquals(mWifiMetrics.getScanReturnEntry( WifiMetricsProto.WifiLog.SCAN_FAILURE_INVALID_CONFIGURATION), 1); @@ -922,6 +922,71 @@ public class WifiScanningServiceTest { } /** + * Do a single scan that includes DFS channels and verify that both oneshot scan count and + * oneshot scan count with dfs are incremented. + */ + @Test + public void testMetricsForOneshotScanWithDFSIsIncremented() throws Exception { + WifiScanner.ScanSettings requestSettings = createRequest( + WifiScanner.WIFI_BAND_BOTH_WITH_DFS, 0, 0, 20, + WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); + int requestId = 33; + WorkSource workSource = new WorkSource(Binder.getCallingUid()); // don't explicitly set + + startServiceAndLoadDriver(); + mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); + + Handler handler = mock(Handler.class); + BidirectionalAsyncChannel controlChannel = connectChannel(handler); + InOrder order = inOrder(handler, mWifiScannerImpl); + + // successful start + when(mWifiScannerImpl.startSingleScan(any(WifiNative.ScanSettings.class), + any(WifiNative.ScanEventHandler.class))).thenReturn(true); + + sendSingleScanRequest(controlChannel, requestId, requestSettings, null); + + assertEquals(0, mWifiMetrics.getOneshotScanCount()); + assertEquals(0, mWifiMetrics.getOneshotScanWithDfsCount()); + // Scan is successfully queue + mLooper.dispatchAll(); + assertEquals(1, mWifiMetrics.getOneshotScanCount()); + assertEquals(1, mWifiMetrics.getOneshotScanWithDfsCount()); + } + + /** + * Do a single scan that excludes DFS channels and verify that only oneshot scan count is + * incremented. + */ + @Test + public void testMetricsForOneshotScanWithDFSIsNotIncremented() throws Exception { + WifiScanner.ScanSettings requestSettings = createRequest( + WifiScanner.WIFI_BAND_5_GHZ, 0, 0, 20, + WifiScanner.REPORT_EVENT_AFTER_EACH_SCAN); + int requestId = 33; + WorkSource workSource = new WorkSource(Binder.getCallingUid()); // don't explicitly set + + startServiceAndLoadDriver(); + mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); + + Handler handler = mock(Handler.class); + BidirectionalAsyncChannel controlChannel = connectChannel(handler); + InOrder order = inOrder(handler, mWifiScannerImpl); + + // successful start + when(mWifiScannerImpl.startSingleScan(any(WifiNative.ScanSettings.class), + any(WifiNative.ScanEventHandler.class))).thenReturn(true); + + sendSingleScanRequest(controlChannel, requestId, requestSettings, null); + + assertEquals(0, mWifiMetrics.getOneshotScanCount()); + // Scan is successfully queue + mLooper.dispatchAll(); + assertEquals(1, mWifiMetrics.getOneshotScanCount()); + assertEquals(0, mWifiMetrics.getOneshotScanWithDfsCount()); + } + + /** * Send a single scan request and then disable Wi-Fi before it completes */ @Test |