summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-06-19 04:30:27 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-06-19 04:30:27 +0000
commit9f8e81eb31a689122f97a1a5ab78aa279dff48d2 (patch)
tree52c88a873efac5ab84821b4a11acb3bcfb041a1f /common
parent2fb96dbad12434f494694a326eaa6cf292d154a3 (diff)
parent1b41f5d2586462e55c5bff5449e3b78d69bc911c (diff)
downloadplatform_packages_modules_NetworkStack-9f8e81eb31a689122f97a1a5ab78aa279dff48d2.tar.gz
platform_packages_modules_NetworkStack-9f8e81eb31a689122f97a1a5ab78aa279dff48d2.tar.bz2
platform_packages_modules_NetworkStack-9f8e81eb31a689122f97a1a5ab78aa279dff48d2.zip
Merge "Retry networkAddInterface on EBUSY errorCode" am: ca9c116925 am: 1b41f5d258
Original change: https://android-review.googlesource.com/c/platform/packages/modules/NetworkStack/+/1335528 Change-Id: I1208aade79fc42edd025e9e3ba4665003a512ee5
Diffstat (limited to 'common')
-rw-r--r--common/moduleutils/src/android/net/shared/NetdUtils.java41
1 files changed, 39 insertions, 2 deletions
diff --git a/common/moduleutils/src/android/net/shared/NetdUtils.java b/common/moduleutils/src/android/net/shared/NetdUtils.java
index 0137bb77..5fa29c9b 100644
--- a/common/moduleutils/src/android/net/shared/NetdUtils.java
+++ b/common/moduleutils/src/android/net/shared/NetdUtils.java
@@ -17,6 +17,7 @@
package android.net.shared;
import static android.net.RouteInfo.RTN_UNICAST;
+import static android.system.OsConstants.EBUSY;
import android.net.INetd;
import android.net.IpPrefix;
@@ -24,6 +25,8 @@ import android.net.RouteInfo;
import android.net.TetherConfigParcel;
import android.os.RemoteException;
import android.os.ServiceSpecificException;
+import android.os.SystemClock;
+import android.util.Log;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +36,8 @@ import java.util.List;
* @hide
*/
public class NetdUtils {
+ private static final String TAG = NetdUtils.class.getSimpleName();
+
/** Start tethering. */
public static void tetherStart(final INetd netd, final boolean usingLegacyDnsProxy,
final String[] dhcpRange) throws RemoteException, ServiceSpecificException {
@@ -45,14 +50,46 @@ public class NetdUtils {
/** Setup interface for tethering. */
public static void tetherInterface(final INetd netd, final String iface, final IpPrefix dest)
throws RemoteException, ServiceSpecificException {
- netd.tetherInterfaceAdd(iface);
+ tetherInterface(netd, iface, dest, 20 /* maxAttempts */, 50 /* pollingIntervalMs */);
+ }
- netd.networkAddInterface(INetd.LOCAL_NET_ID, iface);
+ /** Setup interface with configurable retries for tethering. */
+ public static void tetherInterface(final INetd netd, final String iface, final IpPrefix dest,
+ int maxAttempts, int pollingIntervalMs)
+ throws RemoteException, ServiceSpecificException {
+ netd.tetherInterfaceAdd(iface);
+ networkAddInterface(netd, iface, maxAttempts, pollingIntervalMs);
List<RouteInfo> routes = new ArrayList<>();
routes.add(new RouteInfo(dest, null, iface, RTN_UNICAST));
RouteUtils.addRoutesToLocalNetwork(netd, iface, routes);
}
+ /**
+ * Retry Netd#networkAddInterface for EBUSY error code.
+ * If the same interface (e.g., wlan0) is in client mode and then switches to tethered mode.
+ * There can be a race where puts the interface into the local network but interface is still
+ * in use in netd because the ConnectivityService thread hasn't processed the disconnect yet.
+ * See b/158269544 for detail.
+ */
+ private static void networkAddInterface(final INetd netd, final String iface,
+ int maxAttempts, int pollingIntervalMs)
+ throws ServiceSpecificException, RemoteException {
+ for (int i = 1; i <= maxAttempts; i++) {
+ try {
+ netd.networkAddInterface(INetd.LOCAL_NET_ID, iface);
+ return;
+ } catch (ServiceSpecificException e) {
+ if (e.errorCode == EBUSY && i < maxAttempts) {
+ SystemClock.sleep(pollingIntervalMs);
+ continue;
+ }
+
+ Log.e(TAG, "Retry Netd#networkAddInterface failure: " + e);
+ throw e;
+ }
+ }
+ }
+
/** Reset interface for tethering. */
public static void untetherInterface(final INetd netd, String iface)
throws RemoteException, ServiceSpecificException {