diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2013-11-26 01:03:05 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2013-11-26 01:03:06 +0000 |
commit | 9d4ac9703657142b190d3c256de7c3329e5a4b29 (patch) | |
tree | d2a5bf64fd3bb9ee4ddfa45ff44750459ead8d94 | |
parent | eede7e89c94b3bb56c26aec137c53d592d3bc7c3 (diff) | |
parent | 5ae4a531cc31be2868f65c40e8636658f1ae2f06 (diff) | |
download | frameworks_base-9d4ac9703657142b190d3c256de7c3329e5a4b29.zip frameworks_base-9d4ac9703657142b190d3c256de7c3329e5a4b29.tar.gz frameworks_base-9d4ac9703657142b190d3c256de7c3329e5a4b29.tar.bz2 |
Merge "Pass DNS server info notifications to observers."
4 files changed, 90 insertions, 0 deletions
diff --git a/core/java/android/net/INetworkManagementEventObserver.aidl b/core/java/android/net/INetworkManagementEventObserver.aidl index b76e4c2..c720c7b 100644 --- a/core/java/android/net/INetworkManagementEventObserver.aidl +++ b/core/java/android/net/INetworkManagementEventObserver.aidl @@ -90,4 +90,13 @@ interface INetworkManagementEventObserver { * @param active True if the interface is actively transmitting data, false if it is idle. */ void interfaceClassDataActivityChanged(String label, boolean active); + + /** + * Information about available DNS servers has been received. + * + * @param iface The interface on which the information was received. + * @param lifetime The time in seconds for which the DNS servers may be used. + * @param servers The IP addresses of the DNS servers. + */ + void interfaceDnsServerInfo(String iface, long lifetime, in String[] servers); } diff --git a/core/java/com/android/server/net/BaseNetworkObserver.java b/core/java/com/android/server/net/BaseNetworkObserver.java index fa54c5f..a02c602 100644 --- a/core/java/com/android/server/net/BaseNetworkObserver.java +++ b/core/java/com/android/server/net/BaseNetworkObserver.java @@ -64,4 +64,9 @@ public class BaseNetworkObserver extends INetworkManagementEventObserver.Stub { public void limitReached(String limitName, String iface) { // default no-op } + + @Override + public void interfaceDnsServerInfo(String iface, long lifetime, String[] servers) { + // default no-op + } } diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java index 9a0d648..8089fbc 100644 --- a/services/java/com/android/server/NetworkManagementService.java +++ b/services/java/com/android/server/NetworkManagementService.java @@ -136,6 +136,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub public static final int BandwidthControl = 601; public static final int InterfaceClassActivity = 613; public static final int InterfaceAddressChange = 614; + public static final int InterfaceDnsServerInfo = 615; } /** @@ -431,6 +432,21 @@ public class NetworkManagementService extends INetworkManagementService.Stub mObservers.finishBroadcast(); } + /** + * Notify our observers of DNS server information received. + */ + private void notifyInterfaceDnsServerInfo(String iface, long lifetime, String[] addresses) { + final int length = mObservers.beginBroadcast(); + for (int i = 0; i < length; i++) { + try { + mObservers.getBroadcastItem(i).interfaceDnsServerInfo(iface, lifetime, addresses); + } catch (RemoteException e) { + } catch (RuntimeException e) { + } + } + mObservers.finishBroadcast(); + } + // // Netd Callback handling // @@ -535,6 +551,26 @@ public class NetworkManagementService extends INetworkManagementService.Stub } return true; // break; + case NetdResponseCode.InterfaceDnsServerInfo: + /* + * Information about available DNS servers has been received. + * Format: "NNN DnsInfo servers <interface> <lifetime> <servers>" + */ + long lifetime; // Actually a 32-bit unsigned integer. + + if (cooked.length == 6 && + cooked[1].equals("DnsInfo") && + cooked[2].equals("servers")) { + try { + lifetime = Long.parseLong(cooked[4]); + } catch (NumberFormatException e) { + throw new IllegalStateException(errorMessage); + } + String[] servers = cooked[5].split(","); + notifyInterfaceDnsServerInfo(cooked[3], lifetime, servers); + } + return true; + // break; default: break; } return false; diff --git a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java index 30d4eff..4385dcd 100644 --- a/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/NetworkManagementServiceTest.java @@ -172,6 +172,46 @@ public class NetworkManagementServiceTest extends AndroidTestCase { sendMessage("666 Address added 2001:db8::1/64 wlan0 1 0"); // Invalid code. + + /** + * DNS information broadcasts. + */ + sendMessage("615 DnsInfo servers rmnet_usb0 3600 2001:db8::1"); + expectSoon(observer).interfaceDnsServerInfo("rmnet_usb0", 3600, + new String[]{"2001:db8::1"}); + + sendMessage("615 DnsInfo servers wlan0 14400 2001:db8::1,2001:db8::2"); + expectSoon(observer).interfaceDnsServerInfo("wlan0", 14400, + new String[]{"2001:db8::1", "2001:db8::2"}); + + // We don't check for negative lifetimes, only for parse errors. + sendMessage("615 DnsInfo servers wlan0 -3600 ::1"); + expectSoon(observer).interfaceDnsServerInfo("wlan0", -3600, + new String[]{"::1"}); + + sendMessage("615 DnsInfo servers wlan0 SIXHUNDRED ::1"); + // Non-numeric lifetime. + + sendMessage("615 DnsInfo servers wlan0 2001:db8::1"); + // Missing lifetime. + + sendMessage("615 DnsInfo servers wlan0 3600"); + // No servers. + + sendMessage("615 DnsInfo servers 3600 wlan0 2001:db8::1,2001:db8::2"); + // Non-numeric lifetime. + + sendMessage("615 DnsInfo wlan0 7200 2001:db8::1,2001:db8::2"); + // Invalid tokens. + + sendMessage("666 DnsInfo servers wlan0 5400 2001:db8::1"); + // Invalid code. + + // No syntax checking on the addresses. + sendMessage("615 DnsInfo servers wlan0 600 ,::,,foo,::1,"); + expectSoon(observer).interfaceDnsServerInfo("wlan0", 600, + new String[]{"", "::", "", "foo", "::1"}); + // Make sure nothing else was called. verifyNoMoreInteractions(observer); } |