blob: cff9025d74cdc2a0d74ebae113f407c802e1d79c [file] [log] [blame]
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07001/*
Wink Saville6e809972010-09-21 09:15:35 -07002 * Copyright (C) 2010 The Android Open Source Project
Robert Greenwalt47f69fe2010-06-15 15:43:39 -07003 *
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
17package android.net;
18
Jason Monk207900c2014-04-25 15:00:09 -040019import android.net.ProxyInfo;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070020import android.os.Parcelable;
21import android.os.Parcel;
John Wang4e900092011-04-04 12:35:42 -070022import android.text.TextUtils;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070023
24import java.net.InetAddress;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -080025import java.net.Inet4Address;
Lorenzo Colitti4faa0272013-08-08 11:00:12 +090026import java.net.Inet6Address;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -080027
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070028import java.net.UnknownHostException;
29import java.util.ArrayList;
30import java.util.Collection;
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070031import java.util.Collections;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -080032import java.util.Hashtable;
Robert Greenwaltdf2b8782014-06-06 10:30:11 -070033import java.util.List;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070034
35/**
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070036 * Describes the properties of a network link.
Robert Greenwalt992564e2011-02-09 13:56:06 -080037 *
38 * A link represents a connection to a network.
39 * It may have multiple addresses and multiple gateways,
Robert Greenwalt4f05d552014-05-18 22:01:38 -070040 * multiple dns servers but only one http proxy and one
41 * network interface.
Robert Greenwalt992564e2011-02-09 13:56:06 -080042 *
Robert Greenwalt4f05d552014-05-18 22:01:38 -070043 * Note that this is just a holder of data. Modifying it
44 * does not affect live networks.
Robert Greenwalt992564e2011-02-09 13:56:06 -080045 *
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070046 */
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070047public class LinkProperties implements Parcelable {
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -080048 // The interface described by the network link.
Robert Greenwalt4717c262012-10-31 14:32:53 -070049 private String mIfaceName;
Lorenzo Colitti64483942013-11-15 18:43:52 +090050 private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
51 private ArrayList<InetAddress> mDnses = new ArrayList<InetAddress>();
Robert Greenwalt8058f622012-11-09 10:52:27 -080052 private String mDomains;
Lorenzo Colitti64483942013-11-15 18:43:52 +090053 private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
Jason Monk207900c2014-04-25 15:00:09 -040054 private ProxyInfo mHttpProxy;
sy.yun9d9b74a2013-09-02 05:24:09 +090055 private int mMtu;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070056
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -080057 // Stores the properties of links that are "stacked" above this link.
58 // Indexed by interface name to allow modification and to prevent duplicates being added.
59 private Hashtable<String, LinkProperties> mStackedLinks =
60 new Hashtable<String, LinkProperties>();
61
Robert Greenwaltdf2b8782014-06-06 10:30:11 -070062 /**
63 * @hide
64 */
Robert Greenwalt0a46db52011-07-14 14:28:05 -070065 public static class CompareResult<T> {
Robert Greenwaltdf2b8782014-06-06 10:30:11 -070066 public List<T> removed = new ArrayList<T>();
67 public List<T> added = new ArrayList<T>();
Wink Savillee8222252011-07-13 13:44:13 -070068
69 @Override
70 public String toString() {
Robert Greenwalt0a46db52011-07-14 14:28:05 -070071 String retVal = "removed=[";
72 for (T addr : removed) retVal += addr.toString() + ",";
73 retVal += "] added=[";
74 for (T addr : added) retVal += addr.toString() + ",";
Wink Savillee8222252011-07-13 13:44:13 -070075 retVal += "]";
76 return retVal;
77 }
78 }
79
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070080 public LinkProperties() {
Robert Greenwalt47f69fe2010-06-15 15:43:39 -070081 }
82
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070083 public LinkProperties(LinkProperties source) {
Irfan Sheriffef6c1432010-08-30 20:37:17 -070084 if (source != null) {
Irfan Sheriffed5d7d12010-10-01 16:08:28 -070085 mIfaceName = source.getInterfaceName();
Robert Greenwalt0d8acea2011-07-28 17:21:25 -070086 for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
Robert Greenwaltdf2b8782014-06-06 10:30:11 -070087 for (InetAddress i : source.getDnsServers()) mDnses.add(i);
Robert Greenwalt8058f622012-11-09 10:52:27 -080088 mDomains = source.getDomains();
Robert Greenwalt0d8acea2011-07-28 17:21:25 -070089 for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
Wink Savillebe2b0582011-05-18 15:59:04 -070090 mHttpProxy = (source.getHttpProxy() == null) ?
Jason Monk207900c2014-04-25 15:00:09 -040091 null : new ProxyInfo(source.getHttpProxy());
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -080092 for (LinkProperties l: source.mStackedLinks.values()) {
93 addStackedLink(l);
94 }
sy.yun9d9b74a2013-09-02 05:24:09 +090095 setMtu(source.getMtu());
Irfan Sheriffef6c1432010-08-30 20:37:17 -070096 }
Robert Greenwalt37e65eb2010-08-30 10:56:47 -070097 }
98
Robert Greenwalt4f05d552014-05-18 22:01:38 -070099 /**
100 * Sets the interface name for this link. All {@link RouteInfo} already set for this
101 * will have their interface changed to match this new value.
102 *
103 * @param iface The name of the network interface used for this link.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700104 * @hide
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700105 */
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700106 public void setInterfaceName(String iface) {
107 mIfaceName = iface;
Lorenzo Colitti45b9a5b2013-03-08 11:30:39 -0800108 ArrayList<RouteInfo> newRoutes = new ArrayList<RouteInfo>(mRoutes.size());
109 for (RouteInfo route : mRoutes) {
110 newRoutes.add(routeWithInterface(route));
111 }
112 mRoutes = newRoutes;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700113 }
114
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700115 /**
116 * Gets the interface name for this link. May be {@code null} if not set.
117 *
118 * @return The interface name set for this link or {@code null}.
119 */
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700120 public String getInterfaceName() {
121 return mIfaceName;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700122 }
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700123
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700124 /**
125 * @hide
126 */
127 public List<String> getAllInterfaceNames() {
128 List<String> interfaceNames = new ArrayList<String>(mStackedLinks.size() + 1);
Robert Greenwalt55187f12013-03-22 12:00:17 -0700129 if (mIfaceName != null) interfaceNames.add(new String(mIfaceName));
Lorenzo Colitti4aa9bcf2013-03-20 19:22:58 +0900130 for (LinkProperties stacked: mStackedLinks.values()) {
131 interfaceNames.addAll(stacked.getAllInterfaceNames());
132 }
133 return interfaceNames;
134 }
135
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900136 /**
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700137 * Returns all the addresses on this link. We often think of a link having a single address,
138 * however, particularly with Ipv6 several addresses are typical. Note that the
139 * {@code LinkProperties} actually contains {@link LinkAddress} objects which also include
140 * prefix lengths for each address. This is a simplified utility alternative to
141 * {@link LinkProperties#getLinkAddresses}.
142 *
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700143 * @return An umodifiable {@link List} of {@link InetAddress} for this link.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700144 * @hide
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900145 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700146 public List<InetAddress> getAddresses() {
147 List<InetAddress> addresses = new ArrayList<InetAddress>();
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700148 for (LinkAddress linkAddress : mLinkAddresses) {
149 addresses.add(linkAddress.getAddress());
150 }
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700151 return Collections.unmodifiableList(addresses);
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700152 }
153
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900154 /**
155 * Returns all the addresses on this link and all the links stacked above it.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700156 * @hide
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900157 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700158 public List<InetAddress> getAllAddresses() {
159 List<InetAddress> addresses = new ArrayList<InetAddress>();
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900160 for (LinkAddress linkAddress : mLinkAddresses) {
161 addresses.add(linkAddress.getAddress());
162 }
163 for (LinkProperties stacked: mStackedLinks.values()) {
164 addresses.addAll(stacked.getAllAddresses());
165 }
166 return addresses;
167 }
168
Lorenzo Colitti64483942013-11-15 18:43:52 +0900169 private int findLinkAddressIndex(LinkAddress address) {
170 for (int i = 0; i < mLinkAddresses.size(); i++) {
171 if (mLinkAddresses.get(i).isSameAddressAs(address)) {
172 return i;
173 }
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900174 }
Lorenzo Colitti64483942013-11-15 18:43:52 +0900175 return -1;
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900176 }
177
178 /**
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700179 * Adds a {@link LinkAddress} to this {@code LinkProperties} if a {@link LinkAddress} of the
180 * same address/prefix does not already exist. If it does exist it is replaced.
Lorenzo Colitti64483942013-11-15 18:43:52 +0900181 * @param address The {@code LinkAddress} to add.
182 * @return true if {@code address} was added or updated, false otherwise.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700183 * @hide
Lorenzo Colitti64483942013-11-15 18:43:52 +0900184 */
185 public boolean addLinkAddress(LinkAddress address) {
186 if (address == null) {
187 return false;
188 }
189 int i = findLinkAddressIndex(address);
190 if (i < 0) {
191 // Address was not present. Add it.
192 mLinkAddresses.add(address);
193 return true;
194 } else if (mLinkAddresses.get(i).equals(address)) {
195 // Address was present and has same properties. Do nothing.
196 return false;
197 } else {
198 // Address was present and has different properties. Update it.
199 mLinkAddresses.set(i, address);
200 return true;
201 }
202 }
203
204 /**
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700205 * Removes a {@link LinkAddress} from this {@code LinkProperties}. Specifically, matches
206 * and {@link LinkAddress} with the same address and prefix.
207 *
208 * @param toRemove A {@link LinkAddress} specifying the address to remove.
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900209 * @return true if the address was removed, false if it did not exist.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700210 * @hide
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900211 */
212 public boolean removeLinkAddress(LinkAddress toRemove) {
Lorenzo Colitti64483942013-11-15 18:43:52 +0900213 int i = findLinkAddressIndex(toRemove);
214 if (i >= 0) {
215 mLinkAddresses.remove(i);
216 return true;
217 }
218 return false;
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700219 }
220
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900221 /**
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700222 * Returns all the {@link LinkAddress} on this link. Typically a link will have
223 * one IPv4 address and one or more IPv6 addresses.
224 *
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700225 * @return An unmodifiable {@link List} of {@link LinkAddress} for this link.
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900226 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700227 public List<LinkAddress> getLinkAddresses() {
228 return Collections.unmodifiableList(mLinkAddresses);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700229 }
230
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900231 /**
232 * Returns all the addresses on this link and all the links stacked above it.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700233 * @hide
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900234 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700235 public List<LinkAddress> getAllLinkAddresses() {
236 List<LinkAddress> addresses = new ArrayList<LinkAddress>();
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900237 addresses.addAll(mLinkAddresses);
238 for (LinkProperties stacked: mStackedLinks.values()) {
239 addresses.addAll(stacked.getAllLinkAddresses());
240 }
241 return addresses;
242 }
243
Lorenzo Colitti22f407b2013-08-23 20:54:49 +0900244 /**
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700245 * Replaces the {@link LinkAddress} in this {@code LinkProperties} with
246 * the given {@link Collection} of {@link LinkAddress}.
247 *
248 * @param addresses The {@link Collection} of {@link LinkAddress} to set in this
249 * object.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700250 * @hide
Lorenzo Colitti22f407b2013-08-23 20:54:49 +0900251 */
252 public void setLinkAddresses(Collection<LinkAddress> addresses) {
253 mLinkAddresses.clear();
254 for (LinkAddress address: addresses) {
255 addLinkAddress(address);
256 }
257 }
258
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700259 /**
260 * Adds the given {@link InetAddress} to the list of DNS servers.
261 *
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700262 * @param dnsServer The {@link InetAddress} to add to the list of DNS servers.
263 * @hide
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700264 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700265 public void addDnsServer(InetAddress dnsServer) {
266 if (dnsServer != null) mDnses.add(dnsServer);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700267 }
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700268
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700269 /**
270 * Returns all the {@link LinkAddress} for DNS servers on this link.
271 *
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700272 * @return An umodifiable {@link List} of {@link InetAddress} for DNS servers on
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700273 * this link.
274 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700275 public List<InetAddress> getDnsServers() {
276 return Collections.unmodifiableList(mDnses);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700277 }
278
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700279 /**
280 * Sets the DNS domain search path used on this link.
281 *
282 * @param domains A {@link String} listing in priority order the comma separated
283 * domains to search when resolving host names on this link.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700284 * @hide
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700285 */
Robert Greenwalt8058f622012-11-09 10:52:27 -0800286 public void setDomains(String domains) {
287 mDomains = domains;
288 }
289
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700290 /**
291 * Get the DNS domains search path set for this link.
292 *
293 * @return A {@link String} containing the comma separated domains to search when resolving
294 * host names on this link.
295 */
296 public String getDomains() {
297 return mDomains;
298 }
299
300 /**
301 * Sets the Maximum Transmission Unit size to use on this link. This should not be used
302 * unless the system default (1500) is incorrect. Values less than 68 or greater than
303 * 10000 will be ignored.
304 *
305 * @param mtu The MTU to use for this link.
306 * @hide
307 */
sy.yun9d9b74a2013-09-02 05:24:09 +0900308 public void setMtu(int mtu) {
309 mMtu = mtu;
310 }
311
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700312 /**
313 * Gets any non-default MTU size set for this link. Note that if the default is being used
314 * this will return 0.
315 *
316 * @return The mtu value set for this link.
317 * @hide
318 */
sy.yun9d9b74a2013-09-02 05:24:09 +0900319 public int getMtu() {
320 return mMtu;
321 }
322
Lorenzo Colitti45b9a5b2013-03-08 11:30:39 -0800323 private RouteInfo routeWithInterface(RouteInfo route) {
324 return new RouteInfo(
325 route.getDestination(),
326 route.getGateway(),
327 mIfaceName);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700328 }
Lorenzo Colitti45b9a5b2013-03-08 11:30:39 -0800329
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700330 /**
331 * Adds a {@link RouteInfo} to this {@code LinkProperties}. If the {@link RouteInfo}
332 * had an interface name set and that differs from the interface set for this
333 * {@code LinkProperties} an {@link IllegalArgumentException} will be thrown. The
334 * proper course is to add either un-named or properly named {@link RouteInfo}.
335 *
336 * @param route A {@link RouteInfo} to add to this object.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700337 * @hide
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700338 */
Lorenzo Colitti45b9a5b2013-03-08 11:30:39 -0800339 public void addRoute(RouteInfo route) {
340 if (route != null) {
341 String routeIface = route.getInterface();
342 if (routeIface != null && !routeIface.equals(mIfaceName)) {
Lorenzo Colitti1994bc12013-03-08 19:11:40 -0800343 throw new IllegalArgumentException(
Lorenzo Colitti45b9a5b2013-03-08 11:30:39 -0800344 "Route added with non-matching interface: " + routeIface +
Lorenzo Colitti1994bc12013-03-08 19:11:40 -0800345 " vs. " + mIfaceName);
Lorenzo Colitti45b9a5b2013-03-08 11:30:39 -0800346 }
347 mRoutes.add(routeWithInterface(route));
348 }
349 }
350
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800351 /**
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700352 * Returns all the {@link RouteInfo} set on this link.
353 *
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700354 * @return An unmodifiable {@link List} of {@link RouteInfo} for this link.
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800355 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700356 public List<RouteInfo> getRoutes() {
357 return Collections.unmodifiableList(mRoutes);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700358 }
359
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800360 /**
361 * Returns all the routes on this link and all the links stacked above it.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700362 * @hide
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800363 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700364 public List<RouteInfo> getAllRoutes() {
365 List<RouteInfo> routes = new ArrayList();
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800366 routes.addAll(mRoutes);
367 for (LinkProperties stacked: mStackedLinks.values()) {
368 routes.addAll(stacked.getAllRoutes());
369 }
Robert Greenwalt6629bcd2013-03-15 11:28:50 -0700370 return routes;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800371 }
372
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700373 /**
374 * Sets the recommended {@link ProxyInfo} to use on this link, or {@code null} for none.
375 * Note that Http Proxies are only a hint - the system recommends their use, but it does
376 * not enforce it and applications may ignore them.
377 *
378 * @param proxy A {@link ProxyInfo} defining the Http Proxy to use on this link.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700379 * @hide
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700380 */
Jason Monk207900c2014-04-25 15:00:09 -0400381 public void setHttpProxy(ProxyInfo proxy) {
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700382 mHttpProxy = proxy;
383 }
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700384
385 /**
386 * Gets the recommended {@link ProxyInfo} (or {@code null}) set on this link.
387 *
388 * @return The {@link ProxyInfo} set on this link
389 */
Jason Monk207900c2014-04-25 15:00:09 -0400390 public ProxyInfo getHttpProxy() {
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700391 return mHttpProxy;
392 }
393
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800394 /**
395 * Adds a stacked link.
396 *
397 * If there is already a stacked link with the same interfacename as link,
398 * that link is replaced with link. Otherwise, link is added to the list
399 * of stacked links. If link is null, nothing changes.
400 *
401 * @param link The link to add.
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900402 * @return true if the link was stacked, false otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700403 * @hide
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800404 */
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900405 public boolean addStackedLink(LinkProperties link) {
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800406 if (link != null && link.getInterfaceName() != null) {
407 mStackedLinks.put(link.getInterfaceName(), link);
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900408 return true;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800409 }
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900410 return false;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800411 }
412
413 /**
414 * Removes a stacked link.
415 *
416 * If there a stacked link with the same interfacename as link, it is
417 * removed. Otherwise, nothing changes.
418 *
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900419 * @param link The link to remove.
420 * @return true if the link was removed, false otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700421 * @hide
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800422 */
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900423 public boolean removeStackedLink(LinkProperties link) {
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800424 if (link != null && link.getInterfaceName() != null) {
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900425 LinkProperties removed = mStackedLinks.remove(link.getInterfaceName());
426 return removed != null;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800427 }
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900428 return false;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800429 }
430
431 /**
432 * Returns all the links stacked on top of this link.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700433 * @hide
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800434 */
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700435 public List<LinkProperties> getStackedLinks() {
436 List<LinkProperties> stacked = new ArrayList<LinkProperties>();
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800437 for (LinkProperties link : mStackedLinks.values()) {
438 stacked.add(new LinkProperties(link));
439 }
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700440 return Collections.unmodifiableList(stacked);
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800441 }
442
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700443 /**
444 * Clears this object to its initial state.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700445 * @hide
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700446 */
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700447 public void clear() {
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700448 mIfaceName = null;
Wink Savillee8222252011-07-13 13:44:13 -0700449 mLinkAddresses.clear();
450 mDnses.clear();
Robert Greenwalt8058f622012-11-09 10:52:27 -0800451 mDomains = null;
Wink Savillee8222252011-07-13 13:44:13 -0700452 mRoutes.clear();
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700453 mHttpProxy = null;
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800454 mStackedLinks.clear();
sy.yun9d9b74a2013-09-02 05:24:09 +0900455 mMtu = 0;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700456 }
457
458 /**
459 * Implement the Parcelable interface
460 * @hide
461 */
462 public int describeContents() {
463 return 0;
464 }
465
Wink Saville1f6408a2010-08-27 11:15:18 -0700466 @Override
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700467 public String toString() {
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700468 String ifaceName = (mIfaceName == null ? "" : "InterfaceName: " + mIfaceName + " ");
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700469
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700470 String linkAddresses = "LinkAddresses: [";
John Wang4e900092011-04-04 12:35:42 -0700471 for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString() + ",";
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700472 linkAddresses += "] ";
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700473
474 String dns = "DnsAddresses: [";
Wink Saville1f6408a2010-08-27 11:15:18 -0700475 for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700476 dns += "] ";
477
Robert Greenwalt8058f622012-11-09 10:52:27 -0800478 String domainName = "Domains: " + mDomains;
479
sy.yun9d9b74a2013-09-02 05:24:09 +0900480 String mtu = "MTU: " + mMtu;
481
Robert Greenwalt8058f622012-11-09 10:52:27 -0800482 String routes = " Routes: [";
Robert Greenwaltaa70f102011-04-28 14:28:50 -0700483 for (RouteInfo route : mRoutes) routes += route.toString() + ",";
484 routes += "] ";
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700485 String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " ");
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700486
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800487 String stacked = "";
488 if (mStackedLinks.values().size() > 0) {
489 stacked += " Stacked: [";
490 for (LinkProperties link: mStackedLinks.values()) {
491 stacked += " [" + link.toString() + " ],";
492 }
493 stacked += "] ";
494 }
sy.yun9d9b74a2013-09-02 05:24:09 +0900495 return "{" + ifaceName + linkAddresses + routes + dns + domainName + mtu
496 + proxy + stacked + "}";
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800497 }
498
499 /**
500 * Returns true if this link has an IPv4 address.
501 *
502 * @return {@code true} if there is an IPv4 address, {@code false} otherwise.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700503 * @hide
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800504 */
505 public boolean hasIPv4Address() {
506 for (LinkAddress address : mLinkAddresses) {
507 if (address.getAddress() instanceof Inet4Address) {
508 return true;
509 }
510 }
511 return false;
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700512 }
513
Wink Savillee8222252011-07-13 13:44:13 -0700514 /**
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900515 * Returns true if this link has an IPv6 address.
516 *
517 * @return {@code true} if there is an IPv6 address, {@code false} otherwise.
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700518 * @hide
Lorenzo Colitti4faa0272013-08-08 11:00:12 +0900519 */
520 public boolean hasIPv6Address() {
521 for (LinkAddress address : mLinkAddresses) {
522 if (address.getAddress() instanceof Inet6Address) {
523 return true;
524 }
525 }
526 return false;
527 }
528
529 /**
Wink Savillee8222252011-07-13 13:44:13 -0700530 * Compares this {@code LinkProperties} interface name against the target
531 *
532 * @param target LinkProperties to compare.
533 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700534 * @hide
Wink Savillee8222252011-07-13 13:44:13 -0700535 */
536 public boolean isIdenticalInterfaceName(LinkProperties target) {
537 return TextUtils.equals(getInterfaceName(), target.getInterfaceName());
538 }
539
540 /**
Robert Greenwalt4717c262012-10-31 14:32:53 -0700541 * Compares this {@code LinkProperties} interface addresses against the target
Wink Savillee8222252011-07-13 13:44:13 -0700542 *
543 * @param target LinkProperties to compare.
544 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700545 * @hide
Wink Savillee8222252011-07-13 13:44:13 -0700546 */
547 public boolean isIdenticalAddresses(LinkProperties target) {
548 Collection<InetAddress> targetAddresses = target.getAddresses();
549 Collection<InetAddress> sourceAddresses = getAddresses();
550 return (sourceAddresses.size() == targetAddresses.size()) ?
551 sourceAddresses.containsAll(targetAddresses) : false;
552 }
553
554 /**
555 * Compares this {@code LinkProperties} DNS addresses against the target
556 *
557 * @param target LinkProperties to compare.
558 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700559 * @hide
Wink Savillee8222252011-07-13 13:44:13 -0700560 */
561 public boolean isIdenticalDnses(LinkProperties target) {
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700562 Collection<InetAddress> targetDnses = target.getDnsServers();
Robert Greenwalt8058f622012-11-09 10:52:27 -0800563 String targetDomains = target.getDomains();
564 if (mDomains == null) {
565 if (targetDomains != null) return false;
566 } else {
567 if (mDomains.equals(targetDomains) == false) return false;
568 }
Wink Savillee8222252011-07-13 13:44:13 -0700569 return (mDnses.size() == targetDnses.size()) ?
570 mDnses.containsAll(targetDnses) : false;
571 }
572
573 /**
574 * Compares this {@code LinkProperties} Routes against the target
575 *
576 * @param target LinkProperties to compare.
577 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700578 * @hide
Wink Savillee8222252011-07-13 13:44:13 -0700579 */
580 public boolean isIdenticalRoutes(LinkProperties target) {
581 Collection<RouteInfo> targetRoutes = target.getRoutes();
582 return (mRoutes.size() == targetRoutes.size()) ?
583 mRoutes.containsAll(targetRoutes) : false;
584 }
585
586 /**
587 * Compares this {@code LinkProperties} HttpProxy against the target
588 *
589 * @param target LinkProperties to compare.
590 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700591 * @hide
Wink Savillee8222252011-07-13 13:44:13 -0700592 */
593 public boolean isIdenticalHttpProxy(LinkProperties target) {
594 return getHttpProxy() == null ? target.getHttpProxy() == null :
595 getHttpProxy().equals(target.getHttpProxy());
596 }
John Wang4e900092011-04-04 12:35:42 -0700597
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800598 /**
599 * Compares this {@code LinkProperties} stacked links against the target
600 *
601 * @param target LinkProperties to compare.
602 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700603 * @hide
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800604 */
605 public boolean isIdenticalStackedLinks(LinkProperties target) {
Lorenzo Colitti213f98b2013-04-01 10:47:43 +0900606 if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) {
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800607 return false;
608 }
609 for (LinkProperties stacked : mStackedLinks.values()) {
610 // Hashtable values can never be null.
611 String iface = stacked.getInterfaceName();
612 if (!stacked.equals(target.mStackedLinks.get(iface))) {
613 return false;
614 }
615 }
616 return true;
617 }
618
sy.yun9d9b74a2013-09-02 05:24:09 +0900619 /**
620 * Compares this {@code LinkProperties} MTU against the target
621 *
Ying Wangd57de6a2013-09-06 22:53:16 -0700622 * @param target LinkProperties to compare.
sy.yun9d9b74a2013-09-02 05:24:09 +0900623 * @return {@code true} if both are identical, {@code false} otherwise.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700624 * @hide
sy.yun9d9b74a2013-09-02 05:24:09 +0900625 */
626 public boolean isIdenticalMtu(LinkProperties target) {
627 return getMtu() == target.getMtu();
628 }
629
John Wang4e900092011-04-04 12:35:42 -0700630 @Override
631 /**
632 * Compares this {@code LinkProperties} instance against the target
633 * LinkProperties in {@code obj}. Two LinkPropertieses are equal if
634 * all their fields are equal in values.
635 *
636 * For collection fields, such as mDnses, containsAll() is used to check
637 * if two collections contains the same elements, independent of order.
638 * There are two thoughts regarding containsAll()
639 * 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal.
640 * 2. Worst case performance is O(n^2).
641 *
642 * @param obj the object to be tested for equality.
643 * @return {@code true} if both objects are equal, {@code false} otherwise.
644 */
645 public boolean equals(Object obj) {
646 if (this == obj) return true;
647
648 if (!(obj instanceof LinkProperties)) return false;
649
John Wang4e900092011-04-04 12:35:42 -0700650 LinkProperties target = (LinkProperties) obj;
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700651 /**
652 * This method does not check that stacked interfaces are equal, because
653 * stacked interfaces are not so much a property of the link as a
654 * description of connections between links.
655 */
Wink Savillee8222252011-07-13 13:44:13 -0700656 return isIdenticalInterfaceName(target) &&
657 isIdenticalAddresses(target) &&
658 isIdenticalDnses(target) &&
659 isIdenticalRoutes(target) &&
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800660 isIdenticalHttpProxy(target) &&
sy.yun9d9b74a2013-09-02 05:24:09 +0900661 isIdenticalStackedLinks(target) &&
662 isIdenticalMtu(target);
Wink Savillee8222252011-07-13 13:44:13 -0700663 }
John Wang4e900092011-04-04 12:35:42 -0700664
Wink Savillee8222252011-07-13 13:44:13 -0700665 /**
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900666 * Compares the addresses in this LinkProperties with another
667 * LinkProperties, examining only addresses on the base link.
Wink Savillee8222252011-07-13 13:44:13 -0700668 *
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900669 * @param target a LinkProperties with the new list of addresses
670 * @return the differences between the addresses.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700671 * @hide
Wink Savillee8222252011-07-13 13:44:13 -0700672 */
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700673 public CompareResult<LinkAddress> compareAddresses(LinkProperties target) {
Wink Savillee8222252011-07-13 13:44:13 -0700674 /*
675 * Duplicate the LinkAddresses into removed, we will be removing
676 * address which are common between mLinkAddresses and target
677 * leaving the addresses that are different. And address which
678 * are in target but not in mLinkAddresses are placed in the
679 * addedAddresses.
680 */
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700681 CompareResult<LinkAddress> result = new CompareResult<LinkAddress>();
Wink Savillee8222252011-07-13 13:44:13 -0700682 result.removed = new ArrayList<LinkAddress>(mLinkAddresses);
683 result.added.clear();
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700684 if (target != null) {
685 for (LinkAddress newAddress : target.getLinkAddresses()) {
686 if (! result.removed.remove(newAddress)) {
687 result.added.add(newAddress);
688 }
Wink Savillee8222252011-07-13 13:44:13 -0700689 }
690 }
691 return result;
John Wang4e900092011-04-04 12:35:42 -0700692 }
693
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700694 /**
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900695 * Compares the DNS addresses in this LinkProperties with another
696 * LinkProperties, examining only DNS addresses on the base link.
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700697 *
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900698 * @param target a LinkProperties with the new list of dns addresses
699 * @return the differences between the DNS addresses.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700700 * @hide
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700701 */
702 public CompareResult<InetAddress> compareDnses(LinkProperties target) {
703 /*
704 * Duplicate the InetAddresses into removed, we will be removing
705 * dns address which are common between mDnses and target
706 * leaving the addresses that are different. And dns address which
707 * are in target but not in mDnses are placed in the
708 * addedAddresses.
709 */
710 CompareResult<InetAddress> result = new CompareResult<InetAddress>();
711
712 result.removed = new ArrayList<InetAddress>(mDnses);
713 result.added.clear();
714 if (target != null) {
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700715 for (InetAddress newAddress : target.getDnsServers()) {
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700716 if (! result.removed.remove(newAddress)) {
717 result.added.add(newAddress);
718 }
719 }
720 }
721 return result;
722 }
723
724 /**
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900725 * Compares all routes in this LinkProperties with another LinkProperties,
726 * examining both the the base link and all stacked links.
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700727 *
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900728 * @param target a LinkProperties with the new list of routes
729 * @return the differences between the routes.
Robert Greenwalt4f05d552014-05-18 22:01:38 -0700730 * @hide
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700731 */
Lorenzo Colittid1e0fae2013-07-31 23:23:21 +0900732 public CompareResult<RouteInfo> compareAllRoutes(LinkProperties target) {
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700733 /*
734 * Duplicate the RouteInfos into removed, we will be removing
Lorenzo Colitti1994bc12013-03-08 19:11:40 -0800735 * routes which are common between mRoutes and target
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700736 * leaving the routes that are different. And route address which
737 * are in target but not in mRoutes are placed in added.
738 */
739 CompareResult<RouteInfo> result = new CompareResult<RouteInfo>();
740
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800741 result.removed = getAllRoutes();
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700742 result.added.clear();
743 if (target != null) {
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800744 for (RouteInfo r : target.getAllRoutes()) {
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700745 if (! result.removed.remove(r)) {
746 result.added.add(r);
747 }
748 }
749 }
750 return result;
751 }
752
Paul Jensen992f2522014-04-28 10:33:11 -0400753 /**
754 * Compares all interface names in this LinkProperties with another
755 * LinkProperties, examining both the the base link and all stacked links.
756 *
757 * @param target a LinkProperties with the new list of interface names
758 * @return the differences between the interface names.
759 * @hide
760 */
761 public CompareResult<String> compareAllInterfaceNames(LinkProperties target) {
762 /*
763 * Duplicate the interface names into removed, we will be removing
764 * interface names which are common between this and target
765 * leaving the interface names that are different. And interface names which
766 * are in target but not in this are placed in added.
767 */
768 CompareResult<String> result = new CompareResult<String>();
769
770 result.removed = getAllInterfaceNames();
771 result.added.clear();
772 if (target != null) {
773 for (String r : target.getAllInterfaceNames()) {
774 if (! result.removed.remove(r)) {
775 result.added.add(r);
776 }
777 }
778 }
779 return result;
780 }
781
Robert Greenwalt0a46db52011-07-14 14:28:05 -0700782
John Wang4e900092011-04-04 12:35:42 -0700783 @Override
784 /**
785 * generate hashcode based on significant fields
786 * Equal objects must produce the same hash code, while unequal objects
787 * may have the same hash codes.
788 */
789 public int hashCode() {
790 return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
791 + mLinkAddresses.size() * 31
792 + mDnses.size() * 37
Robert Greenwalt8058f622012-11-09 10:52:27 -0800793 + ((null == mDomains) ? 0 : mDomains.hashCode())
Robert Greenwaltaa70f102011-04-28 14:28:50 -0700794 + mRoutes.size() * 41
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800795 + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode())
sy.yun9d9b74a2013-09-02 05:24:09 +0900796 + mStackedLinks.hashCode() * 47)
797 + mMtu * 51;
John Wang4e900092011-04-04 12:35:42 -0700798 }
799
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700800 /**
801 * Implement the Parcelable interface.
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700802 */
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700803 public void writeToParcel(Parcel dest, int flags) {
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700804 dest.writeString(getInterfaceName());
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700805 dest.writeInt(mLinkAddresses.size());
806 for(LinkAddress linkAddress : mLinkAddresses) {
807 dest.writeParcelable(linkAddress, flags);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700808 }
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700809
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700810 dest.writeInt(mDnses.size());
811 for(InetAddress d : mDnses) {
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700812 dest.writeByteArray(d.getAddress());
813 }
Robert Greenwalt8058f622012-11-09 10:52:27 -0800814 dest.writeString(mDomains);
sy.yun9d9b74a2013-09-02 05:24:09 +0900815 dest.writeInt(mMtu);
Robert Greenwaltaa70f102011-04-28 14:28:50 -0700816 dest.writeInt(mRoutes.size());
817 for(RouteInfo route : mRoutes) {
818 dest.writeParcelable(route, flags);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700819 }
Robert Greenwalt992564e2011-02-09 13:56:06 -0800820
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700821 if (mHttpProxy != null) {
822 dest.writeByte((byte)1);
823 dest.writeParcelable(mHttpProxy, flags);
824 } else {
825 dest.writeByte((byte)0);
826 }
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800827 ArrayList<LinkProperties> stackedLinks = new ArrayList(mStackedLinks.values());
828 dest.writeList(stackedLinks);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700829 }
830
831 /**
832 * Implement the Parcelable interface.
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700833 */
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700834 public static final Creator<LinkProperties> CREATOR =
835 new Creator<LinkProperties>() {
836 public LinkProperties createFromParcel(Parcel in) {
837 LinkProperties netProp = new LinkProperties();
Robert Greenwalt4717c262012-10-31 14:32:53 -0700838
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700839 String iface = in.readString();
840 if (iface != null) {
Robert Greenwalt4717c262012-10-31 14:32:53 -0700841 netProp.setInterfaceName(iface);
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700842 }
843 int addressCount = in.readInt();
844 for (int i=0; i<addressCount; i++) {
Irfan Sheriffed5d7d12010-10-01 16:08:28 -0700845 netProp.addLinkAddress((LinkAddress)in.readParcelable(null));
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700846 }
847 addressCount = in.readInt();
848 for (int i=0; i<addressCount; i++) {
849 try {
Robert Greenwaltdf2b8782014-06-06 10:30:11 -0700850 netProp.addDnsServer(InetAddress.getByAddress(in.createByteArray()));
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700851 } catch (UnknownHostException e) { }
852 }
Robert Greenwalt8058f622012-11-09 10:52:27 -0800853 netProp.setDomains(in.readString());
sy.yun9d9b74a2013-09-02 05:24:09 +0900854 netProp.setMtu(in.readInt());
Robert Greenwalt992564e2011-02-09 13:56:06 -0800855 addressCount = in.readInt();
856 for (int i=0; i<addressCount; i++) {
Robert Greenwaltaa70f102011-04-28 14:28:50 -0700857 netProp.addRoute((RouteInfo)in.readParcelable(null));
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700858 }
859 if (in.readByte() == 1) {
Jason Monk207900c2014-04-25 15:00:09 -0400860 netProp.setHttpProxy((ProxyInfo)in.readParcelable(null));
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700861 }
Lorenzo Colitti419a4ce2013-03-07 10:59:25 -0800862 ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>();
863 in.readList(stackedLinks, LinkProperties.class.getClassLoader());
864 for (LinkProperties stackedLink: stackedLinks) {
865 netProp.addStackedLink(stackedLink);
866 }
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700867 return netProp;
868 }
869
Robert Greenwalt37e65eb2010-08-30 10:56:47 -0700870 public LinkProperties[] newArray(int size) {
871 return new LinkProperties[size];
Robert Greenwalt47f69fe2010-06-15 15:43:39 -0700872 }
873 };
874}