commit 81d257809445fc5d9c3e32f34d5cc43f036fdaa9 Author: n8fr8 nathan@guardianproject.info Date: Wed Aug 11 16:28:22 2021 -0400
ensure tor conn events are set properly by waiting one second longer (waiting for a better fix from TorService library on this) --- .../torproject/android/service/OrbotService.java | 61 +++++++++++++--------- 1 file changed, 37 insertions(+), 24 deletions(-)
diff --git a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java index 1ba938e9..23b1ab9c 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java @@ -39,6 +39,7 @@ import android.provider.BaseColumns; import android.text.TextUtils; import android.util.Log;
+import net.freehaven.tor.control.RawEventListener; import net.freehaven.tor.control.TorControlCommands; import net.freehaven.tor.control.TorControlConnection;
@@ -828,37 +829,49 @@ public class OrbotService extends VpnService implements TorServiceConstants, Orb @Override public void onServiceConnected(ComponentName componentName, IBinder iBinder) { torService = ((TorService.LocalBinder) iBinder).getService(); - try { - conn = torService.getTorControlConnection(); - while (conn == null) { - Log.v(TAG, "Waiting for Tor Control Connection..."); - Thread.sleep(500); - conn = torService.getTorControlConnection(); + + while ((conn = torService.getTorControlConnection())==null) + { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } } + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + mEventHandler = new TorEventHandler(OrbotService.this); - logNotice("adding control port event handler"); + + ArrayList<String> events = new ArrayList<>(Arrays.asList( + TorControlCommands.EVENT_OR_CONN_STATUS, + TorControlCommands.EVENT_CIRCUIT_STATUS, + TorControlCommands.EVENT_NOTICE_MSG, + TorControlCommands.EVENT_WARN_MSG, + TorControlCommands.EVENT_ERR_MSG, + TorControlCommands.EVENT_BANDWIDTH_USED, + TorControlCommands.EVENT_NEW_DESC, + TorControlCommands.EVENT_ADDRMAP)); + if (Prefs.useDebugLogging()) { + events.add(TorControlCommands.EVENT_DEBUG_MSG); + events.add(TorControlCommands.EVENT_INFO_MSG); + } + try { conn.setEventHandler(mEventHandler); - ArrayList<String> events = new ArrayList<>(Arrays.asList( - TorControlCommands.EVENT_OR_CONN_STATUS, - TorControlCommands.EVENT_CIRCUIT_STATUS, - TorControlCommands.EVENT_NOTICE_MSG, - TorControlCommands.EVENT_WARN_MSG, - TorControlCommands.EVENT_ERR_MSG, - TorControlCommands.EVENT_BANDWIDTH_USED, - TorControlCommands.EVENT_NEW_DESC, - TorControlCommands.EVENT_ADDRMAP)); - if (Prefs.useDebugLogging()) { - events.add(TorControlCommands.EVENT_DEBUG_MSG); - events.add(TorControlCommands.EVENT_INFO_MSG); - } conn.setEvents(events); logNotice("SUCCESS added control port event handler"); - initControlConnection(); - } catch (IOException | InterruptedException e) { + } catch (IOException e) { e.printStackTrace(); - stopTorOnError(e.getLocalizedMessage()); - conn = null; } + + + initControlConnection(); + showConnectedToTorNetworkNotification(); + }
@Override
tor-commits@lists.torproject.org