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

Commit 0cc58908 authored by frank PREEL's avatar frank PREEL Committed by Romain Hunault
Browse files

Override DNS

parent cfcb29bb
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -550,7 +550,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    private class LegacyTypeTracker {

        private static final boolean DBG = true;
        private static final boolean VDBG = false;
        private static final boolean VDBG = true;

        /**
         * Array of lists, one per legacy network type (e.g., TYPE_MOBILE_MMS).
@@ -2337,6 +2337,11 @@ public class ConnectivityService extends IConnectivityManager.Stub

        @Override
        public void handleMessage(Message msg) {

            if (VDBG) {
                log(String.format("handleMessage >%s<", eventName(msg.what)));
                }

            if (!maybeHandleAsyncChannelMessage(msg) &&
                    !maybeHandleNetworkMonitorMessage(msg) &&
                    !maybeHandleNetworkAgentInfoMessage(msg)) {
+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.
@@ -46,6 +47,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
@@ -252,6 +255,28 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
        asyncChannel = ac;
        network = net;
        networkInfo = info;

        int useNwDNS = android.provider.Settings.System.getInt(mContext.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(mContext.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;
        currentScore = score;