fixed permission issues; added green notification icon; improved root/su checking logic

svn:r23269
This commit is contained in:
Nathan Freitas 2010-09-21 01:26:40 +00:00
parent 573ade18f5
commit 81f31ffde6
18 changed files with 179 additions and 149 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.torproject.android" android:versionName="1.0.4" android:versionCode="10">
package="org.torproject.android" android:versionName="0.2.2.14-orbot-alpha-1.0.3" android:versionCode="9">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".Orbot"
android:theme="@android:style/Theme.NoTitleBar">
@ -44,7 +44,7 @@
</application>
<uses-sdk android:minSdkVersion="3"/>
<uses-sdk android:minSdkVersion="4"/>

View File

@ -41,6 +41,7 @@
</intent-filter>
</service>
<!--
<receiver android:name=".OnBootReceiver">
<intent-filter>
<action
@ -48,11 +49,11 @@
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
-->
</application>
<uses-sdk android:minSdkVersion="3"/>
<uses-sdk android:minSdkVersion="4"/>

View File

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".Orbot"
android:theme="@android:style/Theme.NoTitleBar">
@ -44,7 +44,7 @@
</application>
<uses-sdk android:minSdkVersion="3"/>
<uses-sdk android:minSdkVersion="4"/>

View File

@ -3,7 +3,10 @@ NOTE: Specific #s below correspond to Trac tickets logged and maintained at http
1.0.4
- Added Russian, Persian, Arabic and other .po translations (see res/values-* folders)
- Fixed incorrect try to clear iptables rules for non-root devices
- Fixed bug that stopped wizard helper from showing
- Fixed bug that stopped wizard helper from showing first time
- Added new green notification icon when Tor is connected
- Fixed app selector layout in settings
- Moved minSDK to 4 (Android 1.6); discontinued 1.5 support
1.0.3
- Fixed spanish language issues with settings screen

View File

@ -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 contains the path to the SDK. It should *NOT* be checked in in Version

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

View File

@ -49,7 +49,7 @@
<ImageView
android:id="@+id/imgStatus"
android:layout_width="wrap_content"
android:layout_height="175px"
android:layout_height="225px"
android:src="@drawable/toroff"/>
</TableRow>
<TableRow>
@ -58,8 +58,8 @@
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textStyle="bold"
android:width="240px"
android:height="50px"
android:width="320px"
android:height="100px"
android:textColor="#ffffff"
/>
</TableRow>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:duplicateParentState="false">
<TextView android:text="Select apps for Tor:"
<TextView android:text="Select apps to use with Tor:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="3px" />
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/applistview"></ListView>
<ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/applistview"></ListView>
</LinearLayout>

View File

@ -1,18 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:stretchColumns="1">
<TableRow>
<ImageView android:id="@+id/itemicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="3dip"></ImageView>
<ImageView android:id="@+id/itemicon" android:layout_width="48px" android:layout_height="48px"></ImageView>
<TextView android:layout_height="wrap_content" android:id="@+id/itemtext" android:text="uid:packages" android:textSize="18sp" android:padding="3dip"></TextView>
<TextView android:layout_height="wrap_content" android:id="@+id/itemtext" android:text="uid:packages"
android:layout_width="220px" android:textSize="18sp"></TextView>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/itemcheck" ></CheckBox>
</TableRow>
</TableLayout>
<CheckBox android:layout_width="48px" android:layout_height="48px" android:id="@+id/itemcheck"></CheckBox>
</LinearLayout>

View File

@ -58,8 +58,8 @@
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textStyle="bold"
android:width="240px"
android:height="50px"
android:width="320px"
android:height="100px"
android:textColor="#ffffff"
/>
</TableRow>

View File

