check if needed ports are available
dont' reapply transproxy on network reconnect
This commit is contained in:
parent
2628565b45
commit
78e7af4372
|
@ -15,6 +15,8 @@ import java.io.FileNotFoundException;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -121,8 +123,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
if (ENABLE_DEBUG_LOG)
|
if (ENABLE_DEBUG_LOG)
|
||||||
{
|
{
|
||||||
Log.e(TAG,msg,e);
|
Log.e(TAG,msg,e);
|
||||||
sendCallbackLogMessage(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sendCallbackLogMessage(msg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -615,6 +619,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
public void initTor () throws Exception
|
public void initTor () throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
boolean portsAvail = checkPortsAvailable();
|
||||||
|
|
||||||
|
if (!portsAvail)
|
||||||
|
{
|
||||||
|
logNotice("Another app is blocking Tor from starting");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
initBinaries();
|
initBinaries();
|
||||||
|
@ -650,6 +662,31 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
//checkAddressAndCountry();
|
//checkAddressAndCountry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkPortsAvailable ()
|
||||||
|
{
|
||||||
|
int[] ports = {9050,9051,8118};
|
||||||
|
|
||||||
|
for (int port: ports)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
logNotice("checking local port is available: " + port);
|
||||||
|
|
||||||
|
ServerSocket ss = new ServerSocket();
|
||||||
|
ss.bind(new InetSocketAddress(IP_LOCALHOST,port));
|
||||||
|
ss.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logException ("Tor socket is not available",e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* activate means whether to apply the users preferences
|
* activate means whether to apply the users preferences
|
||||||
* or clear them out
|
* or clear them out
|
||||||
|
@ -1576,8 +1613,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
logNotice("Network connectivity is good. Waking Tor up...");
|
logNotice("Network connectivity is good. Waking Tor up...");
|
||||||
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,-1,prefPersistNotifications);
|
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,-1,prefPersistNotifications);
|
||||||
|
|
||||||
if (mHasRoot && mEnableTransparentProxy)
|
|
||||||
enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue