diff options
4 files changed, 30 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index f316b504d..1303d1be0 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -3890,6 +3890,7 @@ public class ClientModeImpl extends StateMachine { mWifiConnectivityManager.setWifiEnabled(true); // Inform metrics that Wifi is Enabled (but not yet connected) mWifiMetrics.setWifiState(WifiMetricsProto.WifiLog.WIFI_DISCONNECTED); + mWifiMetrics.logStaEvent(StaEvent.TYPE_WIFI_ENABLED); // Inform p2p service that wifi is up and ready when applicable p2pSendMessage(ClientModeImpl.CMD_ENABLE_P2P); // Inform sar manager that wifi is Enabled @@ -3907,6 +3908,7 @@ public class ClientModeImpl extends StateMachine { mWifiConnectivityManager.setWifiEnabled(false); // Inform metrics that Wifi is being disabled (Toggled, airplane enabled, etc) mWifiMetrics.setWifiState(WifiMetricsProto.WifiLog.WIFI_DISABLED); + mWifiMetrics.logStaEvent(StaEvent.TYPE_WIFI_DISABLED); // Inform sar manager that wifi is being disabled mSarManager.setClientWifiState(WifiManager.WIFI_STATE_DISABLED); diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 538a014b1..be8e3322b 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -2902,6 +2902,8 @@ public class WifiMetrics { case StaEvent.TYPE_FRAMEWORK_DISCONNECT: case StaEvent.TYPE_SCORE_BREACH: case StaEvent.TYPE_MAC_CHANGE: + case StaEvent.TYPE_WIFI_ENABLED: + case StaEvent.TYPE_WIFI_DISABLED: break; default: Log.e(TAG, "Unknown StaEvent:" + type); @@ -3097,6 +3099,12 @@ public class WifiMetrics { case StaEvent.TYPE_MAC_CHANGE: sb.append("MAC_CHANGE"); break; + case StaEvent.TYPE_WIFI_ENABLED: + sb.append("WIFI_ENABLED"); + break; + case StaEvent.TYPE_WIFI_DISABLED: + sb.append("WIFI_DISABLED"); + break; default: sb.append("UNKNOWN " + event.type + ":"); break; diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 4b04694d6..15acff41a 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -94,6 +94,7 @@ import com.android.internal.util.StateMachine; import com.android.server.wifi.hotspot2.NetworkDetail; import com.android.server.wifi.hotspot2.PasspointManager; import com.android.server.wifi.hotspot2.PasspointProvisioningTestUtil; +import com.android.server.wifi.nano.WifiMetricsProto; import com.android.server.wifi.nano.WifiMetricsProto.StaEvent; import com.android.server.wifi.p2p.WifiP2pServiceImpl; import com.android.server.wifi.util.WifiPermissionsUtil; @@ -1828,6 +1829,7 @@ public class ClientModeImplTest { public void testWifiInfoCleanedUpEnteringExitingConnectModeState() throws Exception { InOrder inOrder = inOrder(mWifiConnectivityManager); InOrder inOrderSarMgr = inOrder(mSarManager); + InOrder inOrderMetrics = inOrder(mWifiMetrics); Log.i(TAG, mCmi.getCurrentState().getName()); String initialBSSID = "aa:bb:cc:dd:ee:ff"; WifiInfo wifiInfo = mCmi.getWifiInfo(); @@ -1839,6 +1841,9 @@ public class ClientModeImplTest { assertEquals(WifiManager.WIFI_STATE_ENABLED, mCmi.syncGetWifiState()); inOrder.verify(mWifiConnectivityManager).setWifiEnabled(eq(true)); inOrderSarMgr.verify(mSarManager).setClientWifiState(WifiManager.WIFI_STATE_ENABLED); + inOrderMetrics.verify(mWifiMetrics) + .setWifiState(WifiMetricsProto.WifiLog.WIFI_DISCONNECTED); + inOrderMetrics.verify(mWifiMetrics).logStaEvent(StaEvent.TYPE_WIFI_ENABLED); assertNull(wifiInfo.getBSSID()); // Send a SUPPLICANT_STATE_CHANGE_EVENT, verify WifiInfo is updated @@ -1859,6 +1864,8 @@ public class ClientModeImplTest { assertEquals(WifiManager.WIFI_STATE_DISABLED, mCmi.syncGetWifiState()); inOrder.verify(mWifiConnectivityManager).setWifiEnabled(eq(false)); inOrderSarMgr.verify(mSarManager).setClientWifiState(WifiManager.WIFI_STATE_DISABLED); + inOrderMetrics.verify(mWifiMetrics).setWifiState(WifiMetricsProto.WifiLog.WIFI_DISABLED); + inOrderMetrics.verify(mWifiMetrics).logStaEvent(StaEvent.TYPE_WIFI_DISABLED); assertNull(wifiInfo.getBSSID()); assertEquals(SupplicantState.DISCONNECTED, wifiInfo.getSupplicantState()); @@ -1880,6 +1887,9 @@ public class ClientModeImplTest { assertEquals(WifiManager.WIFI_STATE_ENABLED, mCmi.syncGetWifiState()); inOrder.verify(mWifiConnectivityManager).setWifiEnabled(eq(true)); inOrderSarMgr.verify(mSarManager).setClientWifiState(WifiManager.WIFI_STATE_ENABLED); + inOrderMetrics.verify(mWifiMetrics) + .setWifiState(WifiMetricsProto.WifiLog.WIFI_DISCONNECTED); + inOrderMetrics.verify(mWifiMetrics).logStaEvent(StaEvent.TYPE_WIFI_ENABLED); assertEquals("DisconnectedState", getCurrentState().getName()); assertEquals(SupplicantState.DISCONNECTED, wifiInfo.getSupplicantState()); assertNull(wifiInfo.getBSSID()); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index bca0cab06..b3127e1ea 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -49,13 +49,13 @@ import com.android.server.wifi.hotspot2.PasspointMatch; import com.android.server.wifi.hotspot2.PasspointProvider; import com.android.server.wifi.nano.WifiMetricsProto; import com.android.server.wifi.nano.WifiMetricsProto.ConnectToNetworkNotificationAndActionCount; +import com.android.server.wifi.nano.WifiMetricsProto.PasspointProfileTypeCount; import com.android.server.wifi.nano.WifiMetricsProto.PnoScanMetrics; import com.android.server.wifi.nano.WifiMetricsProto.SoftApConnectedClientsEvent; import com.android.server.wifi.nano.WifiMetricsProto.StaEvent; import com.android.server.wifi.nano.WifiMetricsProto.WifiIsUnusableEvent; import com.android.server.wifi.nano.WifiMetricsProto.WifiRadioUsage; import com.android.server.wifi.nano.WifiMetricsProto.WpsMetrics; -import com.android.server.wifi.nano.WifiMetricsProto.PasspointProfileTypeCount; import com.android.server.wifi.rtt.RttMetrics; import org.junit.Before; @@ -1469,7 +1469,7 @@ public class WifiMetricsTest { private static final int ASSOC_TIMEOUT = 1; private static final int LOCAL_GEN = 1; private static final int AUTH_FAILURE_REASON = WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD; - private static final int NUM_TEST_STA_EVENTS = 16; + private static final int NUM_TEST_STA_EVENTS = 18; private static final String sSSID = "\"SomeTestSsid\""; private static final WifiSsid sWifiSsid = WifiSsid.createFromAsciiEncoded(sSSID); private static final String sBSSID = "01:02:03:04:05:06"; @@ -1519,7 +1519,9 @@ public class WifiMetricsTest { {StaEvent.TYPE_NETWORK_AGENT_VALID_NETWORK, 0, 0}, {StaEvent.TYPE_FRAMEWORK_DISCONNECT, StaEvent.DISCONNECT_API, 0}, {StaEvent.TYPE_SCORE_BREACH, 0, 0}, - {StaEvent.TYPE_MAC_CHANGE, 0, 1} + {StaEvent.TYPE_MAC_CHANGE, 0, 1}, + {StaEvent.TYPE_WIFI_ENABLED, 0, 0}, + {StaEvent.TYPE_WIFI_DISABLED, 0, 0} }; // Values used to generate the StaEvent log calls from WifiMonitor // <type>, <reason>, <status>, <local_gen>, @@ -1556,7 +1558,11 @@ public class WifiMetricsTest { {StaEvent.TYPE_SCORE_BREACH, -1, -1, 0, /**/ 0, 0, 0, 0}, /**/ {StaEvent.TYPE_MAC_CHANGE, -1, -1, 0, - /**/ 0, 0, 0, 1} /**/ + /**/ 0, 0, 0, 1}, /**/ + {StaEvent.TYPE_WIFI_ENABLED, -1, -1, 0, + /**/ 0, 0, 0, 0}, /**/ + {StaEvent.TYPE_WIFI_DISABLED, -1, -1, 0, + /**/ 0, 0, 0, 0} /**/ }; /** |