@ -12,12 +12,10 @@ import java.util.StringTokenizer;
import org.torproject.android.service.ITorService;
import org.torproject.android.service.ITorServiceCallback;
import org.torproject.android.service.TorServiceConstants;
import org.torproject.android.service.TorTransProxy;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@ -34,18 +32,11 @@ import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
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;
@ -720,9 +711,9 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
if (torStatus == STATUS_ON)
{
imgStatus.setImageResource(R.drawable.toron);
imgStatus.clearAnimation();
// imgStatus.clearAnimation();
String lblMsg = getString(R.string.status_activated) + ": " + torServiceMsg;
String lblMsg = getString(R.string.status_activated) + "\n" + torServiceMsg;
lblStatus.setText(lblMsg);
@ -769,7 +760,7 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
lblStatus.setText(torServiceMsg);
/*
int idx = torServiceMsg.indexOf("%");
if (idx != -1)
@ -778,13 +769,13 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
int ipComp = Integer.parseInt(pComp);
// progressDialog.setProgress(ipComp);
}
}*/
}
else if (torStatus == STATUS_OFF)
{
imgStatus.setImageResource(R.drawable.torstopping);
imgStatus.clearAnimation();
// imgStatus.clearAnimation();
lblStatus.setText(getString(R.string.status_shutting_down));
@ -793,10 +784,10 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
{
imgStatus.clearAnimation();
// imgStatus.clearAnimation();
imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(getString(R.string.status_disabled));
lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start));
@ -827,11 +818,13 @@ public class Orbot extends Activity implements OnClickListener, TorConstants
private void stopTor () throws RemoteException
{
mService.setProfile(PROFILE_ONDEMAND); //these means turn off
if (mService != null)
{
mService.setProfile(PROFILE_ONDEMAND); //these means turn off
Message msg = mHandler.obtainMessage(DISABLE_TOR_MSG);
mHandler.sendMessage(msg);
Message msg = mHandler.obtainMessage(DISABLE_TOR_MSG);
mHandler.sendMessage(msg);
}
}

View File

@ -7,9 +7,12 @@ import org.torproject.android.service.TorServiceUtils;
import org.torproject.android.service.TorTransProxy;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
@ -23,7 +26,6 @@ public class SettingsPreferences
private Preference prefTransProxyApps = null;
private CheckBoxPreference prefHiddenServices = null;
private boolean hasRoot = false;
protected void onCreate(Bundle savedInstanceState)
@ -31,8 +33,19 @@ public class SettingsPreferences
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
hasRoot = TorServiceUtils.checkRootAccess();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.contains("has_root"))
{
hasRoot = prefs.getBoolean("has_root",false);//TorServiceUtils.checkRootAccess();
}
else
{
hasRoot = TorServiceUtils.checkRootAccess();
Editor pEdit = prefs.edit();
pEdit.putBoolean("has_root",hasRoot);
pEdit.commit();
}
}

View File

