[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r21042: {projects} Orbot 0.0.2: major UI improvements w/ editable settings and (in projects/android/trunk/Orbot: . assets res/drawable res/layout src/org/torproject/android)
Author: n8fr8
Date: 2009-11-28 10:41:28 -0500 (Sat, 28 Nov 2009)
New Revision: 21042
Added:
projects/android/trunk/Orbot/res/drawable/bgdarkdroid.png
projects/android/trunk/Orbot/res/drawable/ic_menu_about.png
projects/android/trunk/Orbot/res/drawable/ic_menu_goto.png
projects/android/trunk/Orbot/res/drawable/ic_menu_home.png
projects/android/trunk/Orbot/res/drawable/ic_menu_register.png
projects/android/trunk/Orbot/res/drawable/ic_menu_reports.png
projects/android/trunk/Orbot/res/drawable/torstarting.png
projects/android/trunk/Orbot/res/drawable/torstopping.png
projects/android/trunk/Orbot/res/drawable/vidalia.png
Modified:
projects/android/trunk/Orbot/.classpath
projects/android/trunk/Orbot/BUILD
projects/android/trunk/Orbot/CHANGELOG
projects/android/trunk/Orbot/assets/torrc
projects/android/trunk/Orbot/build.xml
projects/android/trunk/Orbot/default.properties
projects/android/trunk/Orbot/res/drawable/icon.png
projects/android/trunk/Orbot/res/drawable/toroff.png
projects/android/trunk/Orbot/res/drawable/toron.png
projects/android/trunk/Orbot/res/layout/layout_log.xml
projects/android/trunk/Orbot/res/layout/layout_main.xml
projects/android/trunk/Orbot/res/layout/layout_settings.xml
projects/android/trunk/Orbot/src/org/torproject/android/HttpProxy.java
projects/android/trunk/Orbot/src/org/torproject/android/TorBinaryInstaller.java
projects/android/trunk/Orbot/src/org/torproject/android/TorConstants.java
projects/android/trunk/Orbot/src/org/torproject/android/TorControlPanel.java
projects/android/trunk/Orbot/src/org/torproject/android/TorService.java
Log:
Orbot 0.0.2: major UI improvements w/ editable settings and more
Modified: projects/android/trunk/Orbot/.classpath
===================================================================
--- projects/android/trunk/Orbot/.classpath 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/.classpath 2009-11-28 15:41:28 UTC (rev 21042)
@@ -3,6 +3,7 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="jsocks.jar"/>
+ <classpathentry kind="lib" path="libs/jsocks.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/jtorctrl"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: projects/android/trunk/Orbot/BUILD
===================================================================
--- projects/android/trunk/Orbot/BUILD 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/BUILD 2009-11-28 15:41:28 UTC (rev 21042)
@@ -91,6 +91,16 @@
ant jar
cp bin/jar/asocks.jar ../Orbot/libs
+We need to get the TorControl library for Java (https://svn.torproject.org/svn/torctl/trunk/doc/howto.txt):
+
+ git clone git://git.torproject.org/git/jtorctl
+ cd jtorctl
+ mkdir bin
+ javac net/freehaven/tor/control/TorControlConnection.java -d bin
+ cd bin
+ jar cvf jtorctrl.jar *
+ cp jtorctrl.jar {Orbot Home}/libs
+
Finally, we'll make a proper Android package with ant and the Android App SDK:
export APP_SDK=~/Documents/projects/android/android-sdk-linux_x86-1.5_r3/tools
Modified: projects/android/trunk/Orbot/CHANGELOG
===================================================================
--- projects/android/trunk/Orbot/CHANGELOG 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/CHANGELOG 2009-11-28 15:41:28 UTC (rev 21042)
@@ -1,3 +1,10 @@
+0.0.2 - 2009-11-27
+- Major improvement to the user interface including relative layout for different screens
+- New graphics resources
+- Implemented Tor Control Port using official Java library
+- Added 'clear' button to the log screen
+- Added 'save' and editable textbox for the settings screen
+- Moved screen navigation to a pop-up menu
Changes in version 0.0.1-alpha - 2009-10-21
- First code release
@@ -3,3 +10,2 @@
- Major Features: Tor binary application is fully operational, UI: Start/Stop Tor, View Message Log, View Settings (torrc)
-
Modified: projects/android/trunk/Orbot/assets/torrc
===================================================================
--- projects/android/trunk/Orbot/assets/torrc 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/assets/torrc 2009-11-28 15:41:28 UTC (rev 21042)
@@ -52,11 +52,11 @@
## The port on which Tor will listen for local connections from Tor
## controller applications, as documented in control-spec.txt.
-#ControlPort 9051
+ControlPort 9051
## If you enable the controlport, be sure to enable one of these
## authentication methods, to prevent attackers from accessing it.
#HashedControlPassword 16:872860B76453A77D60CA2BB8C1A7042072093276A3D701AD684053EC4C
-#CookieAuthentication 1
+CookieAuthentication 1
############### This section is just for location-hidden services ###
Modified: projects/android/trunk/Orbot/build.xml
===================================================================
--- projects/android/trunk/Orbot/build.xml 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/build.xml 2009-11-28 15:41:28 UTC (rev 21042)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project name="Orbot" default="help">
+<project name="Orbot">
<!-- The local.properties file is created and updated by the 'android' tool.
It contain the path to the SDK. It should *NOT* be checked in in Version
Modified: projects/android/trunk/Orbot/default.properties
===================================================================
--- projects/android/trunk/Orbot/default.properties 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/default.properties 2009-11-28 15:41:28 UTC (rev 21042)
@@ -7,16 +7,8 @@
# "build.properties", and override values to adapt the script to your
# project structure.
-# apk configurations. This property allows creation of APK files with limited
-# resources. For example, if your application contains many locales and
-# you wish to release multiple smaller apks instead of a large one, you can
-# define configuration to create apks with limited language sets.
-# Format is a comma separated list of configuration names. For each
-# configuration, a property will declare the resource configurations to
-# include. Example:
-# apk-configurations=european,northamerica
-# apk-config-european=en,fr,it,de,es
-# apk-config-northamerica=en,es
apk-configurations=
# Project target.
-target=android-2
+target=android-4
+# Indicates whether an apk should be generated for each density.
+split.density=false
Added: projects/android/trunk/Orbot/res/drawable/bgdarkdroid.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/bgdarkdroid.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/ic_menu_about.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/ic_menu_about.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/ic_menu_goto.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/ic_menu_goto.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/ic_menu_home.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/ic_menu_home.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/ic_menu_register.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/ic_menu_register.png
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/ic_menu_reports.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/ic_menu_reports.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: projects/android/trunk/Orbot/res/drawable/icon.png
===================================================================
(Binary files differ)
Modified: projects/android/trunk/Orbot/res/drawable/toroff.png
===================================================================
(Binary files differ)
Modified: projects/android/trunk/Orbot/res/drawable/toron.png
===================================================================
(Binary files differ)
Added: projects/android/trunk/Orbot/res/drawable/torstarting.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/torstarting.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/torstopping.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/torstopping.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: projects/android/trunk/Orbot/res/drawable/vidalia.png
===================================================================
(Binary files differ)
Property changes on: projects/android/trunk/Orbot/res/drawable/vidalia.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: projects/android/trunk/Orbot/res/layout/layout_log.xml
===================================================================
--- projects/android/trunk/Orbot/res/layout/layout_log.xml 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/res/layout/layout_log.xml 2009-11-28 15:41:28 UTC (rev 21042)
@@ -16,13 +16,11 @@
</ScrollView>
- <Button android:id="@+id/btnLogClose"
- android:layout_width="fill_parent"
+
+ <Button android:id="@+id/btnLogClear"
android:layout_height="40px"
- android:text="Close Log"
+ android:text="Clear Log"
android:layout_margin="0sp"
-
-
-
- />
+ android:layout_width="fill_parent"/>
+
</LinearLayout>
Modified: projects/android/trunk/Orbot/res/layout/layout_main.xml
===================================================================
--- projects/android/trunk/Orbot/res/layout/layout_main.xml 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/res/layout/layout_main.xml 2009-11-28 15:41:28 UTC (rev 21042)
@@ -1,63 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
-<AbsoluteLayout
-android:id="@+id/widget29"
-android:layout_width="fill_parent"
-android:layout_height="fill_parent"
-xmlns:android="http://schemas.android.com/apk/res/android"
-android:background="#cccccc"
->
-<AbsoluteLayout
-android:id="@+id/topbox"
-android:layout_width="275px"
-android:layout_height="120px"
-android:layout_x="19px"
-android:layout_y="23px"
->
-<ImageView
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@drawable/bgdarkdroid">
+
+ <ScrollView android:id="@+id/mainview"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+ <TableLayout android:id="@+id/mainLayout"
+ android:layout_gravity="center"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content">
+ <TableRow android:id="@+id/startRow">
+ <TableLayout
+ android:layout_gravity="center"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content">
+ <TableRow>
+
+
+ <ImageView
android:id="@+id/imgStatus"
-android:layout_x="40px"
-android:layout_y="11px"
-android:layout_width="64px"
-android:layout_height="64px"
->
-</ImageView>
-<TextView
-android:id="@+id/lblStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
-android:text="TextView"
-android:layout_x="111px"
-android:layout_y="39px"
-android:textColor="#333333"
->
-</TextView>
-</AbsoluteLayout>
-<Button
-android:id="@+id/btnStart"
-android:layout_width="205px"
-android:layout_height="wrap_content"
-android:text="Start Tor"
-android:layout_x="54px"
-android:layout_y="133px"
->
-</Button>
-<Button
-android:id="@+id/btnLog"
-android:layout_width="206px"
-android:layout_height="wrap_content"
-android:text="View Message Log"
-android:layout_x="54px"
-android:layout_y="221px"
->
-</Button>
-<Button
-android:id="@+id/btnSettings"
-android:layout_width="206px"
-android:layout_height="wrap_content"
-android:text="View Settings"
-android:layout_x="53px"
-android:layout_y="305px"
->
-</Button>
-</AbsoluteLayout>
+android:src="@drawable/toroff"/>
+ </TableRow>
+ <TableRow>
+ <TextView android:id="@+id/lblStatus"
+ android:text=" \n "
+ android:paddingTop="15px"
+ android:layout_gravity="center_horizontal"
+ android:textStyle="bold"
+ android:textColor="#ffffff" />
+ </TableRow>
+ </TableLayout>
+ </TableRow>
+
+ </TableLayout>
+</ScrollView>
+
+
+</LinearLayout>
+
+
Modified: projects/android/trunk/Orbot/res/layout/layout_settings.xml
===================================================================
--- projects/android/trunk/Orbot/res/layout/layout_settings.xml 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/res/layout/layout_settings.xml 2009-11-28 15:41:28 UTC (rev 21042)
@@ -8,21 +8,21 @@
<ScrollView android:layout_height="380px"
android:layout_width="fill_parent">
- <TextView android:id="@+id/textSettings"
+ <EditText android:id="@+id/textSettings"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1.0"
+ android:singleLine="false"
/>
</ScrollView>
- <Button android:id="@+id/btnSettingsClose"
+ <Button android:id="@+id/btnSettingsSave"
android:layout_width="fill_parent"
android:layout_height="40px"
- android:text="Close Log"
+ android:text="Save Settings"
android:layout_margin="0sp"
-
/>
</LinearLayout>
Modified: projects/android/trunk/Orbot/src/org/torproject/android/HttpProxy.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/HttpProxy.java 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/src/org/torproject/android/HttpProxy.java 2009-11-28 15:41:28 UTC (rev 21042)
@@ -51,14 +51,21 @@
*
* Julian Robichaux -- http://www.nsftools.com
*/
-import java.io.*;
-import java.net.*;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
import java.lang.reflect.Array;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
-import net.sourceforge.jsocks.socks.Socks4Proxy;
import net.sourceforge.jsocks.socks.Socks5Proxy;
import net.sourceforge.jsocks.socks.SocksSocket;
+
public class HttpProxy extends Thread
{
public static final int DEFAULT_PORT = 8888;
Modified: projects/android/trunk/Orbot/src/org/torproject/android/TorBinaryInstaller.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/TorBinaryInstaller.java 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/src/org/torproject/android/TorBinaryInstaller.java 2009-11-28 15:41:28 UTC (rev 21042)
@@ -54,11 +54,13 @@
streamToFile(zip.getInputStream(zipen),TORRC_INSTALL_PATH);
zip.close();
+
+ Log.i(LOG_TAG,"SUCCESS: unzipped tor binary from apk");
}
catch (IOException ioe)
{
- Log.i(LOG_TAG,"unable to unzip tor binary from apk",ioe);
+ Log.i(LOG_TAG,"FAIL: unable to unzip tor binary from apk",ioe);
}
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/TorConstants.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/TorConstants.java 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/src/org/torproject/android/TorConstants.java 2009-11-28 15:41:28 UTC (rev 21042)
@@ -28,6 +28,9 @@
//where to send the notices log
public final static String TOR_LOG_PATH = TOR_HOME + "notices.log";
+
+ //control port cookie path
+ public final static String TOR_CONTROL_AUTH_COOKIE = TOR_HOME + "data/control_auth_cookie";
//how to launch tor
public final static String TOR_COMMAND_LINE_ARGS = "-f " + TORRC_INSTALL_PATH;
@@ -55,5 +58,16 @@
//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 = 3000;
+ //status to communicate state
+ public final static int STATUS_OFF = 0;
+ public final static int STATUS_ON = 1;
+ public final static int STATUS_STARTING_UP = 2;
+ public final static int STATUS_SHUTTING_DOWN = 3;
+
+ //control port
+ public final static String TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE = "Bootstrapped 100%";
+
}
Modified: projects/android/trunk/Orbot/src/org/torproject/android/TorControlPanel.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/TorControlPanel.java 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/src/org/torproject/android/TorControlPanel.java 2009-11-28 15:41:28 UTC (rev 21042)
@@ -6,18 +6,23 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
+
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
+import android.widget.Toast;
public class TorControlPanel extends Activity implements OnClickListener, TorConstants
{
@@ -27,13 +32,15 @@
private Intent torService = null;
private boolean updateLog = false;
+ private boolean updateStatus = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+ setTheme(android.R.style.Theme_Black);
+
showMain();
@@ -41,7 +48,50 @@
}
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+
+ MenuItem mItem = menu.add(0, 1, Menu.NONE, "Home");
+ MenuItem mItem2 = menu.add(0, 2, Menu.NONE, "Settings");
+ MenuItem mItem3 = menu.add(0, 3, Menu.NONE, "Log");
+ MenuItem mItem4 = menu.add(0, 4, Menu.NONE, "Browser");
+
+ mItem.setIcon(R.drawable.ic_menu_home);
+ mItem2.setIcon(R.drawable.ic_menu_register);
+ mItem3.setIcon(R.drawable.ic_menu_reports);
+ mItem4.setIcon(R.drawable.ic_menu_goto);
+
+ return true;
+ }
+ /* (non-Javadoc)
+ * @see android.app.Activity#onMenuItemSelected(int, android.view.MenuItem)
+ */
+ @Override
+ public boolean onMenuItemSelected(int featureId, MenuItem item) {
+
+ super.onMenuItemSelected(featureId, item);
+
+ if (item.getItemId() == 1)
+ {
+ this.showMain();
+ }
+ else if (item.getItemId() == 2)
+ {
+ this.showSettings();
+ }
+ else if (item.getItemId() == 3)
+ {
+ this.showMessageLog();
+ }
+ else if (item.getItemId() == 4)
+ {
+ Toast.makeText(this, "Not yet implemented!", Toast.LENGTH_SHORT);
+ }
+
+ return true;
+ }
+
/* (non-Javadoc)
* @see android.app.Activity#onPause()
@@ -63,7 +113,7 @@
// TODO Auto-generated method stub
super.onResume();
- setUIState ();
+ checkStatus ();
}
@@ -77,7 +127,7 @@
// TODO Auto-generated method stub
super.onStart();
- setUIState ();
+ checkStatus ();
}
@@ -100,17 +150,32 @@
private void showMain ()
{
updateLog = false;
+ updateStatus = true;
setContentView(R.layout.layout_main);
- ((Button)findViewById(R.id.btnStart)).setOnClickListener(this);
-
- ((Button)findViewById(R.id.btnLog)).setOnClickListener(this);
-
- ((Button)findViewById(R.id.btnSettings)).setOnClickListener(this);
-
-
- setUIState ();
+ findViewById(R.id.imgStatus).setOnClickListener(this);
+
+
+ Thread thread = new Thread ()
+ {
+ public void run ()
+ {
+
+ while (updateStatus)
+ {
+ handlerStatus.sendEmptyMessage(0);
+ try {
+ Thread.sleep(UPDATE_TIMEOUT);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+
+ thread.start();
}
/*
@@ -119,8 +184,9 @@
private void showMessageLog ()
{
setContentView(R.layout.layout_log);
- ((Button)findViewById(R.id.btnLogClose)).setOnClickListener(this);
+ ((Button)findViewById(R.id.btnLogClear)).setOnClickListener(this);
+ updateStatus = false;
updateLog = true;
Thread thread = new Thread ()
@@ -130,13 +196,15 @@
while (updateLog)
{
- handler.sendEmptyMessage(0);
+
try {
- Thread.sleep(5000);
+ Thread.sleep(UPDATE_TIMEOUT);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+
+ handler.sendEmptyMessage(0);
}
}
};
@@ -153,9 +221,12 @@
TextView tvLog = (TextView)findViewById(R.id.messageLog);
- String output = loadLogFile(TOR_LOG_PATH);
+ if (tvLog != null)
+ {
+ String output = loadTextFile(TOR_LOG_PATH);
- tvLog.setText(output);
+ tvLog.setText(output);
+ }
}
@@ -172,6 +243,21 @@
}
};
+
+ /*
+ * Handle to reload Tor debug log every few seconds while viewing it
+ */
+ private Handler handlerStatus = new Handler() {
+
+ @Override
+ public void handleMessage(Message msg) {
+
+ checkStatus();
+
+ }
+
+ };
+
/*
* Load the basic settings application to display torrc
@@ -179,44 +265,61 @@
*/
private void showSettings ()
{
+ updateStatus = false;
+ updateLog = false;
+
setContentView(R.layout.layout_settings);
+
- TextView tvLog = (TextView)findViewById(R.id.textSettings);
- ((Button)findViewById(R.id.btnSettingsClose)).setOnClickListener(this);
+ String output = loadTextFile(TORRC_INSTALL_PATH);
- String output = loadLogFile(TORRC_INSTALL_PATH);
+ TextView tvSettings = (TextView)findViewById(R.id.textSettings);
+ ((Button)findViewById(R.id.btnSettingsSave)).setOnClickListener(this);
+ tvSettings.setText(output);
- tvLog.setText(output);
-
}
/*
* Set the state of the running/not running graphic and label
*/
- public void setUIState ()
+ public void checkStatus ()
{
TextView lblStatus = (TextView)findViewById(R.id.lblStatus);
ImageView imgStatus = (ImageView)findViewById(R.id.imgStatus);
- Button btnStart = (Button)findViewById(R.id.btnStart);
-
- if (TorService.isRunning())
+ if (imgStatus != null)
{
- btnStart.setText("Stop Tor");
- imgStatus.setImageResource(R.drawable.toron);
- lblStatus.setText("Tor is running");
-
+ int torStatus = TorService.getStatus();
+
+ if (torStatus == STATUS_ON)
+ {
+ imgStatus.setImageResource(R.drawable.toron);
+ lblStatus.setText("Tor is running\n- touch to stop -");
+ updateStatus = false;
+ }
+ else if (torStatus == STATUS_STARTING_UP)
+ {
+ imgStatus.setImageResource(R.drawable.torstarting);
+ lblStatus.setText("Tor is starting up\n(this might take a little bit)");
+
+
+ }
+ else if (torStatus == STATUS_SHUTTING_DOWN)
+ {
+ imgStatus.setImageResource(R.drawable.torstopping);
+ lblStatus.setText("Tor is shutting down\nplease wait...");
+
+ }
+ else
+ {
+ imgStatus.setImageResource(R.drawable.toroff);
+ lblStatus.setText("Tor is not running\n- touch to start -");
+ updateStatus = false;
+ }
}
- else
- {
- btnStart.setText("Start Tor");
- imgStatus.setImageResource(R.drawable.toroff);
- lblStatus.setText("Tor is not running");
-
- }
@@ -229,59 +332,54 @@
public void onClick(View view) {
// the start button
- if (view.getId()==R.id.btnStart)
+ if (view.getId()==R.id.imgStatus)
{
//if Tor binary is not running, then start the service up
- if (!TorService.isRunning())
+ if (TorService.getStatus()==STATUS_OFF)
{
torService = new Intent(this, TorService.class);
torService.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
TorService.setActivity(this);
startService(torService);
-
+
+
}
- else
+ else if (TorService.getStatus()==STATUS_ON)
{
- if (torService == null)
- torService = new Intent(this, TorService.class);
+ //stopService(torService);
- TorService.setActivity(this);
+ TorService.stopTor ();
- stopService(torService);
-
}
- //update the UI
- setUIState ();
-
- }
- else if (view.getId()==R.id.btnLog)
- {
- showMessageLog();
+ showMain ();
}
- else if (view.getId()==R.id.btnSettings)
+ else if (view.getId()==R.id.btnLogClear)
{
- showSettings();
-
+
+ saveTextFile(TOR_LOG_PATH,"");
}
- else if (view.getId()==R.id.btnLogClose || view.getId()==R.id.btnSettingsClose)
+ else if (view.getId()==R.id.btnSettingsSave)
{
- showMain();
+ TextView tvSettings = (TextView)findViewById(R.id.textSettings);
+ String newSettings = tvSettings.getText().toString();
+ saveTextFile(TORRC_INSTALL_PATH, newSettings);
}
}
+
/*
* Load the log file text
*/
- public static String loadLogFile (String path)
+ public static String loadTextFile (String path)
{
String line = null;
@@ -305,6 +403,34 @@
}
+
+ /*
+ * Load the log file text
+ */
+ public static boolean saveTextFile (String path, String contents)
+ {
+
+ try {
+
+ FileWriter writer = new FileWriter( path, false );
+ writer.write( contents );
+
+ writer.close();
+
+
+
+ return true;
+
+ } catch (IOException e) {
+ // Log.i(TAG, "error writing file: " + path, e);
+ e.printStackTrace();
+ return false;
+ }
+
+
+
+ }
+
/*
* Get the last line of the log file for status display
Modified: projects/android/trunk/Orbot/src/org/torproject/android/TorService.java
===================================================================
--- projects/android/trunk/Orbot/src/org/torproject/android/TorService.java 2009-11-28 13:04:12 UTC (rev 21041)
+++ projects/android/trunk/Orbot/src/org/torproject/android/TorService.java 2009-11-28 15:41:28 UTC (rev 21042)
@@ -5,11 +5,20 @@
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.Socket;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
+import net.freehaven.tor.control.EventHandler;
+import net.freehaven.tor.control.NullEventHandler;
+import net.freehaven.tor.control.TorControlConnection;
import net.sourceforge.jsocks.socks.Proxy;
import android.app.Service;
import android.content.Intent;
@@ -28,22 +37,29 @@
private static Process procTor = null;
+ private static int currentStatus = STATUS_OFF;
+
+ private static TorControlConnection conn = null;
+
/** Called when the activity is first created. */
@Override
public void onCreate() {
super.onCreate();
-
}
- public static boolean isRunning ()
+
+ public static int getStatus ()
{
- int procId = findProcessId(TorConstants.TOR_BINARY_INSTALL_PATH);
-
- return (procId != -1);
-
+ try {
+ getTorStatus();
+ } catch (IOException e) {
+ Log.i(TAG,"Unable to get tor status",e);
+ }
+
+ return currentStatus;
+
}
-
/* (non-Javadoc)
@@ -74,13 +90,18 @@
private void startService ()
{
- Log.i(TAG,"Tor thread started");
-
-
- initTor();
-
-
- setupWebProxy(true);
+ Thread thread = new Thread ()
+ {
+ public void run ()
+ {
+
+ Log.i(TAG,"Tor thread started");
+
+ initTor();
+ }
+ };
+
+ thread.start();
}
@@ -90,17 +111,33 @@
public void onDestroy ()
{
- killTorProcess ();
- setupWebProxy(false);
-
}
+ public static void stopTor ()
+ {
+ currentStatus = STATUS_SHUTTING_DOWN;
+
+ Thread thread = new Thread ()
+ {
+ public void run ()
+ {
+ killTorProcess ();
+
+ setupWebProxy(false);
+
+ currentStatus = STATUS_OFF;
+ }
+ };
+
+ thread.start();
+ }
+
public static void setActivity(TorControlPanel activity) {
ACTIVITY = activity;
}
- private void setupWebProxy (boolean enabled)
+ private static void setupWebProxy (boolean enabled)
{
if (enabled)
{
@@ -140,91 +177,142 @@
if (webProxy != null)
{
- showToast("Tor is disabled - browsing is not anonymous!");
- webProxy.setDoSocks(false);
+ //logNotice("Tor is disabled - browsing is not anonymous!");
+ //webProxy.setDoSocks(false);
}
}
}
- private void killTorProcess ()
+ public static void reloadConfig ()
{
+ try
+ {
+ if (conn == null)
+ {
+ initControlConnection ();
+ }
+
+ if (conn != null)
+ {
+ conn.signal("RELOAD");
+ }
+ }
+ catch (Exception e)
+ {
+ Log.i(TAG,"Unable to reload configuration",e);
+ }
+ }
+
+ private void shutdownTor ()
+ {
+ try
+ {
+ currentStatus = STATUS_SHUTTING_DOWN;
+
+ if (conn == null)
+ {
+ initControlConnection ();
+ }
+
+ if (conn != null)
+ {
+ conn.signal("SHUTDOWN");
+ }
+ }
+ catch (Exception e)
+ {
+ }
+ }
+ private static void killTorProcess ()
+ {
//doCommand(SHELL_CMD_KILLALL, CHMOD_EXE_VALUE, TOR_BINARY_INSTALL_PATH);
-
+
+ /*
if (procTor != null)
{
Log.i(TAG,"shutting down Tor process...");
-
procTor.destroy();
+
try {
procTor.waitFor();
}
- catch(Exception e)
+ catch(Exception e2)
{
- e.printStackTrace();
+ e2.printStackTrace();
}
int exitStatus = procTor.exitValue();
Log.i(TAG,"Tor exit: " + exitStatus);
-
+
+
procTor = null;
- }
+ }*/
int procId = findProcessId(TorConstants.TOR_BINARY_INSTALL_PATH);
if (procId != -1)
{
+
Log.i(TAG,"Found Tor PID=" + procId + " - killing now...");
doCommand(SHELL_CMD_KILLALL, procId + "");
+
}
- if (ACTIVITY != null)
- ((TorControlPanel)ACTIVITY).setUIState();
-
-
+ conn = null;
+
}
- private void showToast (String msg)
+ private static void logNotice (String msg)
{
- Toast toast = Toast.makeText(ACTIVITY, msg, Toast.LENGTH_LONG);
- toast.show();
+ Log.i(TAG, msg);
}
+ private void checkBinary ()
+ {
+
+ boolean binaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
+
+ if (!binaryExists)
+ {
+ killTorProcess ();
+
+ TorBinaryInstaller installer = new TorBinaryInstaller();
+ installer.start(true);
+
+ binaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
+ if (binaryExists)
+ {
+ logNotice("Tor binary installed!");
+
+ }
+ else
+ {
+ logNotice("Tor binary install FAILED!");
+ return;
+ }
+ }
+
+ Log.i(TAG,"Setting permission on Tor binary");
+ doCommand(SHELL_CMD_CHMOD, CHMOD_EXE_VALUE + ' ' + TOR_BINARY_INSTALL_PATH);
+ }
+
public void initTor ()
{
try {
+ currentStatus = STATUS_STARTING_UP;
+
+ killTorProcess ();
- boolean binaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
+ checkBinary ();
- if (!binaryExists)
- {
- TorBinaryInstaller installer = new TorBinaryInstaller();
- installer.start(false);
-
- binaryExists = new File(TOR_BINARY_INSTALL_PATH).exists();
- if (binaryExists)
- {
- showToast("Tor binary installed!");
- }
- else
- {
- showToast("Tor binary install FAILED!");
- return;
- }
- }
-
- Log.i(TAG,"Setting permission on Tor binary");
- doCommand(SHELL_CMD_CHMOD, CHMOD_EXE_VALUE + ' ' + TOR_BINARY_INSTALL_PATH);
-
- killTorProcess ();
-
doCommand(SHELL_CMD_RM,TOR_LOG_PATH);
Log.i(TAG,"Starting tor process");
@@ -232,12 +320,14 @@
//Log.i(TAG,"Tor process id=" + procTor.);
- showToast("Tor is starting up...");
+ currentStatus = STATUS_STARTING_UP;
+ logNotice("Tor is starting up...");
- ((TorControlPanel)ACTIVITY).setUIState();
+ Thread.sleep(2000);
+ initControlConnection ();
+
+ } catch (Exception e) {
- } catch (Exception e) {
-
Log.w(TAG,"unable to start Tor Process",e);
e.printStackTrace();
@@ -311,7 +401,7 @@
}
- public Process doCommand(String command, String arg1)
+ public static Process doCommand(String command, String arg1)
{
Runtime r = Runtime.getRuntime();
@@ -335,57 +425,161 @@
return child;
}
- /*
- public static String doCommand(String command, String arg0, String arg1, boolean logOutput) {
- try {
- // android.os.Exec is not included in android.jar so we need to use reflection.
- Class execClass = Class.forName("android.os.Exec");
- Method createSubprocess = execClass.getMethod("createSubprocess",
- String.class, String.class, String.class, int[].class);
- Method waitFor = execClass.getMethod("waitFor", int.class);
-
- // Executes the command.
- // NOTE: createSubprocess() is asynchronous.
- int[] pid = new int[1];
- FileDescriptor fd = (FileDescriptor)createSubprocess.invoke(
- null, command, arg0, arg1, pid);
-
- StringBuffer output = new StringBuffer();
+
+ public static String generateHashPassword ()
+ {
+ /*
+ PasswordDigest d = PasswordDigest.generateDigest();
+ byte[] s = d.getSecret(); // pass this to authenticate
+ String h = d.getHashedPassword(); // pass this to the Tor on startup.
+*/
+ return null;
+ }
+
+ public static synchronized void initControlConnection () throws Exception, RuntimeException
+ {
+ if (conn == null)
+ {
+ Log.i(TAG,"Connecting to control port: " + TOR_CONTROL_PORT);
+ Socket s = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
+ conn = TorControlConnection.getConnection(s);
+ // conn.authenticate(new byte[0]); // See section 3.2
+
+ Log.i(TAG,"SUCCESS connected to control port");
+
+ //
+ File fileCookie = new File(TOR_CONTROL_AUTH_COOKIE);
+ byte[] cookie = new byte[(int)fileCookie.length()];
+ new FileInputStream(new File(TOR_CONTROL_AUTH_COOKIE)).read(cookie);
+ conn.authenticate(cookie);
+
+ Log.i(TAG,"SUCCESS authenticated to control port");
+
+ addEventHandler();
+ }
+
- if (logOutput)
+ }
+
+ public void modifyConf () throws IOException
+ {
+ // Get one configuration variable.
+ List options = conn.getConf("contact");
+ // Get a set of configuration variables.
+ // List options = conn.getConf(Arrays.asList(new String[]{
+ // "contact", "orport", "socksport"}));
+ // Change a single configuration variable
+ conn.setConf("BandwidthRate", "1 MB");
+ // Change several configuration variables
+ conn.setConf(Arrays.asList(new String[]{
+ "HiddenServiceDir /home/tor/service1",
+ "HiddenServicePort 80",
+ }));
+ // Reset some variables to their defaults
+ conn.resetConf(Arrays.asList(new String[]{
+ "contact", "socksport"
+ }));
+ // Flush the configuration to disk.
+ conn.saveConf();
+
+ }
+
+ private static void getTorStatus () throws IOException
+ {
+ try
+ {
+
+ if (conn == null && (currentStatus == STATUS_STARTING_UP || currentStatus == STATUS_ON))
{
- // Reads stdout.
- // NOTE: You can write to stdin of the command using new FileOutputStream(fd).
- FileInputStream in = new FileInputStream(fd);
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
- try {
- String line;
- while ((line = reader.readLine()) != null) {
- output.append(line);
- output.append('\n');
- }
- } catch (IOException e) {
- // It seems IOException is thrown when it reaches EOF.
- Log.e(TAG, "error reading output file", e);
-
- }
- // Waits for the command to finish.
- waitFor.invoke(null, pid[0]);
+ initControlConnection ();
+
}
+
+ if (conn != null)
+ {
+ // get a single value.
+
+ // get several values
+
+ if (currentStatus == STATUS_STARTING_UP)
+ {
+ //Map vals = conn.getInfo(Arrays.asList(new String[]{
+ // "status/bootstrap-phase", "status","version"}));
-
- // send output to the textbox
- return output.toString();
-
- }
+ String bsPhase = conn.getInfo("status/bootstrap-phase");
+ // Log.i(TAG, "bootstrap-phase: " + bsPhase);
+
+ if (bsPhase.indexOf("PROGRESS=100")!=-1)
+ {
+ currentStatus = STATUS_ON;
+ }
+ }
+ else
+ {
+ // String status = conn.getInfo("status/circuit-established");
+ // Log.i(TAG, "status/circuit-established=" + status);
+ }
+ }
+ }
catch (Exception e)
{
- Log.i(TAG, "unable to execute command",e);
- e.printStackTrace();
- return null;
+ Log.i(TAG, "Unable to get Tor status from control port");
}
- }*/
+
+ }
+ /*
+ * The recognized signal names are:
+ "RELOAD" -- Reload configuration information
+ "SHUTDOWN" -- Start a clean shutdown of the Tor process
+ "DUMP" -- Write current statistics to the logs
+ "DEBUG" -- Switch the logs to debugging verbosity
+ "HALT" -- Stop the Tor process immediately.
+
+ */
+ public void sendSignal () throws IOException
+ {
+
+ conn.signal("RELOAD");
+
+ }
+
+ public static void addEventHandler () throws IOException
+ {
+ // We extend NullEventHandler so that we don't need to provide empty
+ // implementations for all the events we don't care about.
+ // ...
+ Log.i(TAG,"adding control port event handler");
+
+
+ EventHandler eh = new NullEventHandler()
+ {
+ public void message(String severity, String msg) {
+
+ // Log.println(priority, tag, msg)("["+severity+"] "+msg);
+ //Toast.makeText(, text, duration)
+ // Toast.makeText(ACTIVITY, severity + ": " + msg, Toast.LENGTH_SHORT);
+ Log.i(TAG, "[Tor Control Port] " + severity + ": " + msg);
+
+ if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
+ {
+ currentStatus = STATUS_ON;
+ setupWebProxy(true);
+
+ }
+
+ }
+ };
+
+ conn.setEventHandler(eh);
+ conn.setEvents(Arrays.asList(new String[]{
+ "ORCONN", "CIRC", "INFO", "NOTICE", "ERR"}));
+ // conn.setEvents(Arrays.asList(new String[]{
+ // "DEBUG", "INFO", "NOTICE", "WARN", "ERR"}));
+
+ Log.i(TAG,"SUCCESS added control port event handler");
+
+ }
}
\ No newline at end of file