Author: n8fr8 Date: 2011-05-10 02:08:16 +0000 (Tue, 10 May 2011) New Revision: 24735
Modified: projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java Log: fixed onboot handling and updated transproxy
Modified: projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java =================================================================== --- projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java 2011-05-10 01:43:30 UTC (rev 24734) +++ projects/android/trunk/Orbot/src/org/torproject/android/OnBootReceiver.java 2011-05-10 02:08:16 UTC (rev 24735) @@ -1,5 +1,7 @@ package org.torproject.android;
+import org.torproject.android.service.TorService; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -8,10 +10,18 @@ @Override 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); + } + + }
Modified: projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java =================================================================== --- projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java 2011-05-10 01:43:30 UTC (rev 24734) +++ projects/android/trunk/Orbot/src/org/torproject/android/Orbot.java 2011-05-10 02:08:16 UTC (rev 24735) @@ -68,7 +68,6 @@
//if Tor binary is not running, then start the service up startService(new Intent(INTENT_TOR_SERVICE)); - bindService ();
setTheme(android.R.style.Theme_Black_NoTitleBar); @@ -81,6 +80,9 @@ lblStatus.setOnLongClickListener(this); imgStatus = (ImageView)findViewById(R.id.imgStatus); imgStatus.setOnLongClickListener(this); + + + }
/* @@ -248,13 +250,10 @@ protected void onPause() { super.onPause(); - if (progressDialog != null) - { - progressDialog.dismiss(); - progressDialog = null; - } - + hideProgressDialog();
+ if (aDialog != null) + aDialog.dismiss(); }
public void onSaveInstanceState(Bundle savedInstanceState) { @@ -333,6 +332,8 @@ protected void onResume() { super.onResume(); + bindService(); + updateStatus(""); if (getIntent() == null) @@ -423,7 +424,6 @@ updateStatus (""); - }
/* (non-Javadoc) @@ -432,7 +432,7 @@ protected void onStop() { super.onStop(); - unbindService(); + //unbindService(); }
@@ -478,13 +478,20 @@ } } + AlertDialog aDialog = null; + 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) { - aDialog = new AlertDialog.Builder(this) + aDialog = new AlertDialog.Builder(this) .setIcon(R.drawable.icon) .setTitle(title) .setMessage(msg) @@ -520,13 +527,8 @@ { imgStatus.setImageResource(R.drawable.toron);
- if (progressDialog != null) - { - progressDialog.dismiss(); - progressDialog = null; - } + hideProgressDialog(); - String lblMsg = getString(R.string.status_activated); //+ "\n" + torServiceMsg; @@ -571,11 +573,8 @@ { imgStatus.setImageResource(R.drawable.toroff); - if (progressDialog != null) - { - progressDialog.dismiss(); - progressDialog = null; - } + + hideProgressDialog(); lblStatus.setText(getString(R.string.status_shutting_down)); @@ -585,11 +584,8 @@ else {
- if (progressDialog != null) - { - progressDialog.dismiss(); - progressDialog = null; - } + + hideProgressDialog(); imgStatus.setImageResource(R.drawable.toroff); lblStatus.setText(getString(R.string.status_disabled) + "\n" + getString(R.string.press_to_start)); @@ -612,6 +608,8 @@ private void startTor () throws RemoteException { + bindService(); + mService.setProfile(TorServiceConstants.PROFILE_ON); //this means turn on imgStatus.setImageResource(R.drawable.torstarting); @@ -633,9 +631,7 @@ mHandler.sendMessage(msg); } - // stopService(new Intent(ITorService.class.getName())); - - + }
/* @@ -655,8 +651,9 @@ else if (mService.getStatus() == STATUS_READY) { + createProgressDialog(getString(R.string.status_starting_up)); + startTor(); - } else { @@ -721,7 +718,6 @@ break; case TorServiceConstants.ENABLE_TOR_MSG: - createProgressDialog(getString(R.string.status_starting_up)); updateStatus((String)msg.getData().getString(HANDLER_TOR_MSG)); @@ -737,17 +733,8 @@ } }
- private synchronized void createProgressDialog (String msg) - { - if (progressDialog == null) - { - progressDialog = ProgressDialog.show(Orbot.this, "", msg); - - progressDialog.setCancelable(true); - } - - }
+ };
@@ -811,8 +798,6 @@ mIsBound = true;
- - }
private void unbindService () @@ -837,4 +822,25 @@ } } + 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(); + + } + + + } }
Modified: projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java =================================================================== --- projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2011-05-10 01:43:30 UTC (rev 24734) +++ projects/android/trunk/Orbot/src/org/torproject/android/service/TorTransProxy.java 2011-05-10 02:08:16 UTC (rev 24735) @@ -313,6 +313,49 @@ 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 { boolean runRoot = true; @@ -329,6 +372,8 @@ purgeIptables(context); + //enableWifiHotspotRules(context); + int torUid = context.getApplicationInfo().uid;
// Set up port redirection
tor-commits@lists.torproject.org