Loading core/java/android/net/NetworkUtils.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import java.net.InetAddress; import java.net.Inet4Address; import java.net.Inet6Address; import java.net.UnknownHostException; import java.util.Collection; import android.util.Log; Loading Loading @@ -235,4 +236,18 @@ public class NetworkUtils { throw new IllegalArgumentException(e); } } /** * Create a string array of host addresses from a collection of InetAddresses * @param addrs a Collection of InetAddresses * @return an array of Strings containing their host addresses */ public static String[] makeStrings(Collection<InetAddress> addrs) { String[] result = new String[addrs.size()]; int i=0; for (InetAddress addr : addrs) { result[i++] = addr.getHostAddress(); } return result; } } core/java/android/os/INetworkManagementService.aidl +19 −0 Original line number Diff line number Diff line Loading @@ -224,4 +224,23 @@ interface INetworkManagementService */ int getInterfaceTxThrottle(String iface); /** * Sets the name fo 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); } services/java/com/android/server/ConnectivityService.java +11 −0 Original line number Diff line number Diff line Loading @@ -1783,8 +1783,19 @@ public class ConnectivityService extends IConnectivityManager.Stub { LinkProperties p = nt.getLinkProperties(); if (p == null) return; Collection<InetAddress> dnses = p.getDnses(); try { mNetd.setDnsServersForInterface(p.getInterfaceName(), NetworkUtils.makeStrings(dnses)); } catch (Exception e) { Slog.e(TAG, "exception setting dns servers: " + e); } boolean changed = false; if (mNetConfigs[netType].isDefault()) { try { mNetd.setDefaultInterfaceForDns(p.getInterfaceName()); } catch (Exception e) { Slog.e(TAG, "exception setting default dns interface: " + e); } int j = 1; if (dnses.size() == 0 && mDefaultDns != null) { String dnsString = mDefaultDns.getHostAddress(); Loading services/java/com/android/server/NetworkManagementService.java +60 −0 Original line number Diff line number Diff line Loading @@ -949,4 +949,64 @@ 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) { InetAddress a = NetworkUtils.numericToInetAddress(s); if (a.isAnyLocalAddress() == false) { cmd += " " + a.getHostAddress(); } } mConnector.doCommand(cmd); } catch (IllegalArgumentException e) { throw new IllegalStateException("Error setting dnsn for interface", e); } catch (NativeDaemonConnectorException e) { throw new IllegalStateException( "Error communicating with native daemon 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 daemon 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 daemon to flush interface " + iface, e); } } } Loading
core/java/android/net/NetworkUtils.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import java.net.InetAddress; import java.net.Inet4Address; import java.net.Inet6Address; import java.net.UnknownHostException; import java.util.Collection; import android.util.Log; Loading Loading @@ -235,4 +236,18 @@ public class NetworkUtils { throw new IllegalArgumentException(e); } } /** * Create a string array of host addresses from a collection of InetAddresses * @param addrs a Collection of InetAddresses * @return an array of Strings containing their host addresses */ public static String[] makeStrings(Collection<InetAddress> addrs) { String[] result = new String[addrs.size()]; int i=0; for (InetAddress addr : addrs) { result[i++] = addr.getHostAddress(); } return result; } }
core/java/android/os/INetworkManagementService.aidl +19 −0 Original line number Diff line number Diff line Loading @@ -224,4 +224,23 @@ interface INetworkManagementService */ int getInterfaceTxThrottle(String iface); /** * Sets the name fo 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); }
services/java/com/android/server/ConnectivityService.java +11 −0 Original line number Diff line number Diff line Loading @@ -1783,8 +1783,19 @@ public class ConnectivityService extends IConnectivityManager.Stub { LinkProperties p = nt.getLinkProperties(); if (p == null) return; Collection<InetAddress> dnses = p.getDnses(); try { mNetd.setDnsServersForInterface(p.getInterfaceName(), NetworkUtils.makeStrings(dnses)); } catch (Exception e) { Slog.e(TAG, "exception setting dns servers: " + e); } boolean changed = false; if (mNetConfigs[netType].isDefault()) { try { mNetd.setDefaultInterfaceForDns(p.getInterfaceName()); } catch (Exception e) { Slog.e(TAG, "exception setting default dns interface: " + e); } int j = 1; if (dnses.size() == 0 && mDefaultDns != null) { String dnsString = mDefaultDns.getHostAddress(); Loading
services/java/com/android/server/NetworkManagementService.java +60 −0 Original line number Diff line number Diff line Loading @@ -949,4 +949,64 @@ 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) { InetAddress a = NetworkUtils.numericToInetAddress(s); if (a.isAnyLocalAddress() == false) { cmd += " " + a.getHostAddress(); } } mConnector.doCommand(cmd); } catch (IllegalArgumentException e) { throw new IllegalStateException("Error setting dnsn for interface", e); } catch (NativeDaemonConnectorException e) { throw new IllegalStateException( "Error communicating with native daemon 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 daemon 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 daemon to flush interface " + iface, e); } } }