summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-04-08 09:09:37 -0700
committerRoshan Pius <rpius@google.com>2020-04-09 09:07:35 -0700
commit11c234cedda86e8b3a863f54d2a32d9c6730e258 (patch)
tree2800aba093dabf5429bb8995dbd2ddbcf21dc19d /service
parent82298418fe24c1d0d8f62ba1b79e55d168bf6351 (diff)
SelfRecovery: Add overlay for the recovery limit
Bug: 153395624 Test: atest com.android.server.wifi Test: Manually crash wpa_supplicant from shell: - Ensured that we restarted the stack the first 2 attempts. - Ensured that we disabled wifi for all further attempts. Change-Id: Iafcd193e373f7e6530446e69a927e2dd0056f402
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/SelfRecovery.java26
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java2
-rw-r--r--service/res/values/config.xml5
-rw-r--r--service/res/values/overlayable.xml1
4 files changed, 25 insertions, 9 deletions
diff --git a/service/java/com/android/server/wifi/SelfRecovery.java b/service/java/com/android/server/wifi/SelfRecovery.java
index e789dd3a4..b7eb72364 100644
--- a/service/java/com/android/server/wifi/SelfRecovery.java
+++ b/service/java/com/android/server/wifi/SelfRecovery.java
@@ -17,12 +17,16 @@
package com.android.server.wifi;
import android.annotation.IntDef;
+import android.content.Context;
import android.util.Log;
+import com.android.wifi.resources.R;
+
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.concurrent.TimeUnit;
/**
* This class is used to recover the wifi stack from a fatal failure. The recovery mechanism
@@ -50,19 +54,19 @@ public class SelfRecovery {
REASON_STA_IFACE_DOWN})
public @interface RecoveryReason {}
- public static final long MAX_RESTARTS_IN_TIME_WINDOW = 2; // 2 restarts per hour
- public static final long MAX_RESTARTS_TIME_WINDOW_MILLIS = 60 * 60 * 1000; // 1 hour
protected static final String[] REASON_STRINGS = {
"Last Resort Watchdog", // REASON_LAST_RESORT_WATCHDOG
"WifiNative Failure", // REASON_WIFINATIVE_FAILURE
"Sta Interface Down" // REASON_STA_IFACE_DOWN
};
+ private final Context mContext;
private final ActiveModeWarden mActiveModeWarden;
private final Clock mClock;
// Time since boot (in millis) that restart occurred
private final LinkedList<Long> mPastRestartTimes;
- public SelfRecovery(ActiveModeWarden activeModeWarden, Clock clock) {
+ public SelfRecovery(Context context, ActiveModeWarden activeModeWarden, Clock clock) {
+ mContext = context;
mActiveModeWarden = activeModeWarden;
mClock = clock;
mPastRestartTimes = new LinkedList<>();
@@ -94,11 +98,17 @@ public class SelfRecovery {
Log.e(TAG, "Triggering recovery for reason: " + REASON_STRINGS[reason]);
if (reason == REASON_WIFINATIVE_FAILURE) {
+ int maxRecoveriesPerHour = mContext.getResources().getInteger(
+ R.integer.config_wifiMaxNativeFailureSelfRecoveryPerHour);
+ if (maxRecoveriesPerHour == 0) {
+ Log.e(TAG, "Recovery disabled. Disabling wifi");
+ mActiveModeWarden.recoveryDisableWifi();
+ return;
+ }
trimPastRestartTimes();
- // Ensure there haven't been too many restarts within MAX_RESTARTS_TIME_WINDOW
- if (mPastRestartTimes.size() >= MAX_RESTARTS_IN_TIME_WINDOW) {
- Log.e(TAG, "Already restarted wifi (" + MAX_RESTARTS_IN_TIME_WINDOW + ") times in"
- + " last (" + MAX_RESTARTS_TIME_WINDOW_MILLIS + "ms ). Disabling wifi");
+ if (mPastRestartTimes.size() >= maxRecoveriesPerHour) {
+ Log.e(TAG, "Already restarted wifi " + maxRecoveriesPerHour + " times in"
+ + " last 1 hour. Disabling wifi");
mActiveModeWarden.recoveryDisableWifi();
return;
}
@@ -115,7 +125,7 @@ public class SelfRecovery {
long now = mClock.getElapsedSinceBootMillis();
while (iter.hasNext()) {
Long restartTimeMillis = iter.next();
- if (now - restartTimeMillis > MAX_RESTARTS_TIME_WINDOW_MILLIS) {
+ if (now - restartTimeMillis > TimeUnit.HOURS.toMillis(1)) {
iter.remove();
} else {
break;
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index 594008975..1e5e54682 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -369,7 +369,7 @@ public class WifiInjector {
this, mFrameworkFacade, mClock);
mLockManager = new WifiLockManager(mContext, mBatteryStats,
mClientModeImpl, mFrameworkFacade, wifiHandler, mWifiNative, mClock, mWifiMetrics);
- mSelfRecovery = new SelfRecovery(mActiveModeWarden, mClock);
+ mSelfRecovery = new SelfRecovery(mContext, mActiveModeWarden, mClock);
mWifiMulticastLockManager = new WifiMulticastLockManager(
mClientModeImpl.getMcastLockManagerFilterController(), mBatteryStats);
mDppManager = new DppManager(wifiHandler, mWifiNative,
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index 4d351b105..43d4a03c5 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -399,4 +399,9 @@
<!-- Enable WPA2 to WPA3 auto-upgrade offload to capable Driver/Firmware -->
<bool translatable="false" name="config_wifiSaeUpgradeOffloadEnabled">false</bool>
+
+ <!-- Number of self recoveries to be attempted per hour. Any fatal errors beyond this will
+ cause the wifi stack to turn wifi off and wait for user input.
+ Set to 0 to turn off recovery attempts and always turn off wifi on failures -->
+ <integer translatable="false" name="config_wifiMaxNativeFailureSelfRecoveryPerHour">2</integer>
</resources>
diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml
index 7244911af..028d7240f 100644
--- a/service/res/values/overlayable.xml
+++ b/service/res/values/overlayable.xml
@@ -126,6 +126,7 @@
<item type="integer" name="config_wifiPollRssiIntervalMilliseconds" />
<item type="bool" name="config_wifiSaeUpgradeEnabled" />
<item type="bool" name="config_wifiSaeUpgradeOffloadEnabled" />
+ <item type="integer" name="config_wifiMaxNativeFailureSelfRecoveryPerHour" />
<!-- Params from config.xml that can be overlayed -->
<!-- Params from strings.xml that can be overlayed -->