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.content.res.Configuration;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
@ -104,11 +103,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent torService;
|
|
||||||
|
|
||||||
private void startService ()
|
private void startService ()
|
||||||
{
|
{
|
||||||
torService = new Intent(this, TorService.class);
|
Intent torService = new Intent(this, TorService.class);
|
||||||
startService(torService);
|
startService(torService);
|
||||||
|
|
||||||
bindService(torService,
|
bindService(torService,
|
||||||
|
@ -435,6 +433,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
mConnection = null;
|
mConnection = null;
|
||||||
mService = null;
|
mService = null;
|
||||||
|
|
||||||
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
}
|
}
|
||||||
|
@ -645,7 +644,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
torStatus = -1;
|
|
||||||
updateStatus ("");
|
updateStatus ("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -844,7 +842,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
protected Integer doInBackground(String... params) {
|
protected Integer doInBackground(String... params) {
|
||||||
|
|
||||||
mTorServiceMsg = params[0];
|
mTorServiceMsg = params[0];
|
||||||
int newTorStatus = -1;
|
int newTorStatus = TorServiceConstants.STATUS_OFF;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (mService != null)
|
if (mService != null)
|
||||||
|
@ -967,19 +965,27 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
|
|
||||||
mTxtOrbotLog.setText("");
|
mTxtOrbotLog.setText("");
|
||||||
|
|
||||||
// this is a bit of a strange/old/borrowed code/design i used to change the service state
|
if (mService != null)
|
||||||
// not sure it really makes sense when what we want to say is just "startTor"
|
{
|
||||||
mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
|
|
||||||
|
|
||||||
//here we update the UI which is a bit sloppy and mixed up code wise
|
// this is a bit of a strange/old/borrowed code/design i used to change the service state
|
||||||
//might be best to just call updateStatus() instead of directly manipulating UI in this method - yep makes sense
|
// not sure it really makes sense when what we want to say is just "startTor"
|
||||||
imgStatus.setImageResource(R.drawable.torstarting);
|
mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
|
||||||
lblStatus.setText(getString(R.string.status_starting_up));
|
|
||||||
|
|
||||||
//we send a message here to the progressDialog i believe, but we can clarify that shortly
|
//here we update the UI which is a bit sloppy and mixed up code wise
|
||||||
Message msg = mHandler.obtainMessage(TorServiceConstants.ENABLE_TOR_MSG);
|
//might be best to just call updateStatus() instead of directly manipulating UI in this method - yep makes sense
|
||||||
msg.getData().putString(HANDLER_TOR_MSG, getString(R.string.status_starting_up));
|
imgStatus.setImageResource(R.drawable.torstarting);
|
||||||
mHandler.sendMessage(msg);
|
lblStatus.setText(getString(R.string.status_starting_up));
|
||||||
|
|
||||||
|
//we send a message here to the progressDialog i believe, but we can clarify that shortly
|
||||||
|
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.
|
// representation of that from the raw service object.
|
||||||
mService = ITorService.Stub.asInterface(service);
|
mService = ITorService.Stub.asInterface(service);
|
||||||
|
|
||||||
torStatus = -1;
|
torStatus = TorServiceConstants.STATUS_OFF;
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -1259,8 +1265,12 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
if (mConnection != null)
|
if (mConnection != null && mService != null)
|
||||||
|
{
|
||||||
unbindService(mConnection);
|
unbindService(mConnection);
|
||||||
|
mConnection = null;
|
||||||
|
mService = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DataCount {
|
public class DataCount {
|
||||||
|
|
|
@ -154,7 +154,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
if (mLastProcessId != -1)
|
if (mLastProcessId != -1)
|
||||||
{
|
{
|
||||||
|
|
||||||
sendCallbackLogMessage (getString(R.string.found_existing_tor_process));
|
sendCallbackLogMessage (getString(R.string.found_existing_tor_process));
|
||||||
|
|
||||||
String state = conn.getInfo("dormant");
|
String state = conn.getInfo("dormant");
|
||||||
|
@ -293,29 +292,25 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
{
|
{
|
||||||
Intent intent = params[0];
|
Intent intent = params[0];
|
||||||
|
|
||||||
initBinaries();
|
if (mNotificationManager == null)
|
||||||
|
{
|
||||||
|
|
||||||
|
IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||||
|
registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
|
||||||
|
|
||||||
IntentFilter mNetworkStateFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
|
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
registerReceiver(mNetworkStateReceiver , mNetworkStateFilter);
|
|
||||||
|
|
||||||
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
if (intent != null && intent.getAction()!=null && intent.getAction().equals("onboot"))
|
||||||
|
{
|
||||||
|
|
||||||
if (intent != null && intent.getAction()!=null && intent.getAction().equals("onboot"))
|
boolean startOnBoot = TorServiceUtils.getSharedPrefs(getApplicationContext()).getBoolean("pref_start_boot",false);
|
||||||
{
|
|
||||||
|
|
||||||
boolean startOnBoot = TorServiceUtils.getSharedPrefs(getApplicationContext()).getBoolean("pref_start_boot",false);
|
if (startOnBoot)
|
||||||
|
{
|
||||||
if (startOnBoot)
|
setTorProfile(PROFILE_ON);
|
||||||
{
|
}
|
||||||
setTorProfile(PROFILE_ON);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
findExistingProc();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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)
|
if (appBinHome == null)
|
||||||
|
@ -617,16 +628,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
currentStatus = STATUS_CONNECTING;
|
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(fileTor);
|
||||||
enableBinExec(filePolipo);
|
enableBinExec(filePolipo);
|
||||||
|
@ -1126,7 +1127,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
public void setTorProfile(int profile) {
|
public void setTorProfile(int profile) {
|
||||||
|
|
||||||
if (currentStatus == STATUS_OFF)
|
if (profile == PROFILE_ON)
|
||||||
{
|
{
|
||||||
|
|
||||||
sendCallbackStatusMessage (getString(R.string.status_starting_up));
|
sendCallbackStatusMessage (getString(R.string.status_starting_up));
|
||||||
|
@ -1368,7 +1369,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
initBinaries();
|
|
||||||
findExistingProc ();
|
findExistingProc ();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -1445,6 +1445,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
processSettingsImpl ();
|
processSettingsImpl ();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1490,6 +1492,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
Iterator<ConfigEntry> itCe = listCe.iterator();
|
Iterator<ConfigEntry> itCe = listCe.iterator();
|
||||||
ConfigEntry ce = null;
|
ConfigEntry ce = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (itCe.hasNext())
|
while (itCe.hasNext())
|
||||||
{
|
{
|
||||||
ce = itCe.next();
|
ce = itCe.next();
|
||||||
|
@ -1518,6 +1522,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
|
||||||
**/
|
**/
|
||||||
public boolean updateConfiguration (String name, String value, boolean saveToDisk)
|
public boolean updateConfiguration (String name, String value, boolean saveToDisk)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (configBuffer == null)
|
if (configBuffer == null)
|
||||||
configBuffer = new ArrayList<String>();
|
configBuffer = new ArrayList<String>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue