fulfilles the wishes of #12413 by support --default-torrc and -f
This commit is contained in:
parent
b6715b4d3c
commit
2eb79a5185
|
@ -116,35 +116,12 @@ public class TorResourceInstaller implements TorServiceConstants {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean updateTorConfig (File fileTorRc, String extraLines) throws IOException, FileNotFoundException, TimeoutException
|
public boolean updateTorConfigCustom (File fileTorRcCustom, String extraLines) throws IOException, FileNotFoundException, TimeoutException
|
||||||
{
|
{
|
||||||
|
|
||||||
InputStream is;
|
|
||||||
|
|
||||||
Shell shell = Shell.startShell(new ArrayList<String>(),installFolder.getAbsolutePath());
|
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.raw.torrc);
|
|
||||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + fileTorRc.getAbsolutePath())).waitForFinish();
|
|
||||||
streamToFile(is,fileTorRc, false, false);
|
|
||||||
|
|
||||||
if (extraLines != null && extraLines.length() > 0)
|
StringBufferInputStream sbis = new StringBufferInputStream(extraLines + '\n');
|
||||||
{
|
streamToFile(sbis,fileTorRcCustom,false,false);
|
||||||
StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
|
|
||||||
streamToFile(sbis,fileTorRc,true,false);
|
|
||||||
}
|
|
||||||
|
|
||||||
is = context.getResources().openRawResource(R.raw.torrcdiag);
|
|
||||||
fileTorRc = new File(installFolder, TORRCDIAG_ASSET_KEY);
|
|
||||||
shell.add(new SimpleCommand(COMMAND_RM_FORCE + fileTorRc.getAbsolutePath())).waitForFinish();
|
|
||||||
streamToFile(is,fileTorRc, false, false);
|
|
||||||
|
|
||||||
if (extraLines != null && extraLines.length() > 0)
|
|
||||||
{
|
|
||||||
StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
|
|
||||||
streamToFile(sbis,fileTorRc,true,false);
|
|
||||||
}
|
|
||||||
|
|
||||||
shell.close();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import net.freehaven.tor.control.ConfigEntry;
|
import net.freehaven.tor.control.ConfigEntry;
|
||||||
|
@ -54,6 +52,7 @@ import android.graphics.Color;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.RemoteCallbackList;
|
import android.os.RemoteCallbackList;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
@ -194,7 +193,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
public int getTorStatus ()
|
public int getTorStatus ()
|
||||||
{
|
{
|
||||||
|
|
||||||
return currentStatus;
|
return currentStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -236,10 +235,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
if (notifyId == ERROR_NOTIFY_ID)
|
if (notifyId == ERROR_NOTIFY_ID)
|
||||||
{
|
{
|
||||||
mNotifyBuilder.setTicker(notifyMsg);
|
mNotifyBuilder.setTicker(notifyMsg);
|
||||||
mNotifyBuilder.setOngoing(false);
|
|
||||||
mNotifyBuilder.setLights(Color.RED, 1000, 1000);
|
mNotifyBuilder.setLights(Color.RED, 1000, 1000);
|
||||||
mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr);
|
mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mNotifyBuilder.setTicker("");
|
||||||
|
//mNotifyBuilder.setLights(Color.GREEN, 5000, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
if (isOngoing)
|
if (isOngoing)
|
||||||
{
|
{
|
||||||
|
@ -559,9 +562,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
extraLines.append('\n');
|
extraLines.append('\n');
|
||||||
extraLines.append(prefs.getString("pref_custom_torrc", ""));
|
extraLines.append(prefs.getString("pref_custom_torrc", ""));
|
||||||
|
|
||||||
logNotice("updating torrc configuration...");
|
logNotice("updating torrc custom configuration...");
|
||||||
|
|
||||||
boolean success = installer.updateTorConfig(fileTorRc, extraLines.toString());
|
File fileTorRcCustom = new File(fileTorRc.getAbsolutePath() + ".custom");
|
||||||
|
boolean success = installer.updateTorConfigCustom(fileTorRcCustom, extraLines.toString());
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
|
@ -765,7 +769,11 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
Shell shell = Shell.startShell();
|
Shell shell = Shell.startShell();
|
||||||
|
|
||||||
|
|
||||||
SimpleCommand cmdTor = new SimpleCommand(fileTor.getCanonicalPath() + " DataDirectory " + appCacheHome.getCanonicalPath() + " -f " + torrcPath + " &");
|
SimpleCommand cmdTor = new SimpleCommand(fileTor.getCanonicalPath()
|
||||||
|
+ " DataDirectory " + appCacheHome.getCanonicalPath()
|
||||||
|
+ " --defaults-torrc " + torrcPath
|
||||||
|
+ " -f " + torrcPath + ".custom"
|
||||||
|
+ " &");
|
||||||
|
|
||||||
shell.add(cmdTor);
|
shell.add(cmdTor);
|
||||||
|
|
||||||
|
@ -1110,7 +1118,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
return PROFILE_ON;
|
return PROFILE_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setTorProfile(int profile) {
|
public void setTorProfile(int profile) {
|
||||||
|
|
||||||
if (currentStatus == STATUS_OFF)
|
if (currentStatus == STATUS_OFF)
|
||||||
|
@ -1123,6 +1130,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
initTor();
|
initTor();
|
||||||
|
|
||||||
currentStatus = STATUS_CONNECTING;
|
currentStatus = STATUS_CONNECTING;
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -1159,6 +1167,48 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Handler mHandlerStatusChecker = null;
|
||||||
|
|
||||||
|
private void enableStatusChecker ()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (mHandlerStatusChecker != null)
|
||||||
|
mHandlerStatusChecker = new Handler();
|
||||||
|
|
||||||
|
mHandlerStatusChecker.postDelayed(new Runnable ()
|
||||||
|
{
|
||||||
|
public void run ()
|
||||||
|
{
|
||||||
|
if (conn != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String state = conn.getInfo("dormant");
|
||||||
|
if (state != null && Integer.parseInt(state) == 0)
|
||||||
|
{
|
||||||
|
currentStatus = STATUS_ON;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentStatus = STATUS_CONNECTING;
|
||||||
|
showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off,prefPersistNotifications);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e){}
|
||||||
|
|
||||||
|
|
||||||
|
mHandlerStatusChecker.postDelayed(this,1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
},1000);
|
||||||
|
}
|
||||||
|
|
||||||
public void newDescriptors(List<String> orList) {
|
public void newDescriptors(List<String> orList) {
|
||||||
|
|
||||||
|
@ -1233,9 +1283,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead);
|
sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead);
|
||||||
|
|
||||||
// if(++notificationCounter%10==0)
|
|
||||||
// startService(new Intent(ITorService.class.getName()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastWritten = written;
|
lastWritten = written;
|
||||||
|
@ -1762,8 +1809,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_));
|
logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_));
|
||||||
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,prefPersistNotifications);
|
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor,prefPersistNotifications);
|
||||||
|
|
||||||
if (mHasRoot && mEnableTransparentProxy)
|
//if (mHasRoot && mEnableTransparentProxy)
|
||||||
enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
|
//enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue