summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/net/DhcpResults.java29
-rw-r--r--core/java/android/net/INetworkStackConnector.aidl4
-rw-r--r--core/java/android/net/NetworkStack.java5
-rw-r--r--core/java/android/net/NetworkUtils.java27
-rw-r--r--core/java/android/net/StaticIpConfiguration.java9
-rw-r--r--core/java/android/net/metrics/DhcpClientEvent.java4
-rw-r--r--core/java/android/net/shared/FdEventsReader.java17
-rw-r--r--core/java/android/net/shared/InetAddressUtils.java58
8 files changed, 93 insertions, 60 deletions
diff --git a/core/java/android/net/DhcpResults.java b/core/java/android/net/DhcpResults.java
index 6c291c25dbdf..6f9e65fdf12c 100644
--- a/core/java/android/net/DhcpResults.java
+++ b/core/java/android/net/DhcpResults.java
@@ -17,6 +17,7 @@
package android.net;
import android.annotation.UnsupportedAppUsage;
+import android.net.shared.InetAddressUtils;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -73,19 +74,21 @@ public final class DhcpResults implements Parcelable {
public StaticIpConfiguration toStaticIpConfiguration() {
final StaticIpConfiguration s = new StaticIpConfiguration();
// All these except dnsServers are immutable, so no need to make copies.
- s.ipAddress = ipAddress;
- s.gateway = gateway;
- s.dnsServers.addAll(dnsServers);
- s.domains = domains;
+ s.setIpAddress(ipAddress);
+ s.setGateway(gateway);
+ for (InetAddress addr : dnsServers) {
+ s.addDnsServer(addr);
+ }
+ s.setDomains(domains);
return s;
}
public DhcpResults(StaticIpConfiguration source) {
if (source != null) {
- ipAddress = source.ipAddress;
- gateway = source.gateway;
- dnsServers.addAll(source.dnsServers);
- domains = source.domains;
+ ipAddress = source.getIpAddress();
+ gateway = source.getGateway();
+ dnsServers.addAll(source.getDnsServers());
+ domains = source.getDomains();
}
}
@@ -177,7 +180,7 @@ public final class DhcpResults implements Parcelable {
toStaticIpConfiguration().writeToParcel(dest, flags);
dest.writeInt(leaseDuration);
dest.writeInt(mtu);
- NetworkUtils.parcelInetAddress(dest, serverAddress, flags);
+ InetAddressUtils.parcelInetAddress(dest, serverAddress, flags);
dest.writeString(vendorInfo);
}
@@ -191,7 +194,7 @@ public final class DhcpResults implements Parcelable {
final DhcpResults dhcpResults = new DhcpResults(s);
dhcpResults.leaseDuration = in.readInt();
dhcpResults.mtu = in.readInt();
- dhcpResults.serverAddress = (Inet4Address) NetworkUtils.unparcelInetAddress(in);
+ dhcpResults.serverAddress = (Inet4Address) InetAddressUtils.unparcelInetAddress(in);
dhcpResults.vendorInfo = in.readString();
return dhcpResults;
}
@@ -200,7 +203,7 @@ public final class DhcpResults implements Parcelable {
// Not part of the superclass because they're only used by the JNI iterface to the DHCP daemon.
public boolean setIpAddress(String addrString, int prefixLength) {
try {
- Inet4Address addr = (Inet4Address) NetworkUtils.numericToInetAddress(addrString);
+ Inet4Address addr = (Inet4Address) InetAddresses.parseNumericAddress(addrString);
ipAddress = new LinkAddress(addr, prefixLength);
} catch (IllegalArgumentException|ClassCastException e) {
Log.e(TAG, "setIpAddress failed with addrString " + addrString + "/" + prefixLength);
@@ -211,7 +214,7 @@ public final class DhcpResults implements Parcelable {
public boolean setGateway(String addrString) {
try {
- gateway = NetworkUtils.numericToInetAddress(addrString);
+ gateway = InetAddresses.parseNumericAddress(addrString);
} catch (IllegalArgumentException e) {
Log.e(TAG, "setGateway failed with addrString " + addrString);
return true;
@@ -222,7 +225,7 @@ public final class DhcpResults implements Parcelable {
public boolean addDns(String addrString) {
if (TextUtils.isEmpty(addrString) == false) {
try {
- dnsServers.add(NetworkUtils.numericToInetAddress(addrString));
+ dnsServers.add(InetAddresses.parseNumericAddress(addrString));
} catch (IllegalArgumentException e) {
Log.e(TAG, "addDns failed with addrString " + addrString);
return true;
diff --git a/core/java/android/net/INetworkStackConnector.aidl b/core/java/android/net/INetworkStackConnector.aidl
index 8b64f1c7c45a..e052488f38c8 100644
--- a/core/java/android/net/INetworkStackConnector.aidl
+++ b/core/java/android/net/INetworkStackConnector.aidl
@@ -16,6 +16,7 @@
package android.net;
import android.net.INetworkMonitorCallbacks;
+import android.net.NetworkParcelable;
import android.net.dhcp.DhcpServingParamsParcel;
import android.net.dhcp.IDhcpServerCallbacks;
import android.net.ip.IIpClientCallbacks;
@@ -24,6 +25,7 @@ import android.net.ip.IIpClientCallbacks;
oneway interface INetworkStackConnector {
void makeDhcpServer(in String ifName, in DhcpServingParamsParcel params,
in IDhcpServerCallbacks cb);
- void makeNetworkMonitor(int netId, String name, in INetworkMonitorCallbacks cb);
+ void makeNetworkMonitor(in NetworkParcelable network, String name,
+ in INetworkMonitorCallbacks cb);
void makeIpClient(in String ifName, in IIpClientCallbacks callbacks);
} \ No newline at end of file
diff --git a/core/java/android/net/NetworkStack.java b/core/java/android/net/NetworkStack.java
index d277034650a1..ac6bff029e8c 100644
--- a/core/java/android/net/NetworkStack.java
+++ b/core/java/android/net/NetworkStack.java
@@ -104,10 +104,11 @@ public class NetworkStack {
*
* <p>The INetworkMonitor will be returned asynchronously through the provided callbacks.
*/
- public void makeNetworkMonitor(Network network, String name, INetworkMonitorCallbacks cb) {
+ public void makeNetworkMonitor(
+ NetworkParcelable network, String name, INetworkMonitorCallbacks cb) {
requestConnector(connector -> {
try {
- connector.makeNetworkMonitor(network.netId, name, cb);
+ connector.makeNetworkMonitor(network, name, cb);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java
index 39db4fef78b5..6a1720353f17 100644
--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -23,7 +23,6 @@ import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.net.shared.Inet4AddressUtils;
import android.os.Build;
-import android.os.Parcel;
import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;
@@ -252,32 +251,6 @@ public class NetworkUtils {
}
/**
- * Writes an InetAddress to a parcel. The address may be null. This is likely faster than
- * calling writeSerializable.
- */
- protected static void parcelInetAddress(Parcel parcel, InetAddress address, int flags) {
- byte[] addressArray = (address != null) ? address.getAddress() : null;
- parcel.writeByteArray(addressArray);
- }
-
- /**
- * Reads an InetAddress from a parcel. Returns null if the address that was written was null
- * or if the data is invalid.
- */
- protected static InetAddress unparcelInetAddress(Parcel in) {
- byte[] addressArray = in.createByteArray();
- if (addressArray == null) {
- return null;
- }
- try {
- return InetAddress.getByAddress(addressArray);
- } catch (UnknownHostException e) {
- return null;
- }
- }
-
-
- /**
* Masks a raw IP address byte array with the specified prefix length.
*/
public static void maskRawAddress(byte[] array, int prefixLength) {
diff --git a/core/java/android/net/StaticIpConfiguration.java b/core/java/android/net/StaticIpConfiguration.java
index 25bae3c57423..99cf3a99f57a 100644
--- a/core/java/android/net/StaticIpConfiguration.java
+++ b/core/java/android/net/StaticIpConfiguration.java
@@ -19,6 +19,7 @@ package android.net;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.annotation.UnsupportedAppUsage;
+import android.net.shared.InetAddressUtils;
import android.os.Parcel;
import android.os.Parcelable;
@@ -232,10 +233,10 @@ public final class StaticIpConfiguration implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(ipAddress, flags);
- NetworkUtils.parcelInetAddress(dest, gateway, flags);
+ InetAddressUtils.parcelInetAddress(dest, gateway, flags);
dest.writeInt(dnsServers.size());
for (InetAddress dnsServer : dnsServers) {
- NetworkUtils.parcelInetAddress(dest, dnsServer, flags);
+ InetAddressUtils.parcelInetAddress(dest, dnsServer, flags);
}
dest.writeString(domains);
}
@@ -244,11 +245,11 @@ public final class StaticIpConfiguration implements Parcelable {
public static StaticIpConfiguration readFromParcel(Parcel in) {
final StaticIpConfiguration s = new StaticIpConfiguration();
s.ipAddress = in.readParcelable(null);
- s.gateway = NetworkUtils.unparcelInetAddress(in);
+ s.gateway = InetAddressUtils.unparcelInetAddress(in);
s.dnsServers.clear();
int size = in.readInt();
for (int i = 0; i < size; i++) {
- s.dnsServers.add(NetworkUtils.unparcelInetAddress(in));
+ s.dnsServers.add(InetAddressUtils.unparcelInetAddress(in));
}
s.domains = in.readString();
return s;
diff --git a/core/java/android/net/metrics/DhcpClientEvent.java b/core/java/android/net/metrics/DhcpClientEvent.java
index 2a942eedcb47..3008115e063b 100644
--- a/core/java/android/net/metrics/DhcpClientEvent.java
+++ b/core/java/android/net/metrics/DhcpClientEvent.java
@@ -31,10 +31,6 @@ import android.os.Parcelable;
public final class DhcpClientEvent implements IpConnectivityLog.Event {
// Names for recording DhcpClient pseudo-state transitions.
- /** {@hide} Represents transitions from DhcpInitState to DhcpBoundState */
- public static final String INITIAL_BOUND = "InitialBoundState";
- /** {@hide} Represents transitions from and to DhcpBoundState via DhcpRenewingState */
- public static final String RENEWING_BOUND = "RenewingBoundState";
/** @hide */
public final String msg;
diff --git a/core/java/android/net/shared/FdEventsReader.java b/core/java/android/net/shared/FdEventsReader.java
index 5ccc560a3091..bffbfb115886 100644
--- a/core/java/android/net/shared/FdEventsReader.java
+++ b/core/java/android/net/shared/FdEventsReader.java
@@ -21,15 +21,15 @@ import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.net.util.SocketUtils;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.system.ErrnoException;
import android.system.OsConstants;
-import libcore.io.IoUtils;
-
import java.io.FileDescriptor;
+import java.io.IOException;
/**
@@ -81,7 +81,10 @@ public abstract class FdEventsReader<BufferType> {
private long mPacketsReceived;
protected static void closeFd(FileDescriptor fd) {
- IoUtils.closeQuietly(fd);
+ try {
+ SocketUtils.closeSocket(fd);
+ } catch (IOException ignored) {
+ }
}
protected FdEventsReader(@NonNull Handler h, @NonNull BufferType buffer) {
@@ -136,8 +139,8 @@ public abstract class FdEventsReader<BufferType> {
}
/**
- * Subclasses MUST create the listening socket here, including setting
- * all desired socket options, interface or address/port binding, etc.
+ * Subclasses MUST create the listening socket here, including setting all desired socket
+ * options, interface or address/port binding, etc. The socket MUST be created nonblocking.
*/
@Nullable
protected abstract FileDescriptor createFd();
@@ -181,10 +184,6 @@ public abstract class FdEventsReader<BufferType> {
try {
mFd = createFd();
- if (mFd != null) {
- // Force the socket to be non-blocking.
- IoUtils.setBlocking(mFd, false);
- }
} catch (Exception e) {
logError("Failed to create socket: ", e);
closeFd(mFd);
diff --git a/core/java/android/net/shared/InetAddressUtils.java b/core/java/android/net/shared/InetAddressUtils.java
new file mode 100644
index 000000000000..c9ee3a7cce4b
--- /dev/null
+++ b/core/java/android/net/shared/InetAddressUtils.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2012 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.shared;
+
+import android.os.Parcel;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Collection of utilities to interact with {@link InetAddress}
+ * @hide
+ */
+public class InetAddressUtils {
+
+ /**
+ * Writes an InetAddress to a parcel. The address may be null. This is likely faster than
+ * calling writeSerializable.
+ * @hide
+ */
+ public static void parcelInetAddress(Parcel parcel, InetAddress address, int flags) {
+ byte[] addressArray = (address != null) ? address.getAddress() : null;
+ parcel.writeByteArray(addressArray);
+ }
+
+ /**
+ * Reads an InetAddress from a parcel. Returns null if the address that was written was null
+ * or if the data is invalid.
+ * @hide
+ */
+ public static InetAddress unparcelInetAddress(Parcel in) {
+ byte[] addressArray = in.createByteArray();
+ if (addressArray == null) {
+ return null;
+ }
+ try {
+ return InetAddress.getByAddress(addressArray);
+ } catch (UnknownHostException e) {
+ return null;
+ }
+ }
+
+ private InetAddressUtils() {}
+}