diff options
5 files changed, 36 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index cdde22268..a64075006 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -284,8 +284,8 @@ public class WifiInjector { mSettingsStore, mWifiServiceHandlerThread.getLooper(), mFrameworkFacade, mWifiStateMachinePrime); mSelfRecovery = new SelfRecovery(mWifiController, mClock); - mWifiLastResortWatchdog = new WifiLastResortWatchdog(mSelfRecovery, mWifiMetrics, - mWifiStateMachine, wifiStateMachineLooper); + mWifiLastResortWatchdog = new WifiLastResortWatchdog(mSelfRecovery, mClock, + mWifiMetrics, mWifiStateMachine, wifiStateMachineLooper); mWifiMulticastLockManager = new WifiMulticastLockManager( mWifiStateMachine.getMcastLockManagerFilterController(), BatteryStatsService.getService()); diff --git a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java index f759b1782..38f1be092 100644 --- a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java +++ b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java @@ -90,16 +90,19 @@ public class WifiLastResortWatchdog { // Is Watchdog allowed to trigger now? Set to false after triggering. Set to true after // successfully connecting or a new network (SSID) becomes available to connect to. private boolean mWatchdogAllowedToTrigger = true; + private long mTimeLastTrigger; private SelfRecovery mSelfRecovery; private WifiMetrics mWifiMetrics; private WifiStateMachine mWifiStateMachine; private Looper mWifiStateMachineLooper; private double mBugReportProbability = PROB_TAKE_BUGREPORT_DEFAULT; + private Clock mClock; - WifiLastResortWatchdog(SelfRecovery selfRecovery, WifiMetrics wifiMetrics, + WifiLastResortWatchdog(SelfRecovery selfRecovery, Clock clock, WifiMetrics wifiMetrics, WifiStateMachine wsm, Looper wifiStateMachineLooper) { mSelfRecovery = selfRecovery; + mClock = clock; mWifiMetrics = wifiMetrics; mWifiStateMachine = wsm; mWifiStateMachineLooper = wifiStateMachineLooper; @@ -223,6 +226,7 @@ public class WifiLastResortWatchdog { Log.e(TAG, "Watchdog triggering recovery"); mSsidAvailableAtFailure.clear(); mSsidAvailableAtFailure.addAll(mSsidFailureCount.keySet()); + mTimeLastTrigger = mClock.getElapsedSinceBootMillis(); mSelfRecovery.trigger(SelfRecovery.REASON_LAST_RESORT_WATCHDOG); // increment various watchdog trigger count stats incrementWifiMetricsTriggerCounts(); @@ -249,6 +253,8 @@ public class WifiLastResortWatchdog { // WiFi has connected after a Watchdog trigger, without any new networks becoming // available, log a Watchdog success in wifi metrics mWifiMetrics.incrementNumLastResortWatchdogSuccesses(); + long durationMs = mClock.getElapsedSinceBootMillis() - mTimeLastTrigger; + mWifiMetrics.setWatchdogSuccessTimeDurationMs(durationMs); if (mSsidAvailableAtFailure.contains(ssid)) { Log.e(TAG, "Wifi failed to connect on " + mSsidAvailableAtFailure.size() + " networks but was able to reconnect to one of them after a restart."); diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java index ea04f2f73..584e51043 100644 --- a/service/java/com/android/server/wifi/WifiMetrics.java +++ b/service/java/com/android/server/wifi/WifiMetrics.java @@ -1144,6 +1144,16 @@ public class WifiMetrics { } /** + * Sets the time taken for wifi to connect after a watchdog triggers a restart. + * @param milliseconds + */ + public void setWatchdogSuccessTimeDurationMs(long ms) { + synchronized (mLock) { + mWifiLogProto.watchdogTriggerToConnectionSuccessDurationMs = ms; + } + } + + /** * Increments the count of alerts by alert reason. * * @param reason The cause of the alert. The reason values are driver-specific. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java index 0cbc06ac2..1cd9750fe 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java @@ -44,6 +44,7 @@ public class WifiLastResortWatchdogTest { @Mock WifiMetrics mWifiMetrics; @Mock SelfRecovery mSelfRecovery; @Mock WifiStateMachine mWifiStateMachine; + @Mock Clock mClock; private String[] mSsids = {"\"test1\"", "\"test2\"", "\"test3\"", "\"test4\""}; private String[] mBssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "de:ad:ba:b1:e5:55", @@ -60,7 +61,7 @@ public class WifiLastResortWatchdogTest { public void setUp() throws Exception { initMocks(this); mLooper = new TestLooper(); - mLastResortWatchdog = new WifiLastResortWatchdog(mSelfRecovery, mWifiMetrics, + mLastResortWatchdog = new WifiLastResortWatchdog(mSelfRecovery, mClock, mWifiMetrics, mWifiStateMachine, mLooper.getLooper()); mLastResortWatchdog.setBugReportProbability(1); } @@ -1456,6 +1457,11 @@ public class WifiLastResortWatchdogTest { assertFailureCountEquals(bssids[i], 0, 0, 0); } + final long timeAtFailure = 100; + final long timeAtReconnect = 5000; + final long expectedDuration = timeAtReconnect - timeAtFailure; + when(mClock.getElapsedSinceBootMillis()).thenReturn(timeAtFailure, timeAtReconnect); + //Increment failure counts for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) { mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( @@ -1490,6 +1496,8 @@ public class WifiLastResortWatchdogTest { // Verify that WifiMetrics counted this as a Watchdog success verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); + verify(mWifiMetrics, times(1)).setWatchdogSuccessTimeDurationMs(eq(expectedDuration)); + // Verify takeBugReport is called mLooper.dispatchAll(); verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString()); @@ -1499,6 +1507,7 @@ public class WifiLastResortWatchdogTest { // Verify that WifiMetrics has still only counted one success verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); + verify(mWifiMetrics, times(1)).setWatchdogSuccessTimeDurationMs(eq(expectedDuration)); // Verify takeBugReport not called again mLooper.dispatchAll(); verify(mWifiStateMachine, times(1)).takeBugReport(anyString(), anyString()); @@ -1542,6 +1551,7 @@ public class WifiLastResortWatchdogTest { // Verify that WifiMetrics did not count another success, as the connection could be due // to the newly available network #5 verify(mWifiMetrics, times(1)).incrementNumLastResortWatchdogSuccesses(); + verify(mWifiMetrics, times(1)).setWatchdogSuccessTimeDurationMs(eq(expectedDuration)); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java index 665b60b46..8212169dc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java @@ -286,6 +286,7 @@ public class WifiMetricsTest { private static final int NUM_WPS_OTHER_CONNECTION_FAILURE = 16; private static final int NUM_WPS_SUPPLICANT_FAILURE = 12; private static final int NUM_WPS_CANCELLATION = 11; + private static final long NUM_WATCHDOG_SUCCESS_DURATION_MS = 65; /** Number of notifications per "Connect to Network" notification type. */ private static final int[] NUM_CONNECT_TO_NETWORK_NOTIFICATIONS = {0, 10, 20, 30, 40}; @@ -659,6 +660,8 @@ public class WifiMetricsTest { for (int i = 0; i < NUM_WPS_CANCELLATION; i++) { mWifiMetrics.incrementWpsCancellationCount(); } + + mWifiMetrics.setWatchdogSuccessTimeDurationMs(NUM_WATCHDOG_SUCCESS_DURATION_MS); } private void addSoftApEventsToMetrics() { @@ -924,6 +927,9 @@ public class WifiMetricsTest { assertEquals(NUM_WPS_OTHER_CONNECTION_FAILURE, wps_metrics.numWpsOtherConnectionFailure); assertEquals(NUM_WPS_SUPPLICANT_FAILURE, wps_metrics.numWpsSupplicantFailure); assertEquals(NUM_WPS_CANCELLATION, wps_metrics.numWpsCancellation); + + assertEquals(NUM_WATCHDOG_SUCCESS_DURATION_MS, + mDecodedProto.watchdogTriggerToConnectionSuccessDurationMs); } /** |