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

Commit 9b5e19c9 authored by frank PREEL's avatar frank PREEL Committed by Aayush Gupta
Browse files

base: Add support for DNS over TLS [2/2]



Change-Id: I141bc65b6d921189f9f8e00f2234748d43028d14
Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
parent e96cfd39
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -2935,6 +2935,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }

        private boolean maybeHandleNetworkMonitorMessage(Message msg) {
            if (DBG) log("maybeHandleNetworkMonitorMessage: " + msg.what);
            switch (msg.what) {
                default:
                    return false;
@@ -6386,6 +6387,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
        final NetworkAgentInfo defaultNai = getDefaultNetwork();
        final boolean isDefaultNetwork = (defaultNai != null && defaultNai.network.netId == netId);

        int useNwDNS = android.provider.Settings.System.getInt(mContext.getContentResolver(), "USE_NETWORK_DNS", 1);
        if (DBG) log("useNwDNS>"+useNwDNS+"<");

        if (DBG) {
            final Collection<InetAddress> dnses = newLp.getDnsServers();
            log("Setting DNS servers for network " + netId + " to " + dnses);
@@ -6401,6 +6405,34 @@ public class ConnectivityService extends IConnectivityManager.Stub
        } catch (Exception e) {
            loge("Exception in setDnsConfigurationForNetwork: " + e);
        }

        if ( useNwDNS == 0 ) {
            try {
                String s = android.provider.Settings.System.getString(mContext.getContentResolver(), "OVERRIDE_DNS_IP_V4");
                if (s == null) s = "9.9.9.9";
                if (DBG) log("Override dnses>"+s+"<");

                ArrayList<InetAddress> _list = new ArrayList<InetAddress>();
                _list.add(InetAddress.getByName(s));
                newLp.setDnsServers((Collection<InetAddress>) _list);

                if (DBG) {
                    final Collection<InetAddress> dnses = newLp.getDnsServers();
                    log("Setting DNS servers for network " + netId + " to " + dnses);
                }
                try {
                    mDnsManager.noteDnsServersForNetwork(netId, newLp);
                    if (isDefaultNetwork) mDnsManager.setDefaultDnsSystemProperties(newLp.getDnsServers());
                    mDnsManager.flushVmDnsCache();
                } catch (Exception e) {
                    loge("Exception in setDnsConfigurationForNetwork: " + e);
                }
            } catch (Exception e) {
                loge("Cannot set custom DNS: " + e);
            }

        }

    }

    private void updateVpnFiltering(LinkProperties newLp, LinkProperties oldLp,
+16 −1
Original line number Diff line number Diff line
@@ -760,7 +760,22 @@ public class NetworkManagementService extends INetworkManagementService.Stub {
     * Notify our observers of DNS server information received.
     */
    private void notifyInterfaceDnsServerInfo(String iface, long lifetime, String[] addresses) {

		int useNwDNS = android.provider.Settings.System.getInt(mContext.getContentResolver(), "USE_NETWORK_DNS", 1);
		//Slog.i(TAG,"notifyInterfaceDnsServerInfo useNwDNS>"+useNwDNS+"<"); 
		
		if ( 0 != useNwDNS ) {
			// Default
			invokeForAllObservers(o -> o.interfaceDnsServerInfo(iface, lifetime, addresses));		
		} else {
			final String[] xaddresses = new String[1];
			String s = android.provider.Settings.System.getString(mContext.getContentResolver(), "OVERRIDE_DNS_IP_V4");
			//Slog.i(TAG,"notifyInterfaceDnsServerInfo Override dnses>"+s+"<");
			xaddresses[0] = s;
			invokeForAllObservers(o -> o.interfaceDnsServerInfo(iface, lifetime, xaddresses));
		}

        
    }

    /**
+20 −0
Original line number Diff line number Diff line
@@ -348,6 +348,26 @@ public class DnsManager {
        final LinkProperties lp = mLinkPropertiesMap.get(netId);
        final int[] transportTypes = mTransportsMap.get(netId);
        if (lp == null || transportTypes == null) return;

        int useNwDNS = android.provider.Settings.System.getInt(mContext.getContentResolver(), "USE_NETWORK_DNS", 1);
        Slog.d(TAG, "useNwDNS>"+useNwDNS+"<");

        if ( 0 != useNwDNS ) {}
        else {
            try {
                String s = android.provider.Settings.System.getString(mContext.getContentResolver(), "OVERRIDE_DNS_IP_V4");
                if (s == null) s = "9.9.9.9";
                Slog.d(TAG, "Override dnses>"+s+"<");

                java.util.ArrayList<InetAddress> _list = new java.util.ArrayList<InetAddress>();
                _list.add(InetAddress.getByName(s));
                lp.setDnsServers((Collection<InetAddress>) _list);

            } catch (Exception e) {
                Slog.d(TAG,"Cannot set custom DNS: " + e);
            }
        }

        updateParametersSettings();
        final ResolverParamsParcel paramsParcel = new ResolverParamsParcel();

+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 * Copyright (C) 2019 e.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -50,6 +51,8 @@ import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;

import java.net.InetAddress;

/**
 * A bag class used by ConnectivityService for holding a collection of most recent
 * information published by a particular NetworkAgent as well as the
@@ -277,6 +280,28 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
        asyncChannel = ac;
        network = net;
        networkInfo = info;

        int useNwDNS = android.provider.Settings.System.getInt(context.getContentResolver(), "USE_NETWORK_DNS", 1);

        if ( 0 != useNwDNS ) {

        } else {
            java.util.Collection<InetAddress> dnses = new java.util.ArrayList<InetAddress>();
            try {
                String s = android.provider.Settings.System.getString(context.getContentResolver(), "OVERRIDE_DNS_IP_V4");
                if (s == null) s = "9.9.9.9";
                //if (DBG) log("Override dnses>"+s+"<");

                InetAddress addr = InetAddress.getByName(s);
                dnses.add(addr);

                lp.setDnsServers(dnses);
                //lp.setDomains("");
            } catch (Exception e) {
                //loge("Cannot set custom DNS: " + e);
            }
        }

        linkProperties = lp;
        networkCapabilities = nc;
        mScore = score;