diff --git a/.classpath b/.classpath
index 807316fa..5e3f5cca 100644
--- a/.classpath
+++ b/.classpath
@@ -1,10 +1,10 @@
-
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4c185e34..4f4f8243 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,10 +1,9 @@
@@ -18,13 +17,12 @@
Orbot
+ Orbot is a free proxy app that empowers other apps to use the internet more securely. Orbot uses Tor to encrypt your Internet traffic and then hides it by bouncing through a series of computers around the world. Tor is free software and an open network that helps you defend against a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security known as traffic analysis.
http://orbot/
http://check.torproject.org
https://check.torproject.org
@@ -86,6 +87,7 @@
If the Android app you are using can support the use of an HTTP or SOCKS proxy, then you can configure it to connect to Orbot and use Tor.\n\n\n The host settings is 127.0.0.1 or \"localhost\". For HTTP, the port setting is 8118. For SOCKS, the proxy is 9050. You should use SOCKS4A or SOCKS5 if possible.\n \n\n\n You can learn more about proxying on Android via the FAQ at: http://tinyurl.com/proxyandroid\n
Orbot is ready!
Hundreds of thousands of people around the world use Tor for a wide variety of reasons.\n\nJournalists and bloggers, human rights defenders, law enforcement officers, soldiers, corporations, citizens of repressive regimes, and just ordinary citizens… and now you are ready to, as well!
+ Please configure Orbot before you can start using it!
You\'ve successfully connected to the Tor network - but this does NOT mean your device is secure. You can use the \'Check\' option from the menu to test your browser. \n\nVisit us at https://guardianproject.info/apps/orbot or send an email to help@guardianproject.info to learn more.
This will open your web browser to https://check.torproject.org in order to see if Orbot is probably configured and you are connected to Tor.
@@ -255,4 +257,23 @@
Network connectivity is good. Waking Tor up...
updating settings in Tor service
+ Tor SOCKS
+ Port that Tor offers its SOCKS proxy on (default: 9050 or 0 to disable)
+ SOCKS Port Config
+
+ Tor TransProxy Port
+ Port that Tor offers its Transparent Proxy on (default: 9040 or 0 to disable)
+ TransProxy Port Config
+
+
+ Tor DNS Port
+ Port that Tor offers its DNS on (default: 5400 or 0 to disable)
+ DNS Port Config
+
+
+ Torrc Custom Config
+ EXPERTS ONLY: enter direct torrc config lines
+ Custom Torrc
+
+
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 095a5d0b..22502b60 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -196,6 +196,36 @@ android:dialogTitle="@string/pref_proxy_password_dialog"
+
+
+
+
+
+
+
+
+
+
0){
if (mTxtOrbotLog.getText().length() > MAX_LOG_LENGTH)
mTxtOrbotLog.setText("");
@@ -373,7 +384,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
else if (item.getItemId() == R.id.menu_wizard)
{
- startWizard();
+ startActivity(new Intent(this, ChooseLocaleWizardActivity.class));
+
}
else if (item.getItemId() == R.id.menu_verify)
{
@@ -416,6 +428,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
//terminology but also making sure there are clear distinctions in control
stopTor();
+ if (mConnection != null)
+ unbindService(mConnection);
+
//perhaps this should be referenced as INTENT_TOR_SERVICE as in startService
stopService(new Intent(this,TorService.class));
@@ -442,6 +457,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
if (aDialog != null)
aDialog.dismiss();
+
}
private void doTorCheck ()
@@ -475,7 +491,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
private void enableHiddenServicePort (int hsPort)
{
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
Editor pEdit = mPrefs.edit();
@@ -515,34 +530,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
setResult(RESULT_OK, nResult);
}
-
- /* (non-Javadoc)
- * @see android.app.Activity#onResume()
- */
- protected void onResume() {
- super.onResume();
-
- bindService();
- updateStatus("");
- }
-
-
-
- @Override
- protected void onNewIntent(Intent intent) {
-
- super.onNewIntent(intent);
- try {
- Log.d("lala", ""+mService.getStatus());
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- updateStatus("");
- handleIntents();
- }
- private void handleIntents ()
+
+ private synchronized void handleIntents ()
{
if (getIntent() == null)
return;
@@ -594,12 +584,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
{
autoStartFromIntent = true;
- if (mService == null)
- {
- bindService();
- }
- else
- {
+ if (mService != null)
+ {
try {
startTor();
} catch (RemoteException e) {
@@ -624,10 +610,23 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
newBridgeValue = URLDecoder.decode(newBridgeValue); //decode the value here
showAlert("Bridges Updated","Restart Orbot to use this bridge: " + newBridgeValue,false);
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
+
+ String bridges = mPrefs.getString(TorConstants.PREF_BRIDGES_LIST, null);
+
Editor pEdit = mPrefs.edit();
- pEdit.putString(TorConstants.PREF_BRIDGES_LIST,newBridgeValue); //set the string to a preference
+ if (bridges != null && bridges.trim().length() > 0)
+ {
+ if (bridges.indexOf('\n')!=-1)
+ bridges += '\n' + newBridgeValue;
+ else
+ bridges += ',' + newBridgeValue;
+ }
+ else
+ bridges = newBridgeValue;
+
+ pEdit.putString(TorConstants.PREF_BRIDGES_LIST,bridges); //set the string to a preference
+ pEdit.putBoolean(TorConstants.PREF_BRIDGES_ENABLED,true);
pEdit.commit();
}
@@ -636,21 +635,16 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
else
{
-
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
- boolean showWizard = mPrefs.getBoolean("show_wizard",true);
+ showWizard = mPrefs.getBoolean("show_wizard",showWizard);
if (showWizard)
{
-
-
Editor pEdit = mPrefs.edit();
pEdit.putBoolean("show_wizard",false);
- pEdit.commit();
-
- startWizard();
-
- //startActivityForResult(new Intent(getApplicationContext(), LotsaText.class), 1);
+ pEdit.commit();
+ showWizard = false;
+
+ startActivity(new Intent(this, ChooseLocaleWizardActivity.class));
}
@@ -661,7 +655,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
-
+ private boolean showWizard = true;
@Override
@@ -669,6 +663,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
super.onConfigurationChanged(newConfig);
doLayout();
+ updateStatus("");
}
/* (non-Javadoc)
@@ -686,7 +681,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
*/
private void openBrowser(final String browserLaunchUrl)
{
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
boolean isOrwebInstalled = appInstalledOrNot("info.guardianproject.browser");
boolean isTransProxy = mPrefs.getBoolean("pref_transparent", false);
@@ -767,20 +761,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
}
- /*
- * Show the help view - a popup dialog
- */
- private void startWizard ()
- {
-
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
- Editor pEdit = mPrefs.edit();
- pEdit.putBoolean("wizardscreen1",true);
- pEdit.commit();
- startActivityForResult(new Intent(getApplicationContext(), ChooseLocaleWizardActivity.class), 1);
- }
-
-
/*
* Load the basic settings application to display torrc
*/
@@ -791,26 +771,32 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
+
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
-
-
- if (requestCode == 1 && mService != null)
+ protected void onResume() {
+ super.onResume();
+
+ if (mService != null)
{
try {
- mService.processSettings();
+
+ if (torStatus != TorServiceConstants.STATUS_ON)
+ mService.processSettings();
+
setLocale();
-
+
+ handleIntents();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
-
- }
-
- AlertDialog aDialog = null;
+
+
+ updateStatus("");
+ }
+
+ AlertDialog aDialog = null;
//general alert dialog for mostly Tor warning messages
//sometimes this can go haywire or crazy with too many error
@@ -852,25 +838,53 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
*/
public void updateStatus (String torServiceMsg)
{
+ new updateStatusAsync().execute(torServiceMsg);
+ }
+
+ private class updateStatusAsync extends AsyncTask {
+
+ String mTorServiceMsg = null;
+
+ @Override
+ protected Integer doInBackground(String... params) {
+
+ mTorServiceMsg = params[0];
+ int newTorStatus = -1;
try
{
- if (torServiceMsg == null || torServiceMsg.length()==0)
- torStatus = -1; //reset Tor status
-
- int newTorStatus = -1;
-
- //if the serivce is bound, query it for the curren status value (int)
- if (mService != null)
- newTorStatus = mService.getStatus();
+ if (mService != null)
+ return new Integer(mService.getStatus());
+ }
+ catch (Exception e)
+ {
+ //error
+ Log.d(TAG,"error in update status",e);
+ }
+
+ return newTorStatus;
+
+ }
+
+ @Override
+ protected void onPostExecute(Integer result) {
+
+ updateUI(result.intValue());
+
+ super.onPostExecute(result);
+ }
+
+ private void updateUI (int newTorStatus)
+ {
+
//now update the layout_main UI based on the status
if (imgStatus != null)
{
if (newTorStatus == TorServiceConstants.STATUS_ON)
{
- if (torStatus != newTorStatus)
- {
+ //if (torStatus != newTorStatus)
+ //{
imgStatus.setImageResource(R.drawable.toron);
// mViewMain.setBackgroundResource(R.drawable.onionrootonly);
@@ -880,13 +894,13 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
if (mItemOnOff != null)
mItemOnOff.setTitle(R.string.menu_stop);
- }
+ //}
- if (torServiceMsg != null && torServiceMsg.length() > 0)
+ if (mTorServiceMsg != null && mTorServiceMsg.length() > 0)
{
- appendLogTextAndScroll(torServiceMsg);
+ appendLogTextAndScroll(mTorServiceMsg);
}
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
+
boolean showFirstTime = mPrefs.getBoolean("connect_first_time",true);
if (showFirstTime)
@@ -921,11 +935,11 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
mItemOnOff.setTitle(R.string.menu_stop);
}
- if (lblStatus != null && torServiceMsg != null)
- if (torServiceMsg.indexOf('%')!=-1)
- lblStatus.setText(torServiceMsg);
+ if (lblStatus != null && mTorServiceMsg != null)
+ if (mTorServiceMsg.indexOf('%')!=-1)
+ lblStatus.setText(mTorServiceMsg);
- appendLogTextAndScroll(torServiceMsg);
+ appendLogTextAndScroll(mTorServiceMsg);
}
@@ -942,14 +956,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
torStatus = newTorStatus;
-
- }
- catch (RemoteException e)
- {
- Log.e(TAG,"remote exception updating status",e);
- }
+
+ }
}
// guess what? this start's Tor! actually no it just requests via the local ITorService to the remote TorService instance
@@ -985,7 +995,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
mService.setProfile(TorServiceConstants.PROFILE_OFF);
Message msg = mHandler.obtainMessage(TorServiceConstants.DISABLE_TOR_MSG);
mHandler.sendMessage(msg);
- //trafficRow.setVisibility(RelativeLayout.GONE);
}
@@ -1004,10 +1013,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
try
{
- if (mService != null && mService.getStatus() == TorServiceConstants.STATUS_OFF)
+ if (torStatus == TorServiceConstants.STATUS_OFF)
{
-
- // createProgressDialog(getString(R.string.status_starting_up));
startTor();
}
@@ -1158,8 +1165,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
public void onServiceConnected(ComponentName className,
IBinder service) {
- mIsBound = true;
-
// This is called when the connection with the service has been
// established, giving us the service object we can use to
// interact with the service. We are communicating with our
@@ -1167,6 +1172,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
// representation of that from the raw service object.
mService = ITorService.Stub.asInterface(service);
+ torStatus = -1;
+
// We want to monitor the service for as long as we are
// connected to it.
try {
@@ -1179,9 +1186,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
}
-
+
handleIntents();
-
+
+ updateStatus("");
} catch (RemoteException e) {
// In this case the service has crashed before we could even
@@ -1202,51 +1210,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
// This is called when the connection with the service has been
// unexpectedly disconnected -- that is, its process crashed.
mService = null;
-
+ Log.d(TAG,"service was disconnected");
}
};
- //this is where we bind!
- private void bindService ()
- {
-
- //since its auto create, we prob don't ever need to call startService
- //also we should again be consistent with using either iTorService.class.getName()
- //or the variable constant
- bindService(mTorService,
- mConnection, Context.BIND_AUTO_CREATE);
-
-
-
- }
-
- //unbind removes the callback, and unbinds the service
- private void unbindService ()
- {
- if (mIsBound) {
- // If we have received the service, and hence registered with
- // it, then now is the time to unregister.
- if (mService != null) {
- try {
- mService.unregisterCallback(mCallback);
-
- } catch (RemoteException e) {
- // There is nothing special we need to do if the service
- // has crashed.
- }
- }
-
- // Detach our existing connection.
- unbindService(mConnection);
- mIsBound = false;
-
-
- //maybe needs this?
- mService = null;
-
-
- }
- }
/*
private void createProgressDialog (String msg)
@@ -1280,7 +1247,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
Configuration config = getResources().getConfiguration();
- SharedPreferences mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
String lang = mPrefs.getString(PREF_DEFAULT_LOCALE, "");
if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang))
@@ -1296,7 +1262,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic
protected void onDestroy() {
super.onDestroy();
- unbindService();
+ //unbindService();
}
public class DataCount {
diff --git a/src/org/torproject/android/OrbotDiagnosticsActivity.java b/src/org/torproject/android/OrbotDiagnosticsActivity.java
index db7ab21d..717d3eec 100644
--- a/src/org/torproject/android/OrbotDiagnosticsActivity.java
+++ b/src/org/torproject/android/OrbotDiagnosticsActivity.java
@@ -57,8 +57,9 @@ public class OrbotDiagnosticsActivity extends Activity {
@Override
protected void onPause() {
- // TODO Auto-generated method stub
super.onPause();
+
+ stopTor();
}
@Override
diff --git a/src/org/torproject/android/TorConstants.java b/src/org/torproject/android/TorConstants.java
index 79ea7e0a..1a9fcdbe 100644
--- a/src/org/torproject/android/TorConstants.java
+++ b/src/org/torproject/android/TorConstants.java
@@ -56,4 +56,6 @@ public interface TorConstants {
public final static int MAX_LOG_LENGTH = 10000;
+ public final static String PREF_SOCKS = "pref_socks";
+
}
diff --git a/src/org/torproject/android/service/TorResourceInstaller.java b/src/org/torproject/android/service/TorResourceInstaller.java
index 2744a55c..3e91ea44 100644
--- a/src/org/torproject/android/service/TorResourceInstaller.java
+++ b/src/org/torproject/android/service/TorResourceInstaller.java
@@ -11,6 +11,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.StringBufferInputStream;
import java.util.ArrayList;
import java.util.concurrent.TimeoutException;
import java.util.zip.ZipEntry;
@@ -115,6 +116,54 @@ public class TorResourceInstaller implements TorServiceConstants {
return true;
}
+ public boolean updateTorConfigCustom (File fileTorRcCustom, String extraLines) throws IOException, FileNotFoundException, TimeoutException
+ {
+
+
+ StringBufferInputStream sbis = new StringBufferInputStream(extraLines + '\n');
+ streamToFile(sbis,fileTorRcCustom,false,false);
+
+ return true;
+ }
+
+ public boolean updatePolipoConfig (File filePolipo, String extraLines) throws IOException, FileNotFoundException, TimeoutException
+ {
+
+ InputStream is;
+
+ Shell shell = Shell.startShell(new ArrayList(),installFolder.getAbsolutePath());
+
+ is = context.getResources().openRawResource(R.raw.torpolipo);
+ shell.add(new SimpleCommand(COMMAND_RM_FORCE + filePolipo.getAbsolutePath())).waitForFinish();
+ streamToFile(is,filePolipo, false, false);
+
+ if (extraLines != null && extraLines.length() > 0)
+ {
+ StringBufferInputStream sbis = new StringBufferInputStream('\n' + extraLines + '\n');
+ streamToFile(sbis,filePolipo,true,false);
+ }
+
+ shell.close();
+
+ return true;
+ }
+
+ public boolean installPolipoConf () throws IOException, FileNotFoundException, TimeoutException
+ {
+
+ InputStream is;
+ File outFile;
+
+ Shell shell = Shell.startShell(new ArrayList(),installFolder.getAbsolutePath());
+
+ is = context.getResources().openRawResource(R.raw.torpolipo);
+ outFile = new File(installFolder, POLIPOCONFIG_ASSET_KEY);
+ shell.add(new SimpleCommand(COMMAND_RM_FORCE + outFile.getAbsolutePath())).waitForFinish();
+ streamToFile(is,outFile, false, false);
+
+ return true;
+ }
+
/*
* Extract the Tor binary from the APK file using ZIP
*/
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index 205be245..c2c86c06 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -8,10 +8,12 @@
package org.torproject.android.service;
+import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
@@ -19,13 +21,13 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.concurrent.TimeoutException;
import net.freehaven.tor.control.ConfigEntry;
import net.freehaven.tor.control.EventHandler;
@@ -55,6 +57,7 @@ import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
+import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@@ -72,7 +75,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private static int currentStatus = STATUS_OFF;
- private final static int CONTROL_SOCKET_TIMEOUT = 3000;
+ private final static int CONTROL_SOCKET_TIMEOUT = 0;
private TorControlConnection conn = null;
private Socket torConnSocket = null;
@@ -81,7 +84,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private static final int NOTIFY_ID = 1;
private static final int TRANSPROXY_NOTIFY_ID = 2;
private static final int ERROR_NOTIFY_ID = 3;
- private static final int HS_NOTIFY_ID = 3;
+ private static final int HS_NOTIFY_ID = 4;
private boolean prefPersistNotifications = true;
String IPADDRESS_PATTERN =
@@ -89,8 +92,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private static final int MAX_START_TRIES = 3;
- private LinkedHashMap configBuffer = null;
- private LinkedHashMap resetBuffer = null;
+ private ArrayList configBuffer = null;
+ private ArrayList resetBuffer = null;
// private String appHome;
private File appBinHome;
@@ -102,6 +105,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private File fileXtables;
private File fileTorRc;
+ private File fileControlPort;
private TorTransProxy mTransProxy;
@@ -130,7 +134,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void logMessage(String msg)
{
- if (ENABLE_DEBUG_LOG)
+ if (ENABLE_DEBUG_LOG)
{
Log.d(TAG,msg);
sendCallbackLogMessage(msg);
@@ -164,8 +168,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sendCallbackLogMessage (getString(R.string.found_existing_tor_process));
- processSettingsImpl();
-
String state = conn.getInfo("dormant");
if (state != null && Integer.parseInt(state) == 0)
currentStatus = STATUS_ON;
@@ -180,7 +182,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
catch (Exception e)
{
- Log.e(TAG,"error finding proc",e);
+ //Log.e(TAG,"error finding proc",e);
return false;
}
}
@@ -201,23 +203,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
- /* (non-Javadoc)
- * @see android.app.Service#onUnbind(android.content.Intent)
- */
- @Override
- public boolean onUnbind(Intent intent) {
-
- if (intent != null)
- logNotice( "onUnbind Called: " + intent.getAction());
-
- return super.onUnbind(intent);
-
-
- }
-
public int getTorStatus ()
{
-
+
return currentStatus;
}
@@ -271,10 +259,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (notifyId == ERROR_NOTIFY_ID)
{
mNotifyBuilder.setTicker(notifyMsg);
- mNotifyBuilder.setOngoing(false);
mNotifyBuilder.setLights(Color.RED, 1000, 1000);
mNotifyBuilder.setSmallIcon(R.drawable.ic_stat_notifyerr);
}
+ else
+ {
+ mNotifyBuilder.setTicker(null); //make sure to clear ticker
+ }
mNotification = mNotifyBuilder.build();
mNotification.bigContentView = expandedView;
@@ -291,24 +282,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
- /* (non-Javadoc)
- * @see android.app.Service#onRebind(android.content.Intent)
- */
- @Override
- public void onRebind(Intent intent) {
- super.onRebind(intent);
-
- try
- {
- sendCallbackLogMessage("Welcome back, Carter!");
- }
- catch (Exception e)
- {
- Log.e(TAG,"unable to init Tor",e);
- throw new RuntimeException("Unable to init Tor");
- }
- }
-
/* (non-Javadoc)
* @see android.app.Service#onStart(android.content.Intent, int)
@@ -317,10 +290,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
try
{
-
new startTorOperation().execute(intent);
- return START_STICKY;
+ return Service.START_NOT_STICKY;
}
catch (Exception e)
@@ -331,7 +303,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
- private class startTorOperation extends AsyncTask {
+ @Override
+ public void onTaskRemoved(Intent rootIntent) {
+ logNotice("Orbot was swiped away... background service will keep running");
+ }
+
+ private class startTorOperation extends AsyncTask {
@Override
protected Boolean doInBackground(Intent... params) {
@@ -382,22 +359,20 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
super.onDestroy();
- if (currentStatus == STATUS_ON)
- {
- this.showToolbarNotification("Tor service stopped unexpectedly", ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
- }
- //Log.d(TAG,"onDestroy called");
+ logNotice("TorService is being destroyed... shutting down!");
- // Unregister all callbacks.
- mCallbacks.kill();
+ stopTor();
+
+ // Unregister all callbacks.
+ mCallbacks.kill();
+
+ unregisterReceiver(mNetworkStateReceiver);
- unregisterReceiver(mNetworkStateReceiver);
}
private void stopTor ()
{
- currentStatus = STATUS_OFF;
-
+
try
{
killTorProcess ();
@@ -432,33 +407,61 @@ public class TorService extends Service implements TorServiceConstants, TorConst
boolean enableHiddenServices = prefs.getBoolean("pref_hs_enable", false);
+ StringBuffer result = new StringBuffer();
+
if (enableHiddenServices)
{
- File file = new File(appCacheHome, "hostname");
-
- if (file.exists())
- {
- try {
- String onionHostname = Utils.readString(new FileInputStream(file)).trim();
- showToolbarNotification(getString(R.string.hidden_service_on) + ' ' + onionHostname, HS_NOTIFY_ID, R.drawable.ic_stat_tor, true);
- Editor pEdit = prefs.edit();
- pEdit.putString("pref_hs_hostname",onionHostname);
- pEdit.commit();
-
- return onionHostname;
-
- } catch (FileNotFoundException e) {
- logException("unable to read onion hostname file",e);
- showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
+ String hsPorts = prefs.getString("pref_hs_ports","");
+
+ StringTokenizer st = new StringTokenizer (hsPorts,",");
+ String hsPortConfig = null;
+
+ while (st.hasMoreTokens())
+ {
+
+ int hsPort = Integer.parseInt(st.nextToken().split(" ")[0]);;
+
+ File fileDir = new File(appCacheHome, "hs" + hsPort);
+ File file = new File(fileDir, "hostname");
+
+
+ if (file.exists())
+ {
+ try {
+ String onionHostname = Utils.readString(new FileInputStream(file)).trim();
+
+ if (result.length() > 0)
+ result.append(",");
+
+ result.append(onionHostname);
+
+
+ } catch (FileNotFoundException e) {
+ logException("unable to read onion hostname file",e);
+ showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
+ return null;
+ }
+ }
+ else
+ {
+ showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
return null;
- }
- }
- else
- {
- showToolbarNotification(getString(R.string.unable_to_read_hidden_service_name), HS_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
-
-
- }
+
+ }
+ }
+
+ if (result.length() > 0)
+ {
+ String onionHostname = result.toString();
+
+ showToolbarNotification(getString(R.string.hidden_service_on) + ' ' + onionHostname, HS_NOTIFY_ID, R.drawable.ic_stat_tor, false);
+ Editor pEdit = prefs.edit();
+ pEdit.putString("pref_hs_hostname",onionHostname);
+ pEdit.commit();
+
+ return onionHostname;
+ }
+
}
return null;
@@ -468,7 +471,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
private void killTorProcess () throws Exception
{
- stopTorMinder();
+ //stopTorMinder();
if (conn != null)
{
@@ -480,6 +483,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice("sending SHUTDOWN signal to Tor process");
conn.shutdownTor("SHUTDOWN");
+ logNotice("closing tor socket");
+ torConnSocket.close();
} catch (Exception e) {
Log.d(TAG,"error shutting down Tor via connection",e);
@@ -488,7 +493,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
conn = null;
}
-
+ killProcess(fileTor);
killProcess(filePolipo);
killProcess(fileObfsclient);
@@ -500,7 +505,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
int procId = -1;
Shell shell = Shell.startShell();
- while ((procId = TorServiceUtils.findProcessId(fileProcBin.getAbsolutePath())) != -1)
+ while ((procId = TorServiceUtils.findProcessId(fileProcBin.getCanonicalPath())) != -1)
{
logNotice("Found fileObfsclient PID=" + procId + " - killing now...");
@@ -549,34 +554,50 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice("checking binary version: " + version);
- if (version == null || (!version.equals(BINARY_TOR_VERSION)))
+ TorResourceInstaller installer = new TorResourceInstaller(this, appBinHome);
+
+ if (version == null || (!version.equals(BINARY_TOR_VERSION)) || (!fileTor.exists()))
{
- stopTor();
-
logNotice("upgrading binaries to latest version: " + BINARY_TOR_VERSION);
- TorResourceInstaller installer = new TorResourceInstaller(this, appBinHome);
boolean success = installer.installResources();
if (success)
prefs.edit().putString(PREF_BINARY_TOR_VERSION_INSTALLED,BINARY_TOR_VERSION).commit();
}
- else if (!fileTorRc.exists())
- {
- stopTor();
- logNotice("upgrading binaries to latest version: " + BINARY_TOR_VERSION);
-
- TorResourceInstaller installer = new TorResourceInstaller(this, appBinHome);
- boolean success = installer.installResources();
+ updateTorConfigFile ();
+
- if (success)
- prefs.edit().putString(PREF_BINARY_TOR_VERSION_INSTALLED,BINARY_TOR_VERSION).commit();
-
- }
-
}
+ private boolean updateTorConfigFile () throws FileNotFoundException, IOException, TimeoutException
+ {
+ SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
+
+ TorResourceInstaller installer = new TorResourceInstaller(this, appBinHome);
+
+ StringBuffer extraLines = new StringBuffer();
+
+ String TORRC_CONTROLPORT_FILE_KEY = "ControlPortWriteToFile";
+ fileControlPort = new File(appBinHome,"control.txt");
+ extraLines.append(TORRC_CONTROLPORT_FILE_KEY).append(' ').append(fileControlPort.getCanonicalPath());
+ extraLines.append('\n');
+ extraLines.append(prefs.getString("pref_custom_torrc", ""));
+
+ logNotice("updating torrc custom configuration...");
+
+ File fileTorRcCustom = new File(fileTorRc.getAbsolutePath() + ".custom");
+ boolean success = installer.updateTorConfigCustom(fileTorRcCustom, extraLines.toString());
+
+ if (success)
+ {
+ logNotice ("success.");
+ }
+
+ return success;
+ }
+
private boolean enableBinExec (File fileBin) throws Exception
{
@@ -584,12 +605,12 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (!fileBin.canExecute())
{
- logNotice("(re)Setting permission on binary: " + fileBin.getAbsolutePath());
- Shell shell = Shell.startShell(new ArrayList(), appBinHome.getAbsolutePath());
+ logNotice("(re)Setting permission on binary: " + fileBin.getCanonicalPath());
+ Shell shell = Shell.startShell(new ArrayList(), appBinHome.getCanonicalPath());
- shell.add(new SimpleCommand("chmod " + CHMOD_EXE_VALUE + ' ' + fileBin.getAbsolutePath())).waitForFinish();
+ shell.add(new SimpleCommand("chmod " + CHMOD_EXE_VALUE + ' ' + fileBin.getCanonicalPath())).waitForFinish();
- File fileTest = new File(fileBin.getAbsolutePath());
+ File fileTest = new File(fileBin.getCanonicalPath());
logNotice(fileTest.getName() + ": POST: Is binary exec? " + fileTest.canExecute());
shell.close();
@@ -646,6 +667,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (mHasRoot && mEnableTransparentProxy)
enableTransparentProxy(mTransProxyAll, mTransProxyTethering);
+ getHiddenServiceHostname ();
+
//checkAddressAndCountry();
}
@@ -663,16 +686,31 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
mTransProxy = new TorTransProxy(this, fileXtables);
-
}
-
- logMessage ("Transparent Proxying: enabling...");
+
+
+ SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
+ String transProxy = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+ String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+
+ if (transProxy.indexOf(':')!=-1) //we just want the port for this
+ transProxy = transProxy.split(":")[1];
+
+ if (dnsPort.indexOf(':')!=-1) //we just want the port for this
+ dnsPort = dnsPort.split(":")[1];
+
+ mTransProxy.setTransProxyPort(Integer.parseInt(transProxy));
+ mTransProxy.setDNSPort(Integer.parseInt(dnsPort));
+
+
//TODO: Find a nice place for the next (commented) line
//TorTransProxy.setDNSProxying();
int code = 0; // Default state is "okay"
+ logMessage ("Transparent Proxying: clearing existing rules...");
+
//clear rules first
mTransProxy.clearTransparentProxyingAll(this);
@@ -737,13 +775,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
SharedPreferences prefs =TorServiceUtils.getSharedPrefs(getApplicationContext());
- String torrcPath = new File(appBinHome, TORRC_ASSET_KEY).getAbsolutePath();
+ String torrcPath = new File(appBinHome, TORRC_ASSET_KEY).getCanonicalPath();
boolean transProxyTethering = prefs.getBoolean("pref_transparent_tethering", false);
if (transProxyTethering)
{
- torrcPath = new File(appBinHome, TORRC_TETHER_KEY).getAbsolutePath();
+ torrcPath = new File(appBinHome, TORRC_TETHER_KEY).getCanonicalPath();
}
int torRetryWaitTimeMS = 1000;
@@ -752,7 +790,14 @@ public class TorService extends Service implements TorServiceConstants, TorConst
//start Tor in the background
Shell shell = Shell.startShell();
- SimpleCommand cmdTor = new SimpleCommand(fileTor.getAbsolutePath() + " DataDirectory " + appCacheHome.getAbsolutePath() + " -f " + torrcPath + " &");
+
+
+ SimpleCommand cmdTor = new SimpleCommand(fileTor.getCanonicalPath()
+ + " DataDirectory " + appCacheHome.getCanonicalPath()
+ + " --defaults-torrc " + torrcPath
+ + " -f " + torrcPath + ".custom"
+ + " &");
+
shell.add(cmdTor);
Thread.sleep(torRetryWaitTimeMS);
@@ -764,6 +809,9 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
logNotice(getString(R.string.couldn_t_start_tor_process_) + "; exit=" + cmdTor.getExitCode() + ": " + cmdTor.getOutput());
sendCallbackStatusMessage(getString(R.string.couldn_t_start_tor_process_));
+
+ logNotice("Tor exit code: " + cmdTor.getExitCode());
+
throw new Exception ("Unable to start Tor");
}
@@ -773,11 +821,13 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice("Tor started; process id=" + mLastProcessId);
processSettingsImpl();
+
+ // startTorMinder ();
+
}
shell.close();
- startTorMinder ();
}
private void runPolipoShellCmd () throws Exception
@@ -785,7 +835,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
logNotice( "Starting polipo process");
- int polipoProcId = TorServiceUtils.findProcessId(filePolipo.getAbsolutePath());
+ int polipoProcId = TorServiceUtils.findProcessId(filePolipo.getCanonicalPath());
StringBuilder log = null;
@@ -797,15 +847,15 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
log = new StringBuilder();
- String polipoConfigPath = new File(appBinHome, POLIPOCONFIG_ASSET_KEY).getAbsolutePath();
- SimpleCommand cmdPolipo = new SimpleCommand(filePolipo.getAbsolutePath() + " -c " + polipoConfigPath + " &");
+ String polipoConfigPath = new File(appBinHome, POLIPOCONFIG_ASSET_KEY).getCanonicalPath();
+ SimpleCommand cmdPolipo = new SimpleCommand(filePolipo.getCanonicalPath() + " -c " + polipoConfigPath + " &");
shell.add(cmdPolipo);
//wait one second to make sure it has started up
Thread.sleep(1000);
- while ((polipoProcId = TorServiceUtils.findProcessId(filePolipo.getAbsolutePath())) == -1 && attempts < MAX_START_TRIES)
+ while ((polipoProcId = TorServiceUtils.findProcessId(filePolipo.getCanonicalPath())) == -1 && attempts < MAX_START_TRIES)
{
logNotice("Couldn't find Polipo process... retrying...\n" + log);
Thread.sleep(3000);
@@ -840,61 +890,90 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (conn != null)
{
+ File fileCookie = new File(appCacheHome, TOR_CONTROL_COOKIE);
+
+ if (fileCookie.exists())
+ {
+ byte[] cookie = new byte[(int)fileCookie.length()];
+ DataInputStream fis = new DataInputStream(new FileInputStream(fileCookie));
+ fis.read(cookie);
+ fis.close();
+ conn.authenticate(cookie);
+
+ }
+
String torProcId = conn.getInfo("process/pid");
return Integer.parseInt(torProcId);
}
else
{
-
while (conn == null && i++ < maxAttempts)
{
try
{
- logNotice( "Connecting to control port: " + TOR_CONTROL_PORT);
- torConnSocket = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
- torConnSocket.setSoTimeout(CONTROL_SOCKET_TIMEOUT);
+ int controlPort = getControlPort();
- conn = TorControlConnection.getConnection(torConnSocket);
-
- logNotice( "SUCCESS connected to Tor control port");
-
- File fileCookie = new File(appCacheHome, TOR_CONTROL_COOKIE);
-
- if (fileCookie.exists())
- {
- byte[] cookie = new byte[(int)fileCookie.length()];
- DataInputStream fis = new DataInputStream(new FileInputStream(fileCookie));
- fis.read(cookie);
- fis.close();
- conn.authenticate(cookie);
-
- logNotice( "SUCCESS - authenticated to control port");
+ if (controlPort == -1 && i == maxAttempts)
+ controlPort = DEFAULT_CONTROL_PORT;
+
+ if (controlPort != -1)
+ {
+ logNotice( "Connecting to control port: " + controlPort);
+
+ torConnSocket = new Socket(IP_LOCALHOST, controlPort);
+ torConnSocket.setSoTimeout(CONTROL_SOCKET_TIMEOUT);
+
+ conn = TorControlConnection.getConnection(torConnSocket);
- sendCallbackStatusMessage(getString(R.string.tor_process_starting) + ' ' + getString(R.string.tor_process_complete));
-
- addEventHandler();
-
- String torProcId = conn.getInfo("process/pid");
+ if (ENABLE_DEBUG_LOG)
+ {
+ conn.setDebugging(System.out);
+
+ }
- return Integer.parseInt(torProcId);
+ logNotice( "SUCCESS connected to Tor control port");
+
+ File fileCookie = new File(appCacheHome, TOR_CONTROL_COOKIE);
+
+ if (fileCookie.exists())
+ {
+ byte[] cookie = new byte[(int)fileCookie.length()];
+ DataInputStream fis = new DataInputStream(new FileInputStream(fileCookie));
+ fis.read(cookie);
+ fis.close();
+ conn.authenticate(cookie);
+
+ logNotice( "SUCCESS - authenticated to control port");
+
+ sendCallbackStatusMessage(getString(R.string.tor_process_starting) + ' ' + getString(R.string.tor_process_complete));
+
+ addEventHandler();
+
+ String torProcId = conn.getInfo("process/pid");
+
+ return Integer.parseInt(torProcId);
+
+ }
+ else
+ {
+ logNotice ("Tor authentication cookie does not exist yet");
+ conn = null;
+
+ }
+ }
- }
- else
- {
- logNotice ("Tor authentication cookie does not exist yet; trying again...");
- }
}
catch (Exception ce)
{
conn = null;
- logNotice( "Error connecting to Tor local control port: " + ce.getLocalizedMessage());
-
- // Log.d(TAG,"Attempt: Error connecting to control port: " + ce.getLocalizedMessage(),ce);
+ logException( "Error connecting to Tor local control port",ce);
}
- sendCallbackStatusMessage(getString(R.string.tor_process_waiting));
- Thread.sleep(3000);
+ try {
+ logNotice("waiting...");
+ Thread.sleep(5000); }
+ catch (Exception e){}
}
}
@@ -903,6 +982,47 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
+ private int getControlPort ()
+ {
+ int result = -1;
+
+ try
+ {
+ if (fileControlPort.exists())
+ {
+ logNotice("Reading control port config file: " + fileControlPort.getCanonicalPath());
+ BufferedReader bufferedReader = new BufferedReader(new FileReader(fileControlPort));
+ String line = bufferedReader.readLine();
+
+ //PORT=127.0.0.1:45051
+
+ if (line != null)
+ {
+ String[] lineParts = line.split(":");
+ result = Integer.parseInt(lineParts[1]);
+ }
+
+ bufferedReader.close();
+ }
+ else
+ {
+ logNotice("Control Port config file does not yet exist (waiting for tor): " + fileControlPort.getCanonicalPath());
+ }
+
+
+ }
+ catch (FileNotFoundException e)
+ {
+ logNotice("unable to get control port; file not found");
+ }
+ catch (IOException e)
+ {
+ logNotice("unable to read control port config file");
+ }
+
+ return result;
+ }
+
private void checkAddressAndCountry () throws IOException
{
@@ -987,7 +1107,30 @@ public class TorService extends Service implements TorServiceConstants, TorConst
* Returns the port number that the SOCKS proxy is running on
*/
public int getSOCKSPort() throws RemoteException {
- return TorServiceConstants.PORT_SOCKS;
+
+ int socksPort = -1;
+
+ SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
+
+ String socksConfig = prefs.getString(TorConstants.PREF_SOCKS, TorServiceConstants.PORT_SOCKS_DEFAULT);
+
+ try
+ {
+
+ if (!socksConfig.equalsIgnoreCase("auto"))
+ if (socksConfig.contains(":"))
+ socksPort = Integer.parseInt(socksConfig.split(":")[1]);
+ else
+ socksPort = Integer.parseInt(socksConfig);
+
+ }
+ catch (Exception e)
+ {
+ logException ("unable to parse socks config: " + socksConfig,e);
+
+ }
+
+ return socksPort;
}
@@ -999,58 +1142,38 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
public void setTorProfile(int profile) {
- // logNotice("Tor profile set to " + profile);
-
- if (profile == PROFILE_ON)
- {
-
- new StartStopTorOperation().execute(true);
- }
- else if (profile == PROFILE_OFF)
- {
+
+ if (currentStatus == STATUS_OFF)
+ {
+
+ sendCallbackStatusMessage (getString(R.string.status_starting_up));
- new StartStopTorOperation().execute(false);
-
- }
+ try
+ {
+ initTor();
+
+ currentStatus = STATUS_CONNECTING;
+
+ }
+ catch (Exception e)
+ {
+
+ stopTor();
+ logException("Unable to start Tor: " + e.toString(),e);
+ currentStatus = STATUS_OFF;
+ showToolbarNotification(getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
+ }
+ }
+ else
+ {
+ sendCallbackStatusMessage (getString(R.string.status_shutting_down));
+
+ stopTor();
+
+ currentStatus = STATUS_OFF;
+ }
}
- private class StartStopTorOperation extends AsyncTask {
- @Override
- protected Boolean doInBackground(Boolean... params) {
-
- if (params[0].booleanValue() == true)
- {
-
- currentStatus = STATUS_CONNECTING;
- sendCallbackStatusMessage (getString(R.string.status_starting_up));
-
- try
- {
- initTor();
- }
- catch (Exception e)
- {
-
- logException("Unable to start Tor: " + e.toString(),e);
- currentStatus = STATUS_OFF;
- showToolbarNotification(getString(R.string.unable_to_start_tor) + ": " + e.getMessage(), ERROR_NOTIFY_ID, R.drawable.ic_stat_notifyerr, false);
- }
- }
- else
- {
- currentStatus = STATUS_OFF;
- sendCallbackStatusMessage (getString(R.string.status_shutting_down));
-
- stopTor();
-
- }
-
-
- return true;
- }
-
- }
-
public void message(String severity, String msg) {
@@ -1067,6 +1190,48 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
+
+
+
+ private Handler mHandlerStatusChecker = null;
+
+ private void enableStatusChecker ()
+ {
+
+ if (mHandlerStatusChecker != null)
+ mHandlerStatusChecker = new Handler();
+
+ mHandlerStatusChecker.postDelayed(new Runnable ()
+ {
+ public void run ()
+ {
+ if (conn != null)
+ {
+ try
+ {
+ String state = conn.getInfo("dormant");
+ if (state != null && Integer.parseInt(state) == 0)
+ {
+ currentStatus = STATUS_ON;
+
+ }
+ else
+ {
+ currentStatus = STATUS_CONNECTING;
+ showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off,prefPersistNotifications);
+
+ }
+ }
+ catch (Exception e){}
+
+
+ mHandlerStatusChecker.postDelayed(this,1000);
+ }
+
+
+ }
+ },1000);
+ }
public void newDescriptors(List orList) {
@@ -1141,9 +1306,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
sendCallbackStatusMessage(written, read, mTotalTrafficWritten, mTotalTrafficRead);
- // if(++notificationCounter%10==0)
- // startService(new Intent(ITorService.class.getName()));
-
}
lastWritten = written;
@@ -1335,13 +1497,34 @@ public class TorService extends Service implements TorServiceConstants, TorConst
public void setProfile (int profile)
{
- setTorProfile(profile);
+
+ new AsyncTask() {
+ @Override
+ protected Boolean doInBackground(Integer... params) {
+
+ try
+ {
+
+ setTorProfile(params[0].intValue());
+
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG,"error onBind",e);
+ }
+
+
+ return true;
+ }
+
+ }.execute(profile);
}
+
public void processSettings ()
{
-
+ /*
Thread thread = new Thread()
{
@@ -1359,6 +1542,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
};
thread.start();
+ */
}
@@ -1415,25 +1599,31 @@ public class TorService extends Service implements TorServiceConstants, TorConst
return null;
}
+ private final static String RESET_STRING = "=\"\"";
/**
* Set configuration
**/
public boolean updateConfiguration (String name, String value, boolean saveToDisk)
{
if (configBuffer == null)
- configBuffer = new LinkedHashMap();
+ configBuffer = new ArrayList();
if (resetBuffer == null)
- resetBuffer = new LinkedHashMap();
+ resetBuffer = new ArrayList();
if (value == null || value.length() == 0)
{
- resetBuffer.put(name,"");
+ resetBuffer.add(name + RESET_STRING);
}
else
{
- configBuffer.put(name,value);
+ StringBuffer sbConf = new StringBuffer();
+ sbConf.append(name);
+ sbConf.append(' ');
+ sbConf.append(value);
+
+ configBuffer.add(sbConf.toString());
}
return false;
@@ -1470,24 +1660,31 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (resetBuffer != null && resetBuffer.size() > 0)
{
- conn.resetConf(resetBuffer.keySet());
+ for (String value : configBuffer)
+ {
+
+ logMessage("removing torrc conf: " + value);
+
+
+ }
+
+ conn.resetConf(resetBuffer);
resetBuffer = null;
}
if (configBuffer != null && configBuffer.size() > 0)
{
- for (String key : configBuffer.keySet())
- {
-
- String value = configBuffer.get(key);
-
- if (TorService.ENABLE_DEBUG_LOG)
- logMessage("Setting conf: " + key + "=" + value);
-
- conn.setConf(key, value);
-
- }
+ for (String value : configBuffer)
+ {
+
+ logMessage("Setting torrc conf: " + value);
+
+
+ }
+
+ conn.setConf(configBuffer);
+
configBuffer = null;
}
@@ -1678,7 +1875,15 @@ public class TorService extends Service implements TorServiceConstants, TorConst
SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext());
- enableSocks ("127.0.0.1",9050,false);
+ String socksConfig = prefs.getString(TorConstants.PREF_SOCKS, TorServiceConstants.PORT_SOCKS_DEFAULT);
+
+ enableSocks (socksConfig,false);
+
+ String transPort = prefs.getString("pref_transport", TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT+"");
+ String dnsPort = prefs.getString("pref_dnsport", TorServiceConstants.TOR_DNS_PORT_DEFAULT+"");
+
+ enableTransProxyAndDNSPorts(transPort, dnsPort);
+
boolean useBridges = prefs.getBoolean(TorConstants.PREF_BRIDGES_ENABLED, false);
@@ -1739,8 +1944,8 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
- mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getAbsolutePath(), false);
- mBinder.updateConfiguration("GeoIPv6File", fileGeoIP6.getAbsolutePath(), false);
+ mBinder.updateConfiguration("GeoIPFile", fileGeoIP.getCanonicalPath(), false);
+ mBinder.updateConfiguration("GeoIPv6File", fileGeoIP6.getCanonicalPath(), false);
}
catch (Exception e)
@@ -1798,7 +2003,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (obfsBridges)
{
- String bridgeConfig = "obfs2,obfs3,scramblesuit exec " + fileObfsclient.getAbsolutePath();
+ String bridgeConfig = "obfs2,obfs3,scramblesuit exec " + fileObfsclient.getCanonicalPath();
logMessage ("Using OBFUSCATED bridges: " + bridgeConfig);
@@ -1880,7 +2085,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
logNotice("hidden services are enabled");
- mBinder.updateConfiguration("HiddenServiceDir",appCacheHome.getAbsolutePath(), false);
//mBinder.updateConfiguration("RendPostPeriod", "600 seconds", false); //possible feature to investigate
String hsPorts = prefs.getString("pref_hs_ports","");
@@ -1893,18 +2097,23 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
try
{
- hsPortConfig = st.nextToken();
+ hsPortConfig = st.nextToken().trim();
if (hsPortConfig.indexOf(":")==-1) //setup the port to localhost if not specifed
{
- hsPortConfig = hsPortConfig + " 0.0.0.0:" + hsPortConfig;
+ hsPortConfig = hsPortConfig + " 127.0.0.1:" + hsPortConfig;
}
+ hsPort = Integer.parseInt(hsPortConfig.split(" ")[0]);
+
+ String hsDirPath = new File(appCacheHome,"hs" + hsPort).getCanonicalPath();
+
logMessage("Adding hidden service on port: " + hsPortConfig);
+
+ mBinder.updateConfiguration("HiddenServiceDir",hsDirPath, false);
mBinder.updateConfiguration("HiddenServicePort",hsPortConfig, false);
- hsPort = Integer.parseInt(hsPortConfig.split(" ")[0]);
} catch (NumberFormatException e) {
Log.e(this.TAG,"error parsing hsport",e);
@@ -1926,13 +2135,27 @@ public class TorService extends Service implements TorServiceConstants, TorConst
return true;
}
- private void enableSocks (String ip, int port, boolean safeSocks) throws RemoteException
- {
- mBinder.updateConfiguration("SOCKSPort", ip + ":" + port + "", false);
+ private void enableSocks (String socks, boolean safeSocks) throws RemoteException
+ {
+ mBinder.updateConfiguration("SOCKSPort", socks, false);
mBinder.updateConfiguration("SafeSocks", safeSocks ? "1" : "0", false);
mBinder.updateConfiguration("TestSocks", "1", false);
mBinder.updateConfiguration("WarnUnsafeSocks", "1", false);
-
+ mBinder.saveConfiguration();
+
+ }
+
+ private void enableTransProxyAndDNSPorts (String transPort, String dnsPort) throws RemoteException
+ {
+ logMessage ("Transparent Proxying: enabling port...");
+
+ mBinder.updateConfiguration("TransPort",transPort,false);
+ mBinder.updateConfiguration("DNSPort",dnsPort,false);
+ mBinder.updateConfiguration("VirtualAddrNetwork","10.192.0.0/10",false);
+ mBinder.updateConfiguration("AutomapHostsOnResolve","1",false);
+ mBinder.saveConfiguration();
+
+
}
private void blockPlaintextPorts (String portList) throws RemoteException
@@ -1951,7 +2174,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
bw.println("nameserver 8.8.4.4");
bw.close();
- return file.getAbsolutePath();
+ return file.getCanonicalPath();
}
@SuppressLint("NewApi")
@@ -2040,6 +2263,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
}
+ /**
private Timer mTorMinder;
private void startTorMinder ()
@@ -2057,7 +2281,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
{
try {
- int foundPrcId = TorServiceUtils.findProcessId(fileTor.getAbsolutePath());
+ int foundPrcId = TorServiceUtils.findProcessId(fileTor.getCanonicalPath());
if (foundPrcId != -1)
{
@@ -2075,6 +2299,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst
} catch (Exception e1) {
logException("Error in Tor heartbeat checker",e1);
+
}
}
@@ -2088,6 +2313,6 @@ public class TorService extends Service implements TorServiceConstants, TorConst
if (mTorMinder != null)
mTorMinder.cancel();
}
-
+ **/
}
diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java
index c964289f..8c537793 100644
--- a/src/org/torproject/android/service/TorServiceConstants.java
+++ b/src/org/torproject/android/service/TorServiceConstants.java
@@ -35,7 +35,7 @@ public interface TorServiceConstants {
public final static String SHELL_CMD_CHMOD = "chmod";
public final static String SHELL_CMD_KILL = "kill -9";
public final static String SHELL_CMD_RM = "rm";
- public final static String SHELL_CMD_PS = "ps";
+ public final static String SHELL_CMD_PS = "toolbox ps";
//public final static String SHELL_CMD_PIDOF = "pidof";
public final static String SHELL_CMD_LINK = "ln -s";
public final static String SHELL_CMD_CP = "cp";
@@ -49,15 +49,14 @@ public interface TorServiceConstants {
public final static int PORT_HTTP = 8118; //just like Privoxy!
//Socks port client connects to, server is the Tor binary
- public final static int PORT_SOCKS = 9050;
+ public final static String PORT_SOCKS_DEFAULT = "9050";
//what is says!
public final static String IP_LOCALHOST = "127.0.0.1";
- public final static int TOR_CONTROL_PORT = 9051;
public final static int UPDATE_TIMEOUT = 1000;
- public final static int TOR_TRANSPROXY_PORT = 9040;
+ public final static int TOR_TRANSPROXY_PORT_DEFAULT = 9040;
public final static int STANDARD_DNS_PORT = 53;
- public final static int TOR_DNS_PORT = 5400;
+ public final static int TOR_DNS_PORT_DEFAULT = 5400;
//path to check Tor against
public final static String URL_TOR_CHECK = "https://check.torproject.org";
@@ -77,7 +76,7 @@ public interface TorServiceConstants {
public static final int DISABLE_TOR_MSG = 3;
public static final int LOG_MSG = 4;
- public static final String BINARY_TOR_VERSION = "0.2.5.4-alpha-openssl1.0.1g";
+ public static final String BINARY_TOR_VERSION = "0.2.4.22-openssl1.0.1h.u2";
public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED";
//obfsproxy
@@ -89,5 +88,7 @@ public interface TorServiceConstants {
//name of the iptables binary
public final static String IPTABLES_ASSET_KEY = "xtables";
+ public final static int DEFAULT_CONTROL_PORT = 9051;
+
}
diff --git a/src/org/torproject/android/service/TorServiceUtils.java b/src/org/torproject/android/service/TorServiceUtils.java
index 70c57466..af83709f 100644
--- a/src/org/torproject/android/service/TorServiceUtils.java
+++ b/src/org/torproject/android/service/TorServiceUtils.java
@@ -78,16 +78,19 @@ public class TorServiceUtils implements TorServiceConstants {
Process procPs = null;
- //String processKey = new File(command).getName();
+ String processKey = new File(command).getName();
- procPs = r.exec(SHELL_CMD_PS); // this is the android ps command
+ procPs = r.exec(SHELL_CMD_PS + ' ' + processKey); // this is the android ps command
BufferedReader reader = new BufferedReader(new InputStreamReader(procPs.getInputStream()));
- String line = reader.readLine(); //read first line "headers" USER PID PPID etc
+ String line = null;
while ((line = reader.readLine())!=null)
{
- if (line.contains(command))
+ if (line.contains("PID"))
+ continue;
+
+ if (line.contains(processKey))
{
String[] lineParts = line.split("\\s+");
@@ -109,7 +112,6 @@ public class TorServiceUtils implements TorServiceConstants {
}
- @TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static SharedPreferences getSharedPrefs (Context context)
{
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB)
diff --git a/src/org/torproject/android/service/TorTransProxy.java b/src/org/torproject/android/service/TorTransProxy.java
index 57226124..400b1dbd 100644
--- a/src/org/torproject/android/service/TorTransProxy.java
+++ b/src/org/torproject/android/service/TorTransProxy.java
@@ -23,10 +23,24 @@ public class TorTransProxy implements TorServiceConstants {
private final static String ALLOW_LOCAL = " ! -o lo ! -d 127.0.0.1 ! -s 127.0.0.1 ";
+ private int mTransProxyPort = TorServiceConstants.TOR_TRANSPROXY_PORT_DEFAULT;
+ private int mDNSPort = TorServiceConstants.TOR_DNS_PORT_DEFAULT;
+
public TorTransProxy (TorService torService, File fileXTables)
{
mTorService = torService;
mFileXtables = fileXTables;
+
+ }
+
+ public void setTransProxyPort (int transProxyPort)
+ {
+ mTransProxyPort = transProxyPort;
+ }
+
+ public void setDNSPort (int dnsPort)
+ {
+ mDNSPort = dnsPort;
}
public String getIpTablesPath (Context context)
@@ -383,7 +397,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(tApp.getUid());
script.append(" -m tcp --syn");
script.append(" -j REDIRECT --to-ports ");
- script.append(TOR_TRANSPROXY_PORT);
+ script.append(mTransProxyPort);
executeCommand (shell, script.toString());
script = new StringBuilder();
@@ -398,7 +412,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -m udp --dport ");
script.append(STANDARD_DNS_PORT);
script.append(" -j REDIRECT --to-ports ");
- script.append(TOR_DNS_PORT);
+ script.append(mDNSPort);
executeCommand (shell, script.toString());
script = new StringBuilder();
@@ -454,7 +468,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -t nat -A PREROUTING -i ");
script.append(hwinterfaces[i]);
script.append(" -p udp --dport 53 -j REDIRECT --to-ports ");
- script.append(TOR_DNS_PORT);
+ script.append(mDNSPort);
executeCommand (shell, script.toString());
script = new StringBuilder();
@@ -465,7 +479,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -t nat -A PREROUTING -i ");
script.append(hwinterfaces[i]);
script.append(" -p tcp -j REDIRECT --to-ports ");
- script.append(TOR_TRANSPROXY_PORT);
+ script.append(mTransProxyPort);
lastExit = executeCommand (shell, script.toString());
script = new StringBuilder();
@@ -642,7 +656,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(torUid);
script.append(" -m tcp --syn");
script.append(" -j REDIRECT --to-ports ");
- script.append(TOR_TRANSPROXY_PORT);
+ script.append(mTransProxyPort);
executeCommand (shell, script.toString());
script = new StringBuilder();
@@ -658,7 +672,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -m udp --dport ");
script.append(STANDARD_DNS_PORT);
script.append(" -j REDIRECT --to-ports ");
- script.append(TOR_DNS_PORT);
+ script.append(mDNSPort);
executeCommand (shell, script.toString());
script = new StringBuilder();
@@ -699,7 +713,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName);
script.append(" -p tcp");
script.append(" -m tcp");
- script.append(" --dport ").append(TOR_TRANSPROXY_PORT);
+ script.append(" --dport ").append(mTransProxyPort);
script.append(" -j ACCEPT");
executeCommand (shell, script.toString());
@@ -711,7 +725,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName);
script.append(" -p tcp");
script.append(" -m tcp");
- script.append(" --dport ").append(PORT_SOCKS);
+ script.append(" --dport ").append(PORT_SOCKS_DEFAULT);
script.append(" -j ACCEPT");
executeCommand (shell, script.toString());
@@ -735,7 +749,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName);
script.append(" -p udp");
script.append(" -m udp");
- script.append(" --dport ").append(TOR_DNS_PORT);
+ script.append(" --dport ").append(mDNSPort);
script.append(" -j ACCEPT");
executeCommand (shell, script.toString());
@@ -747,7 +761,7 @@ public class TorTransProxy implements TorServiceConstants {
script.append(" -A ").append(srcChainName);
script.append(" -p udp");
script.append(" -m udp");
- script.append(" --dport ").append(TOR_DNS_PORT);
+ script.append(" --dport ").append(mDNSPort);
script.append(" -j ACCEPT");
executeCommand (shell, script.toString());
diff --git a/src/org/torproject/android/wizard/ChooseLocaleWizardActivity.java b/src/org/torproject/android/wizard/ChooseLocaleWizardActivity.java
index 6385227a..1a620c19 100644
--- a/src/org/torproject/android/wizard/ChooseLocaleWizardActivity.java
+++ b/src/org/torproject/android/wizard/ChooseLocaleWizardActivity.java
@@ -7,19 +7,20 @@ import org.torproject.android.TorConstants;
import org.torproject.android.service.TorServiceUtils;
import android.app.Activity;
-import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.os.Bundle;
-import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
+import android.widget.Toast;
public class ChooseLocaleWizardActivity extends Activity implements TorConstants {
@@ -38,55 +39,42 @@ public class ChooseLocaleWizardActivity extends Activity implements TorConstants
super.onStart();
setContentView(R.layout.layout_wizard_locale);
- stepSix();
-
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
-
- }
+ listLocales = (ListView)findViewById(R.id.wizard_locale_list);
+ Button next = ((Button)findViewById(R.id.btnWizard2));
+ // next.setEnabled(false);
+
+ String[] strLangs = getResources().getStringArray(R.array.languages);
+ strLangs[0] = Locale.getDefault().getDisplayName();
+ ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, strLangs);
+ listLocales.setAdapter(adapter);
+
+ listLocales.setSelection(0);
+
+
+ listLocales.setOnItemClickListener(new OnItemClickListener() {
+
-
- private void stepSix(){
-
- listLocales = (ListView)findViewById(R.id.wizard_locale_list);
- Button next = ((Button)findViewById(R.id.btnWizard2));
- // next.setEnabled(false);
-
- String[] strLangs = getResources().getStringArray(R.array.languages);
- strLangs[0] = Locale.getDefault().getDisplayName();
- ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, strLangs);
- listLocales.setAdapter(adapter);
-
- listLocales.setSelection(0);
-
-
- listLocales.setOnItemClickListener(new OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> arg0, View arg1,
+ int arg2, long arg3) {
-
- @Override
- public void onItemClick(AdapterView> arg0, View arg1,
- int arg2, long arg3) {
-
- setLocalePref(arg2);
- startActivityForResult(new Intent(ChooseLocaleWizardActivity.this, LotsaText.class), 1);
-
- }
- });
-
- next.setOnClickListener(new View.OnClickListener() {
+ setLocalePref(arg2);
+ finish();
+ startActivity(new Intent(ChooseLocaleWizardActivity.this, LotsaText.class));
- public void onClick(View v) {
-
-
- startActivityForResult(new Intent(ChooseLocaleWizardActivity.this, LotsaText.class), 1);
+ }
+ });
+
+ next.setOnClickListener(new View.OnClickListener() {
+
+ public void onClick(View v) {
+ setLocalePref(0);
+ finish();
+ startActivity(new Intent(ChooseLocaleWizardActivity.this, LotsaText.class));
- }
- });
+ }
+ });
@@ -135,4 +123,14 @@ public class ChooseLocaleWizardActivity extends Activity implements TorConstants
super.onSaveInstanceState(outState);
}
+
+ //Code to override the back button!
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if(keyCode == KeyEvent.KEYCODE_BACK){
+ Toast.makeText(getApplicationContext(), R.string.wizard_exit_at_first_screen_toast, Toast.LENGTH_SHORT).show();
+ return true;
+ }
+ return false;
+ }
}
\ No newline at end of file
diff --git a/src/org/torproject/android/wizard/ConfigureTransProxy.java b/src/org/torproject/android/wizard/ConfigureTransProxy.java
index abbaee6a..ca7f3aca 100644
--- a/src/org/torproject/android/wizard/ConfigureTransProxy.java
+++ b/src/org/torproject/android/wizard/ConfigureTransProxy.java
@@ -20,6 +20,8 @@ import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -62,18 +64,6 @@ public class ConfigureTransProxy extends Activity implements TorConstants {
}
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch(resultCode)
- {
- case RESULT_CLOSE_ALL:
- setResult(RESULT_CLOSE_ALL);
- finish();
- }
- super.onActivityResult(requestCode, resultCode, data);
- }
-
private void setupUI ()
{
@@ -119,16 +109,16 @@ public class ConfigureTransProxy extends Activity implements TorConstants {
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
-
- startActivityForResult(new Intent(ConfigureTransProxy.this, Permissions.class), 1);
+ finish();
+ startActivity(new Intent(ConfigureTransProxy.this, Permissions.class));
}
});
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
-
- startActivityForResult(new Intent(ConfigureTransProxy.this, TipsAndTricks.class), 1);
+ finish();
+ startActivity(new Intent(ConfigureTransProxy.this, TipsAndTricks.class));
}
});
@@ -143,10 +133,7 @@ public class ConfigureTransProxy extends Activity implements TorConstants {
public void onClick(View v) {
- context.startActivity(new Intent(context, AppManager.class));
-
-
-
+ startActivity(new Intent(ConfigureTransProxy.this, AppManager.class));
}
});
@@ -239,4 +226,16 @@ public class ConfigureTransProxy extends Activity implements TorConstants {
super.onSaveInstanceState(outState);
}
+
+ //Code to override the back button!
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if(keyCode == KeyEvent.KEYCODE_BACK){
+ finish();
+ startActivityForResult(new Intent(getBaseContext(), Permissions.class), 1);
+ return true;
+ }
+ return false;
+ }
+
}
\ No newline at end of file
diff --git a/src/org/torproject/android/wizard/LotsaText.java b/src/org/torproject/android/wizard/LotsaText.java
index 3568779d..536edabf 100644
--- a/src/org/torproject/android/wizard/LotsaText.java
+++ b/src/org/torproject/android/wizard/LotsaText.java
@@ -2,10 +2,6 @@ package org.torproject.android.wizard;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
-import org.torproject.android.R.drawable;
-import org.torproject.android.R.id;
-import org.torproject.android.R.layout;
-import org.torproject.android.R.string;
import org.torproject.android.service.TorServiceUtils;
import android.app.Activity;
@@ -14,11 +10,9 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.support.v4.app.ActivityCompat;
+import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
-import android.widget.ImageView;
import android.widget.TextView;
public class LotsaText extends Activity implements TorConstants{
@@ -57,19 +51,6 @@ public class LotsaText extends Activity implements TorConstants{
}
-
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch(resultCode)
- {
- case RESULT_CLOSE_ALL:
- setResult(RESULT_CLOSE_ALL);
- finish();
- }
- super.onActivityResult(requestCode, resultCode, data);
- }
-
private void stepOne() {
@@ -135,11 +116,22 @@ public class LotsaText extends Activity implements TorConstants{
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- startActivityForResult(new Intent(LotsaText.this, Permissions.class), 1);
+ finish();
+ startActivity(new Intent(LotsaText.this, Permissions.class));
}
});
}
-
+
+ //Code to override the back button!
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if(keyCode == KeyEvent.KEYCODE_BACK){
+ finish();
+ startActivity(new Intent(getBaseContext(), ChooseLocaleWizardActivity.class));
+ return true;
+ }
+ return true;
+ }
}
\ No newline at end of file
diff --git a/src/org/torproject/android/wizard/Permissions.java b/src/org/torproject/android/wizard/Permissions.java
index 37db1857..229f5bdc 100644
--- a/src/org/torproject/android/wizard/Permissions.java
+++ b/src/org/torproject/android/wizard/Permissions.java
@@ -3,7 +3,6 @@ package org.torproject.android.wizard;
import org.sufficientlysecure.rootcommands.RootCommands;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
-import org.torproject.android.service.TorService;
import org.torproject.android.service.TorServiceUtils;
import android.app.Activity;
@@ -12,14 +11,13 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
-import android.widget.ImageView;
import android.widget.TextView;
public class Permissions extends Activity implements TorConstants {
@@ -50,17 +48,6 @@ public class Permissions extends Activity implements TorConstants {
}
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch(resultCode)
- {
- case RESULT_CLOSE_ALL:
- setResult(RESULT_CLOSE_ALL);
- finish();
- }
- super.onActivityResult(requestCode, resultCode, data);
- }
-
private void stepFourRoot(){
@@ -138,9 +125,8 @@ public class Permissions extends Activity implements TorConstants {
}
else
{
- startActivityForResult(new Intent(Permissions.this, ConfigureTransProxy.class), 1);
-
-
+ finish();
+ startActivity(new Intent(Permissions.this, ConfigureTransProxy.class));
}
@@ -150,8 +136,8 @@ public class Permissions extends Activity implements TorConstants {
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
-
- startActivityForResult(new Intent(Permissions.this, LotsaText.class), 1);
+ finish();
+ startActivity(new Intent(Permissions.this, LotsaText.class));
}
});
@@ -160,7 +146,8 @@ public class Permissions extends Activity implements TorConstants {
public void onClick(View v) {
- startActivityForResult(new Intent(Permissions.this, TipsAndTricks.class), 1);
+ finish();
+ startActivity(new Intent(Permissions.this, TipsAndTricks.class));
}
});
@@ -186,25 +173,34 @@ public class Permissions extends Activity implements TorConstants {
Button grantPermissions = ((Button)findViewById(R.id.grantPermissions));
grantPermissions.setVisibility(Button.GONE);
-
CheckBox consent = (CheckBox)findViewById(R.id.checkBox);
consent.setVisibility(CheckBox.GONE);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
-
- startActivityForResult(new Intent(Permissions.this, LotsaText.class), 1);
+ finish();
+ startActivity(new Intent(Permissions.this, LotsaText.class));
}
});
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- startActivityForResult(new Intent(Permissions.this, TipsAndTricks.class), 1);
+ finish();
+ startActivity(new Intent(Permissions.this, TipsAndTricks.class));
}
});
}
+ //Code to override the back button!
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if(keyCode == KeyEvent.KEYCODE_BACK){
+ finish();
+ startActivity(new Intent(getBaseContext(), LotsaText.class));
+ return true;
+ }
+ return false;
+ }
}
\ No newline at end of file
diff --git a/src/org/torproject/android/wizard/TipsAndTricks.java b/src/org/torproject/android/wizard/TipsAndTricks.java
index 300730b7..2fcf9d2e 100644
--- a/src/org/torproject/android/wizard/TipsAndTricks.java
+++ b/src/org/torproject/android/wizard/TipsAndTricks.java
@@ -3,25 +3,16 @@ package org.torproject.android.wizard;
import org.torproject.android.Orbot;
import org.torproject.android.R;
import org.torproject.android.TorConstants;
-import org.torproject.android.R.drawable;
-import org.torproject.android.R.id;
-import org.torproject.android.R.layout;
-import org.torproject.android.R.string;
import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.Bundle;
-import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
-import android.widget.ImageView;
import android.widget.TextView;
public class TipsAndTricks extends Activity implements TorConstants {
@@ -48,17 +39,6 @@ public class TipsAndTricks extends Activity implements TorConstants {
}
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- switch(resultCode)
- {
- case RESULT_CLOSE_ALL:
- setResult(RESULT_CLOSE_ALL);
- finish();
- }
- super.onActivityResult(requestCode, resultCode, data);
- }
void stepFive(){
@@ -74,6 +54,7 @@ public class TipsAndTricks extends Activity implements TorConstants {
public void onClick(View view) {
String url = getString(R.string.gibberbot_apk_url);
+ finish();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
@@ -86,6 +67,7 @@ public class TipsAndTricks extends Activity implements TorConstants {
public void onClick(View view) {
String url = getString(R.string.orweb_apk_url);
+ finish();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
@@ -98,6 +80,7 @@ public class TipsAndTricks extends Activity implements TorConstants {
public void onClick(View view) {
String url = getString(R.string.duckgo_apk_url);
+ finish();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
@@ -110,6 +93,7 @@ public class TipsAndTricks extends Activity implements TorConstants {
public void onClick(View view) {
String url = getString(R.string.proxymob_setup_url);
+ finish();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
@@ -122,6 +106,7 @@ public class TipsAndTricks extends Activity implements TorConstants {
public void onClick(View view) {
String url = getString(R.string.twitter_setup_url);
+ finish();
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
@@ -160,7 +145,7 @@ public class TipsAndTricks extends Activity implements TorConstants {
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
-
+ finish();
startActivityForResult(new Intent(TipsAndTricks.this, Permissions.class), 1);
}
});
@@ -195,19 +180,30 @@ public class TipsAndTricks extends Activity implements TorConstants {
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- startActivityForResult(new Intent(TipsAndTricks.this, Permissions.class), 1);
-
+ finish();
+ startActivity(new Intent(TipsAndTricks.this, Permissions.class));
}
});
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- startActivityForResult(new Intent(TipsAndTricks.this, Orbot.class), 1);
-
+ finish();
}
});
}
+
+ //Code to override the back button!
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if(keyCode == KeyEvent.KEYCODE_BACK){
+ finish();
+ startActivity(new Intent(getBaseContext(), Permissions.class));
+ return true;
+ }
+ return false;
+ }
+
/*
private void showWizardFinal ()
{