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:
Robert Greenwalt
2010-09-01 11:34:05 -07:00
parent 7323ea10cd
commit 94daa185b8

View File

@@ -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,12 +1483,20 @@ public class ConnectivityService extends IConnectivityManager.Stub {
Collection<InetAddress> dnses = p.getDnses();
if (mNetAttributes[netType].isDefault()) {
int j = 1;
for (InetAddress dns : dnses) {
if (dnses.size() == 0 && mDefaultDns != null) {
if (DBG) {
Slog.d(TAG, "adding dns " + dns + " for " +
nt.getNetworkInfo().getTypeName());
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 " +
nt.getNetworkInfo().getTypeName());
}
SystemProperties.set("net.dns" + j++, dns.getHostAddress());
}
SystemProperties.set("net.dns" + j++, dns.getHostAddress());
}
for (int k=j ; k<mNumDnsEntries; k++) {
if (DBG) Slog.d(TAG, "erasing net.dns" + k);