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

Commit d5299ff3 authored by Jean-Baptiste Queru's avatar Jean-Baptiste Queru
Browse files

Merge 37dbfcaf

Change-Id: Iae55ecada8dc231c88bb87b32e8bd5e7b6a47bd0
parents 1a65b441 37dbfcaf
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -241,4 +241,23 @@ interface INetworkManagementService
     */
    int getInterfaceTxThrottle(String iface);

    /**
     * Sets the name of the default interface in the DNS resolver.
     */
    void setDefaultInterfaceForDns(String iface);

    /**
     * Bind name servers to an interface in the DNS resolver.
     */
    void setDnsServersForInterface(String iface, in String[] servers);

    /**
     * Flush the DNS cache associated with the default interface
     */
    void flushDefaultDnsCache();

    /**
     * Flush the DNS cache associated with the specified interface
     */
    void flushInterfaceDnsCache(String iface);
}
+62 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -1230,4 +1231,65 @@ class NetworkManagementService extends INetworkManagementService.Stub {
            return -1;
        }
    }

    public void setDefaultInterfaceForDns(String iface) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        try {
            String cmd = "resolver setdefaultif " + iface;

            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Error communicating with native daemon to set default interface", e);
        }
    }

    public void setDnsServersForInterface(String iface, String[] servers)
            throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_NETWORK_STATE,
                "NetworkManagementService");
        try {
            String cmd = "resolver setifdns " + iface;
            for (String s : servers) {
                if (s != null && !"0.0.0.0".equals(s) &&
                        !"::".equals(s) && !"0:0:0:0:0:0:0:0".equals(s)) {
                    cmd += " " + InetAddress.getByName(s).getHostAddress();
                }
            }

            mConnector.doCommand(cmd);
        } catch (UnknownHostException e) {
            throw new IllegalStateException("failed to resolve dns address.", e);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Error communicating with native deamon to set dns for interface", e);
        }
    }

    public void flushDefaultDnsCache() throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        try {
            String cmd = "resolver flushdefaultif";

            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Error communicating with native deamon to flush default interface", e);
        }
    }

    public void flushInterfaceDnsCache(String iface) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
        try {
            String cmd = "resolver flushif " + iface;

            mConnector.doCommand(cmd);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Error communicating with native deamon to flush interface " + iface, e);
        }
    }
}