From c1fe536aeb482d88231c745757cdfddd6a9f3ac0 Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Sun, 1 Feb 2015 23:36:19 -0500 Subject: [PATCH] add button handle logic --- src/org/torproject/android/Orbot.java | 36 +++++++++++-------- .../android/vpn/OrbotVpnService.java | 25 ++++++++----- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/org/torproject/android/Orbot.java b/src/org/torproject/android/Orbot.java index a55f53ed..edb3c09d 100644 --- a/src/org/torproject/android/Orbot.java +++ b/src/org/torproject/android/Orbot.java @@ -65,10 +65,10 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic private MenuItem mItemOnOff = null; private TextView downloadText = null; private TextView uploadText = null; - // private TextView mTxtOrbotLog = null; - // private SlidingDrawer mDrawer = null; private boolean mDrawerOpen = false; - // private View mViewMain = null; + + private Button mBtnBrowser = null; + private Button mBtnVPN = null; /* Some tracking bits */ private int torStatus = TorServiceConstants.STATUS_OFF; //latest status reported from the tor service @@ -174,7 +174,7 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic private void doLayout () { setContentView(R.layout.layout_main); - + // lblStatus = (TextView)findViewById(R.id.lblStatus); // lblStatus.setOnLongClickListener(this); imgStatus = (ImageProgressView)findViewById(R.id.imgStatus); @@ -230,8 +230,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic // Gesture detection mGestureDetector = new GestureDetector(this, new MyGestureDetector()); - Button btnBrowser = (Button)findViewById(R.id.btnBrowser); - btnBrowser.setOnClickListener(new View.OnClickListener () + mBtnBrowser = (Button)findViewById(R.id.btnBrowser); + mBtnBrowser.setOnClickListener(new View.OnClickListener () { @Override @@ -243,8 +243,8 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic }); - Button btnVPN = (Button)findViewById(R.id.btnVPN); - btnVPN.setOnClickListener(new View.OnClickListener () + mBtnVPN = (Button)findViewById(R.id.btnVPN); + mBtnVPN.setOnClickListener(new View.OnClickListener () { @Override @@ -401,10 +401,6 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic startActivity(new Intent(this, ChooseLocaleWizardActivity.class)); } - else if (item.getItemId() == R.id.menu_verify) - { - doTorCheck(); - } else if (item.getItemId() == R.id.menu_exit) { //exit app @@ -418,12 +414,18 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic } + + /** + else if (item.getItemId() == R.id.menu_verify) + { + doTorCheck(); + } else if (item.getItemId() == R.id.menu_vpn) { startVpnService(); - } + }*/ - return true; + return true; } /** @@ -901,6 +903,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic imgStatus.setImageResource(R.drawable.toron); + mBtnBrowser.setEnabled(true); + mBtnVPN.setEnabled(true); + String lblMsg = getString(R.string.status_activated); //lblStatus.setText(lblMsg); @@ -961,6 +966,9 @@ public class Orbot extends ActionBarActivity implements TorConstants, OnLongClic if (mItemOnOff != null) mItemOnOff.setTitle(R.string.menu_start); + + mBtnBrowser.setEnabled(false); + mBtnVPN.setEnabled(false); } } diff --git a/src/org/torproject/android/vpn/OrbotVpnService.java b/src/org/torproject/android/vpn/OrbotVpnService.java index 9a58b663..443bc784 100644 --- a/src/org/torproject/android/vpn/OrbotVpnService.java +++ b/src/org/torproject/android/vpn/OrbotVpnService.java @@ -114,16 +114,25 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { // (i.e., Farsi and Arabic).^M Locale.setDefault(new Locale("en")); + String vpnName = "OrbotVPN"; + String virtualGateway = "10.0.0.1"; + String virtualRoute = "10.0.0.0"; + String virtualIP = "10.0.0.2"; + String virtualNetMask = "255.255.2555.0"; + String localSocks = "localhost:" + TorServiceConstants.PORT_SOCKS_DEFAULT; + String localDNS = "localhost:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT; + + Builder builder = new Builder(); builder.setMtu(VPN_MTU); - builder.addAddress("10.0.0.1",8); - builder.setSession("OrbotVPN"); + builder.addAddress(virtualGateway,8); + builder.setSession(vpnName); + builder.addRoute("0.0.0.0",0); - builder.addRoute("10.0.0.0",8); - //builder.addRoute("192.0.0.0",8); - //builder.addRoute("192.168.43.0",8); - builder.addDnsServer("8.8.8.8"); + builder.addRoute(virtualRoute,8); + + //builder.addDnsServer("8.8.8.8"); // Create a new interface using the builder and save the parameters. mInterface = builder.setSession(mSessionName) @@ -132,7 +141,7 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { try { - Tun2Socks.Start(mInterface, VPN_MTU, "10.0.0.2", "255.255.255.0", "localhost:" + TorServiceConstants.PORT_SOCKS_DEFAULT, "50.116.51.157:7300", true); + Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true); } catch (Exception e) { @@ -170,7 +179,7 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { /* private void debugPacket(ByteBuffer packet) - { + {b int buffer = packet.get(); int version;