diff options
author | Oscar Shu <xshu@google.com> | 2020-09-08 04:44:47 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-09-08 04:44:47 +0000 |
commit | a0d01b665d79abaeabcbddba79c46d7d3b10e168 (patch) | |
tree | e15bc0510e80e0b2a0cb45e7bd9fd17305eaf5c6 /tests | |
parent | e4e5a49dbe4ca726c51d9350fa61088c2bb23d8a (diff) | |
parent | da1b2e9ed28829fd434cd2bedd5932961696e479 (diff) |
Merge changes from topic "additionalUserActionMetrics" into rvc-qpr-dev
* changes:
Adding network disabled status to user action metrics
Add WifiStatus to UserAction metrics
Breakdown manual connection events
Diffstat (limited to 'tests')
3 files changed, 145 insertions, 5 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java index e3c8d52fa..d6333b363 100644 --- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java @@ -776,4 +776,24 @@ public class BssidBlocklistMonitorTest { simulateRssiUpdate(TEST_BSSID_1, TEST_SUFFICIENT_RSSI); assertTrue(mBssidBlocklistMonitor.updateAndGetBssidBlocklist().contains(TEST_BSSID_1)); } + + /** + * Verify the failure reasons for all blocked BSSIDs are retrieved. + */ + @Test + public void testGetFailureReasonsForSsid() { + // Null input should not crash + mBssidBlocklistMonitor.getFailureReasonsForSsid(null).size(); + assertEquals(0, mBssidBlocklistMonitor.getFailureReasonsForSsid(TEST_SSID_1).size()); + mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, 1000, + BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, TEST_GOOD_RSSI); + mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_2, TEST_SSID_1, 1000, + BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT, TEST_GOOD_RSSI); + + assertEquals(2, mBssidBlocklistMonitor.getFailureReasonsForSsid(TEST_SSID_1).size()); + assertTrue(mBssidBlocklistMonitor.getFailureReasonsForSsid(TEST_SSID_1) + .contains(BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA)); + assertTrue(mBssidBlocklistMonitor.getFailureReasonsForSsid(TEST_SSID_1) + .contains(BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index d16ef3dcf..b4cd7592c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -60,6 +60,7 @@ import android.net.wifi.SoftApCapability; import android.net.wifi.SoftApConfiguration; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiEnterpriseConfig; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; @@ -98,6 +99,7 @@ import com.android.server.wifi.proto.nano.WifiMetricsProto.Int32Count; import com.android.server.wifi.proto.nano.WifiMetricsProto.LinkProbeStats; import com.android.server.wifi.proto.nano.WifiMetricsProto.LinkProbeStats.ExperimentProbeCounts; import com.android.server.wifi.proto.nano.WifiMetricsProto.LinkProbeStats.LinkProbeFailureReasonCount; +import com.android.server.wifi.proto.nano.WifiMetricsProto.NetworkDisableReason; import com.android.server.wifi.proto.nano.WifiMetricsProto.NetworkSelectionExperimentDecisions; import com.android.server.wifi.proto.nano.WifiMetricsProto.PasspointProfileTypeCount; import com.android.server.wifi.proto.nano.WifiMetricsProto.PasspointProvisionStats; @@ -129,9 +131,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -2399,9 +2403,8 @@ public class WifiMetricsTest extends WifiBaseTest { int testNetworkId = 0; long testStartTimeMillis = 123123L; when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartTimeMillis); - WifiConfiguration config = mock(WifiConfiguration.class); - when(config.isEphemeral()).thenReturn(true); - when(config.isPasspoint()).thenReturn(true); + WifiConfiguration config = WifiConfigurationTestUtil.createPasspointNetwork(); + config.ephemeral = true; when(mWcm.getConfiguredNetwork(testNetworkId)).thenReturn(config); mWifiMetrics.logUserActionEvent(testEventType, testNetworkId); @@ -2414,6 +2417,118 @@ public class WifiMetricsTest extends WifiBaseTest { assertEquals(testStartTimeMillis, userActionEvents[0].startTimeMillis); assertEquals(true, userActionEvents[0].targetNetworkInfo.isEphemeral); assertEquals(true, userActionEvents[0].targetNetworkInfo.isPasspoint); + + // Verify that there are no disabled WifiConfiguration and BSSIDs + NetworkDisableReason networkDisableReason = userActionEvents[0].networkDisableReason; + assertEquals(NetworkDisableReason.REASON_UNKNOWN, networkDisableReason.disableReason); + assertEquals(false, networkDisableReason.configTemporarilyDisabled); + assertEquals(false, networkDisableReason.configPermanentlyDisabled); + assertEquals(0, networkDisableReason.bssidDisableReasons.length); + } + + /** + * Verify the WifiStatus field in a UserActionEvent is populated correctly. + * @throws Exception + */ + @Test + public void testLogWifiStatusInUserActionEvent() throws Exception { + // setups WifiStatus for information + int expectedRssi = -55; + int testNetworkId = 1; + int expectedTx = 1234; + int expectedRx = 2345; + + WifiInfo wifiInfo = mock(WifiInfo.class); + when(wifiInfo.getRssi()).thenReturn(expectedRssi); + when(wifiInfo.getNetworkId()).thenReturn(testNetworkId); + mWifiMetrics.handlePollResult(wifiInfo); + mWifiMetrics.incrementThroughputKbpsCount(expectedTx, expectedRx, RSSI_POLL_FREQUENCY); + mWifiMetrics.setNominatorForNetwork(testNetworkId, + WifiMetricsProto.ConnectionEvent.NOMINATOR_SAVED_USER_CONNECT_CHOICE); + + // generate a user action event and then verify fields + int testEventType = WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI; + mWifiMetrics.logUserActionEvent(testEventType, testNetworkId); + dumpProtoAndDeserialize(); + + WifiMetricsProto.UserActionEvent[] userActionEvents = mDecodedProto.userActionEvents; + assertEquals(1, userActionEvents.length); + assertEquals(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, + userActionEvents[0].eventType); + assertEquals(expectedRssi, userActionEvents[0].wifiStatus.lastRssi); + assertEquals(expectedTx, userActionEvents[0].wifiStatus.estimatedTxKbps); + assertEquals(expectedRx, userActionEvents[0].wifiStatus.estimatedRxKbps); + assertTrue(userActionEvents[0].wifiStatus.isStuckDueToUserConnectChoice); + } + + /** + * verify NetworkDisableReason is populated properly when there exists a disabled + * WifiConfiguration and BSSID. + */ + @Test + public void testNetworkDisableReasonInUserActionEvent() throws Exception { + // Setup a temporarily blocked config due to DISABLED_ASSOCIATION_REJECTION + WifiConfiguration testConfig = WifiConfigurationTestUtil.createOpenNetwork(); + NetworkSelectionStatus status = testConfig.getNetworkSelectionStatus(); + status.setNetworkSelectionStatus( + NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED); + status.setNetworkSelectionDisableReason( + NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION); + when(mWcm.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(testConfig); + + // Also setup the same BSSID level failure + Set<Integer> testBssidBlocklistReasons = new HashSet<>(); + testBssidBlocklistReasons.add(BssidBlocklistMonitor.REASON_ASSOCIATION_REJECTION); + when(mBssidBlocklistMonitor.getFailureReasonsForSsid(anyString())) + .thenReturn(testBssidBlocklistReasons); + + // Logging the user action event + mWifiMetrics.logUserActionEvent(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, + TEST_NETWORK_ID); + dumpProtoAndDeserialize(); + + WifiMetricsProto.UserActionEvent[] userActionEvents = mDecodedProto.userActionEvents; + assertEquals(1, userActionEvents.length); + assertEquals(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, + userActionEvents[0].eventType); + NetworkDisableReason networkDisableReason = userActionEvents[0].networkDisableReason; + assertEquals(NetworkDisableReason.REASON_ASSOCIATION_REJECTION, + networkDisableReason.disableReason); + assertEquals(true, networkDisableReason.configTemporarilyDisabled); + assertEquals(false, networkDisableReason.configPermanentlyDisabled); + assertEquals(1, networkDisableReason.bssidDisableReasons.length); + assertEquals(NetworkDisableReason.REASON_ASSOCIATION_REJECTION, + networkDisableReason.bssidDisableReasons[0]); + } + + /** + * verify that auto-join disable overrides any other disable reasons in NetworkDisableReason. + */ + @Test + public void testNetworkDisableReasonDisableAutojoinInUserActionEvent() throws Exception { + // Setup a temporarily blocked config due to DISABLED_ASSOCIATION_REJECTION + WifiConfiguration testConfig = WifiConfigurationTestUtil.createOpenNetwork(); + NetworkSelectionStatus status = testConfig.getNetworkSelectionStatus(); + status.setNetworkSelectionStatus( + NetworkSelectionStatus.NETWORK_SELECTION_TEMPORARY_DISABLED); + status.setNetworkSelectionDisableReason( + NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION); + when(mWcm.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(testConfig); + + // Disable autojoin + testConfig.allowAutojoin = false; + + // Logging the user action event + mWifiMetrics.logUserActionEvent(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, + TEST_NETWORK_ID); + dumpProtoAndDeserialize(); + + WifiMetricsProto.UserActionEvent[] userActionEvents = mDecodedProto.userActionEvents; + NetworkDisableReason networkDisableReason = userActionEvents[0].networkDisableReason; + assertEquals(NetworkDisableReason.REASON_AUTO_JOIN_DISABLED, + networkDisableReason.disableReason); + assertEquals(false, networkDisableReason.configTemporarilyDisabled); + assertEquals(true, networkDisableReason.configPermanentlyDisabled); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 6d1ae2927..22561a159 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -571,7 +571,8 @@ public class WifiServiceImplTest extends WifiBaseTest { assertTrue(mWifiServiceImpl.setWifiEnabled(TEST_PACKAGE_NAME, false)); inorder.verify(mWifiMetrics).logUserActionEvent(UserActionEvent.EVENT_TOGGLE_WIFI_ON); inorder.verify(mWifiMetrics).incrementNumWifiToggles(eq(true), eq(true)); - inorder.verify(mWifiMetrics).logUserActionEvent(UserActionEvent.EVENT_TOGGLE_WIFI_OFF); + inorder.verify(mWifiMetrics).logUserActionEvent(eq(UserActionEvent.EVENT_TOGGLE_WIFI_OFF), + anyInt()); inorder.verify(mWifiMetrics).incrementNumWifiToggles(eq(true), eq(false)); } @@ -3621,7 +3622,8 @@ public class WifiServiceImplTest extends WifiBaseTest { mock(IActionListener.class), 0); verify(mClientModeImpl).connect(any(WifiConfiguration.class), anyInt(), any(Binder.class), any(IActionListener.class), anyInt(), anyInt()); - verify(mWifiMetrics).logUserActionEvent(eq(UserActionEvent.EVENT_MANUAL_CONNECT), anyInt()); + verify(mWifiMetrics).logUserActionEvent(eq(UserActionEvent.EVENT_ADD_OR_UPDATE_NETWORK), + anyInt()); } /** @@ -3632,8 +3634,11 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testSaveNetworkWithPrivilegedPermission() throws Exception { when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); + when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true); mWifiServiceImpl.save(mock(WifiConfiguration.class), mock(Binder.class), mock(IActionListener.class), 0); + verify(mWifiMetrics).logUserActionEvent(eq(UserActionEvent.EVENT_ADD_OR_UPDATE_NETWORK), + anyInt()); verify(mClientModeImpl).save(any(WifiConfiguration.class), any(Binder.class), any(IActionListener.class), anyInt(), anyInt()); } |