From 4036c533b3da963ef103a923037ca944e3c283ea Mon Sep 17 00:00:00 2001 From: xshu Date: Tue, 11 Aug 2020 19:17:44 -0700 Subject: Breakdown manual connection events (cherry-picked from ebf39c906b8f2afe499f96e6f33379ba110fc194) Adding a new event type, EVENT_ADD_OR_UPDATE_NETWORK to track adding new networks and modifying credentials for existing networks. Bug: 163663606 Test: atest com.android.server.wifi Test: Manual sanity test Updated-pdd: TRUE Change-Id: If2c611b50c03463d4041d6b1bd96778b2d567469 Merged-In: If2c611b50c03463d4041d6b1bd96778b2d567469 --- service/java/com/android/server/wifi/WifiMetrics.java | 3 +++ service/java/com/android/server/wifi/WifiServiceImpl.java | 11 ++++++++++- service/proto/src/metrics.proto | 2 ++ .../src/com/android/server/wifi/WifiServiceImplTest.java | 6 +++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 6c2b5e369..cfc06b5b5 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -824,6 +824,9 @@ public class WifiMetrics { case UserActionEvent.EVENT_MANUAL_CONNECT: eventType = "EVENT_MANUAL_CONNECT"; break; + case UserActionEvent.EVENT_ADD_OR_UPDATE_NETWORK: + eventType = "EVENT_ADD_OR_UPDATE_NETWORK"; + break; } sb.append(" eventType=").append(eventType); sb.append(" startTimeMillis=").append(mUserActionEvent.startTimeMillis); diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index a398eacaf..20aea050a 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -4120,7 +4120,12 @@ public class WifiServiceImpl extends BaseWifiService { mLog.info("connect uid=%").c(uid).flush(); mClientModeImpl.connect(config, netId, binder, callback, callbackIdentifier, uid); if (mWifiPermissionsUtil.checkNetworkSettingsPermission(uid)) { - mWifiMetrics.logUserActionEvent(UserActionEvent.EVENT_MANUAL_CONNECT, netId); + if (config == null) { + mWifiMetrics.logUserActionEvent(UserActionEvent.EVENT_MANUAL_CONNECT, netId); + } else { + mWifiMetrics.logUserActionEvent( + UserActionEvent.EVENT_ADD_OR_UPDATE_NETWORK, config.networkId); + } } } @@ -4135,6 +4140,10 @@ public class WifiServiceImpl extends BaseWifiService { throw new SecurityException(TAG + ": Permission denied"); } mLog.info("save uid=%").c(Binder.getCallingUid()).flush(); + if (mWifiPermissionsUtil.checkNetworkSettingsPermission(Binder.getCallingUid())) { + mWifiMetrics.logUserActionEvent( + UserActionEvent.EVENT_ADD_OR_UPDATE_NETWORK, config.networkId); + } mClientModeImpl.save( config, binder, callback, callbackIdentifier, Binder.getCallingUid()); } diff --git a/service/proto/src/metrics.proto b/service/proto/src/metrics.proto index 30b1690cc..c16ecfbba 100644 --- a/service/proto/src/metrics.proto +++ b/service/proto/src/metrics.proto @@ -3156,6 +3156,8 @@ message UserActionEvent { EVENT_MANUAL_CONNECT = 11; // User changes the metered setting to "detect automatically" EVENT_CONFIGURE_METERED_STATUS_AUTO = 12; + // User adds a new network or updates configurations for an existing network. + EVENT_ADD_OR_UPDATE_NETWORK = 13; } // The type of user action diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 6d1ae2927..49ccf9bd3 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -3621,7 +3621,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 +3633,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()); } -- cgit v1.2.3