diff options
4 files changed, 87 insertions, 2 deletions
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl index 68b0a9fb2969..b546da021e18 100644 --- a/core/java/android/os/INetworkManagementService.aidl +++ b/core/java/android/os/INetworkManagementService.aidl @@ -324,6 +324,11 @@ interface INetworkManagementService void removeIdleTimer(String iface); /** + * Configure name servers, search paths, and resolver parameters for the given network. + */ + void setDnsConfigurationForNetwork(int netId, in String[] servers, String domains); + + /** * Bind name servers to a network in the DNS resolver. */ void setDnsServersForNetwork(int netId, in String[] servers, String domains); diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index d98e2177058a..700c2d28b3dd 100755 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -6974,6 +6974,33 @@ public final class Settings { public static final String STORAGE_BENCHMARK_INTERVAL = "storage_benchmark_interval"; /** + * Sample validity in seconds to configure for the system DNS resolver. + * {@hide} + */ + public static final String DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS = + "dns_resolver_sample_validity_seconds"; + + /** + * Success threshold in percent for use with the system DNS resolver. + * {@hide} + */ + public static final String DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT = + "dns_resolver_success_threshold_percent"; + + /** + * Minimum number of samples needed for statistics to be considered meaningful in the + * system DNS resolver. + * {@hide} + */ + public static final String DNS_RESOLVER_MIN_SAMPLES = "dns_resolver_min_samples"; + + /** + * Maximum number taken into account for statistics purposes in the system DNS resolver. + * {@hide} + */ + public static final String DNS_RESOLVER_MAX_SAMPLES = "dns_resolver_max_samples"; + + /** * Whether to disable the automatic scheduling of system updates. * 1 = system updates won't be automatically scheduled (will always * present notification instead). diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index f5e9d1968eb8..00dcdeae3a27 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -4317,10 +4317,10 @@ public class ConnectivityService extends IConnectivityManager.Stub Collection<InetAddress> dnses = newLp.getDnsServers(); if (DBG) log("Setting DNS servers for network " + netId + " to " + dnses); try { - mNetd.setDnsServersForNetwork( + mNetd.setDnsConfigurationForNetwork( netId, NetworkUtils.makeStrings(dnses), newLp.getDomains()); } catch (Exception e) { - loge("Exception in setDnsServersForNetwork: " + e); + loge("Exception in setDnsConfigurationForNetwork: " + e); } final NetworkAgentInfo defaultNai = getDefaultNetwork(); if (defaultNai != null && defaultNai.network.netId == netId) { diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java index d73b06b07584..2418160255f8 100644 --- a/services/core/java/com/android/server/NetworkManagementService.java +++ b/services/core/java/com/android/server/NetworkManagementService.java @@ -47,6 +47,7 @@ import static com.android.server.NetworkManagementService.NetdResponseCode.TtyLi import static com.android.server.NetworkManagementSocketTagger.PROP_QTAGUID_ENABLED; import android.annotation.NonNull; import android.app.ActivityManagerNative; +import android.content.ContentResolver; import android.content.Context; import android.net.ConnectivityManager; import android.net.INetd; @@ -76,6 +77,7 @@ import android.os.ServiceSpecificException; import android.os.StrictMode; import android.os.SystemClock; import android.os.SystemProperties; +import android.provider.Settings; import android.telephony.DataConnectionRealTimeInfo; import android.telephony.PhoneStateListener; import android.telephony.SubscriptionManager; @@ -175,6 +177,12 @@ public class NetworkManagementService extends INetworkManagementService.Stub public static final int StrictCleartext = 617; } + /* Defaults for resolver parameters. */ + public static final int DNS_RESOLVER_DEFAULT_SAMPLE_VALIDITY_SECONDS = 1800; + public static final int DNS_RESOLVER_DEFAULT_SUCCESS_THRESHOLD_PERCENT = 25; + public static final int DNS_RESOLVER_DEFAULT_MIN_SAMPLES = 8; + public static final int DNS_RESOLVER_DEFAULT_MAX_SAMPLES = 64; + /** * String indicating a softap command. */ @@ -1927,6 +1935,51 @@ public class NetworkManagementService extends INetworkManagementService.Stub } @Override + public void setDnsConfigurationForNetwork(int netId, String[] servers, String domains) { + mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); + + ContentResolver resolver = mContext.getContentResolver(); + + int sampleValidity = Settings.Global.getInt(resolver, + Settings.Global.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS, + DNS_RESOLVER_DEFAULT_SAMPLE_VALIDITY_SECONDS); + if (sampleValidity < 0 || sampleValidity > 65535) { + Slog.w(TAG, "Invalid sampleValidity=" + sampleValidity + ", using default=" + + DNS_RESOLVER_DEFAULT_SAMPLE_VALIDITY_SECONDS); + sampleValidity = DNS_RESOLVER_DEFAULT_SAMPLE_VALIDITY_SECONDS; + } + + int successThreshold = Settings.Global.getInt(resolver, + Settings.Global.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT, + DNS_RESOLVER_DEFAULT_SUCCESS_THRESHOLD_PERCENT); + if (successThreshold < 0 || successThreshold > 100) { + Slog.w(TAG, "Invalid successThreshold=" + successThreshold + ", using default=" + + DNS_RESOLVER_DEFAULT_SUCCESS_THRESHOLD_PERCENT); + successThreshold = DNS_RESOLVER_DEFAULT_SUCCESS_THRESHOLD_PERCENT; + } + + int minSamples = Settings.Global.getInt(resolver, + Settings.Global.DNS_RESOLVER_MIN_SAMPLES, DNS_RESOLVER_DEFAULT_MIN_SAMPLES); + int maxSamples = Settings.Global.getInt(resolver, + Settings.Global.DNS_RESOLVER_MAX_SAMPLES, DNS_RESOLVER_DEFAULT_MAX_SAMPLES); + if (minSamples < 0 || minSamples > maxSamples || maxSamples > 64) { + Slog.w(TAG, "Invalid sample count (min, max)=(" + minSamples + ", " + maxSamples + + "), using default=(" + DNS_RESOLVER_DEFAULT_MIN_SAMPLES + ", " + + DNS_RESOLVER_DEFAULT_MAX_SAMPLES + ")"); + minSamples = DNS_RESOLVER_DEFAULT_MIN_SAMPLES; + maxSamples = DNS_RESOLVER_DEFAULT_MAX_SAMPLES; + } + + final String[] domainStrs = domains == null ? new String[0] : domains.split(" "); + final int[] params = { sampleValidity, successThreshold, minSamples, maxSamples }; + try { + mNetdService.setResolverConfiguration(netId, servers, domainStrs, params); + } catch (RemoteException e) { + throw new RuntimeException(e); + } + } + + @Override public void setDnsServersForNetwork(int netId, String[] servers, String domains) { mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); |