From da1b2e9ed28829fd434cd2bedd5932961696e479 Mon Sep 17 00:00:00 2001 From: xshu Date: Wed, 19 Aug 2020 17:07:03 -0700 Subject: Adding network disabled status to user action metrics (cherry-picked from acd5659d05dacf1de79489c7740c87e95cbf5b03) When a user action is triggered, take note of the reasons WifiConfigurations and BSSIDs are disabled. This information will be used to gain insight why we did not auto-connect to manaually selected networks. Updated-PDD: true Bug: 165118962 Test: com.android.server.wifi Test: Manual verification with dumpsys log Change-Id: I7d3a0a933e4f9f45b20019ace3013e1661212fad Merged-In: I7d3a0a933e4f9f45b20019ace3013e1661212fad --- .../server/wifi/BssidBlocklistMonitorTest.java | 20 +++++ .../com/android/server/wifi/WifiMetricsTest.java | 86 +++++++++++++++++++++- .../android/server/wifi/WifiServiceImplTest.java | 3 +- 3 files changed, 105 insertions(+), 4 deletions(-) (limited to 'tests') 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 0a5a512b2..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,13 @@ 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); } /** @@ -2451,6 +2461,76 @@ public class WifiMetricsTest extends WifiBaseTest { 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 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); + } + /** * Test the logging of UserActionEvent with invalid network ID */ diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 49ccf9bd3..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)); } -- cgit v1.2.3