diff options
author | Ningyuan Wang <nywang@google.com> | 2017-04-28 16:51:25 -0700 |
---|---|---|
committer | Ningyuan Wang <nywang@google.com> | 2017-05-04 10:16:59 -0700 |
commit | 3895a16e00aa5899e90c014566e4fe33a63e3619 (patch) | |
tree | 9bbb109e77750a6847724a0b387571851d9fca3d /service | |
parent | bd6f2f3e73224237808660fc89c6251797412caf (diff) |
Add retry logic for wifi Hal starting failure
This add the retry logic for starting the wifi HAL because
wifi HAL might still be in the process of stopping.
Bug: 37681479
Test: compile, unittests
Test: manual test toggling the hotspot mode quickly
Change-Id: If87d8a0ebdcdf8a0aca233808b9d84393d21f738
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/HalDeviceManager.java | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/HalDeviceManager.java b/service/java/com/android/server/wifi/HalDeviceManager.java index 4203c36c7..c54be9b9a 100644 --- a/service/java/com/android/server/wifi/HalDeviceManager.java +++ b/service/java/com/android/server/wifi/HalDeviceManager.java @@ -42,6 +42,8 @@ import android.util.MutableBoolean; import android.util.MutableInt; import android.util.SparseArray; +import com.android.internal.annotations.VisibleForTesting; + import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; @@ -60,6 +62,12 @@ public class HalDeviceManager { private static final String TAG = "HalDeviceManager"; private static final boolean DBG = false; + private static final int START_HAL_RETRY_INTERVAL_MS = 20; + // Number of attempts a start() is re-tried. A value of 0 means no retries after a single + // attempt. + @VisibleForTesting + public static final int START_HAL_RETRY_TIMES = 3; + // public API public HalDeviceManager() { mInterfaceAvailableForRequestListeners.put(IfaceType.STA, new HashSet<>()); @@ -1054,15 +1062,35 @@ public class HalDeviceManager { Log.w(TAG, "startWifi called but mWifi is null!?"); return false; } else { - WifiStatus status = mWifi.start(); - boolean success = status.code == WifiStatusCode.SUCCESS; - if (success) { - initIWifiChipDebugListeners(); - managerStatusListenerDispatch(); - } else { - Log.e(TAG, "Cannot start IWifi: " + statusString(status)); + int triedCount = 0; + while (triedCount <= START_HAL_RETRY_TIMES) { + WifiStatus status = mWifi.start(); + if (status.code == WifiStatusCode.SUCCESS) { + initIWifiChipDebugListeners(); + managerStatusListenerDispatch(); + if (triedCount != 0) { + Log.d(TAG, "start IWifi succeeded after trying " + + triedCount + " times"); + } + return true; + } else if (status.code == WifiStatusCode.ERROR_NOT_AVAILABLE) { + // Should retry. Hal might still be stopping. + Log.e(TAG, "Cannot start IWifi: " + statusString(status) + + ", Retrying..."); + try { + Thread.sleep(START_HAL_RETRY_INTERVAL_MS); + } catch (InterruptedException ignore) { + // no-op + } + triedCount++; + } else { + // Should not retry on other failures. + Log.e(TAG, "Cannot start IWifi: " + statusString(status)); + return false; + } } - return success; + Log.e(TAG, "Cannot start IWifi after trying " + triedCount + " times"); + return false; } } catch (RemoteException e) { Log.e(TAG, "startWifi exception: " + e); |