Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e90aa5e9 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

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
parent 276e8d44
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -2384,6 +2384,12 @@ public final class Settings {
         */
         */
        public static final String SET_GLOBAL_HTTP_PROXY = "set_global_http_proxy";
        public static final String SET_GLOBAL_HTTP_PROXY = "set_global_http_proxy";


        /**
         * Setting for default DNS in case nobody suggests one
         * @hide
         */
        public static final String DEFAULT_DNS_SERVER = "default_dns_server";

        /**
        /**
         * Whether the package installer should allow installation of apps downloaded from
         * Whether the package installer should allow installation of apps downloaded from
         * sources other than the Android Market (vending machine).
         * sources other than the Android Market (vending machine).
+2 −0
Original line number Original line Diff line number Diff line
@@ -399,4 +399,6 @@
         device is data-only. -->
         device is data-only. -->
    <bool name="config_voice_capable">true</bool>
    <bool name="config_voice_capable">true</bool>


    <!-- IP address of the dns server to use if nobody else suggests one -->
    <string name="config_default_dns_server">8.8.8.8</string>
</resources>
</resources>
+27 −4
Original line number Original line Diff line number Diff line
@@ -121,6 +121,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    private int mNetTransitionWakeLockSerialNumber;
    private int mNetTransitionWakeLockSerialNumber;
    private int mNetTransitionWakeLockTimeout;
    private int mNetTransitionWakeLockTimeout;


    private InetAddress mDefaultDns;

    private static class NetworkAttributes {
    private static class NetworkAttributes {
        /**
        /**
         * Class for holding settings read from resources.
         * Class for holding settings read from resources.
@@ -209,6 +211,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            SystemProperties.set("net.hostname", name);
            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;
        mContext = context;


        PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
        PowerManager powerManager = (PowerManager)mContext.getSystemService(Context.POWER_SERVICE);
@@ -1468,6 +1483,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            Collection<InetAddress> dnses = p.getDnses();
            Collection<InetAddress> dnses = p.getDnses();
            if (mNetAttributes[netType].isDefault()) {
            if (mNetAttributes[netType].isDefault()) {
                int j = 1;
                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) {
                    for (InetAddress dns : dnses) {
                        if (DBG) {
                        if (DBG) {
                            Slog.d(TAG, "adding dns " + dns + " for " +
                            Slog.d(TAG, "adding dns " + dns + " for " +
@@ -1475,6 +1497,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                        }
                        }
                        SystemProperties.set("net.dns" + j++, dns.getHostAddress());
                        SystemProperties.set("net.dns" + j++, dns.getHostAddress());
                    }
                    }
                }
                for (int k=j ; k<mNumDnsEntries; k++) {
                for (int k=j ; k<mNumDnsEntries; k++) {
                    if (DBG) Slog.d(TAG, "erasing net.dns" + k);
                    if (DBG) Slog.d(TAG, "erasing net.dns" + k);
                    SystemProperties.set("net.dns" + k, "");
                    SystemProperties.set("net.dns" + k, "");