@@ -949,4 +949,64 @@ public int getInterfaceRxThrottle(String iface) {
949949 public int getInterfaceTxThrottle (String iface ) {
950950 return getInterfaceThrottle (iface , false );
951951 }
952+
953+ public void setDefaultInterfaceForDns (String iface ) throws IllegalStateException {
954+ mContext .enforceCallingOrSelfPermission (
955+ android .Manifest .permission .CHANGE_NETWORK_STATE , "NetworkManagementService" );
956+ try {
957+ String cmd = "resolver setdefaultif " + iface ;
958+
959+ mConnector .doCommand (cmd );
960+ } catch (NativeDaemonConnectorException e ) {
961+ throw new IllegalStateException (
962+ "Error communicating with native daemon to set default interface" , e );
963+ }
964+ }
965+
966+ public void setDnsServersForInterface (String iface , String [] servers )
967+ throws IllegalStateException {
968+ mContext .enforceCallingOrSelfPermission (android .Manifest .permission .CHANGE_NETWORK_STATE ,
969+ "NetworkManagementService" );
970+ try {
971+ String cmd = "resolver setifdns " + iface ;
972+ for (String s : servers ) {
973+ InetAddress a = NetworkUtils .numericToInetAddress (s );
974+ if (a .isAnyLocalAddress () == false ) {
975+ cmd += " " + a .getHostAddress ();
976+ }
977+ }
978+ mConnector .doCommand (cmd );
979+ } catch (IllegalArgumentException e ) {
980+ throw new IllegalStateException ("Error setting dnsn for interface" , e );
981+ } catch (NativeDaemonConnectorException e ) {
982+ throw new IllegalStateException (
983+ "Error communicating with native daemon to set dns for interface" , e );
984+ }
985+ }
986+
987+ public void flushDefaultDnsCache () throws IllegalStateException {
988+ mContext .enforceCallingOrSelfPermission (
989+ android .Manifest .permission .CHANGE_NETWORK_STATE , "NetworkManagementService" );
990+ try {
991+ String cmd = "resolver flushdefaultif" ;
992+
993+ mConnector .doCommand (cmd );
994+ } catch (NativeDaemonConnectorException e ) {
995+ throw new IllegalStateException (
996+ "Error communicating with native daemon to flush default interface" , e );
997+ }
998+ }
999+
1000+ public void flushInterfaceDnsCache (String iface ) throws IllegalStateException {
1001+ mContext .enforceCallingOrSelfPermission (
1002+ android .Manifest .permission .CHANGE_NETWORK_STATE , "NetworkManagementService" );
1003+ try {
1004+ String cmd = "resolver flushif " + iface ;
1005+
1006+ mConnector .doCommand (cmd );
1007+ } catch (NativeDaemonConnectorException e ) {
1008+ throw new IllegalStateException (
1009+ "Error communicating with native daemon to flush interface " + iface , e );
1010+ }
1011+ }
9521012}
0 commit comments