diff options
4 files changed, 60 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java index efc59e64b..5dc799d65 100644 --- a/service/java/com/android/server/wifi/WifiLastResortWatchdog.java +++ b/service/java/com/android/server/wifi/WifiLastResortWatchdog.java @@ -28,6 +28,7 @@ import android.util.Log; import android.util.Pair; import com.android.internal.annotations.VisibleForTesting; +import com.android.wifi.R; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -119,7 +120,7 @@ public class WifiLastResortWatchdog { private final Handler mHandler; private final WifiThreadRunner mWifiThreadRunner; - private boolean mWatchdogFeatureEnabled = true; + private boolean mWatchdogFeatureEnabled; /** * Local log used for debugging any WifiLastResortWatchdog issues. @@ -142,6 +143,8 @@ public class WifiLastResortWatchdog { processMessage(msg); } }; + mWatchdogFeatureEnabled = mContext.getResources() + .getBoolean(R.bool.config_wifi_watchdog_enabled); } /** diff --git a/service/res/values/config.xml b/service/res/values/config.xml index 0b3623229..3cc44babe 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -225,4 +225,7 @@ <!-- Indicates that a full bugreport should be triggered when wifi diagnostics detects an error on non-user (i.e debug) builds --> <bool translatable="false" name="config_wifi_diagnostics_bugreport_enabled">false</bool> + + <!-- Indicates that wifi watchdog is enabled on this device --> + <bool translatable="false" name="config_wifi_watchdog_enabled">true</bool> </resources> diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index 909a669eb..c42212dff 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -98,6 +98,7 @@ <item type="string" name="wifi_tether_configure_ssid_default" /> <item type="string" name="wifi_localhotspot_configure_ssid_default" /> <item type="bool" name="config_wifi_diagnostics_bugreport_enabled" /> + <item type="bool" name="config_wifi_watchdog_enabled" /> <!-- Params from config.xml that can be overlayed --> <!-- Params from strings.xml that can be overlayed --> diff --git a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java index 023fddb17..fc85b4d6e 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiLastResortWatchdogTest.java @@ -31,6 +31,8 @@ import android.util.Pair; import androidx.test.filters.SmallTest; +import com.android.wifi.R; + import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -44,7 +46,6 @@ import java.util.List; */ @SmallTest public class WifiLastResortWatchdogTest extends WifiBaseTest { - WifiLastResortWatchdog mLastResortWatchdog; @Mock WifiInjector mWifiInjector; @Mock WifiMetrics mWifiMetrics; @Mock SelfRecovery mSelfRecovery; @@ -54,6 +55,8 @@ public class WifiLastResortWatchdogTest extends WifiBaseTest { @Mock Context mContext; @Mock DeviceConfigFacade mDeviceConfigFacade; + private WifiLastResortWatchdog mLastResortWatchdog; + private MockResources mResources; 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", "c0:ff:ee:ee:e3:ee"}; @@ -75,13 +78,20 @@ public class WifiLastResortWatchdogTest extends WifiBaseTest { when(mDeviceConfigFacade.isAbnormalConnectionBugreportEnabled()).thenReturn(true); when(mDeviceConfigFacade.getAbnormalConnectionDurationMs()).thenReturn( DEFAULT_ABNORMAL_CONNECTION_DURATION_MS); + mResources = new MockResources(); + mResources.setBoolean(R.bool.config_wifi_watchdog_enabled, true); + when(mContext.getResources()).thenReturn(mResources); + createWifiLastResortWatchdog(); + when(mClientModeImpl.getWifiInfo()).thenReturn(mWifiInfo); + when(mWifiInfo.getSSID()).thenReturn(TEST_NETWORK_SSID); + } + + private void createWifiLastResortWatchdog() { WifiThreadRunner wifiThreadRunner = new WifiThreadRunner(new Handler(mLooper.getLooper())); mLastResortWatchdog = new WifiLastResortWatchdog(mWifiInjector, mContext, mClock, mWifiMetrics, mClientModeImpl, mLooper.getLooper(), mDeviceConfigFacade, wifiThreadRunner); mLastResortWatchdog.setBugReportProbability(1); - when(mClientModeImpl.getWifiInfo()).thenReturn(mWifiInfo); - when(mWifiInfo.getSSID()).thenReturn(TEST_NETWORK_SSID); } private List<Pair<ScanDetail, WifiConfiguration>> createFilteredQnsCandidates(String[] ssids, @@ -2304,4 +2314,43 @@ public class WifiLastResortWatchdogTest extends WifiBaseTest { verify(mWifiMetrics, never()).incrementNumLastResortWatchdogSuccesses(); verify(mClientModeImpl, never()).takeBugReport(anyString(), anyString()); } + + /** + * Test recovery won't be triggered when feature is not enabled. + */ + @Test + public void testWatchdogFeatureNotEnabled() { + String[] ssids = {"\"test1\""}; + String[] bssids = {"6c:f3:7f:ae:8c:f3"}; + int[] frequencies = {2437}; + String[] caps = {"[WPA2-EAP-CCMP][ESS]"}; + int[] levels = {-60}; + boolean[] isEphemeral = {false}; + boolean[] hasEverConnected = {true}; + + // Set watchdog feature disabled + mResources.setBoolean(R.bool.config_wifi_watchdog_enabled, false); + createWifiLastResortWatchdog(); + + List<Pair<ScanDetail, WifiConfiguration>> candidates = createFilteredQnsCandidates(ssids, + bssids, frequencies, caps, levels, isEphemeral, hasEverConnected); + mLastResortWatchdog.updateAvailableNetworks(candidates); + + // Ensure new networks have zero'ed failure counts + for (int i = 0; i < ssids.length; i++) { + assertFailureCountEquals(bssids[i], 0, 0, 0); + } + + // Increment failure counts + for (int i = 0; i < WifiLastResortWatchdog.FAILURE_THRESHOLD; i++) { + mLastResortWatchdog.noteConnectionFailureAndTriggerIfNeeded( + ssids[0], bssids[0], WifiLastResortWatchdog.FAILURE_CODE_ASSOCIATION); + } + + // Verify watchdog never trigger recovery + verify(mWifiMetrics, never()).incrementNumLastResortWatchdogTriggers(); + // Verify watchdog still trigger bugreport + mLooper.dispatchAll(); + verify(mClientModeImpl, times(1)).takeBugReport(anyString(), anyString()); + } } |