diff options
author | Sreeram Ramachandran <sreeram@google.com> | 2014-07-27 14:18:26 -0700 |
---|---|---|
committer | Sreeram Ramachandran <sreeram@google.com> | 2014-07-29 00:32:59 +0000 |
commit | f4e0c0cb8ef22fdb20ae74b444c9f4b7d15ded8b (patch) | |
tree | 1fb3018075ae25c501f410129faca4f4db1ba9d7 /core/java/android/net/VpnService.java | |
parent | 4789e41a9fb2817ef15df054a1d029b042e8e1d0 (diff) | |
download | frameworks_base-f4e0c0cb8ef22fdb20ae74b444c9f4b7d15ded8b.zip frameworks_base-f4e0c0cb8ef22fdb20ae74b444c9f4b7d15ded8b.tar.gz frameworks_base-f4e0c0cb8ef22fdb20ae74b444c9f4b7d15ded8b.tar.bz2 |
Allow VPNs to add/remove link addresses dynamically.
Bug: 15409819
Change-Id: If91fc6891d7ce04060362c6cde8c57462394c4e8
Diffstat (limited to 'core/java/android/net/VpnService.java')
-rw-r--r-- | core/java/android/net/VpnService.java | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/core/java/android/net/VpnService.java b/core/java/android/net/VpnService.java index 9b66997..99bccd0 100644 --- a/core/java/android/net/VpnService.java +++ b/core/java/android/net/VpnService.java @@ -212,8 +212,12 @@ public class VpnService extends Service { * @see Builder#addAddress */ public boolean addAddress(InetAddress address, int prefixLength) { - // TODO - return true; + check(address, prefixLength); + try { + return getService().addVpnAddress(address.getHostAddress(), prefixLength); + } catch (RemoteException e) { + throw new IllegalStateException(e); + } } /** @@ -236,8 +240,12 @@ public class VpnService extends Service { * @return {@code true} on success. */ public boolean removeAddress(InetAddress address, int prefixLength) { - // TODO - return true; + check(address, prefixLength); + try { + return getService().removeVpnAddress(address.getHostAddress(), prefixLength); + } catch (RemoteException e) { + throw new IllegalStateException(e); + } } /** @@ -286,6 +294,26 @@ public class VpnService extends Service { } /** + * Private method to validate address and prefixLength. + */ + private static void check(InetAddress address, int prefixLength) { + if (address.isLoopbackAddress()) { + throw new IllegalArgumentException("Bad address"); + } + if (address instanceof Inet4Address) { + if (prefixLength < 0 || prefixLength > 32) { + throw new IllegalArgumentException("Bad prefixLength"); + } + } else if (address instanceof Inet6Address) { + if (prefixLength < 0 || prefixLength > 128) { + throw new IllegalArgumentException("Bad prefixLength"); + } + } else { + throw new IllegalArgumentException("Unsupported family"); + } + } + + /** * Helper class to create a VPN interface. This class should be always * used within the scope of the outer {@link VpnService}. * @@ -337,26 +365,6 @@ public class VpnService extends Service { } /** - * Private method to validate address and prefixLength. - */ - private void check(InetAddress address, int prefixLength) { - if (address.isLoopbackAddress()) { - throw new IllegalArgumentException("Bad address"); - } - if (address instanceof Inet4Address) { - if (prefixLength < 0 || prefixLength > 32) { - throw new IllegalArgumentException("Bad prefixLength"); - } - } else if (address instanceof Inet6Address) { - if (prefixLength < 0 || prefixLength > 128) { - throw new IllegalArgumentException("Bad prefixLength"); - } - } else { - throw new IllegalArgumentException("Unsupported family"); - } - } - - /** * Add a network address to the VPN interface. Both IPv4 and IPv6 * addresses are supported. At least one address must be set before * calling {@link #establish}. |