fixed onboot handling and updated transproxy

svn:r24735
This commit is contained in:
Nathan Freitas 2011-05-10 02:08:16 +00:00
parent 87016a51b7
commit 7be11d01f2
3 changed files with 108 additions and 47 deletions

View File

@ -1,5 +1,7 @@
package org.torproject.android; package org.torproject.android;
import org.torproject.android.service.TorService;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -8,10 +10,18 @@ public class OnBootReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("org.torproject.android.service.TorService");
context.startService(serviceIntent);
if (intent.getAction() != null
&& intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
{
//Phase 1: Launch a service
Intent service = new Intent();
service.setAction("onboot");
service.setClass(context, TorService.class);
context.startService(service);
}
} }

View File

@ -68,7 +68,6 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
//if Tor binary is not running, then start the service up //if Tor binary is not running, then start the service up
startService(new Intent(INTENT_TOR_SERVICE)); startService(new Intent(INTENT_TOR_SERVICE));
bindService ();
setTheme(android.R.style.Theme_Black_NoTitleBar); setTheme(android.R.style.Theme_Black_NoTitleBar);
@ -81,6 +80,9 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
lblStatus.setOnLongClickListener(this); lblStatus.setOnLongClickListener(this);
imgStatus = (ImageView)findViewById(R.id.imgStatus); imgStatus = (ImageView)findViewById(R.id.imgStatus);
imgStatus.setOnLongClickListener(this); imgStatus.setOnLongClickListener(this);
} }
/* /*
@ -248,13 +250,10 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
if (progressDialog != null) hideProgressDialog();
{
progressDialog.dismiss();
progressDialog = null;
}
if (aDialog != null)
aDialog.dismiss();
} }
public void onSaveInstanceState(Bundle savedInstanceState) { public void onSaveInstanceState(Bundle savedInstanceState) {
@ -333,6 +332,8 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
bindService();
updateStatus(""); updateStatus("");
if (getIntent() == null) if (getIntent() == null)
@ -423,7 +424,6 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
updateStatus (""); updateStatus ("");
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -432,7 +432,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
unbindService(); //unbindService();
} }
@ -478,13 +478,20 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
} }
} }
AlertDialog aDialog = null;
private void showAlert(String title, String msg, boolean button) private void showAlert(String title, String msg, boolean button)
{ {
AlertDialog aDialog = null; try
{
if (aDialog != null && aDialog.isShowing())
aDialog.dismiss();
}
catch (Exception e){} //swallow any errors
if (button) if (button)
{ {
aDialog = new AlertDialog.Builder(this) aDialog = new AlertDialog.Builder(this)
.setIcon(R.drawable.icon) .setIcon(R.drawable.icon)
.setTitle(title) .setTitle(title)
.setMessage(msg) .setMessage(msg)
@ -520,12 +527,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
{ {
imgStatus.setImageResource(R.drawable.toron); imgStatus.setImageResource(R.drawable.toron);
if (progressDialog != null) hideProgressDialog();
{
progressDialog.dismiss();
progressDialog = null;
}
String lblMsg = getString(R.string.status_activated); String lblMsg = getString(R.string.status_activated);
//+ "\n" + torServiceMsg; //+ "\n" + torServiceMsg;
@ -571,11 +573,8 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
{ {
imgStatus.setImageResource(R.drawable.toroff); imgStatus.setImageResource(R.drawable.toroff);
if (progressDialog != null)
{ hideProgressDialog();
progressDialog.dismiss();
progressDialog = null;
}
lblStatus.setText(getString(R.string.status_shutting_down)); lblStatus.setText(getString(R.string.status_shutting_down));
@ -585,11 +584,8 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
else else
{ {
if (progressDialog != null)
{ hideProgressDialog();
progressDialog.dismiss();
progressDialog = null;
}
imgStatus.setImageResource(R.drawable.toroff); imgStatus.setImageResource(R.drawable.toroff);
lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start)); lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start));
@ -612,6 +608,8 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
private void startTor () throws RemoteException private void startTor () throws RemoteException
{ {
bindService();
mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on
imgStatus.setImageResource(R.drawable.torstarting); imgStatus.setImageResource(R.drawable.torstarting);
@ -633,9 +631,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
mHandler.sendMessage(msg); mHandler.sendMessage(msg);
} }
// stopService(new Intent(ITorService.class.getName()));
} }
/* /*
@ -655,8 +651,9 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
else if (mService.getStatus() == STATUS_READY) else if (mService.getStatus() == STATUS_READY)
{ {
createProgressDialog(getString(R.string.status_starting_up));
startTor(); startTor();
} }
else else
{ {
@ -721,7 +718,6 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
break; break;
case TorServiceConstants.ENABLE_TOR_MSG: case TorServiceConstants.ENABLE_TOR_MSG:
createProgressDialog(getString(R.string.status_starting_up));
updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG)); updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG));
@ -737,16 +733,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
} }
} }
private synchronized void createProgressDialog (String msg)
{
if (progressDialog == null)
{
progressDialog = ProgressDialog.show(Orbot.this, "", msg);
progressDialog.setCancelable(true);
}
}
}; };
@ -811,8 +798,6 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
mIsBound = true; mIsBound = true;
} }
private void unbindService () private void unbindService ()
@ -837,4 +822,25 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
} }
} }
private void createProgressDialog (String msg)
{
if (progressDialog != null && progressDialog.isShowing())
return;
progressDialog = ProgressDialog.show(Orbot.this, "", msg);
progressDialog.setCancelable(true);
}
private void hideProgressDialog ()
{
if (progressDialog != null && progressDialog.isShowing())
{
progressDialog.dismiss();
}
}
} }

View File

@ -313,6 +313,49 @@ public class TorTransProxy implements TorServiceConstants {
return code; return code;
} }
public static int enableWifiHotspotRules (Context context) throws Exception
{
boolean runRoot = true;
boolean waitFor = true;
//redirectDNSResolvConf(); //not working yet
String ipTablesPath = new File(context.getDir("bin", 0),"iptables").getAbsolutePath();
StringBuilder script = new StringBuilder();
StringBuilder res = new StringBuilder();
int code = -1;
script.append(ipTablesPath);
script.append(" -I FORWARD");
script.append(" -m state --state ESTABLISHED,RELATED -j ACCEPT");
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -I FORWARD");
script.append(" -s 192.168.43.0/24 -j ACCEPT");
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -P FORWARD DROP");
script.append(" || exit\n");
script.append(ipTablesPath);
script.append(" -t nat -I POSTROUTING -s 192.168.43.0/24 -j MASQUERADE");
script.append(" || exit\n");
String[] cmdAdd = {script.toString()};
code = TorServiceUtils.doShellCommand(cmdAdd, res, runRoot, waitFor);
String msg = res.toString();
TorService.logMessage(cmdAdd[0] + ";errCode=" + code + ";resp=" + msg);
return code;
}
public static int setTransparentProxyingAll(Context context) throws Exception public static int setTransparentProxyingAll(Context context) throws Exception
{ {
boolean runRoot = true; boolean runRoot = true;
@ -329,6 +372,8 @@ public class TorTransProxy implements TorServiceConstants {
purgeIptables(context); purgeIptables(context);
//enableWifiHotspotRules(context);
int torUid = context.getApplicationInfo().uid; int torUid = context.getApplicationInfo().uid;
// Set up port redirection // Set up port redirection