Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Artur Satayev | 9c2add6 | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 22 | import android.compat.annotation.UnsupportedAppUsage; |
Mathew Inwood | e1a17ba | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 23 | import android.os.Build; |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 24 | import android.os.Parcel; |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 25 | import android.os.Parcelable; |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 26 | |
Chalard Jean | 059356d | 2020-07-31 20:00:30 +0900 | [diff] [blame] | 27 | import com.android.net.module.util.InetAddressUtils; |
Roshan Pius | 32b898b | 2019-11-14 12:20:41 -0800 | [diff] [blame] | 28 | |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 29 | import java.net.Inet4Address; |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 30 | import java.net.InetAddress; |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 31 | import java.util.ArrayList; |
| 32 | import java.util.List; |
| 33 | import java.util.Objects; |
| 34 | |
| 35 | /** |
| 36 | * Class that describes static IP configuration. |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 37 | */ |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 38 | public final class StaticIpConfiguration implements Parcelable { |
| 39 | /** @hide */ |
Mathew Inwood | e1a17ba | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 40 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 41 | @Nullable |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 42 | public LinkAddress ipAddress; |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 43 | /** @hide */ |
Mathew Inwood | e1a17ba | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 44 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 45 | @Nullable |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 46 | public InetAddress gateway; |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 47 | /** @hide */ |
Mathew Inwood | e1a17ba | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 48 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 49 | @NonNull |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 50 | public final ArrayList<InetAddress> dnsServers; |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 51 | /** @hide */ |
Mathew Inwood | e1a17ba | 2020-11-04 09:29:36 +0000 | [diff] [blame] | 52 | @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 53 | @Nullable |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 54 | public String domains; |
| 55 | |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 56 | /** @hide */ |
| 57 | @SystemApi |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 58 | public StaticIpConfiguration() { |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 59 | dnsServers = new ArrayList<>(); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 60 | } |
| 61 | |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 62 | /** @hide */ |
| 63 | @SystemApi |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 64 | public StaticIpConfiguration(@Nullable StaticIpConfiguration source) { |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 65 | this(); |
| 66 | if (source != null) { |
| 67 | // All of these except dnsServers are immutable, so no need to make copies. |
| 68 | ipAddress = source.ipAddress; |
| 69 | gateway = source.gateway; |
| 70 | dnsServers.addAll(source.dnsServers); |
| 71 | domains = source.domains; |
| 72 | } |
| 73 | } |
| 74 | |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 75 | /** @hide */ |
| 76 | @SystemApi |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 77 | public void clear() { |
| 78 | ipAddress = null; |
| 79 | gateway = null; |
| 80 | dnsServers.clear(); |
| 81 | domains = null; |
| 82 | } |
| 83 | |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 84 | /** |
| 85 | * Get the static IP address included in the configuration. |
| 86 | */ |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 87 | public @NonNull LinkAddress getIpAddress() { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 88 | return ipAddress; |
| 89 | } |
| 90 | |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 91 | /** |
| 92 | * Get the gateway included in the configuration. |
| 93 | */ |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 94 | public @Nullable InetAddress getGateway() { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 95 | return gateway; |
| 96 | } |
| 97 | |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 98 | /** |
| 99 | * Get the DNS servers included in the configuration. |
| 100 | */ |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 101 | public @NonNull List<InetAddress> getDnsServers() { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 102 | return dnsServers; |
| 103 | } |
| 104 | |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 105 | /** |
Remi NGUYEN VAN | 9ed3208 | 2019-04-03 15:54:25 +0900 | [diff] [blame] | 106 | * Get a {@link String} containing the comma separated domains to search when resolving host |
| 107 | * names on this link, in priority order. |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 108 | */ |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 109 | public @Nullable String getDomains() { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 110 | return domains; |
| 111 | } |
| 112 | |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 113 | /** |
| 114 | * Helper class to build a new instance of {@link StaticIpConfiguration}. |
| 115 | */ |
| 116 | public static final class Builder { |
| 117 | private LinkAddress mIpAddress; |
| 118 | private InetAddress mGateway; |
| 119 | private Iterable<InetAddress> mDnsServers; |
| 120 | private String mDomains; |
| 121 | |
| 122 | /** |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 123 | * Set the IP address to be included in the configuration. |
| 124 | * |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 125 | * @return The {@link Builder} for chaining. |
| 126 | */ |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 127 | public @NonNull Builder setIpAddress(@NonNull LinkAddress ipAddress) { |
| 128 | if (ipAddress != null && !(ipAddress.getAddress() instanceof Inet4Address)) { |
| 129 | throw new IllegalArgumentException( |
| 130 | "Only IPv4 addresses can be used for the IP configuration"); |
| 131 | } |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 132 | mIpAddress = ipAddress; |
| 133 | return this; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Set the address of the gateway to be included in the configuration; null by default. |
| 138 | * @return The {@link Builder} for chaining. |
| 139 | */ |
| 140 | public @NonNull Builder setGateway(@Nullable InetAddress gateway) { |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 141 | if (gateway != null && !(gateway instanceof Inet4Address)) { |
| 142 | throw new IllegalArgumentException( |
| 143 | "Only IPv4 addresses can be used for the gateway configuration"); |
| 144 | } |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 145 | mGateway = gateway; |
| 146 | return this; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Set the addresses of the DNS servers included in the configuration; empty by default. |
| 151 | * @return The {@link Builder} for chaining. |
| 152 | */ |
| 153 | public @NonNull Builder setDnsServers(@NonNull Iterable<InetAddress> dnsServers) { |
Remi NGUYEN VAN | 81f6842 | 2021-03-15 07:31:54 +0000 | [diff] [blame] | 154 | Objects.requireNonNull(dnsServers); |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 155 | for (InetAddress inetAddress: dnsServers) { |
| 156 | if (!(inetAddress instanceof Inet4Address)) { |
| 157 | throw new IllegalArgumentException( |
| 158 | "Only IPv4 addresses can be used for the DNS server configuration"); |
| 159 | } |
| 160 | } |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 161 | mDnsServers = dnsServers; |
| 162 | return this; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Sets the DNS domain search path to be used on the link; null by default. |
| 167 | * @param newDomains A {@link String} containing the comma separated domains to search when |
| 168 | * resolving host names on this link, in priority order. |
| 169 | * @return The {@link Builder} for chaining. |
| 170 | */ |
| 171 | public @NonNull Builder setDomains(@Nullable String newDomains) { |
| 172 | mDomains = newDomains; |
| 173 | return this; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Create a {@link StaticIpConfiguration} from the parameters in this {@link Builder}. |
| 178 | * @return The newly created StaticIpConfiguration. |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 179 | * @throws IllegalArgumentException if an invalid configuration is attempted, e.g. |
| 180 | * if an IP Address was not configured via {@link #setIpAddress(LinkAddress)}. |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 181 | */ |
| 182 | public @NonNull StaticIpConfiguration build() { |
| 183 | final StaticIpConfiguration config = new StaticIpConfiguration(); |
| 184 | config.ipAddress = mIpAddress; |
| 185 | config.gateway = mGateway; |
Roshan Pius | 32b898b | 2019-11-14 12:20:41 -0800 | [diff] [blame] | 186 | if (mDnsServers != null) { |
| 187 | for (InetAddress server : mDnsServers) { |
| 188 | config.dnsServers.add(server); |
| 189 | } |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 190 | } |
| 191 | config.domains = mDomains; |
| 192 | return config; |
| 193 | } |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /** |
| 197 | * Add a DNS server to this configuration. |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 198 | * @hide |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 199 | */ |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 200 | @SystemApi |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 201 | public void addDnsServer(@NonNull InetAddress server) { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 202 | dnsServers.add(server); |
| 203 | } |
| 204 | |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 205 | /** |
| 206 | * Returns the network routes specified by this object. Will typically include a |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 207 | * directly-connected route for the IP address's local subnet and a default route. |
| 208 | * @param iface Interface to include in the routes. |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 209 | * @hide |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 210 | */ |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 211 | @SystemApi |
Remi NGUYEN VAN | be381ab | 2019-03-25 16:41:08 +0900 | [diff] [blame] | 212 | public @NonNull List<RouteInfo> getRoutes(@Nullable String iface) { |
Lorenzo Colitti | c915d4c | 2015-01-20 15:53:02 +0900 | [diff] [blame] | 213 | List<RouteInfo> routes = new ArrayList<RouteInfo>(3); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 214 | if (ipAddress != null) { |
Lorenzo Colitti | c915d4c | 2015-01-20 15:53:02 +0900 | [diff] [blame] | 215 | RouteInfo connectedRoute = new RouteInfo(ipAddress, null, iface); |
| 216 | routes.add(connectedRoute); |
Remi NGUYEN VAN | 04c58fe | 2019-04-01 17:09:05 +0900 | [diff] [blame] | 217 | // If the default gateway is not covered by the directly-connected route, also add a |
| 218 | // host route to the gateway as well. This configuration is arguably invalid, but it |
| 219 | // used to work in K and earlier, and other OSes appear to accept it. |
Lorenzo Colitti | c915d4c | 2015-01-20 15:53:02 +0900 | [diff] [blame] | 220 | if (gateway != null && !connectedRoute.matches(gateway)) { |
| 221 | routes.add(RouteInfo.makeHostRoute(gateway, iface)); |
| 222 | } |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 223 | } |
| 224 | if (gateway != null) { |
Lorenzo Colitti | c915d4c | 2015-01-20 15:53:02 +0900 | [diff] [blame] | 225 | routes.add(new RouteInfo((IpPrefix) null, gateway, iface)); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 226 | } |
| 227 | return routes; |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Returns a LinkProperties object expressing the data in this object. Note that the information |
| 232 | * contained in the LinkProperties will not be a complete picture of the link's configuration, |
| 233 | * because any configuration information that is obtained dynamically by the network (e.g., |
| 234 | * IPv6 configuration) will not be included. |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 235 | * @hide |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 236 | */ |
paulhu | 3806853 | 2019-03-15 17:17:02 +0800 | [diff] [blame] | 237 | public @NonNull LinkProperties toLinkProperties(String iface) { |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 238 | LinkProperties lp = new LinkProperties(); |
| 239 | lp.setInterfaceName(iface); |
| 240 | if (ipAddress != null) { |
| 241 | lp.addLinkAddress(ipAddress); |
| 242 | } |
| 243 | for (RouteInfo route : getRoutes(iface)) { |
| 244 | lp.addRoute(route); |
| 245 | } |
| 246 | for (InetAddress dns : dnsServers) { |
| 247 | lp.addDnsServer(dns); |
| 248 | } |
Paul Jensen | 99366a8 | 2014-11-05 09:35:26 -0500 | [diff] [blame] | 249 | lp.setDomains(domains); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 250 | return lp; |
| 251 | } |
| 252 | |
Aurimas Liutikas | 8fae9935 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 253 | @NonNull |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 254 | @Override |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 255 | public String toString() { |
| 256 | StringBuffer str = new StringBuffer(); |
| 257 | |
| 258 | str.append("IP address "); |
| 259 | if (ipAddress != null ) str.append(ipAddress).append(" "); |
| 260 | |
| 261 | str.append("Gateway "); |
| 262 | if (gateway != null) str.append(gateway.getHostAddress()).append(" "); |
| 263 | |
| 264 | str.append(" DNS servers: ["); |
| 265 | for (InetAddress dnsServer : dnsServers) { |
| 266 | str.append(" ").append(dnsServer.getHostAddress()); |
| 267 | } |
| 268 | |
Erik Kline | 7b0a581 | 2016-05-13 17:50:25 +0900 | [diff] [blame] | 269 | str.append(" ] Domains "); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 270 | if (domains != null) str.append(domains); |
| 271 | return str.toString(); |
| 272 | } |
| 273 | |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 274 | @Override |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 275 | public int hashCode() { |
| 276 | int result = 13; |
| 277 | result = 47 * result + (ipAddress == null ? 0 : ipAddress.hashCode()); |
| 278 | result = 47 * result + (gateway == null ? 0 : gateway.hashCode()); |
| 279 | result = 47 * result + (domains == null ? 0 : domains.hashCode()); |
| 280 | result = 47 * result + dnsServers.hashCode(); |
| 281 | return result; |
| 282 | } |
| 283 | |
| 284 | @Override |
Aurimas Liutikas | 8fae9935 | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 285 | public boolean equals(@Nullable Object obj) { |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 286 | if (this == obj) return true; |
| 287 | |
| 288 | if (!(obj instanceof StaticIpConfiguration)) return false; |
| 289 | |
| 290 | StaticIpConfiguration other = (StaticIpConfiguration) obj; |
| 291 | |
| 292 | return other != null && |
| 293 | Objects.equals(ipAddress, other.ipAddress) && |
| 294 | Objects.equals(gateway, other.gateway) && |
| 295 | dnsServers.equals(other.dnsServers) && |
| 296 | Objects.equals(domains, other.domains); |
| 297 | } |
| 298 | |
| 299 | /** Implement the Parcelable interface */ |
Jeff Sharkey | f852528 | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 300 | public static final @android.annotation.NonNull Creator<StaticIpConfiguration> CREATOR = |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 301 | new Creator<StaticIpConfiguration>() { |
| 302 | public StaticIpConfiguration createFromParcel(Parcel in) { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 303 | return readFromParcel(in); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | public StaticIpConfiguration[] newArray(int size) { |
| 307 | return new StaticIpConfiguration[size]; |
| 308 | } |
| 309 | }; |
| 310 | |
| 311 | /** Implement the Parcelable interface */ |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 312 | @Override |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 313 | public int describeContents() { |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | /** Implement the Parcelable interface */ |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 318 | @Override |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 319 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 320 | dest.writeParcelable(ipAddress, flags); |
Remi NGUYEN VAN | 6e82be4 | 2019-01-29 15:38:52 +0900 | [diff] [blame] | 321 | InetAddressUtils.parcelInetAddress(dest, gateway, flags); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 322 | dest.writeInt(dnsServers.size()); |
| 323 | for (InetAddress dnsServer : dnsServers) { |
Remi NGUYEN VAN | 6e82be4 | 2019-01-29 15:38:52 +0900 | [diff] [blame] | 324 | InetAddressUtils.parcelInetAddress(dest, dnsServer, flags); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 325 | } |
Lorenzo Colitti | 68a1a34 | 2015-01-29 17:10:52 +0900 | [diff] [blame] | 326 | dest.writeString(domains); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 327 | } |
| 328 | |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 329 | /** @hide */ |
Etan Cohen | 1e86b3a | 2021-12-12 02:14:06 +0000 | [diff] [blame] | 330 | public static @NonNull StaticIpConfiguration readFromParcel(Parcel in) { |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 331 | final StaticIpConfiguration s = new StaticIpConfiguration(); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 332 | s.ipAddress = in.readParcelable(null); |
Remi NGUYEN VAN | 6e82be4 | 2019-01-29 15:38:52 +0900 | [diff] [blame] | 333 | s.gateway = InetAddressUtils.unparcelInetAddress(in); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 334 | s.dnsServers.clear(); |
| 335 | int size = in.readInt(); |
| 336 | for (int i = 0; i < size; i++) { |
Remi NGUYEN VAN | 6e82be4 | 2019-01-29 15:38:52 +0900 | [diff] [blame] | 337 | s.dnsServers.add(InetAddressUtils.unparcelInetAddress(in)); |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 338 | } |
Lorenzo Colitti | 68a1a34 | 2015-01-29 17:10:52 +0900 | [diff] [blame] | 339 | s.domains = in.readString(); |
Remi NGUYEN VAN | 8bd18cf | 2019-01-28 13:28:35 +0900 | [diff] [blame] | 340 | return s; |
Lorenzo Colitti | ef734f8 | 2014-07-31 00:48:01 +0900 | [diff] [blame] | 341 | } |
| 342 | } |