diff options
author | Mattias Falk <mattias.falk@sonyericsson.com> | 2011-04-04 16:10:36 +0200 |
---|---|---|
committer | Johan Redestig <johan.redestig@sonyericsson.com> | 2011-04-19 13:42:35 +0200 |
commit | 7475c0cea622f126af966c3b5b9741f547e83450 (patch) | |
tree | 6f47c303339a9d5146e1e94d4db5488c81f8348d | |
parent | 08d9d9a46250c4fad66e9b637e8898a3524c4286 (diff) | |
download | frameworks_base-7475c0cea622f126af966c3b5b9741f547e83450.zip frameworks_base-7475c0cea622f126af966c3b5b9741f547e83450.tar.gz frameworks_base-7475c0cea622f126af966c3b5b9741f547e83450.tar.bz2 |
Added methods to support dns cache per interface
Added some methods to NetworkManagementService
as part of the work to implement a dns cache
per interface.
Change-Id: I5c7369075dee6b6a4ff67b27f1df7cc124f54c14
-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 212c5fb..08403af 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -207,4 +207,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 f0acdc0..edc7c5a 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -784,4 +784,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); + } + } } |