• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Révision572b7048a6ed6cf6c5f6bc6c9d542dc377d601ff (tree)
l'heure2011-07-26 09:00:13
AuteurRobert Greenwalt <rgreenwalt@goog...>
CommiterRobert Greenwalt

Message de Log

Use dns proxy a bit.

Sets the current default interface and sets the dns per interface.
port of changes 23041 and 22098 from opensource.
bug:5060618

Change-Id: I80e7ef88727eeb8ff2b48059f69b270e5a6b5c16

Change Summary

Modification

--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -20,6 +20,7 @@ import java.net.InetAddress;
2020 import java.net.Inet4Address;
2121 import java.net.Inet6Address;
2222 import java.net.UnknownHostException;
23+import java.util.Collection;
2324
2425 import android.util.Log;
2526
@@ -235,4 +236,18 @@ public class NetworkUtils {
235236 throw new IllegalArgumentException(e);
236237 }
237238 }
239+
240+ /**
241+ * Create a string array of host addresses from a collection of InetAddresses
242+ * @param addrs a Collection of InetAddresses
243+ * @return an array of Strings containing their host addresses
244+ */
245+ public static String[] makeStrings(Collection<InetAddress> addrs) {
246+ String[] result = new String[addrs.size()];
247+ int i=0;
248+ for (InetAddress addr : addrs) {
249+ result[i++] = addr.getHostAddress();
250+ }
251+ return result;
252+ }
238253 }
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -224,4 +224,23 @@ interface INetworkManagementService
224224 */
225225 int getInterfaceTxThrottle(String iface);
226226
227+ /**
228+ * Sets the name fo the default interface in the DNS resolver.
229+ */
230+ void setDefaultInterfaceForDns(String iface);
231+
232+ /**
233+ * Bind name servers to an interface in the DNS resolver.
234+ */
235+ void setDnsServersForInterface(String iface, in String[] servers);
236+
237+ /**
238+ * Flush the DNS cache associated with the default interface.
239+ */
240+ void flushDefaultDnsCache();
241+
242+ /**
243+ * Flush the DNS cache associated with the specified interface.
244+ */
245+ void flushInterfaceDnsCache(String iface);
227246 }
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -1757,8 +1757,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
17571757 LinkProperties p = nt.getLinkProperties();
17581758 if (p == null) return;
17591759 Collection<InetAddress> dnses = p.getDnses();
1760+ try {
1761+ mNetd.setDnsServersForInterface(p.getInterfaceName(),
1762+ NetworkUtils.makeStrings(dnses));
1763+ } catch (Exception e) {
1764+ Slog.e(TAG, "exception setting dns servers: " + e);
1765+ }
17601766 boolean changed = false;
17611767 if (mNetConfigs[netType].isDefault()) {
1768+ try {
1769+ mNetd.setDefaultInterfaceForDns(p.getInterfaceName());
1770+ } catch (Exception e) {
1771+ Slog.e(TAG, "exception setting default dns interface: " + e);
1772+ }
17621773 int j = 1;
17631774 if (dnses.size() == 0 && mDefaultDns != null) {
17641775 String dnsString = mDefaultDns.getHostAddress();
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -949,4 +949,64 @@ class NetworkManagementService extends INetworkManagementService.Stub {
949949 public int getInterfaceTxThrottle(String iface) {
950950 return getInterfaceThrottle(iface, false);
951951 }
952+
953+ public void setDefaultInterfaceForDns(String iface) throws IllegalStateException {
954+ mContext.enforceCallingOrSelfPermission(
955+ android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
956+ try {
957+ String cmd = "resolver setdefaultif " + iface;
958+
959+ mConnector.doCommand(cmd);
960+ } catch (NativeDaemonConnectorException e) {
961+ throw new IllegalStateException(
962+ "Error communicating with native daemon to set default interface", e);
963+ }
964+ }
965+
966+ public void setDnsServersForInterface(String iface, String[] servers)
967+ throws IllegalStateException {
968+ mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_NETWORK_STATE,
969+ "NetworkManagementService");
970+ try {
971+ String cmd = "resolver setifdns " + iface;
972+ for (String s : servers) {
973+ InetAddress a = NetworkUtils.numericToInetAddress(s);
974+ if (a.isAnyLocalAddress() == false) {
975+ cmd += " " + a.getHostAddress();
976+ }
977+ }
978+ mConnector.doCommand(cmd);
979+ } catch (IllegalArgumentException e) {
980+ throw new IllegalStateException("Error setting dnsn for interface", e);
981+ } catch (NativeDaemonConnectorException e) {
982+ throw new IllegalStateException(
983+ "Error communicating with native daemon to set dns for interface", e);
984+ }
985+ }
986+
987+ public void flushDefaultDnsCache() throws IllegalStateException {
988+ mContext.enforceCallingOrSelfPermission(
989+ android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
990+ try {
991+ String cmd = "resolver flushdefaultif";
992+
993+ mConnector.doCommand(cmd);
994+ } catch (NativeDaemonConnectorException e) {
995+ throw new IllegalStateException(
996+ "Error communicating with native daemon to flush default interface", e);
997+ }
998+ }
999+
1000+ public void flushInterfaceDnsCache(String iface) throws IllegalStateException {
1001+ mContext.enforceCallingOrSelfPermission(
1002+ android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
1003+ try {
1004+ String cmd = "resolver flushif " + iface;
1005+
1006+ mConnector.doCommand(cmd);
1007+ } catch (NativeDaemonConnectorException e) {
1008+ throw new IllegalStateException(
1009+ "Error communicating with native daemon to flush interface " + iface, e);
1010+ }
1011+ }
9521012 }