Move createTunInterface to Dependencies for testing
Test: TH Change-Id: I7b253db7242084c7343a589c733eccf68b3be728
This commit is contained in:
parent
1cf990e003
commit
1ad7cbfb74
1 changed files with 24 additions and 22 deletions
|
|
@ -237,32 +237,11 @@ public class L2capNetworkProvider {
|
|||
mProvider.unregisterNetworkOffer(reservedOffer);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static ParcelFileDescriptor createTunInterface(String ifname) {
|
||||
final ParcelFileDescriptor fd;
|
||||
try {
|
||||
fd = ParcelFileDescriptor.adoptFd(
|
||||
ServiceConnectivityJni.createTunTap(
|
||||
true /*isTun*/, true /*hasCarrier*/, true /*setIffMulticast*/, ifname));
|
||||
ServiceConnectivityJni.bringUpInterface(ifname);
|
||||
// TODO: consider adding a parameter to createTunTap() (or the Builder that should
|
||||
// be added) to configure i/o blocking.
|
||||
final int flags = Os.fcntlInt(fd.getFileDescriptor(), F_GETFL, 0);
|
||||
Os.fcntlInt(fd.getFileDescriptor(), F_SETFL, flags & ~O_NONBLOCK);
|
||||
} catch (Exception e) {
|
||||
// Note: createTunTap currently throws an IllegalStateException on failure.
|
||||
// TODO: native functions should throw ErrnoException.
|
||||
Log.e(TAG, "Failed to create tun interface", e);
|
||||
return null;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private L2capNetwork createL2capNetwork(BluetoothSocket socket, NetworkCapabilities caps,
|
||||
L2capNetwork.ICallback cb) {
|
||||
final String ifname = TUN_IFNAME + String.valueOf(sTunIndex++);
|
||||
final ParcelFileDescriptor tunFd = createTunInterface(ifname);
|
||||
final ParcelFileDescriptor tunFd = mDeps.createTunInterface(ifname);
|
||||
if (tunFd == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -652,6 +631,29 @@ public class L2capNetworkProvider {
|
|||
thread.start();
|
||||
return thread;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ParcelFileDescriptor createTunInterface(String ifname) {
|
||||
final ParcelFileDescriptor fd;
|
||||
try {
|
||||
fd = ParcelFileDescriptor.adoptFd(ServiceConnectivityJni.createTunTap(
|
||||
true /*isTun*/,
|
||||
true /*hasCarrier*/,
|
||||
true /*setIffMulticast*/,
|
||||
ifname));
|
||||
ServiceConnectivityJni.bringUpInterface(ifname);
|
||||
// TODO: consider adding a parameter to createTunTap() (or the Builder that should
|
||||
// be added) to configure i/o blocking.
|
||||
final int flags = Os.fcntlInt(fd.getFileDescriptor(), F_GETFL, 0);
|
||||
Os.fcntlInt(fd.getFileDescriptor(), F_SETFL, flags & ~O_NONBLOCK);
|
||||
} catch (Exception e) {
|
||||
// Note: createTunTap currently throws an IllegalStateException on failure.
|
||||
// TODO: native functions should throw ErrnoException.
|
||||
Log.e(TAG, "Failed to create tun interface", e);
|
||||
return null;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
public L2capNetworkProvider(Context context) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue