Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 1 | /* |
Wink Saville | 6e80997 | 2010-09-21 09:15:35 -0700 | [diff] [blame] | 2 | * Copyright (C) 2010 The Android Open Source Project |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 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 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 19 | import android.net.ProxyProperties; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 20 | import android.os.Parcelable; |
| 21 | import android.os.Parcel; |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 22 | import android.text.TextUtils; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 23 | |
| 24 | import java.net.InetAddress; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 25 | import java.net.Inet4Address; |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 26 | import java.net.Inet6Address; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 27 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 28 | import java.net.UnknownHostException; |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.Collection; |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 31 | import java.util.Collections; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 32 | import java.util.Hashtable; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 35 | * Describes the properties of a network link. |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 36 | * |
| 37 | * A link represents a connection to a network. |
| 38 | * It may have multiple addresses and multiple gateways, |
| 39 | * multiple dns servers but only one http proxy. |
| 40 | * |
| 41 | * Because it's a single network, the dns's |
| 42 | * are interchangeable and don't need associating with |
| 43 | * particular addresses. The gateways similarly don't |
| 44 | * need associating with particular addresses. |
| 45 | * |
| 46 | * A dual stack interface works fine in this model: |
| 47 | * each address has it's own prefix length to describe |
| 48 | * the local network. The dns servers all return |
| 49 | * both v4 addresses and v6 addresses regardless of the |
| 50 | * address family of the server itself (rfc4213) and we |
| 51 | * don't care which is used. The gateways will be |
| 52 | * selected based on the destination address and the |
| 53 | * source address has no relavence. |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 54 | * |
| 55 | * Links can also be stacked on top of each other. |
| 56 | * This can be used, for example, to represent a tunnel |
| 57 | * interface that runs on top of a physical interface. |
| 58 | * |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 59 | * @hide |
| 60 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 61 | public class LinkProperties implements Parcelable { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 62 | // The interface described by the network link. |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 63 | private String mIfaceName; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 64 | private Collection<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>(); |
| 65 | private Collection<InetAddress> mDnses = new ArrayList<InetAddress>(); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 66 | private String mDomains; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 67 | private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 68 | private ProxyProperties mHttpProxy; |
| 69 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 70 | // Stores the properties of links that are "stacked" above this link. |
| 71 | // Indexed by interface name to allow modification and to prevent duplicates being added. |
| 72 | private Hashtable<String, LinkProperties> mStackedLinks = |
| 73 | new Hashtable<String, LinkProperties>(); |
| 74 | |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 75 | public static class CompareResult<T> { |
Robert Greenwalt | ad55d35 | 2011-07-22 11:55:33 -0700 | [diff] [blame] | 76 | public Collection<T> removed = new ArrayList<T>(); |
| 77 | public Collection<T> added = new ArrayList<T>(); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 78 | |
| 79 | @Override |
| 80 | public String toString() { |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 81 | String retVal = "removed=["; |
| 82 | for (T addr : removed) retVal += addr.toString() + ","; |
| 83 | retVal += "] added=["; |
| 84 | for (T addr : added) retVal += addr.toString() + ","; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 85 | retVal += "]"; |
| 86 | return retVal; |
| 87 | } |
| 88 | } |
| 89 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 90 | public LinkProperties() { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 91 | clear(); |
| 92 | } |
| 93 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 94 | // copy constructor instead of clone |
| 95 | public LinkProperties(LinkProperties source) { |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 96 | if (source != null) { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 97 | mIfaceName = source.getInterfaceName(); |
Robert Greenwalt | 0d8acea | 2011-07-28 17:21:25 -0700 | [diff] [blame] | 98 | for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l); |
| 99 | for (InetAddress i : source.getDnses()) mDnses.add(i); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 100 | mDomains = source.getDomains(); |
Robert Greenwalt | 0d8acea | 2011-07-28 17:21:25 -0700 | [diff] [blame] | 101 | for (RouteInfo r : source.getRoutes()) mRoutes.add(r); |
Wink Saville | be2b058 | 2011-05-18 15:59:04 -0700 | [diff] [blame] | 102 | mHttpProxy = (source.getHttpProxy() == null) ? |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 103 | null : new ProxyProperties(source.getHttpProxy()); |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 104 | for (LinkProperties l: source.mStackedLinks.values()) { |
| 105 | addStackedLink(l); |
| 106 | } |
Irfan Sheriff | ef6c143 | 2010-08-30 20:37:17 -0700 | [diff] [blame] | 107 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 110 | public void setInterfaceName(String iface) { |
| 111 | mIfaceName = iface; |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 112 | ArrayList<RouteInfo> newRoutes = new ArrayList<RouteInfo>(mRoutes.size()); |
| 113 | for (RouteInfo route : mRoutes) { |
| 114 | newRoutes.add(routeWithInterface(route)); |
| 115 | } |
| 116 | mRoutes = newRoutes; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 119 | public String getInterfaceName() { |
| 120 | return mIfaceName; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 121 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 122 | |
Lorenzo Colitti | 4aa9bcf | 2013-03-20 19:22:58 +0900 | [diff] [blame] | 123 | public Collection<String> getAllInterfaceNames() { |
| 124 | Collection interfaceNames = new ArrayList<String>(mStackedLinks.size() + 1); |
Robert Greenwalt | 55187f1 | 2013-03-22 12:00:17 -0700 | [diff] [blame] | 125 | if (mIfaceName != null) interfaceNames.add(new String(mIfaceName)); |
Lorenzo Colitti | 4aa9bcf | 2013-03-20 19:22:58 +0900 | [diff] [blame] | 126 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 127 | interfaceNames.addAll(stacked.getAllInterfaceNames()); |
| 128 | } |
| 129 | return interfaceNames; |
| 130 | } |
| 131 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 132 | /** |
| 133 | * Returns all the addresses on this link. |
| 134 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 135 | public Collection<InetAddress> getAddresses() { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 136 | Collection<InetAddress> addresses = new ArrayList<InetAddress>(); |
| 137 | for (LinkAddress linkAddress : mLinkAddresses) { |
| 138 | addresses.add(linkAddress.getAddress()); |
| 139 | } |
| 140 | return Collections.unmodifiableCollection(addresses); |
| 141 | } |
| 142 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 143 | /** |
| 144 | * Returns all the addresses on this link and all the links stacked above it. |
| 145 | */ |
| 146 | public Collection<InetAddress> getAllAddresses() { |
| 147 | Collection<InetAddress> addresses = new ArrayList<InetAddress>(); |
| 148 | for (LinkAddress linkAddress : mLinkAddresses) { |
| 149 | addresses.add(linkAddress.getAddress()); |
| 150 | } |
| 151 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 152 | addresses.addAll(stacked.getAllAddresses()); |
| 153 | } |
| 154 | return addresses; |
| 155 | } |
| 156 | |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 157 | /** |
| 158 | * Adds a link address if it does not exist, or update it if it does. |
| 159 | * @param address The {@code LinkAddress} to add. |
| 160 | * @return true if the address was added, false if it already existed. |
| 161 | */ |
| 162 | public boolean addLinkAddress(LinkAddress address) { |
| 163 | // TODO: when the LinkAddress has other attributes beyond the |
| 164 | // address and the prefix length, update them here. |
| 165 | if (address != null && !mLinkAddresses.contains(address)) { |
| 166 | mLinkAddresses.add(address); |
| 167 | return true; |
| 168 | } |
| 169 | return false; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Removes a link address. |
| 174 | * @param address The {@code LinkAddress} to remove. |
| 175 | * @return true if the address was removed, false if it did not exist. |
| 176 | */ |
| 177 | public boolean removeLinkAddress(LinkAddress toRemove) { |
| 178 | return mLinkAddresses.remove(toRemove); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 181 | /** |
| 182 | * Returns all the addresses on this link. |
| 183 | */ |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 184 | public Collection<LinkAddress> getLinkAddresses() { |
| 185 | return Collections.unmodifiableCollection(mLinkAddresses); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 188 | /** |
| 189 | * Returns all the addresses on this link and all the links stacked above it. |
| 190 | */ |
| 191 | public Collection<LinkAddress> getAllLinkAddresses() { |
| 192 | Collection<LinkAddress> addresses = new ArrayList<LinkAddress>(); |
| 193 | addresses.addAll(mLinkAddresses); |
| 194 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 195 | addresses.addAll(stacked.getAllLinkAddresses()); |
| 196 | } |
| 197 | return addresses; |
| 198 | } |
| 199 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 200 | public void addDns(InetAddress dns) { |
Robert Greenwalt | 04cac40 | 2011-03-02 17:03:37 -0800 | [diff] [blame] | 201 | if (dns != null) mDnses.add(dns); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 202 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 203 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 204 | public Collection<InetAddress> getDnses() { |
| 205 | return Collections.unmodifiableCollection(mDnses); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 208 | public String getDomains() { |
| 209 | return mDomains; |
| 210 | } |
| 211 | |
| 212 | public void setDomains(String domains) { |
| 213 | mDomains = domains; |
| 214 | } |
| 215 | |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 216 | private RouteInfo routeWithInterface(RouteInfo route) { |
| 217 | return new RouteInfo( |
| 218 | route.getDestination(), |
| 219 | route.getGateway(), |
| 220 | mIfaceName); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 221 | } |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 222 | |
| 223 | public void addRoute(RouteInfo route) { |
| 224 | if (route != null) { |
| 225 | String routeIface = route.getInterface(); |
| 226 | if (routeIface != null && !routeIface.equals(mIfaceName)) { |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 227 | throw new IllegalArgumentException( |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 228 | "Route added with non-matching interface: " + routeIface + |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 229 | " vs. " + mIfaceName); |
Lorenzo Colitti | 45b9a5b | 2013-03-08 11:30:39 -0800 | [diff] [blame] | 230 | } |
| 231 | mRoutes.add(routeWithInterface(route)); |
| 232 | } |
| 233 | } |
| 234 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 235 | /** |
| 236 | * Returns all the routes on this link. |
| 237 | */ |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 238 | public Collection<RouteInfo> getRoutes() { |
| 239 | return Collections.unmodifiableCollection(mRoutes); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 242 | /** |
| 243 | * Returns all the routes on this link and all the links stacked above it. |
| 244 | */ |
| 245 | public Collection<RouteInfo> getAllRoutes() { |
| 246 | Collection<RouteInfo> routes = new ArrayList(); |
| 247 | routes.addAll(mRoutes); |
| 248 | for (LinkProperties stacked: mStackedLinks.values()) { |
| 249 | routes.addAll(stacked.getAllRoutes()); |
| 250 | } |
Robert Greenwalt | 6629bcd | 2013-03-15 11:28:50 -0700 | [diff] [blame] | 251 | return routes; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 254 | public void setHttpProxy(ProxyProperties proxy) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 255 | mHttpProxy = proxy; |
| 256 | } |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 257 | public ProxyProperties getHttpProxy() { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 258 | return mHttpProxy; |
| 259 | } |
| 260 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 261 | /** |
| 262 | * Adds a stacked link. |
| 263 | * |
| 264 | * If there is already a stacked link with the same interfacename as link, |
| 265 | * that link is replaced with link. Otherwise, link is added to the list |
| 266 | * of stacked links. If link is null, nothing changes. |
| 267 | * |
| 268 | * @param link The link to add. |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 269 | * @return true if the link was stacked, false otherwise. |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 270 | */ |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 271 | public boolean addStackedLink(LinkProperties link) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 272 | if (link != null && link.getInterfaceName() != null) { |
| 273 | mStackedLinks.put(link.getInterfaceName(), link); |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 274 | return true; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 275 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 276 | return false; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Removes a stacked link. |
| 281 | * |
| 282 | * If there a stacked link with the same interfacename as link, it is |
| 283 | * removed. Otherwise, nothing changes. |
| 284 | * |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 285 | * @param link The link to remove. |
| 286 | * @return true if the link was removed, false otherwise. |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 287 | */ |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 288 | public boolean removeStackedLink(LinkProperties link) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 289 | if (link != null && link.getInterfaceName() != null) { |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 290 | LinkProperties removed = mStackedLinks.remove(link.getInterfaceName()); |
| 291 | return removed != null; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 292 | } |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 293 | return false; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Returns all the links stacked on top of this link. |
| 298 | */ |
| 299 | public Collection<LinkProperties> getStackedLinks() { |
| 300 | Collection<LinkProperties> stacked = new ArrayList<LinkProperties>(); |
| 301 | for (LinkProperties link : mStackedLinks.values()) { |
| 302 | stacked.add(new LinkProperties(link)); |
| 303 | } |
| 304 | return Collections.unmodifiableCollection(stacked); |
| 305 | } |
| 306 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 307 | public void clear() { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 308 | mIfaceName = null; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 309 | mLinkAddresses.clear(); |
| 310 | mDnses.clear(); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 311 | mDomains = null; |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 312 | mRoutes.clear(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 313 | mHttpProxy = null; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 314 | mStackedLinks.clear(); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Implement the Parcelable interface |
| 319 | * @hide |
| 320 | */ |
| 321 | public int describeContents() { |
| 322 | return 0; |
| 323 | } |
| 324 | |
Wink Saville | 1f6408a | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 325 | @Override |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 326 | public String toString() { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 327 | String ifaceName = (mIfaceName == null ? "" : "InterfaceName: " + mIfaceName + " "); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 328 | |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 329 | String linkAddresses = "LinkAddresses: ["; |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 330 | for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString() + ","; |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 331 | linkAddresses += "] "; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 332 | |
| 333 | String dns = "DnsAddresses: ["; |
Wink Saville | 1f6408a | 2010-08-27 11:15:18 -0700 | [diff] [blame] | 334 | for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ","; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 335 | dns += "] "; |
| 336 | |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 337 | String domainName = "Domains: " + mDomains; |
| 338 | |
| 339 | String routes = " Routes: ["; |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 340 | for (RouteInfo route : mRoutes) routes += route.toString() + ","; |
| 341 | routes += "] "; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 342 | String proxy = (mHttpProxy == null ? "" : "HttpProxy: " + mHttpProxy.toString() + " "); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 343 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 344 | String stacked = ""; |
| 345 | if (mStackedLinks.values().size() > 0) { |
| 346 | stacked += " Stacked: ["; |
| 347 | for (LinkProperties link: mStackedLinks.values()) { |
| 348 | stacked += " [" + link.toString() + " ],"; |
| 349 | } |
| 350 | stacked += "] "; |
| 351 | } |
Wink Saville | 15bc62f | 2013-03-27 16:21:43 -0700 | [diff] [blame] | 352 | return "{" + ifaceName + linkAddresses + routes + dns + domainName + proxy + stacked + "}"; |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Returns true if this link has an IPv4 address. |
| 357 | * |
| 358 | * @return {@code true} if there is an IPv4 address, {@code false} otherwise. |
| 359 | */ |
| 360 | public boolean hasIPv4Address() { |
| 361 | for (LinkAddress address : mLinkAddresses) { |
| 362 | if (address.getAddress() instanceof Inet4Address) { |
| 363 | return true; |
| 364 | } |
| 365 | } |
| 366 | return false; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 369 | /** |
Lorenzo Colitti | 4faa027 | 2013-08-08 11:00:12 +0900 | [diff] [blame^] | 370 | * Returns true if this link has an IPv6 address. |
| 371 | * |
| 372 | * @return {@code true} if there is an IPv6 address, {@code false} otherwise. |
| 373 | */ |
| 374 | public boolean hasIPv6Address() { |
| 375 | for (LinkAddress address : mLinkAddresses) { |
| 376 | if (address.getAddress() instanceof Inet6Address) { |
| 377 | return true; |
| 378 | } |
| 379 | } |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | /** |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 384 | * Compares this {@code LinkProperties} interface name against the target |
| 385 | * |
| 386 | * @param target LinkProperties to compare. |
| 387 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 388 | */ |
| 389 | public boolean isIdenticalInterfaceName(LinkProperties target) { |
| 390 | return TextUtils.equals(getInterfaceName(), target.getInterfaceName()); |
| 391 | } |
| 392 | |
| 393 | /** |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 394 | * Compares this {@code LinkProperties} interface addresses against the target |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 395 | * |
| 396 | * @param target LinkProperties to compare. |
| 397 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 398 | */ |
| 399 | public boolean isIdenticalAddresses(LinkProperties target) { |
| 400 | Collection<InetAddress> targetAddresses = target.getAddresses(); |
| 401 | Collection<InetAddress> sourceAddresses = getAddresses(); |
| 402 | return (sourceAddresses.size() == targetAddresses.size()) ? |
| 403 | sourceAddresses.containsAll(targetAddresses) : false; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Compares this {@code LinkProperties} DNS addresses against the target |
| 408 | * |
| 409 | * @param target LinkProperties to compare. |
| 410 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 411 | */ |
| 412 | public boolean isIdenticalDnses(LinkProperties target) { |
| 413 | Collection<InetAddress> targetDnses = target.getDnses(); |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 414 | String targetDomains = target.getDomains(); |
| 415 | if (mDomains == null) { |
| 416 | if (targetDomains != null) return false; |
| 417 | } else { |
| 418 | if (mDomains.equals(targetDomains) == false) return false; |
| 419 | } |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 420 | return (mDnses.size() == targetDnses.size()) ? |
| 421 | mDnses.containsAll(targetDnses) : false; |
| 422 | } |
| 423 | |
| 424 | /** |
| 425 | * Compares this {@code LinkProperties} Routes against the target |
| 426 | * |
| 427 | * @param target LinkProperties to compare. |
| 428 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 429 | */ |
| 430 | public boolean isIdenticalRoutes(LinkProperties target) { |
| 431 | Collection<RouteInfo> targetRoutes = target.getRoutes(); |
| 432 | return (mRoutes.size() == targetRoutes.size()) ? |
| 433 | mRoutes.containsAll(targetRoutes) : false; |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Compares this {@code LinkProperties} HttpProxy against the target |
| 438 | * |
| 439 | * @param target LinkProperties to compare. |
| 440 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 441 | */ |
| 442 | public boolean isIdenticalHttpProxy(LinkProperties target) { |
| 443 | return getHttpProxy() == null ? target.getHttpProxy() == null : |
| 444 | getHttpProxy().equals(target.getHttpProxy()); |
| 445 | } |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 446 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 447 | /** |
| 448 | * Compares this {@code LinkProperties} stacked links against the target |
| 449 | * |
| 450 | * @param target LinkProperties to compare. |
| 451 | * @return {@code true} if both are identical, {@code false} otherwise. |
| 452 | */ |
| 453 | public boolean isIdenticalStackedLinks(LinkProperties target) { |
Lorenzo Colitti | 213f98b | 2013-04-01 10:47:43 +0900 | [diff] [blame] | 454 | if (!mStackedLinks.keySet().equals(target.mStackedLinks.keySet())) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 455 | return false; |
| 456 | } |
| 457 | for (LinkProperties stacked : mStackedLinks.values()) { |
| 458 | // Hashtable values can never be null. |
| 459 | String iface = stacked.getInterfaceName(); |
| 460 | if (!stacked.equals(target.mStackedLinks.get(iface))) { |
| 461 | return false; |
| 462 | } |
| 463 | } |
| 464 | return true; |
| 465 | } |
| 466 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 467 | @Override |
| 468 | /** |
| 469 | * Compares this {@code LinkProperties} instance against the target |
| 470 | * LinkProperties in {@code obj}. Two LinkPropertieses are equal if |
| 471 | * all their fields are equal in values. |
| 472 | * |
| 473 | * For collection fields, such as mDnses, containsAll() is used to check |
| 474 | * if two collections contains the same elements, independent of order. |
| 475 | * There are two thoughts regarding containsAll() |
| 476 | * 1. Duplicated elements. eg, (A, B, B) and (A, A, B) are equal. |
| 477 | * 2. Worst case performance is O(n^2). |
| 478 | * |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 479 | * This method does not check that stacked interfaces are equal, because |
| 480 | * stacked interfaces are not so much a property of the link as a |
| 481 | * description of connections between links. |
| 482 | * |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 483 | * @param obj the object to be tested for equality. |
| 484 | * @return {@code true} if both objects are equal, {@code false} otherwise. |
| 485 | */ |
| 486 | public boolean equals(Object obj) { |
| 487 | if (this == obj) return true; |
| 488 | |
| 489 | if (!(obj instanceof LinkProperties)) return false; |
| 490 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 491 | LinkProperties target = (LinkProperties) obj; |
| 492 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 493 | return isIdenticalInterfaceName(target) && |
| 494 | isIdenticalAddresses(target) && |
| 495 | isIdenticalDnses(target) && |
| 496 | isIdenticalRoutes(target) && |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 497 | isIdenticalHttpProxy(target) && |
| 498 | isIdenticalStackedLinks(target); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 499 | } |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 500 | |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 501 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 502 | * Compares the addresses in this LinkProperties with another |
| 503 | * LinkProperties, examining only addresses on the base link. |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 504 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 505 | * @param target a LinkProperties with the new list of addresses |
| 506 | * @return the differences between the addresses. |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 507 | */ |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 508 | public CompareResult<LinkAddress> compareAddresses(LinkProperties target) { |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 509 | /* |
| 510 | * Duplicate the LinkAddresses into removed, we will be removing |
| 511 | * address which are common between mLinkAddresses and target |
| 512 | * leaving the addresses that are different. And address which |
| 513 | * are in target but not in mLinkAddresses are placed in the |
| 514 | * addedAddresses. |
| 515 | */ |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 516 | CompareResult<LinkAddress> result = new CompareResult<LinkAddress>(); |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 517 | result.removed = new ArrayList<LinkAddress>(mLinkAddresses); |
| 518 | result.added.clear(); |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 519 | if (target != null) { |
| 520 | for (LinkAddress newAddress : target.getLinkAddresses()) { |
| 521 | if (! result.removed.remove(newAddress)) { |
| 522 | result.added.add(newAddress); |
| 523 | } |
Wink Saville | e822225 | 2011-07-13 13:44:13 -0700 | [diff] [blame] | 524 | } |
| 525 | } |
| 526 | return result; |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 529 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 530 | * Compares the DNS addresses in this LinkProperties with another |
| 531 | * LinkProperties, examining only DNS addresses on the base link. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 532 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 533 | * @param target a LinkProperties with the new list of dns addresses |
| 534 | * @return the differences between the DNS addresses. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 535 | */ |
| 536 | public CompareResult<InetAddress> compareDnses(LinkProperties target) { |
| 537 | /* |
| 538 | * Duplicate the InetAddresses into removed, we will be removing |
| 539 | * dns address which are common between mDnses and target |
| 540 | * leaving the addresses that are different. And dns address which |
| 541 | * are in target but not in mDnses are placed in the |
| 542 | * addedAddresses. |
| 543 | */ |
| 544 | CompareResult<InetAddress> result = new CompareResult<InetAddress>(); |
| 545 | |
| 546 | result.removed = new ArrayList<InetAddress>(mDnses); |
| 547 | result.added.clear(); |
| 548 | if (target != null) { |
| 549 | for (InetAddress newAddress : target.getDnses()) { |
| 550 | if (! result.removed.remove(newAddress)) { |
| 551 | result.added.add(newAddress); |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | return result; |
| 556 | } |
| 557 | |
| 558 | /** |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 559 | * Compares all routes in this LinkProperties with another LinkProperties, |
| 560 | * examining both the the base link and all stacked links. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 561 | * |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 562 | * @param target a LinkProperties with the new list of routes |
| 563 | * @return the differences between the routes. |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 564 | */ |
Lorenzo Colitti | d1e0fae | 2013-07-31 23:23:21 +0900 | [diff] [blame] | 565 | public CompareResult<RouteInfo> compareAllRoutes(LinkProperties target) { |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 566 | /* |
| 567 | * Duplicate the RouteInfos into removed, we will be removing |
Lorenzo Colitti | 1994bc1 | 2013-03-08 19:11:40 -0800 | [diff] [blame] | 568 | * routes which are common between mRoutes and target |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 569 | * leaving the routes that are different. And route address which |
| 570 | * are in target but not in mRoutes are placed in added. |
| 571 | */ |
| 572 | CompareResult<RouteInfo> result = new CompareResult<RouteInfo>(); |
| 573 | |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 574 | result.removed = getAllRoutes(); |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 575 | result.added.clear(); |
| 576 | if (target != null) { |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 577 | for (RouteInfo r : target.getAllRoutes()) { |
Robert Greenwalt | 0a46db5 | 2011-07-14 14:28:05 -0700 | [diff] [blame] | 578 | if (! result.removed.remove(r)) { |
| 579 | result.added.add(r); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | return result; |
| 584 | } |
| 585 | |
| 586 | |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 587 | @Override |
| 588 | /** |
| 589 | * generate hashcode based on significant fields |
| 590 | * Equal objects must produce the same hash code, while unequal objects |
| 591 | * may have the same hash codes. |
| 592 | */ |
| 593 | public int hashCode() { |
| 594 | return ((null == mIfaceName) ? 0 : mIfaceName.hashCode() |
| 595 | + mLinkAddresses.size() * 31 |
| 596 | + mDnses.size() * 37 |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 597 | + ((null == mDomains) ? 0 : mDomains.hashCode()) |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 598 | + mRoutes.size() * 41 |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 599 | + ((null == mHttpProxy) ? 0 : mHttpProxy.hashCode()) |
| 600 | + mStackedLinks.hashCode() * 47); |
John Wang | 4e90009 | 2011-04-04 12:35:42 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 603 | /** |
| 604 | * Implement the Parcelable interface. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 605 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 606 | public void writeToParcel(Parcel dest, int flags) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 607 | dest.writeString(getInterfaceName()); |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 608 | dest.writeInt(mLinkAddresses.size()); |
| 609 | for(LinkAddress linkAddress : mLinkAddresses) { |
| 610 | dest.writeParcelable(linkAddress, flags); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 611 | } |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 612 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 613 | dest.writeInt(mDnses.size()); |
| 614 | for(InetAddress d : mDnses) { |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 615 | dest.writeByteArray(d.getAddress()); |
| 616 | } |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 617 | dest.writeString(mDomains); |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 618 | |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 619 | dest.writeInt(mRoutes.size()); |
| 620 | for(RouteInfo route : mRoutes) { |
| 621 | dest.writeParcelable(route, flags); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 622 | } |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 623 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 624 | if (mHttpProxy != null) { |
| 625 | dest.writeByte((byte)1); |
| 626 | dest.writeParcelable(mHttpProxy, flags); |
| 627 | } else { |
| 628 | dest.writeByte((byte)0); |
| 629 | } |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 630 | ArrayList<LinkProperties> stackedLinks = new ArrayList(mStackedLinks.values()); |
| 631 | dest.writeList(stackedLinks); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Implement the Parcelable interface. |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 636 | */ |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 637 | public static final Creator<LinkProperties> CREATOR = |
| 638 | new Creator<LinkProperties>() { |
| 639 | public LinkProperties createFromParcel(Parcel in) { |
| 640 | LinkProperties netProp = new LinkProperties(); |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 641 | |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 642 | String iface = in.readString(); |
| 643 | if (iface != null) { |
Robert Greenwalt | 4717c26 | 2012-10-31 14:32:53 -0700 | [diff] [blame] | 644 | netProp.setInterfaceName(iface); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 645 | } |
| 646 | int addressCount = in.readInt(); |
| 647 | for (int i=0; i<addressCount; i++) { |
Irfan Sheriff | ed5d7d1 | 2010-10-01 16:08:28 -0700 | [diff] [blame] | 648 | netProp.addLinkAddress((LinkAddress)in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 649 | } |
| 650 | addressCount = in.readInt(); |
| 651 | for (int i=0; i<addressCount; i++) { |
| 652 | try { |
Irfan Sheriff | 1cf56ab | 2010-08-04 15:15:49 -0700 | [diff] [blame] | 653 | netProp.addDns(InetAddress.getByAddress(in.createByteArray())); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 654 | } catch (UnknownHostException e) { } |
| 655 | } |
Robert Greenwalt | 8058f62 | 2012-11-09 10:52:27 -0800 | [diff] [blame] | 656 | netProp.setDomains(in.readString()); |
Robert Greenwalt | 992564e | 2011-02-09 13:56:06 -0800 | [diff] [blame] | 657 | addressCount = in.readInt(); |
| 658 | for (int i=0; i<addressCount; i++) { |
Robert Greenwalt | aa70f10 | 2011-04-28 14:28:50 -0700 | [diff] [blame] | 659 | netProp.addRoute((RouteInfo)in.readParcelable(null)); |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 660 | } |
| 661 | if (in.readByte() == 1) { |
| 662 | netProp.setHttpProxy((ProxyProperties)in.readParcelable(null)); |
| 663 | } |
Lorenzo Colitti | 419a4ce | 2013-03-07 10:59:25 -0800 | [diff] [blame] | 664 | ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>(); |
| 665 | in.readList(stackedLinks, LinkProperties.class.getClassLoader()); |
| 666 | for (LinkProperties stackedLink: stackedLinks) { |
| 667 | netProp.addStackedLink(stackedLink); |
| 668 | } |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 669 | return netProp; |
| 670 | } |
| 671 | |
Robert Greenwalt | 37e65eb | 2010-08-30 10:56:47 -0700 | [diff] [blame] | 672 | public LinkProperties[] newArray(int size) { |
| 673 | return new LinkProperties[size]; |
Robert Greenwalt | 47f69fe | 2010-06-15 15:43:39 -0700 | [diff] [blame] | 674 | } |
| 675 | }; |
| 676 | } |