Merge "Fix tethering WTF issue"

This commit is contained in:
Treehugger Robot 2022-07-22 12:52:13 +00:00 • committed by Gerrit Code Review
commit e522b7ff75

View file

@ -23,6 +23,7 @@ import static android.system.OsConstants.IPPROTO_RAW;
import static android.system.OsConstants.SOCK_DGRAM;
import static android.system.OsConstants.SOCK_NONBLOCK;
import static android.system.OsConstants.SOCK_RAW;
import static android.system.OsConstants.ENODEV;
import android.net.util.SocketUtils;
import android.os.Handler;
@ -131,7 +132,13 @@ public class NeighborPacketForwarder extends PacketReader {
ETH_P_IPV6, mListenIfaceParams.index);
Os.bind(mFd, bindAddress);
} catch (ErrnoException | SocketException e) {
Log.wtf(mTag, "Failed to create socket", e);
// An ENODEV(No such device) will rise if tethering stopped before this function, this
// may happen when enable/disable tethering quickly.
if (e instanceof ErrnoException && ((ErrnoException) e).errno == ENODEV) {
Log.w(mTag, "Failed to create socket because tethered interface is gone", e);
} else {
Log.wtf(mTag, "Failed to create socket", e);
}
closeSocketQuietly(mFd);
return null;
}