more tuning of Tor service startup and status checking
This commit is contained in:
parent
9c4c3496f1
commit
8ee5e9e0fb
|
@ -17,7 +17,7 @@ import org.torproject.android.wizard.ChooseLocaleWizardActivity;
|
||||||
import org.torproject.android.wizard.TipsAndTricks;
|
import org.torproject.android.wizard.TipsAndTricks;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.NotificationManager;
|
import android.app.ProgressDialog;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -101,10 +101,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgressDialog mProgressDialog;
|
||||||
|
|
||||||
private void startService ()
|
private void startService ()
|
||||||
{
|
{
|
||||||
appendLogTextAndScroll("starting Tor background service... ");
|
|
||||||
|
|
||||||
Intent torService = new Intent(this, TorService.class);
|
Intent torService = new Intent(this, TorService.class);
|
||||||
startService(torService);
|
startService(torService);
|
||||||
|
@ -112,6 +112,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
bindService(torService,
|
bindService(torService,
|
||||||
mConnection, Context.BIND_AUTO_CREATE);
|
mConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
|
appendLogTextAndScroll("starting Tor background service... ");
|
||||||
|
mProgressDialog = ProgressDialog.show(this, "", getString(R.string.status_starting_up), true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,11 +126,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
lblStatus.setOnLongClickListener(this);
|
lblStatus.setOnLongClickListener(this);
|
||||||
imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
|
imgStatus = (ImageProgressView)findViewById(R.id.imgStatus);
|
||||||
imgStatus.setOnLongClickListener(this);
|
imgStatus.setOnLongClickListener(this);
|
||||||
|
|
||||||
imgStatus.setOnTouchListener(this);
|
imgStatus.setOnTouchListener(this);
|
||||||
|
|
||||||
imgStatus.setEnabled(false);
|
|
||||||
|
|
||||||
lblStatus.setText("Initializing the application...");
|
lblStatus.setText("Initializing the application...");
|
||||||
|
|
||||||
downloadText = (TextView)findViewById(R.id.trafficDown);
|
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
|
// 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"
|
// 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
|
//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
|
//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)
|
if (mService != null)
|
||||||
{
|
{
|
||||||
mService.setProfile(TorServiceConstants.PROFILE_OFF);
|
mService.setProfile(TorServiceConstants.STATUS_OFF);
|
||||||
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
|
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
|
||||||
mHandler.sendMessage(msg);
|
mHandler.sendMessage(msg);
|
||||||
|
|
||||||
|
@ -1200,6 +1199,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
public void onServiceConnected(ComponentName className,
|
public void onServiceConnected(ComponentName className,
|
||||||
IBinder service) {
|
IBinder service) {
|
||||||
|
|
||||||
|
if (mProgressDialog != null && mProgressDialog.isShowing())
|
||||||
|
mProgressDialog.dismiss();
|
||||||
|
|
||||||
appendLogTextAndScroll("Tor background service connected.");
|
appendLogTextAndScroll("Tor background service connected.");
|
||||||
|
|
||||||
// This is called when the connection with the service has been
|
// This is called when the connection with the service has been
|
||||||
|
@ -1209,9 +1211,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
// representation of that from the raw service object.
|
// representation of that from the raw service object.
|
||||||
mService = ITorService.Stub.asInterface(service);
|
mService = ITorService.Stub.asInterface(service);
|
||||||
|
|
||||||
|
|
||||||
imgStatus.setEnabled(true);
|
|
||||||
|
|
||||||
// We want to monitor the service for as long as we are
|
// We want to monitor the service for as long as we are
|
||||||
// connected to it.
|
// connected to it.
|
||||||
try {
|
try {
|
||||||
|
@ -1233,6 +1232,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName className) {
|
public void onServiceDisconnected(ComponentName className) {
|
||||||
|
|
||||||
appendLogTextAndScroll("Tor background service disconnected.");
|
appendLogTextAndScroll("Tor background service disconnected.");
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
public static boolean ENABLE_DEBUG_LOG = false;
|
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;
|
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));
|
sendCallbackLogMessage (getString(R.string.found_existing_tor_process));
|
||||||
|
|
||||||
currentStatus = STATUS_ON;
|
mCurrentStatus = STATUS_ON;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
public int getTorStatus ()
|
public int getTorStatus ()
|
||||||
{
|
{
|
||||||
|
|
||||||
return currentStatus;
|
return mCurrentStatus;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,12 +340,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
initialize();
|
||||||
if (fileTor == null)
|
|
||||||
initBinariesAndDirectories();
|
|
||||||
|
|
||||||
updateSettings ();
|
|
||||||
|
|
||||||
new Thread (new TorStarter(intent)).start();
|
new Thread (new TorStarter(intent)).start();
|
||||||
|
|
||||||
return Service.START_STICKY;
|
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 this is a start on boot launch turn tor on
|
||||||
if (mIntent != null && mIntent.getAction()!=null && mIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
|
if (mIntent != null && mIntent.getAction()!=null && mIntent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
|
||||||
{
|
{
|
||||||
setTorProfile(PROFILE_ON);
|
setTorProfile(STATUS_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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
|
//stop the foreground priority and make sure to remove the persistant notification
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
|
||||||
currentStatus = STATUS_OFF;
|
mCurrentStatus = STATUS_OFF;
|
||||||
|
|
||||||
if (mHasRoot && mEnableTransparentProxy)
|
if (mHasRoot && mEnableTransparentProxy)
|
||||||
disableTransparentProxy();
|
disableTransparentProxy();
|
||||||
|
@ -744,7 +739,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
public void startTor () throws Exception
|
public void startTor () throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
currentStatus = STATUS_CONNECTING;
|
mCurrentStatus = STATUS_CONNECTING;
|
||||||
|
|
||||||
if (fileTor == null)
|
if (fileTor == null)
|
||||||
initBinariesAndDirectories();
|
initBinariesAndDirectories();
|
||||||
|
@ -1127,7 +1122,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
conn.setConf("Log", "debug file " + fileLog2.getCanonicalPath());
|
conn.setConf("Log", "debug file " + fileLog2.getCanonicalPath());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
currentStatus = STATUS_CONNECTING;
|
mCurrentStatus = STATUS_CONNECTING;
|
||||||
|
|
||||||
String confSocks = conn.getInfo("net/listeners/socks");
|
String confSocks = conn.getInfo("net/listeners/socks");
|
||||||
StringTokenizer st = new StringTokenizer(confSocks," ");
|
StringTokenizer st = new StringTokenizer(confSocks," ");
|
||||||
|
@ -1297,7 +1292,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
// get several values
|
// get several values
|
||||||
|
|
||||||
if (currentStatus == STATUS_CONNECTING)
|
if (mCurrentStatus == STATUS_CONNECTING)
|
||||||
{
|
{
|
||||||
//Map vals = conn.getInfo(Arrays.asList(new String[]{
|
//Map vals = conn.getInfo(Arrays.asList(new String[]{
|
||||||
// "status/bootstrap-phase", "status","version"}));
|
// "status/bootstrap-phase", "status","version"}));
|
||||||
|
@ -1317,7 +1312,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.d(TAG, "Unable to get Tor status from control port");
|
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) {
|
public void setTorProfile(int profile) {
|
||||||
|
|
||||||
if (profile == PROFILE_ON)
|
if (profile == STATUS_ON)
|
||||||
{
|
{
|
||||||
|
|
||||||
sendCallbackStatusMessage (getString(R.string.status_starting_up));
|
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);
|
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);
|
showToolbarNotification(getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr);
|
||||||
stopTor();
|
stopTor();
|
||||||
}
|
}
|
||||||
|
@ -1393,7 +1381,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
stopTor();
|
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)
|
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);
|
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"))
|
else if(status.equals("BUILT"))
|
||||||
{
|
{
|
||||||
|
|
||||||
if (currentStatus == STATUS_CONNECTING)
|
if (mCurrentStatus == STATUS_CONNECTING)
|
||||||
currentStatus = STATUS_ON;
|
mCurrentStatus = STATUS_ON;
|
||||||
|
|
||||||
logNotice(sb.toString());
|
logNotice(sb.toString());
|
||||||
|
|
||||||
|
@ -1679,9 +1667,17 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
|
|
||||||
|
logNotice("Background service is bound. Status=" + mCurrentStatus);
|
||||||
|
|
||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRebind(Intent intent) {
|
||||||
|
|
||||||
|
super.onRebind(intent);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean checkAndInitImpl ()
|
public boolean checkAndInitImpl ()
|
||||||
{
|
{
|
||||||
if (fileTor != null)
|
if (fileTor != null)
|
||||||
|
@ -1693,8 +1689,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
logException("error init Tor", e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2026,7 +2021,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
mBinder.saveConfiguration();
|
mBinder.saveConfiguration();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentStatus != STATUS_OFF)
|
if (mCurrentStatus != STATUS_OFF)
|
||||||
{
|
{
|
||||||
if (!mConnectivity)
|
if (!mConnectivity)
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,9 +71,6 @@ public interface TorServiceConstants {
|
||||||
public final static int STATUS_ON = 1;
|
public final static int STATUS_ON = 1;
|
||||||
public final static int STATUS_CONNECTING = 2;
|
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 STATUS_MSG = 1;
|
||||||
public static final int ENABLE_TOR_MSG = 2;
|
public static final int ENABLE_TOR_MSG = 2;
|
||||||
public static final int DISABLE_TOR_MSG = 3;
|
public static final int DISABLE_TOR_MSG = 3;
|
||||||
|
|
Loading…
Reference in New Issue