@ -87,6 +87,12 @@ public class WizardHelper implements TorConstants {
boolean hasRoot = TorServiceUtils.checkRootAccess();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Editor pEdit = prefs.edit();
pEdit.putBoolean("has_root",hasRoot);
pEdit.commit();
if (hasRoot)
{
currentDialog.dismiss();

View File

@ -29,6 +29,7 @@ import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
@ -42,6 +43,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private static int currentStatus = STATUS_READY;
private TorControlConnection conn = null;
private Socket torConnSocket = null;
private static TorService _torInstance;
@ -51,12 +53,12 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private ArrayList<String> configBuffer = null;
private boolean isBound = false;
private String appHome = null;
private String torBinaryPath = null;
private String privoxyPath = null;
private String appHome = "/data/data/" + TOR_APP_USERNAME + "/";;
private String torBinaryPath = appHome + TOR_BINARY_ASSET_KEY;
private String privoxyPath = appHome + PRIVOXY_ASSET_KEY;
private boolean hasRoot = false;
/** Called when the activity is first created. */
@ -83,7 +85,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
initControlConnection();
currentStatus = STATUS_ON;
return true;
@ -124,7 +125,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// logNotice( "onUnbind Called: " + intent.getAction());
isBound = false;
return super.onUnbind(intent);
@ -172,7 +173,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
public void onRebind(Intent intent) {
super.onRebind(intent);
isBound = true;
}
@ -182,9 +182,13 @@ public class TorService extends Service implements TorServiceConstants, Runnable
*/
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
hasRoot = TorServiceUtils.checkRootAccess();
try {
checkTorBinaries ();
} catch (Exception e) {
Log.e(TAG, "error checking tor binaries", e);
}
}
public void run ()
@ -272,21 +276,33 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void killTorProcess () throws Exception
{
//android.os.Debug.waitForDebugger();
StringBuilder log = new StringBuilder();
int procId = -1;
if (conn != null)
{
logNotice("Using control port to shutdown Tor");
try {
logNotice("sending SHUTDOWN signal to Tor process");
conn.signal("SHUTDOWN");
//torConnSocket.close();
} catch (Exception e) {
Log.d(TAG,"error shutting down Tor via connection",e);
}
conn = null;
}
StringBuilder log = new StringBuilder();
try //wait a second for this
{ Thread.sleep(1000); }
catch (Exception e) {}
int procId = TorServiceUtils.findProcessId(torBinaryPath);
logNotice("Checking for existing Tor process via path: " + torBinaryPath);
procId = TorServiceUtils.findProcessId(torBinaryPath);
while (procId != -1)
{
@ -298,7 +314,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
procId = TorServiceUtils.findProcessId(torBinaryPath);
}
logNotice("Checking for existing Privoxy process via path: " + privoxyPath);
procId = TorServiceUtils.findProcessId(privoxyPath);
while (procId != -1)
@ -383,15 +401,17 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{
logNotice( "checking Tor binaries");
appHome = "/data/data/" + TOR_APP_USERNAME + "/";
//appHome = getApplicationContext().getFilesDir().getAbsolutePath();
//appHome = getApplicationContext().getFilesDir().getAbsolutePath();
appHome = "/data/data/" + TOR_APP_USERNAME + "/";
logNotice( "appHome=" + appHome);
logNotice( "appHome=" + appHome);
torBinaryPath = appHome + TOR_BINARY_ASSET_KEY;
privoxyPath = appHome + PRIVOXY_ASSET_KEY;
logNotice( "checking Tor binaries");
String apkPath = findAPK();
logNotice( "found apk at: " + apkPath);
boolean apkExists = new File(apkPath).exists();
@ -400,11 +420,11 @@ public class TorService extends Service implements TorServiceConstants, Runnable
{
Log.w(TAG,"APK file not found at: " + apkPath);
Log.w(TAG,"Binary installation aborted");
logNotice(getString(R.string.status_install_fail));
sendCallbackStatusMessage(getString(R.string.status_install_fail));
return false;
}
torBinaryPath = appHome + TOR_BINARY_ASSET_KEY;
privoxyPath = appHome + PRIVOXY_ASSET_KEY;
boolean torBinaryExists = new File(torBinaryPath).exists();
boolean privoxyBinaryExists = new File(privoxyPath).exists();
@ -440,12 +460,10 @@ public class TorService extends Service implements TorServiceConstants, Runnable
else
{
logNotice("Found Tor binary: " + torBinaryPath);
logNotice("Found Privoxy binary: " + privoxyPath);
}
StringBuilder log = new StringBuilder ();
logNotice("(re)Setting permission on Tor binary");
@ -455,7 +473,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
logNotice("(re)Setting permission on Privoxy binary");
String[] cmd2 = {SHELL_CMD_CHMOD + ' ' + CHMOD_EXE_VALUE + ' ' + privoxyPath};
TorServiceUtils.doShellCommand(cmd2, log, false, true);
return true;
}
@ -472,25 +490,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
killTorProcess ();
checkTorBinaries ();
new Thread()
{
public void run ()
{
try {
runPrivoxyShellCmd();
} catch (Exception e) {
currentStatus = STATUS_OFF;
Log.d(TAG,"Unable to start Privoxy: " + e.getMessage(),e);
sendCallbackLogMessage("Unable to start Privoxy: " + e.getMessage());
}
}
}.start();
new Thread()
{
@ -500,6 +499,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
runTorShellCmd();
setupTransProxy(true);
runPrivoxyShellCmd();
} catch (Exception e) {
Log.d(TAG,"Unable to start Tor: " + e.getMessage(),e);
@ -518,34 +520,38 @@ public class TorService extends Service implements TorServiceConstants, Runnable
StringBuilder log = new StringBuilder();
String torrcPath = appHome + TORRC_ASSET_KEY;
String[] torCmd = {torBinaryPath + " -f " + torrcPath + " || exit\n"};
TorServiceUtils.doShellCommand(torCmd, log, false, false);
logNotice( "Starting tor process: " + torCmd[0]);
Thread.sleep(1000);
int procId = TorServiceUtils.findProcessId(torBinaryPath);
boolean runAsRootFalse = false;
boolean waitForProcess = false;
int procId = -1;
int attempts = 0;
int torRetryWaitTimeMS = 5000;
while (procId == -1 && attempts < MAX_START_TRIES)
{
log = new StringBuilder();
logNotice(torCmd[0]);
sendCallbackStatusMessage(getString(R.string.status_starting_up));
TorServiceUtils.doShellCommand(torCmd, log, runAsRootFalse, waitForProcess);
Thread.sleep(torRetryWaitTimeMS);
TorServiceUtils.doShellCommand(torCmd, log, false, false);
procId = TorServiceUtils.findProcessId(torBinaryPath);
logNotice("got tor proc id: " + procId);
if (procId == -1)
{
sendCallbackStatusMessage("Couldn't start Tor process...\n" + log.toString());
Thread.sleep(1000);
sendCallbackStatusMessage(getString(R.string.status_starting_up));
Thread.sleep(3000);
sendCallbackStatusMessage("Couldn't start Tor process.\nretrying..." + log.toString());
Thread.sleep(torRetryWaitTimeMS);
attempts++;
}
@ -637,8 +643,8 @@ public class TorService extends Service implements TorServiceConstants, Runnable
String baseMessage = getString(R.string.tor_process_connecting);
sendCallbackStatusMessage(baseMessage);
Socket s = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
conn = TorControlConnection.getConnection(s);
torConnSocket = new Socket(IP_LOCALHOST, TOR_CONTROL_PORT);
conn = TorControlConnection.getConnection(torConnSocket);
// conn.authenticate(new byte[0]); // See section 3.2
sendCallbackStatusMessage(getString(R.string.tor_process_connecting_step2));
@ -790,7 +796,7 @@ public class TorService extends Service implements TorServiceConstants, Runnable
if (msg.indexOf(TOR_CONTROL_PORT_MSG_BOOTSTRAP_DONE)!=-1)
{
currentStatus = STATUS_ON;
showToolbarNotification (getString(R.string.status_activated),R.drawable.tornotification);
showToolbarNotification (getString(R.string.status_activated),R.drawable.tornotificationon);
}
@ -893,22 +899,21 @@ public class TorService extends Service implements TorServiceConstants, Runnable
// a single interface, you can just return it here without checking
// the Intent.
if (appHome == null)
{
try
{
checkTorBinaries();
findExistingProc ();
_torInstance = this;
}
catch (Exception e)
{
Log.d(TAG,"Unable to check for Tor binaries",e);
return null;
}
}
try
{
checkTorBinaries();
findExistingProc ();
_torInstance = this;
}
catch (Exception e)
{
Log.d(TAG,"Unable to check for Tor binaries",e);
return null;
}
if (ITorService.class.getName().equals(intent.getAction())) {
return mBinder;
@ -1058,7 +1063,6 @@ public class TorService extends Service implements TorServiceConstants, Runnable
private void sendCallbackStatusMessage (String newStatus)
{
sendCallbackLogMessage (newStatus); //we want everything to go to the log!
// Broadcast to all clients the new value.
final int N = mCallbacks.beginBroadcast();
@ -1277,6 +1281,18 @@ public class TorService extends Service implements TorServiceConstants, Runnable
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication());
if (prefs.contains("has_root"))
{
hasRoot = prefs.getBoolean("has_root",false);//TorServiceUtils.checkRootAccess();
}
else
{
hasRoot = TorServiceUtils.checkRootAccess();
Editor pEdit = prefs.edit();
pEdit.putBoolean("has_root",hasRoot);
pEdit.commit();
}
boolean enableTransparentProxy = prefs.getBoolean("pref_transparent", false);
boolean transProxyAll = prefs.getBoolean("pref_transparent_all", false);
@ -1309,12 +1325,9 @@ public class TorService extends Service implements TorServiceConstants, Runnable
}
}
}
else
else if (hasRoot)
{
if (hasRoot)
{
TorTransProxy.purgeIptables(this,AppManager.getApps(this));
}
TorTransProxy.purgeIptables(this,AppManager.getApps(this));
}
return true;

View File

@ -95,32 +95,34 @@ public class TorTransProxy implements TorServiceConstants {
StringBuilder res = new StringBuilder();
int code = -1;
for (int i = 0; i < apps.length; i++)
{
for (int i = 0; i < apps.length; i++)
{
//flush nat for every app
script.append(baseDir);
script.append("iptables -t nat -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -F || exit\n");
script.append("iptables -t filter -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -F || exit\n");
}
String[] cmd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String msg = res.toString();
logNotice(cmd[0] + ";errCode=" + code + ";resp=" + msg);
//flush nat for every app
script.append(baseDir);
script.append("iptables -t nat -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -F || exit\n");
script.append("iptables -t filter -m owner --uid-owner ");
script.append(apps[i].getUid());
script.append(" -F || exit\n");
}
String[] cmd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmd, res, true, true);
String msg = res.toString();
logNotice(cmd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
}
/*
// 9/19/2010 - NF This code is in process... /etc path on System partition
// is read-only on Android for now.
public static int redirectDNSResolvConf () throws Exception
{
StringBuilder script = new StringBuilder();
@ -160,6 +162,7 @@ public class TorTransProxy implements TorServiceConstants {
return code;
}
*/
public static int setTransparentProxyingByApp(Context context, TorifiedApp[] apps, boolean forceAll) throws Exception
{