diff options
author | xshu <xshu@google.com> | 2020-04-06 19:55:37 -0700 |
---|---|---|
committer | xshu <xshu@google.com> | 2020-04-14 15:33:54 -0700 |
commit | 8b8fafe34020b5fe5b43fa99685fb38dcb506c4a (patch) | |
tree | 8a2b1176dfb106f75fcc606c6d19778f44d3f2cd /tests | |
parent | 20641dfcb5c341b8335c7c44d272c58de7a5adbf (diff) |
Wifi user action metrics
Adds logging support for user action metrics.
Logs a user action metrics when user forgets network.
Bug: 153925826
Test: atest com.android.service.wifi
Test: manual sanity test
Change-Id: Ief1d4d391bc55cc41bdeaf7ca31705d05e57929f
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java | 60 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 8 |
2 files changed, 67 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 3964d2d37..8b67c046a 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -2409,6 +2409,66 @@ public class WifiMetricsTest extends WifiBaseTest { } /** + * Test the logging of UserActionEvent with a valid network ID + */ + @Test + public void testLogUserActionEventValidNetworkId() throws Exception { + int testEventType = WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI; + 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); + when(mWcm.getConfiguredNetwork(testNetworkId)).thenReturn(config); + + mWifiMetrics.logUserActionEvent(testEventType, testNetworkId); + dumpProtoAndDeserialize(); + + WifiMetricsProto.UserActionEvent[] userActionEvents = mDecodedProto.userActionEvents; + assertEquals(1, userActionEvents.length); + assertEquals(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, + userActionEvents[0].eventType); + assertEquals(testStartTimeMillis, userActionEvents[0].startTimeMillis); + assertEquals(true, userActionEvents[0].targetNetworkInfo.isEphemeral); + assertEquals(true, userActionEvents[0].targetNetworkInfo.isPasspoint); + } + + /** + * Test the logging of UserActionEvent with invalid network ID + */ + @Test + public void testLogUserActionEventInvalidNetworkId() throws Exception { + int testEventType = WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI; + int testNetworkId = 0; + long testStartTimeMillis = 123123L; + when(mClock.getElapsedSinceBootMillis()).thenReturn(testStartTimeMillis); + when(mWcm.getConfiguredNetwork(testNetworkId)).thenReturn(null); + + mWifiMetrics.logUserActionEvent(testEventType, testNetworkId); + dumpProtoAndDeserialize(); + + WifiMetricsProto.UserActionEvent[] userActionEvents = mDecodedProto.userActionEvents; + assertEquals(1, userActionEvents.length); + assertEquals(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, + userActionEvents[0].eventType); + assertEquals(testStartTimeMillis, userActionEvents[0].startTimeMillis); + assertNull(userActionEvents[0].targetNetworkInfo); + } + + /** + * Verify that the max length of the UserActionEvent list is limited to MAX_USER_ACTION_EVENTS. + */ + @Test + public void testLogUserActionEventCapped() throws Exception { + for (int i = 0; i < WifiMetrics.MAX_USER_ACTION_EVENTS + 1; i++) { + mWifiMetrics.logUserActionEvent(WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, 0); + } + dumpProtoAndDeserialize(); + assertEquals(WifiMetrics.MAX_USER_ACTION_EVENTS, mDecodedProto.userActionEvents.length); + } + + /** * Ensure WifiMetrics doesn't cause a null pointer exception when called with null args */ @Test diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index b5c5e7b42..fcc290560 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -152,6 +152,7 @@ import com.android.internal.util.AsyncChannel; import com.android.server.wifi.WifiServiceImpl.LocalOnlyRequestorCallback; import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.hotspot2.PasspointProvisioningTestUtil; +import com.android.server.wifi.proto.nano.WifiMetricsProto; import com.android.server.wifi.util.ApConfigUtil; import com.android.server.wifi.util.WifiAsyncChannel; import com.android.server.wifi.util.WifiPermissionsUtil; @@ -3566,9 +3567,14 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testForgetNetworkWithPrivilegedPermission() throws Exception { when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); + when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true); mWifiServiceImpl.forget(TEST_NETWORK_ID, mock(Binder.class), mock(IActionListener.class), 0); - verify(mClientModeImpl).forget(anyInt(), any(Binder.class), + + InOrder inOrder = inOrder(mClientModeImpl, mWifiMetrics); + inOrder.verify(mWifiMetrics).logUserActionEvent( + WifiMetricsProto.UserActionEvent.EVENT_FORGET_WIFI, TEST_NETWORK_ID); + inOrder.verify(mClientModeImpl).forget(anyInt(), any(Binder.class), any(IActionListener.class), anyInt(), anyInt()); } |