diff options
| author | 2011-07-06 07:48:21 -0700 | |
|---|---|---|
| committer | 2011-07-06 07:48:21 -0700 | |
| commit | 37dbfcaf836cf37d1e404cd2cf25f4ed670bc80f (patch) | |
| tree | 80ef6ef90c6aed3449334b60e9f9cf85f3072d4d | |
| parent | c0c07d4ff689a6050ef368933b9c53283a01520a (diff) | |
| parent | 7022db4cd2ca3721631595d7379eabb2cc77f6a9 (diff) | |
am 7022db4c: am 2b62c4fb: am 38bb0123: Merge "Added methods to support dns cache per interface"
* commit '7022db4cd2ca3721631595d7379eabb2cc77f6a9':
Added methods to support dns cache per interface
| -rw-r--r-- | core/java/android/os/INetworkManagementService.aidl | 19 | ||||
| -rw-r--r-- | services/java/com/android/server/NetworkManagementService.java | 61 |
2 files changed, 80 insertions, 0 deletions
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl index 5a245f878545..3f02a6794315 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -224,4 +224,23 @@ interface INetworkManagementService */ int getInterfaceTxThrottle(String iface); + /** + * Sets the name of the default interface in the DNS resolver. + */ + void setDefaultInterfaceForDns(String iface); + + /** + * Bind name servers to an interface in the DNS resolver. + */ + void setDnsServersForInterface(String iface, in String[] servers); + + /** + * Flush the DNS cache associated with the default interface + */ + void flushDefaultDnsCache(); + + /** + * Flush the DNS cache associated with the specified interface + */ + void flushInterfaceDnsCache(String iface); } diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index 0b4b95893254..b34906fbda23 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -949,4 +949,65 @@ class NetworkManagementService extends INetworkManagementService.Stub { public int getInterfaceTxThrottle(String iface) { return getInterfaceThrottle(iface, false); } + + public void setDefaultInterfaceForDns(String iface) throws IllegalStateException { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); + try { + String cmd = "resolver setdefaultif " + iface; + + mConnector.doCommand(cmd); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native daemon to set default interface", e); + } + } + + public void setDnsServersForInterface(String iface, String[] servers) + throws IllegalStateException { + mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_NETWORK_STATE, + "NetworkManagementService"); + try { + String cmd = "resolver setifdns " + iface; + for (String s : servers) { + if (s != null && !"0.0.0.0".equals(s) && + !"::".equals(s) && !"0:0:0:0:0:0:0:0".equals(s)) { + cmd += " " + InetAddress.getByName(s).getHostAddress(); + } + } + + mConnector.doCommand(cmd); + } catch (UnknownHostException e) { + throw new IllegalStateException("failed to resolve dns address.", e); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native deamon to set dns for interface", e); + } + } + + public void flushDefaultDnsCache() throws IllegalStateException { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); + try { + String cmd = "resolver flushdefaultif"; + + mConnector.doCommand(cmd); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native deamon to flush default interface", e); + } + } + + public void flushInterfaceDnsCache(String iface) throws IllegalStateException { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService"); + try { + String cmd = "resolver flushif " + iface; + + mConnector.doCommand(cmd); + } catch (NativeDaemonConnectorException e) { + throw new IllegalStateException( + "Error communicating with native deamon to flush interface " + iface, e); + } + } } |