diff options
author | Les Lee <lesl@google.com> | 2020-03-25 06:01:25 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-03-25 06:01:25 +0000 |
commit | 90ba39085632cfb1864429bb1d03f90f11e86338 (patch) | |
tree | 6c38a6cd07a0bc17d7d61c18378c2a8e52a24ca2 /tests | |
parent | 3f5d6666567720d9784b06cb7b55108b85160cc3 (diff) | |
parent | 5e82d0ef5a926953ac237c026460b11ac95d188e (diff) |
Merge changes I4b026b2b,I080cc866 into rvc-dev
* changes:
wifi: Add softap metrics to record the event when reach limitation
wifi: Add Softap configuration/capability metric
Diffstat (limited to 'tests')
3 files changed, 175 insertions, 11 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index 21c3305f2..0e63b51ee 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -96,6 +96,7 @@ public class SoftApManagerTest extends WifiBaseTest { private static final String TEST_COUNTRY_CODE = "TestCountry"; private static final String TEST_INTERFACE_NAME = "testif0"; private static final String OTHER_INTERFACE_NAME = "otherif"; + private static final long TEST_DEFAULT_SHUTDOWN_TIMEOUT_MILLS = 600_000; private static final MacAddress TEST_MAC_ADDRESS = MacAddress.fromString("22:33:44:55:66:77"); private static final MacAddress TEST_MAC_ADDRESS_2 = MacAddress.fromString("aa:bb:cc:dd:ee:ff"); private static final WifiClient TEST_CONNECTED_CLIENT = new WifiClient(TEST_MAC_ADDRESS); @@ -154,7 +155,7 @@ public class SoftApManagerTest extends WifiBaseTest { .thenReturn(mNotificationManager); when(mResources.getInteger(R.integer.config_wifiFrameworkSoftApShutDownTimeoutMilliseconds)) - .thenReturn(600000); + .thenReturn((int) TEST_DEFAULT_SHUTDOWN_TIMEOUT_MILLS); when(mWifiNative.setCountryCodeHal( TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT))) .thenReturn(true); @@ -1388,8 +1389,6 @@ public class SoftApManagerTest extends WifiBaseTest { new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build(), mTestSoftApCapability); startSoftApAndVerifyEnabled(apConfig); - verify(mResources, never()) - .getInteger(R.integer.config_wifiFrameworkSoftApShutDownTimeoutMilliseconds); // Verify timer is scheduled verify(mAlarmManager.getAlarmManager()).setExact(anyInt(), anyLong(), @@ -1624,6 +1623,12 @@ public class SoftApManagerTest extends WifiBaseTest { WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_NO_MORE_STAS); verify(mWifiMetrics, never()).addSoftApNumAssociatedStationsChangedEvent( 2, apConfig.getTargetMode()); + // Trigger connection again + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT_2, true); + mLooper.dispatchAll(); + // Verify just update metrics one time + verify(mWifiMetrics).noteSoftApClientBlocked(1); } @Test @@ -1775,7 +1780,12 @@ public class SoftApManagerTest extends WifiBaseTest { WIFI_AP_STATE_ENABLING, HOTSPOT_NO_ERROR, TEST_INTERFACE_NAME, softApConfig.getTargetMode()); verify(mListener).onStarted(); - verify(mWifiMetrics).addSoftApUpChangedEvent(true, softApConfig.getTargetMode()); + verify(mWifiMetrics).addSoftApUpChangedEvent(true, softApConfig.getTargetMode(), + TEST_DEFAULT_SHUTDOWN_TIMEOUT_MILLS); + verify(mWifiMetrics).updateSoftApConfiguration(config == null ? mDefaultApConfig : config, + softApConfig.getTargetMode()); + verify(mWifiMetrics).updateSoftApCapability(softApConfig.getCapability(), + softApConfig.getTargetMode()); } private void checkApStateChangedBroadcast(Intent intent, int expectedCurrentState, @@ -1863,6 +1873,8 @@ public class SoftApManagerTest extends WifiBaseTest { verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0); verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_FAILED, WifiManager.SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION); + verify(mWifiMetrics).incrementSoftApStartResult(false, + WifiManager.SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION); verify(mListener).onStartFailure(); } @@ -1915,6 +1927,8 @@ public class SoftApManagerTest extends WifiBaseTest { verify(mAlarmManager.getAlarmManager()).setExact(anyInt(), anyLong(), eq(mSoftApManager.SOFT_AP_SEND_MESSAGE_TIMEOUT_TAG), any(), any()); verify(mCallback).onConnectedClientsChanged(new ArrayList<>()); + verify(mWifiMetrics).updateSoftApConfiguration(configBuilder.build(), + WifiManager.IFACE_IP_MODE_TETHERED); mLooper.dispatchAll(); @@ -1927,6 +1941,8 @@ public class SoftApManagerTest extends WifiBaseTest { // Verify timer setup again verify(mAlarmManager.getAlarmManager(), times(2)).setExact(anyInt(), anyLong(), eq(mSoftApManager.SOFT_AP_SEND_MESSAGE_TIMEOUT_TAG), any(), any()); + verify(mWifiMetrics).updateSoftApConfiguration(configBuilder.build(), + WifiManager.IFACE_IP_MODE_TETHERED); } @@ -1982,7 +1998,7 @@ public class SoftApManagerTest extends WifiBaseTest { // Verify timer is canceled at this point verify(mAlarmManager.getAlarmManager()).cancel(any(WakeupMessage.class)); - // Second client connect and max client set is 1. + // Second client connect and max client set is 2. mSoftApListenerCaptor.getValue().onConnectedClientsChanged( TEST_NATIVE_CLIENT_2, true); mLooper.dispatchAll(); @@ -2002,4 +2018,73 @@ public class SoftApManagerTest extends WifiBaseTest { verify(mWifiNative).forceClientDisconnect( any(), any(), anyInt()); } + + @Test + public void testConfigChangeWillTriggerUpdateMetricsAgain() throws Exception { + Builder configBuilder = new SoftApConfiguration.Builder(); + configBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configBuilder.setSsid(TEST_SSID); + configBuilder.setMaxNumberOfClients(1); + SoftApModeConfiguration apConfig = + new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, + configBuilder.build(), mTestSoftApCapability); + startSoftApAndVerifyEnabled(apConfig); + + verify(mCallback).onConnectedClientsChanged(new ArrayList<>()); + + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT, true); + mLooper.dispatchAll(); + + verify(mCallback, times(2)).onConnectedClientsChanged( + Mockito.argThat((List<WifiClient> clients) -> + clients.contains(TEST_CONNECTED_CLIENT)) + ); + + verify(mWifiMetrics).addSoftApNumAssociatedStationsChangedEvent( + 1, apConfig.getTargetMode()); + // Verify timer is canceled at this point + verify(mAlarmManager.getAlarmManager()).cancel(any(WakeupMessage.class)); + + // Second client connect and max client set is 1. + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT_2, true); + mLooper.dispatchAll(); + verify(mWifiNative).forceClientDisconnect( + TEST_INTERFACE_NAME, TEST_MAC_ADDRESS_2, + WifiManager.SAP_CLIENT_BLOCK_REASON_CODE_NO_MORE_STAS); + + // Verify update metrics + verify(mWifiMetrics).noteSoftApClientBlocked(1); + + // Trigger Configuration Change + configBuilder.setMaxNumberOfClients(2); + mSoftApManager.updateConfiguration(configBuilder.build()); + mLooper.dispatchAll(); + + // Second client connect and max client set is 2. + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT_2, true); + mLooper.dispatchAll(); + verify(mCallback, times(3)).onConnectedClientsChanged( + Mockito.argThat((List<WifiClient> clients) -> + clients.contains(TEST_CONNECTED_CLIENT_2)) + ); + + // Trigger Configuration Change + configBuilder.setMaxNumberOfClients(1); + mSoftApManager.updateConfiguration(configBuilder.build()); + mLooper.dispatchAll(); + // Let client disconnect due to maximum number change to small. + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT, false); + mLooper.dispatchAll(); + + // Trigger connection again + mSoftApListenerCaptor.getValue().onConnectedClientsChanged( + TEST_NATIVE_CLIENT, true); + mLooper.dispatchAll(); + // Verify just update metrics one time + verify(mWifiMetrics, times(2)).noteSoftApClientBlocked(1); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java index 4aacb1d78..0996ce43c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java @@ -78,6 +78,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { @Mock private Context mContext; @Mock private WifiInjector mWifiInjector; + @Mock private WifiMetrics mWifiMetrics; private TestLooper mLooper; private Handler mHandler; @Mock private BackupManagerProxy mBackupManagerProxy; @@ -126,7 +127,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { private WifiApConfigStore createWifiApConfigStore() throws Exception { WifiApConfigStore store = new WifiApConfigStore( mContext, mWifiInjector, mHandler, mBackupManagerProxy, - mWifiConfigStore, mWifiConfigManager, mActiveModeWarden); + mWifiConfigStore, mWifiConfigManager, mActiveModeWarden, mWifiMetrics); verify(mWifiConfigStore).registerStoreData(any()); ArgumentCaptor<SoftApStoreData.DataSource> dataStoreSourceArgumentCaptor = ArgumentCaptor.forClass(SoftApStoreData.DataSource.class); @@ -652,5 +653,6 @@ public class WifiApConfigStoreTest extends WifiBaseTest { SoftApConfiguration resetedConfig = store.resetToDefaultForUnsupportedConfig(sae_config); assertEquals(resetedConfig.getMaxNumberOfClients(), 0); assertFalse(resetedConfig.isClientControlByUserEnabled()); + verify(mWifiMetrics).noteSoftApConfigReset(sae_config, resetedConfig); } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 1cf3597f8..315a17bc1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -55,6 +55,8 @@ import android.content.Context; import android.net.wifi.EAPConstants; import android.net.wifi.IOnWifiUsabilityStatsListener; import android.net.wifi.ScanResult; +import android.net.wifi.SoftApCapability; +import android.net.wifi.SoftApConfiguration; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; @@ -449,6 +451,11 @@ public class WifiMetricsTest extends WifiBaseTest { private static final int NUM_SOFT_AP_ASSOCIATED_STATIONS = 3; private static final int SOFT_AP_CHANNEL_FREQUENCY = 2437; private static final int SOFT_AP_CHANNEL_BANDWIDTH = SoftApConnectedClientsEvent.BANDWIDTH_20; + private static final int SOFT_AP_MAX_CLIENT_SETTING = 10; + private static final int SOFT_AP_MAX_CLIENT_CAPABILITY = 16; + private static final long SOFT_AP_SHUTDOWN_TIMEOUT_SETTING = 10_000; + private static final long SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING = 600_000; + private static final boolean SOFT_AP_CLIENT_CONTROL_ENABLE = true; private static final boolean IS_MAC_RANDOMIZATION_ON = true; private static final int NUM_LINK_SPEED_LEVELS_TO_INCREMENT = 30; private static final int TEST_RSSI_LEVEL = -80; @@ -985,21 +992,39 @@ public class WifiMetricsTest extends WifiBaseTest { private void addSoftApEventsToMetrics() { // Total number of events recorded is NUM_SOFT_AP_EVENT_ENTRIES in both modes - mWifiMetrics.addSoftApUpChangedEvent(true, WifiManager.IFACE_IP_MODE_TETHERED); + mWifiMetrics.addSoftApUpChangedEvent(true, WifiManager.IFACE_IP_MODE_TETHERED, + SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING); mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent(NUM_SOFT_AP_ASSOCIATED_STATIONS, WifiManager.IFACE_IP_MODE_TETHERED); mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent(NUM_SOFT_AP_ASSOCIATED_STATIONS, WifiManager.IFACE_IP_MODE_UNSPECIFIED); // Should be dropped. - mWifiMetrics.addSoftApUpChangedEvent(false, WifiManager.IFACE_IP_MODE_TETHERED); + mWifiMetrics.addSoftApUpChangedEvent(false, WifiManager.IFACE_IP_MODE_TETHERED, + SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING); // Channel switch info should be added to the last Soft AP UP event in the list mWifiMetrics.addSoftApChannelSwitchedEvent(SOFT_AP_CHANNEL_FREQUENCY, SOFT_AP_CHANNEL_BANDWIDTH, WifiManager.IFACE_IP_MODE_TETHERED); - mWifiMetrics.addSoftApUpChangedEvent(true, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); + SoftApConfiguration testSoftApConfig = new SoftApConfiguration.Builder() + .setSsid("Test_Metric_SSID") + .setMaxNumberOfClients(SOFT_AP_MAX_CLIENT_SETTING) + .setShutdownTimeoutMillis(SOFT_AP_SHUTDOWN_TIMEOUT_SETTING) + .setClientControlByUserEnabled(SOFT_AP_CLIENT_CONTROL_ENABLE) + .build(); + mWifiMetrics.updateSoftApConfiguration(testSoftApConfig, + WifiManager.IFACE_IP_MODE_TETHERED); + SoftApCapability testSoftApCapability = new SoftApCapability(0); + testSoftApCapability.setMaxSupportedClients(SOFT_AP_MAX_CLIENT_CAPABILITY); + mWifiMetrics.updateSoftApCapability(testSoftApCapability, + WifiManager.IFACE_IP_MODE_TETHERED); + + mWifiMetrics.addSoftApUpChangedEvent(true, WifiManager.IFACE_IP_MODE_LOCAL_ONLY, + SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING); mWifiMetrics.addSoftApNumAssociatedStationsChangedEvent(NUM_SOFT_AP_ASSOCIATED_STATIONS, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); // Should be dropped. - mWifiMetrics.addSoftApUpChangedEvent(false, WifiManager.IFACE_IP_MODE_CONFIGURATION_ERROR); - mWifiMetrics.addSoftApUpChangedEvent(false, WifiManager.IFACE_IP_MODE_LOCAL_ONLY); + mWifiMetrics.addSoftApUpChangedEvent(false, WifiManager.IFACE_IP_MODE_CONFIGURATION_ERROR, + SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING); + mWifiMetrics.addSoftApUpChangedEvent(false, WifiManager.IFACE_IP_MODE_LOCAL_ONLY, + SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING); } private void verifySoftApEventsStoredInProto() { @@ -1012,6 +1037,21 @@ public class WifiMetricsTest extends WifiBaseTest { mDecodedProto.softApConnectedClientsEventsTethered[0].channelFrequency); assertEquals(SOFT_AP_CHANNEL_BANDWIDTH, mDecodedProto.softApConnectedClientsEventsTethered[0].channelBandwidth); + assertEquals(SOFT_AP_MAX_CLIENT_SETTING, + mDecodedProto.softApConnectedClientsEventsTethered[0] + .maxNumClientsSettingInSoftapConfiguration); + assertEquals(SOFT_AP_MAX_CLIENT_CAPABILITY, + mDecodedProto.softApConnectedClientsEventsTethered[0] + .maxNumClientsSettingInSoftapCapability); + assertEquals(SOFT_AP_SHUTDOWN_TIMEOUT_SETTING, + mDecodedProto.softApConnectedClientsEventsTethered[0] + .shutdownTimeoutSettingInSoftapConfiguration); + assertEquals(SOFT_AP_SHUTDOWN_TIMEOUT_DEFAULT_SETTING, + mDecodedProto.softApConnectedClientsEventsTethered[0] + .defaultShutdownTimeoutSetting); + assertEquals(SOFT_AP_CLIENT_CONTROL_ENABLE, + mDecodedProto.softApConnectedClientsEventsTethered[0].clientControlIsEnabled); + assertEquals(SoftApConnectedClientsEvent.NUM_CLIENTS_CHANGED, mDecodedProto.softApConnectedClientsEventsTethered[1].eventType); assertEquals(NUM_SOFT_AP_ASSOCIATED_STATIONS, @@ -4487,4 +4527,41 @@ public class WifiMetricsTest extends WifiBaseTest { assertKeyCountsEqual(expectedHistogram, mDecodedProto.wifiOffMetrics.wifiOffDeferringTimeHistogram); } + + /* + * Test the logging of Wi-Fi off + */ + @Test + public void testSoftApConfigLimitationMetrics() throws Exception { + SoftApConfiguration originalConfig = new SoftApConfiguration.Builder() + .setSsid("TestSSID").build(); + SoftApConfiguration needToResetCongig = new SoftApConfiguration.Builder(originalConfig) + .setPassphrase("TestPassphreas", SoftApConfiguration.SECURITY_TYPE_WPA3_SAE) + .setClientControlByUserEnabled(true) + .setMaxNumberOfClients(10) + .build(); + mWifiMetrics.noteSoftApConfigReset(originalConfig, needToResetCongig); + + mWifiMetrics.noteSoftApClientBlocked(5); + mWifiMetrics.noteSoftApClientBlocked(5); + mWifiMetrics.noteSoftApClientBlocked(5); + mWifiMetrics.noteSoftApClientBlocked(8); + + dumpProtoAndDeserialize(); + + assertEquals(1, + mDecodedProto.softApConfigLimitationMetrics.numSecurityTypeResetToDefault); + assertEquals(1, + mDecodedProto.softApConfigLimitationMetrics.numMaxClientSettingResetToDefault); + assertEquals(1, + mDecodedProto.softApConfigLimitationMetrics.numClientControlByUserResetToDefault); + + Int32Count[] expectedHistogram = { + buildInt32Count(5, 3), + buildInt32Count(8, 1), + }; + assertKeyCountsEqual(expectedHistogram, + mDecodedProto.softApConfigLimitationMetrics.maxClientSettingWhenReachHistogram); + } + } |