Merge "Remove workarounds to use core platform API" am: 78dcc73e4c am: 31dbe8b122
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1754889 Change-Id: Ib01bbc0cfec540a6e811ac874c4e731734490dfb
This commit is contained in:
@@ -4948,7 +4948,7 @@ public class ConnectivityManager {
|
|||||||
Log.e(TAG, "Can't set proxy properties", e);
|
Log.e(TAG, "Can't set proxy properties", e);
|
||||||
}
|
}
|
||||||
// Must flush DNS cache as new network may have different DNS resolutions.
|
// Must flush DNS cache as new network may have different DNS resolutions.
|
||||||
InetAddressCompat.clearDnsCache();
|
InetAddress.clearDnsCache();
|
||||||
// Must flush socket pool as idle sockets will be bound to previous network and may
|
// Must flush socket pool as idle sockets will be bound to previous network and may
|
||||||
// cause subsequent fetches to be performed on old network.
|
// cause subsequent fetches to be performed on old network.
|
||||||
NetworkEventDispatcher.getInstance().dispatchNetworkConfigurationChange();
|
NetworkEventDispatcher.getInstance().dispatchNetworkConfigurationChange();
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package android.net;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compatibility utility for InetAddress core platform APIs.
|
|
||||||
*
|
|
||||||
* Connectivity has access to such APIs, but they are not part of the module_current stubs yet
|
|
||||||
* (only core_current). Most stable core platform APIs are included manually in the connectivity
|
|
||||||
* build rules, but because InetAddress is also part of the base java SDK that is earlier on the
|
|
||||||
* classpath, the extra core platform APIs are not seen.
|
|
||||||
*
|
|
||||||
* TODO (b/183097033): remove this utility as soon as core_current is part of module_current
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public class InetAddressCompat {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see InetAddress#clearDnsCache()
|
|
||||||
*/
|
|
||||||
public static void clearDnsCache() {
|
|
||||||
try {
|
|
||||||
InetAddress.class.getMethod("clearDnsCache").invoke(null);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
if (e.getCause() instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException) e.getCause();
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Unknown InvocationTargetException", e.getCause());
|
|
||||||
} catch (IllegalAccessException | NoSuchMethodException e) {
|
|
||||||
Log.wtf(InetAddressCompat.class.getSimpleName(), "Error clearing DNS cache", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see InetAddress#getAllByNameOnNet(String, int)
|
|
||||||
*/
|
|
||||||
public static InetAddress[] getAllByNameOnNet(String host, int netId) throws
|
|
||||||
UnknownHostException {
|
|
||||||
return (InetAddress[]) callGetByNameMethod("getAllByNameOnNet", host, netId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see InetAddress#getByNameOnNet(String, int)
|
|
||||||
*/
|
|
||||||
public static InetAddress getByNameOnNet(String host, int netId) throws
|
|
||||||
UnknownHostException {
|
|
||||||
return (InetAddress) callGetByNameMethod("getByNameOnNet", host, netId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Object callGetByNameMethod(String method, String host, int netId)
|
|
||||||
throws UnknownHostException {
|
|
||||||
try {
|
|
||||||
return InetAddress.class.getMethod(method, String.class, int.class)
|
|
||||||
.invoke(null, host, netId);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
if (e.getCause() instanceof UnknownHostException) {
|
|
||||||
throw (UnknownHostException) e.getCause();
|
|
||||||
}
|
|
||||||
if (e.getCause() instanceof RuntimeException) {
|
|
||||||
throw (RuntimeException) e.getCause();
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Unknown InvocationTargetException", e.getCause());
|
|
||||||
} catch (IllegalAccessException | NoSuchMethodException e) {
|
|
||||||
Log.wtf(InetAddressCompat.class.getSimpleName(), "Error calling " + method, e);
|
|
||||||
throw new IllegalStateException("Error querying via " + method, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -142,7 +142,7 @@ public class Network implements Parcelable {
|
|||||||
* @throws UnknownHostException if the address lookup fails.
|
* @throws UnknownHostException if the address lookup fails.
|
||||||
*/
|
*/
|
||||||
public InetAddress[] getAllByName(String host) throws UnknownHostException {
|
public InetAddress[] getAllByName(String host) throws UnknownHostException {
|
||||||
return InetAddressCompat.getAllByNameOnNet(host, getNetIdForResolv());
|
return InetAddress.getAllByNameOnNet(host, getNetIdForResolv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,7 +155,7 @@ public class Network implements Parcelable {
|
|||||||
* if the address lookup fails.
|
* if the address lookup fails.
|
||||||
*/
|
*/
|
||||||
public InetAddress getByName(String host) throws UnknownHostException {
|
public InetAddress getByName(String host) throws UnknownHostException {
|
||||||
return InetAddressCompat.getByNameOnNet(host, getNetIdForResolv());
|
return InetAddress.getByNameOnNet(host, getNetIdForResolv());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ java_library {
|
|||||||
":net-module-utils-srcs",
|
":net-module-utils-srcs",
|
||||||
],
|
],
|
||||||
libs: [
|
libs: [
|
||||||
"android_system_server_stubs_current",
|
|
||||||
"framework-annotations-lib",
|
"framework-annotations-lib",
|
||||||
"framework-connectivity.impl",
|
"framework-connectivity.impl",
|
||||||
"framework-tethering.stubs.module_lib",
|
"framework-tethering.stubs.module_lib",
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.server.connectivity;
|
|
||||||
|
|
||||||
import android.system.ErrnoException;
|
|
||||||
import android.system.Os;
|
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compatibility utility for android.system.Os core platform APIs.
|
|
||||||
*
|
|
||||||
* Connectivity has access to such APIs, but they are not part of the module_current stubs yet
|
|
||||||
* (only core_current). Most stable core platform APIs are included manually in the connectivity
|
|
||||||
* build rules, but because Os is also part of the base java SDK that is earlier on the
|
|
||||||
* classpath, the extra core platform APIs are not seen.
|
|
||||||
*
|
|
||||||
* TODO (b/157639992, b/183097033): remove as soon as core_current is part of system_server_current
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public class OsCompat {
|
|
||||||
// This value should be correct on all architectures supported by Android, but hardcoding ioctl
|
|
||||||
// numbers should be avoided.
|
|
||||||
/**
|
|
||||||
* @see android.system.OsConstants#TIOCOUTQ
|
|
||||||
*/
|
|
||||||
public static final int TIOCOUTQ = 0x5411;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see android.system.Os#getsockoptInt(FileDescriptor, int, int)
|
|
||||||
*/
|
|
||||||
public static int getsockoptInt(FileDescriptor fd, int level, int option) throws
|
|
||||||
ErrnoException {
|
|
||||||
try {
|
|
||||||
return (int) Os.class.getMethod(
|
|
||||||
"getsockoptInt", FileDescriptor.class, int.class, int.class)
|
|
||||||
.invoke(null, fd, level, option);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
if (e.getCause() instanceof ErrnoException) {
|
|
||||||
throw (ErrnoException) e.getCause();
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Error calling getsockoptInt", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see android.system.Os#ioctlInt(FileDescriptor, int)
|
|
||||||
*/
|
|
||||||
public static int ioctlInt(FileDescriptor fd, int cmd) throws
|
|
||||||
ErrnoException {
|
|
||||||
try {
|
|
||||||
return (int) Os.class.getMethod(
|
|
||||||
"ioctlInt", FileDescriptor.class, int.class).invoke(null, fd, cmd);
|
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
if (e.getCause() instanceof ErrnoException) {
|
|
||||||
throw (ErrnoException) e.getCause();
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("Error calling ioctlInt", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,8 +27,7 @@ import static android.system.OsConstants.IPPROTO_IP;
|
|||||||
import static android.system.OsConstants.IPPROTO_TCP;
|
import static android.system.OsConstants.IPPROTO_TCP;
|
||||||
import static android.system.OsConstants.IP_TOS;
|
import static android.system.OsConstants.IP_TOS;
|
||||||
import static android.system.OsConstants.IP_TTL;
|
import static android.system.OsConstants.IP_TTL;
|
||||||
|
import static android.system.OsConstants.TIOCOUTQ;
|
||||||
import static com.android.server.connectivity.OsCompat.TIOCOUTQ;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.net.InvalidPacketException;
|
import android.net.InvalidPacketException;
|
||||||
@@ -176,10 +175,10 @@ public class TcpKeepaliveController {
|
|||||||
}
|
}
|
||||||
// Query write sequence number from SEND_QUEUE.
|
// Query write sequence number from SEND_QUEUE.
|
||||||
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR_QUEUE, TCP_SEND_QUEUE);
|
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR_QUEUE, TCP_SEND_QUEUE);
|
||||||
tcpDetails.seq = OsCompat.getsockoptInt(fd, IPPROTO_TCP, TCP_QUEUE_SEQ);
|
tcpDetails.seq = Os.getsockoptInt(fd, IPPROTO_TCP, TCP_QUEUE_SEQ);
|
||||||
// Query read sequence number from RECV_QUEUE.
|
// Query read sequence number from RECV_QUEUE.
|
||||||
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR_QUEUE, TCP_RECV_QUEUE);
|
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR_QUEUE, TCP_RECV_QUEUE);
|
||||||
tcpDetails.ack = OsCompat.getsockoptInt(fd, IPPROTO_TCP, TCP_QUEUE_SEQ);
|
tcpDetails.ack = Os.getsockoptInt(fd, IPPROTO_TCP, TCP_QUEUE_SEQ);
|
||||||
// Switch to NO_QUEUE to prevent illegal socket read/write in repair mode.
|
// Switch to NO_QUEUE to prevent illegal socket read/write in repair mode.
|
||||||
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR_QUEUE, TCP_NO_QUEUE);
|
Os.setsockoptInt(fd, IPPROTO_TCP, TCP_REPAIR_QUEUE, TCP_NO_QUEUE);
|
||||||
// Finally, check if socket is still idle. TODO : this check needs to move to
|
// Finally, check if socket is still idle. TODO : this check needs to move to
|
||||||
@@ -199,9 +198,9 @@ public class TcpKeepaliveController {
|
|||||||
tcpDetails.rcvWndScale = trw.rcvWndScale;
|
tcpDetails.rcvWndScale = trw.rcvWndScale;
|
||||||
if (tcpDetails.srcAddress.length == 4 /* V4 address length */) {
|
if (tcpDetails.srcAddress.length == 4 /* V4 address length */) {
|
||||||
// Query TOS.
|
// Query TOS.
|
||||||
tcpDetails.tos = OsCompat.getsockoptInt(fd, IPPROTO_IP, IP_TOS);
|
tcpDetails.tos = Os.getsockoptInt(fd, IPPROTO_IP, IP_TOS);
|
||||||
// Query TTL.
|
// Query TTL.
|
||||||
tcpDetails.ttl = OsCompat.getsockoptInt(fd, IPPROTO_IP, IP_TTL);
|
tcpDetails.ttl = Os.getsockoptInt(fd, IPPROTO_IP, IP_TTL);
|
||||||
}
|
}
|
||||||
} catch (ErrnoException e) {
|
} catch (ErrnoException e) {
|
||||||
Log.e(TAG, "Exception reading TCP state from socket", e);
|
Log.e(TAG, "Exception reading TCP state from socket", e);
|
||||||
@@ -306,7 +305,7 @@ public class TcpKeepaliveController {
|
|||||||
|
|
||||||
private static boolean isReceiveQueueEmpty(FileDescriptor fd)
|
private static boolean isReceiveQueueEmpty(FileDescriptor fd)
|
||||||
throws ErrnoException {
|
throws ErrnoException {
|
||||||
final int result = OsCompat.ioctlInt(fd, SIOCINQ);
|
final int result = Os.ioctlInt(fd, SIOCINQ);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
Log.e(TAG, "Read queue has data");
|
Log.e(TAG, "Read queue has data");
|
||||||
return false;
|
return false;
|
||||||
@@ -316,7 +315,7 @@ public class TcpKeepaliveController {
|
|||||||
|
|
||||||
private static boolean isSendQueueEmpty(FileDescriptor fd)
|
private static boolean isSendQueueEmpty(FileDescriptor fd)
|
||||||
throws ErrnoException {
|
throws ErrnoException {
|
||||||
final int result = OsCompat.ioctlInt(fd, SIOCOUTQ);
|
final int result = Os.ioctlInt(fd, SIOCOUTQ);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
Log.e(TAG, "Write queue has data");
|
Log.e(TAG, "Write queue has data");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user