fixes for status, service, binding and start/stop
This commit is contained in:
parent
fbc1a87c28
commit
70615d669b
|
@ -34,7 +34,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
|||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
|
@ -104,11 +103,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
|
||||
}
|
||||
|
||||
Intent torService;
|
||||
|
||||
private void startService ()
|
||||
{
|
||||
torService = new Intent(this, TorService.class);
|
||||
Intent torService = new Intent(this, TorService.class);
|
||||
startService(torService);
|
||||
|
||||
bindService(torService,
|
||||
|
@ -435,6 +433,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
mConnection = null;
|
||||
mService = null;
|
||||
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, e);
|
||||
}
|
||||
|
@ -645,7 +644,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
|
||||
}
|
||||
|
||||
torStatus = -1;
|
||||
updateStatus ("");
|
||||
|
||||
}
|
||||
|
@ -844,7 +842,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
protected Integer doInBackground(String... params) {
|
||||
|
||||
mTorServiceMsg = params[0];
|
||||
int newTorStatus = -1;
|
||||
int newTorStatus = TorServiceConstants.STATUS_OFF;
|
||||
try
|
||||
{
|
||||
if (mService != null)
|
||||
|
@ -967,6 +965,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
|
||||
mTxtOrbotLog.setText("");
|
||||
|
||||
if (mService != null)
|
||||
{
|
||||
|
||||
// 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
|
||||
|
@ -980,6 +981,11 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
Message msg = mHandler.obtainMessage(TorServiceConstants.ENABLE_TOR_MSG);
|
||||
msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
showAlert(getString(R.string.error),"Tor Service has not started yet. Please wait and try again.",false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1169,7 +1175,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
// representation of that from the raw service object.
|
||||
mService = ITorService.Stub.asInterface(service);
|
||||
|
||||
torStatus = -1;
|
||||
torStatus = TorServiceConstants.STATUS_OFF;
|
||||
|
||||
// We want to monitor the service for as long as we are
|
||||
// connected to it.
|
||||
|
@ -1259,8 +1265,12 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
|||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
if (mConnection != null)
|
||||
if (mConnection != null && mService != null)
|
||||
{
|
||||
unbindService(mConnection);
|
||||
mConnection = null;
|
||||
mService = null;
|
||||
}
|
||||
}
|
||||
|
||||
public class DataCount {
|
||||
|
|
|
@ -154,7 +154,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
|
||||
if (mLastProcessId != -1)
|
||||
{
|
||||
|
||||
sendCallbackLogMessage (getString(R.string.found_existing_tor_process));
|
||||
|
||||
String state = conn.getInfo("dormant");
|
||||
|
@ -293,8 +292,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
{
|
||||
Intent intent = params[0];
|
||||
|
||||
initBinaries();
|
||||
|
||||
if (mNotificationManager == null)
|
||||
{
|
||||
|
||||
IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
|
||||
|
@ -311,10 +310,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
setTorProfile(PROFILE_ON);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
findExistingProc();
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -507,7 +502,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
}
|
||||
}
|
||||
|
||||
private void initBinaries () throws Exception
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
try
|
||||
{
|
||||
initBinariesAndDirectories();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//what error here
|
||||
Log.e(TAG, "Error installing Orbot binaries",e);
|
||||
logNotice("There was an error installing Orbot binaries");
|
||||
}
|
||||
}
|
||||
|
||||
private void initBinariesAndDirectories () throws Exception
|
||||
{
|
||||
|
||||
if (appBinHome == null)
|
||||
|
@ -617,16 +628,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
|
||||
currentStatus = STATUS_CONNECTING;
|
||||
|
||||
try
|
||||
{
|
||||
initBinaries();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logNotice("There was a problem installing the Tor binaries: " + e.getLocalizedMessage());
|
||||
Log.d(TAG,"error installing binaries",e);
|
||||
return;
|
||||
}
|
||||
|
||||
enableBinExec(fileTor);
|
||||
enableBinExec(filePolipo);
|
||||
|
@ -1126,7 +1127,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
|
||||
public void setTorProfile(int profile) {
|
||||
|
||||
if (currentStatus == STATUS_OFF)
|
||||
if (profile == PROFILE_ON)
|
||||
{
|
||||
|
||||
sendCallbackStatusMessage (getString(R.string.status_starting_up));
|
||||
|
@ -1368,7 +1369,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
|
||||
try
|
||||
{
|
||||
initBinaries();
|
||||
findExistingProc ();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -1445,6 +1445,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
{
|
||||
try {
|
||||
|
||||
|
||||
|
||||
processSettingsImpl ();
|
||||
|
||||
|
||||
|
@ -1490,6 +1492,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
Iterator<ConfigEntry> itCe = listCe.iterator();
|
||||
ConfigEntry ce = null;
|
||||
|
||||
|
||||
|
||||
while (itCe.hasNext())
|
||||
{
|
||||
ce = itCe.next();
|
||||
|
@ -1518,6 +1522,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
|||
**/
|
||||
public boolean updateConfiguration (String name, String value, boolean saveToDisk)
|
||||
{
|
||||
|
||||
|
||||
if (configBuffer == null)
|
||||
configBuffer = new ArrayList<String>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue