[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [orbot/master] more tuning of Tor service startup and status checking
commit 8ee5e9e0fbe0f5c1561b9fee6a2178d15b14faff
Author: Nathan Freitas <nathan@xxxxxxxxxxx>
Date: Sat Sep 6 00:46:57 2014 -0400
more tuning of Tor service startup and status checking
---
src/org/torproject/android/Orbot.java | 22 ++++----
src/org/torproject/android/service/TorService.java | 59 +++++++++-----------
.../android/service/TorServiceConstants.java | 3 -
3 files changed, 38 insertions(+), 46 deletions(-)
diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java
index 5300dea..c448ed9 100644
--- a/src/org/torproject/android/Orbot.java
+++ b/src/org/torproject/android/Orbot.java
@@ -17,7 +17,7 @@ import org.torproject.android.wizard.ChooseLocaleWizardActivity;
import org.torproject.android.wizard.TipsAndTricks;
import android.app.AlertDialog;
-import android.app.NotificationManager;
+import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -101,10 +101,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
+ ProgressDialog mProgressDialog;
private void startService ()
{
- appendLogTextAndScroll("starting Tor background service... ");
Intent torService = new Intent(this, TorService.class);
startService(torService);
@@ -112,7 +112,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
bindService(torService,
mConnection, Context.BIND_AUTO_CREATE);
-
+ appendLogTextAndScroll("starting Tor background service... ");
+ mProgressDialog = ProgressDialog.show(this, "", getString(R.string.status_starting_up), true);
+
}
private void doLayout ()
@@ -124,11 +126,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
lblStatus.setOnLongClickListener(this);
imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this);
-
imgStatus.setOnTouchListener(this);
- imgStatus.setEnabled(false);
-
lblStatus.setText("Initializing the application...");
downloadText = (TextView)findViewById(R.id.trafficDown);
@@ -983,7 +982,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
// this is a bit of a strange/old/borrowed code/design i used to change the service state
// not sure it really makes sense when what we want to say is just "startTor"
- mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
+ mService.setProfile(TorServiceConstants.STATUS_ON); //this means turn on
//here we update the UI which is a bit sloppy and mixed up code wise
//might be best to just call updateStatus() instead of directly manipulating UI in this method - yep makes sense
@@ -1010,7 +1009,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
{
if (mService != null)
{
- mService.setProfile(TorServiceConstants.PROFILE_OFF);
+ mService.setProfile(TorServiceConstants.STATUS_OFF);
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
mHandler.sendMessage(msg);
@@ -1200,6 +1199,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
public void onServiceConnected(ComponentName className,
IBinder service) {
+ if (mProgressDialog != null && mProgressDialog.isShowing())
+ mProgressDialog.dismiss();
+
appendLogTextAndScroll("Tor background service connected.");
// This is called when the connection with the service has been
@@ -1208,10 +1210,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
// service through an IDL interface, so get a client-side
// representation of that from the raw service object.
mService = ITorService.Stub.asInterface(service);
-
- imgStatus.setEnabled(true);
-
// We want to monitor the service for as long as we are
// connected to it.
try {
@@ -1233,6 +1232,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
+
public void onServiceDisconnected(ComponentName className) {
appendLogTextAndScroll("Tor background service disconnected.");
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 1dd39f8..b9f3791 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -83,7 +83,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public static boolean ENABLE_DEBUG_LOG = false;
- private static int currentStatus = STATUS_OFF;
+ private int mCurrentStatus = STATUS_OFF;
private final static int CONTROL_SOCKET_TIMEOUT = 0;
@@ -183,7 +183,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
sendCallbackLogMessage (getString(R.string.found_existing_tor_process));
- currentStatus = STATUS_ON;
+ mCurrentStatus = STATUS_ON;
return true;
}
@@ -217,7 +217,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public int getTorStatus ()
{
- return currentStatus;
+ return mCurrentStatus;
}
@@ -340,12 +340,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try
{
-
- if (fileTor == null)
- initBinariesAndDirectories();
-
- updateSettings ();
-
+ initialize();
new Thread (new TorStarter(intent)).start();
return Service.START_STICKY;
@@ -386,7 +381,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
//if this is a start on boot launch turn tor on
if (mIntent != null && mIntent.getAction()!=null && mIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
- setTorProfile(PROFILE_ON);
+ setTorProfile(STATUS_ON);
}
}
catch (Exception e)
@@ -422,7 +417,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
//stop the foreground priority and make sure to remove the persistant notification
stopForeground(true);
- currentStatus = STATUS_OFF;
+ mCurrentStatus = STATUS_OFF;
if (mHasRoot && mEnableTransparentProxy)
disableTransparentProxy();
@@ -744,7 +739,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void startTor () throws Exception
{
- currentStatus = STATUS_CONNECTING;
+ mCurrentStatus = STATUS_CONNECTING;
if (fileTor == null)
initBinariesAndDirectories();
@@ -1127,7 +1122,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
conn.setConf("Log", "debug file " + fileLog2.getCanonicalPath());
}*/
- currentStatus = STATUS_CONNECTING;
+ mCurrentStatus = STATUS_CONNECTING;
String confSocks = conn.getInfo("net/listeners/socks");
StringTokenizer st = new StringTokenizer(confSocks," ");
@@ -1297,7 +1292,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
// get several values
- if (currentStatus == STATUS_CONNECTING)
+ if (mCurrentStatus == STATUS_CONNECTING)
{
//Map vals = conn.getInfo(Arrays.asList(new String[]{
// "status/bootstrap-phase", "status","version"}));
@@ -1317,7 +1312,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
catch (Exception e)
{
Log.d(TAG, "Unable to get Tor status from control port");
- currentStatus = STATUS_UNAVAILABLE;
+ mCurrentStatus = STATUS_UNAVAILABLE;
}
}*/
@@ -1359,16 +1354,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
-
-
- public int getProfile() throws RemoteException {
- //return mProfile;
- return PROFILE_ON;
- }
-
public void setTorProfile(int profile) {
- if (profile == PROFILE_ON)
+ if (profile == STATUS_ON)
{
sendCallbackStatusMessage (getString(R.string.status_starting_up));
@@ -1382,7 +1370,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
logException("Unable to start Tor: " + e.toString(),e);
- currentStatus = STATUS_OFF;
+ mCurrentStatus = STATUS_OFF;
showToolbarNotification(getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
stopTor();
}
@@ -1393,7 +1381,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
stopTor();
- currentStatus = STATUS_OFF;
+ mCurrentStatus = STATUS_OFF;
}
}
@@ -1405,7 +1393,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
{
- currentStatus = STATUS_ON;
+ mCurrentStatus = STATUS_ON;
showToolbarNotification(getString(R.string.status_activated), NOTIFY_ID, R.drawable.ic_stat_tor);
}
@@ -1550,8 +1538,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
else if(status.equals("BUILT"))
{
- if (currentStatus == STATUS_CONNECTING)
- currentStatus = STATUS_ON;
+ if (mCurrentStatus == STATUS_CONNECTING)
+ mCurrentStatus = STATUS_ON;
logNotice(sb.toString());
@@ -1679,10 +1667,18 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public IBinder onBind(Intent intent) {
+ logNotice("Background service is bound. Status=" + mCurrentStatus);
+
return mBinder;
}
- public boolean checkAndInitImpl ()
+ @Override
+ public void onRebind(Intent intent) {
+
+ super.onRebind(intent);
+ }
+
+ public boolean checkAndInitImpl ()
{
if (fileTor != null)
{
@@ -1693,8 +1689,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
return true;
}
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ logException("error init Tor", e);
}
}
@@ -2026,7 +2021,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
mBinder.saveConfiguration();
}
- if (currentStatus != STATUS_OFF)
+ if (mCurrentStatus != STATUS_OFF)
{
if (!mConnectivity)
{
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index 19a99c8..a77cdac 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -71,9 +71,6 @@ public interface TorServiceConstants {
public final static int STATUS_ON = 1;
public final static int STATUS_CONNECTING = 2;
- public final static int PROFILE_OFF = -1;
- public final static int PROFILE_ON = 1;
-
public static final int STATUS_MSG = 1;
public static final int ENABLE_TOR_MSG = 2;
public static final int DISABLE_TOR_MSG = 3;
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits