Add a default dns entry if none is provided
Fixes part of emulator which isn't telling us about dns servers. Gets some stuff running, but browser is still broken. bug:2961703 Change-Id: I53b946eba434aca1bb524c2acaf77922377948d1
This commit is contained in:
@@ -121,6 +121,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
private int mNetTransitionWakeLockSerialNumber;
|
||||
private int mNetTransitionWakeLockTimeout;
|
||||
|
||||
private InetAddress mDefaultDns;
|
||||
|
||||
private static class NetworkAttributes {
|
||||
/**
|
||||
* Class for holding settings read from resources.
|
||||
@@ -209,6 +211,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
SystemProperties.set("net.hostname", name);
|
||||
}
|
||||
|
||||
// read our default dns server ip
|
||||
String dns = Settings.Secure.getString(context.getContentResolver(),
|
||||
Settings.Secure.DEFAULT_DNS_SERVER);
|
||||
if (dns == null || dns.length() == 0) {
|
||||
dns = context.getResources().getString(
|
||||
com.android.internal.R.string.config_default_dns_server);
|
||||
}
|
||||
try {
|
||||
mDefaultDns = InetAddress.getByName(dns);
|
||||
} catch (UnknownHostException e) {
|
||||
Slog.e(TAG, "Error setting defaultDns using " + dns);
|
||||
}
|
||||
|
||||
mContext = context;
|
||||
|
||||
PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
|
||||
@@ -1468,6 +1483,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
Collection<InetAddress> dnses = p.getDnses();
|
||||
if (mNetAttributes[netType].isDefault()) {
|
||||
int j = 1;
|
||||
if (dnses.size() == 0 && mDefaultDns != null) {
|
||||
if (DBG) {
|
||||
Slog.d(TAG, "no dns provided - using " + mDefaultDns.getHostAddress());
|
||||
}
|
||||
SystemProperties.set("net.dns1", mDefaultDns.getHostAddress());
|
||||
j++;
|
||||
} else {
|
||||
for (InetAddress dns : dnses) {
|
||||
if (DBG) {
|
||||
Slog.d(TAG, "adding dns " + dns + " for " +
|
||||
@@ -1475,6 +1497,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
|
||||
}
|
||||
SystemProperties.set("net.dns" + j++, dns.getHostAddress());
|
||||
}
|
||||
}
|
||||
for (int k=j ; k<mNumDnsEntries; k++) {
|
||||
if (DBG) Slog.d(TAG, "erasing net.dns" + k);
|
||||
SystemProperties.set("net.dns" + k, "");
|
||||
|
||||
Reference in New Issue
Block a user