From df19e3cc9f5a5f67b973f5d2de2c8576f9a7b2fd Mon Sep 17 00:00:00 2001 From: Jong Wook Kim Date: Wed, 8 Aug 2018 15:03:31 -0700 Subject: Log when wifi is turned on/off in metrics Generate a StaEvent whenever wifi is enabled/disabled. Bug: 112193991 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: Turn wifi on/off from settings Test: adb shell dumpsys wifi | grep -A10 StaEventList Change-Id: I9ed97ed38e7529a6977bbf1a6004530f2af10a2e Merged-In: I9ed97ed38e7529a6977bbf1a6004530f2af10a2e --- service/java/com/android/server/wifi/WifiMetrics.java | 9 ++++++++- service/java/com/android/server/wifi/WifiStateMachine.java | 2 ++ .../src/com/android/server/wifi/WifiMetricsTest.java | 12 +++++++++--- .../src/com/android/server/wifi/WifiStateMachineTest.java | 10 ++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 15f65c980..d0b051e4e 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -29,7 +29,6 @@ import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.SystemProperties; - import android.util.Base64; import android.util.Log; import android.util.Pair; @@ -2739,6 +2738,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); @@ -2934,6 +2935,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/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index ef5eb027f..394a8ece4 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -3826,6 +3826,7 @@ public class WifiStateMachine 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(WifiStateMachine.CMD_ENABLE_P2P); // Inform sar manager that wifi is Enabled @@ -3843,6 +3844,7 @@ public class WifiStateMachine 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/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 5646efc62..01daa14d6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -1413,7 +1413,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"; @@ -1463,7 +1463,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 // , , , , @@ -1500,7 +1502,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} /**/ }; /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 90f3e0775..8154a02b9 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -95,6 +95,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; @@ -1836,6 +1837,7 @@ public class WifiStateMachineTest { public void testWifiInfoCleanedUpEnteringExitingConnectModeState() throws Exception { InOrder inOrder = inOrder(mWifiConnectivityManager); InOrder inOrderSarMgr = inOrder(mSarManager); + InOrder inOrderMetrics = inOrder(mWifiMetrics); Log.i(TAG, mWsm.getCurrentState().getName()); String initialBSSID = "aa:bb:cc:dd:ee:ff"; WifiInfo wifiInfo = mWsm.getWifiInfo(); @@ -1847,6 +1849,9 @@ public class WifiStateMachineTest { assertEquals(WifiManager.WIFI_STATE_ENABLED, mWsm.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 @@ -1867,6 +1872,8 @@ public class WifiStateMachineTest { assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.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()); @@ -1888,6 +1895,9 @@ public class WifiStateMachineTest { assertEquals(WifiManager.WIFI_STATE_ENABLED, mWsm.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()); -- cgit v1.2.3