diff options
author | Jong Wook Kim <jongwook@google.com> | 2018-11-09 21:16:39 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-11-09 21:16:39 +0000 |
commit | 51134fb02c2b0b64b9705aa293bf929d45b76a65 (patch) | |
tree | b68f2d1e7835853d4df6d8af40f3c59f92b85cc4 | |
parent | 1ce443488506186656621ad28dbc5da21d2873d8 (diff) | |
parent | df19e3cc9f5a5f67b973f5d2de2c8576f9a7b2fd (diff) |
Merge "Log when wifi is turned on/off in metrics" into pi-dev
4 files changed, 29 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index 86d8549bc..440754137 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -2793,6 +2793,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); @@ -2988,6 +2990,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 744b6a157..67b1ad6e7 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 1e49bf2c0..7ff28b5a2 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -1415,7 +1415,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"; @@ -1465,7 +1465,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>, @@ -1502,7 +1504,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()); |