remove duplicate service start/bind code in onResume()
also disable startup button if service is null
This commit is contained in:
parent
9879b53932
commit
c98509d8e6
|
@ -64,7 +64,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
/* Useful UI bits */
|
/* Useful UI bits */
|
||||||
private TextView lblStatus = null; //the main text display widget
|
private TextView lblStatus = null; //the main text display widget
|
||||||
private ImageProgressView imgStatus = null; //the main touchable image for activating Orbot
|
private ImageProgressView imgStatus = null; //the main touchable image for activating Orbot
|
||||||
// private ProgressDialog progressDialog;
|
|
||||||
private MenuItem mItemOnOff = null;
|
private MenuItem mItemOnOff = null;
|
||||||
private TextView downloadText = null;
|
private TextView downloadText = null;
|
||||||
private TextView uploadText = null;
|
private TextView uploadText = null;
|
||||||
|
@ -104,6 +104,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -125,6 +127,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
imgStatus.setOnTouchListener(this);
|
imgStatus.setOnTouchListener(this);
|
||||||
|
|
||||||
|
imgStatus.setEnabled(false);
|
||||||
|
|
||||||
|
lblStatus.setText("Initializing the application...");
|
||||||
|
|
||||||
downloadText = (TextView)findViewById(R.id.trafficDown);
|
downloadText = (TextView)findViewById(R.id.trafficDown);
|
||||||
uploadText = (TextView)findViewById(R.id.trafficUp);
|
uploadText = (TextView)findViewById(R.id.trafficUp);
|
||||||
mTxtOrbotLog = (TextView)findViewById(R.id.orbotLog);
|
mTxtOrbotLog = (TextView)findViewById(R.id.orbotLog);
|
||||||
|
@ -802,20 +808,12 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
setLocale();
|
setLocale();
|
||||||
|
|
||||||
if (mService == null)
|
if (mService != null)
|
||||||
{
|
|
||||||
startService();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
torStatus = mService.getStatus();
|
torStatus = mService.getStatus();
|
||||||
|
|
||||||
if (torStatus != TorServiceConstants.STATUS_ON)
|
|
||||||
mService.processSettings();
|
|
||||||
|
|
||||||
|
|
||||||
handleIntents();
|
handleIntents();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
|
@ -981,7 +979,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
showAlert(getString(R.string.error),"Tor Service has not started yet. Please wait and try again.",false);
|
showAlert(getString(R.string.error),"Tor Service has not started yet. Please wait and try again.",false);
|
||||||
startService ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1177,15 +1175,22 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
// bindService() a million times
|
// bindService() a million times
|
||||||
|
|
||||||
private final ServiceConnection mConnection = new ServiceConnection() {
|
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
|
||||||
|
|
||||||
public void onServiceConnected(ComponentName className,
|
public void onServiceConnected(ComponentName className,
|
||||||
IBinder service) {
|
IBinder service) {
|
||||||
|
|
||||||
|
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
|
||||||
// established, giving us the service object we can use to
|
// established, giving us the service object we can use to
|
||||||
// interact with the service. We are communicating with our
|
// interact with the service. We are communicating with our
|
||||||
// service through an IDL interface, so get a client-side
|
// service through an IDL interface, so get a client-side
|
||||||
// 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.
|
||||||
|
@ -1210,11 +1215,13 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
public void onServiceDisconnected(ComponentName className) {
|
public void onServiceDisconnected(ComponentName className) {
|
||||||
|
|
||||||
|
appendLogTextAndScroll("Tor background service disconnected.");
|
||||||
|
|
||||||
// This is called when the connection with the service has been
|
// This is called when the connection with the service has been
|
||||||
// unexpectedly disconnected -- that is, its process crashed.
|
// unexpectedly disconnected -- that is, its process crashed.
|
||||||
mKeepUpdating = false;
|
mKeepUpdating = false;
|
||||||
mService = null;
|
mService = null;
|
||||||
Log.d(TAG,"service was disconnected");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue