Skip to content

Commit

Permalink
Merge pull request #389 from bitmold/debug_log_once
Browse files Browse the repository at this point in the history
Fixes #73 only log debug information one time if preference is enabled
  • Loading branch information
n8fr8 committed Sep 11, 2020
2 parents 9cca3d0 + ccb03b9 commit 0e27fb0
Showing 1 changed file with 12 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.jaredrummler.android.shell.CommandResult;

import net.freehaven.tor.control.ConfigEntry;
import net.freehaven.tor.control.RawEventListener;
import net.freehaven.tor.control.TorControlConnection;

import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -201,8 +200,8 @@ public void logException(String msg, Exception e)
sendCallbackLogMessage(msg);

}


private boolean findExistingTorDaemon() {
try {
mLastProcessId = initControlConnection(3, true);
Expand Down Expand Up @@ -444,8 +443,6 @@ public void onTaskRemoved(Intent rootIntent){

@Override
public void onDestroy() {


try {
// unregisterReceiver(mNetworkStateReceiver);
unregisterReceiver(mActionBroadcastReceiver);
Expand Down Expand Up @@ -688,9 +685,6 @@ private boolean torUpgradeAndConfig() throws IOException, TimeoutException {
return true;
}




return false;
}

Expand All @@ -707,7 +701,7 @@ private File updateTorrcCustomFile () throws IOException, TimeoutException

extraLines.append("RunAsDaemon 1").append('\n');
extraLines.append("AvoidDiskWrites 1").append('\n');

String socksPortPref = prefs.getString(OrbotConstants.PREF_SOCKS, (TorServiceConstants.SOCKS_PROXY_PORT_DEFAULT));

if (socksPortPref.indexOf(':')!=-1)
Expand Down Expand Up @@ -787,10 +781,8 @@ private File updateTorrcCustomFile () throws IOException, TimeoutException

extraLines.append("DisableNetwork 0").append('\n');

if (Prefs.useDebugLogging())
{
extraLines.append("Log debug syslog").append('\n');
extraLines.append("Log info syslog").append('\n');
if (Prefs.useDebugLogging()) {
extraLines.append("Log debug syslog").append('\n');
extraLines.append("SafeLogging 0").append('\n');
}

Expand Down Expand Up @@ -1084,8 +1076,6 @@ private int exec (String cmd, boolean wait) throws Exception
debug("stderr: " + result.getStderr());

return result.exitCode;


}

private int initControlConnection (int maxTries, boolean isReconnect) throws Exception
Expand Down Expand Up @@ -1152,18 +1142,6 @@ private int initControlConnection (int maxTries, boolean isReconnect) throws Exc
// implementations for all the events we don't care about.
logNotice( "adding control port event handler");

if (Prefs.useDebugLogging()) {
conn.setDebugging(System.out);
conn.addRawEventListener(new RawEventListener() {
@Override
public void onEvent(String keyword, String data) {


debug(keyword + ": " + data);
}
});
}

conn.setEventHandler(mEventHandler);

logNotice( "SUCCESS added control port event handler");
Expand Down Expand Up @@ -1235,8 +1213,6 @@ public void onEvent(String keyword, String data) {
}

throw new Exception("Tor control port could not be found");


}

private int getControlPort () {
Expand Down Expand Up @@ -1506,19 +1482,14 @@ protected void sendCallbackBandwidth(long upload, long download, long written, l
private void sendCallbackLogMessage (final String logMessage)
{

mHandler.post(new Runnable () {

public void run ()
{
mHandler.post(() -> {

Intent intent = new Intent(LOCAL_ACTION_LOG);
// You can also include some extra data.
intent.putExtra(LOCAL_EXTRA_LOG, logMessage);
intent.putExtra(EXTRA_STATUS, mCurrentStatus);

LocalBroadcastManager.getInstance(OrbotService.this).sendBroadcast(intent);
}
Intent intent = new Intent(LOCAL_ACTION_LOG);
// You can also include some extra data.
intent.putExtra(LOCAL_EXTRA_LOG, logMessage);
intent.putExtra(EXTRA_STATUS, mCurrentStatus);

LocalBroadcastManager.getInstance(OrbotService.this).sendBroadcast(intent);
});

}
Expand Down Expand Up @@ -2005,7 +1976,7 @@ private void loadBridgeDefaults ()
{
if (alBridges == null)
{
alBridges = new ArrayList<Bridge>();
alBridges = new ArrayList<>();

try
{
Expand Down

0 comments on commit 0e27fb0

Please sign in to comment.