diff --git a/lint.xml b/lint.xml index ee0eead..7edd00c 100644 --- a/lint.xml +++ b/lint.xml @@ -1,3 +1,4 @@ + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 2b071a3..e148cd0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -159,5 +159,9 @@ AdBlock AdBlock is currently only available in the browser\'s paid version, Lightning Browser+. It is available to download on Google Play. Enable Orbot + It looks like you have Orbot installed. Do you want to use Tor? + Please install Orbot in order to proxy with Tor. + Yes + No \ No newline at end of file diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 6449d3b..d77e023 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/src/acr/browser/lightning/BrowserActivity.java @@ -455,12 +455,48 @@ public class BrowserActivity extends Activity implements BrowserController { PreferenceConstants.USE_PROXY, false); OrbotHelper oh = new OrbotHelper(this); - if (oh.isOrbotInstalled() & useProxy == true) { + if (oh.isOrbotInstalled() + && !mPreferences.getBoolean( + PreferenceConstants.INITIAL_CHECK_FOR_TOR, false)) { + mEditPrefs.putBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, + true); + mEditPrefs.apply(); + DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + mPreferences + .edit() + .putBoolean(PreferenceConstants.USE_PROXY, true) + .apply(); + + initializeTor(); + break; + case DialogInterface.BUTTON_NEGATIVE: + mPreferences + .edit() + .putBoolean(PreferenceConstants.USE_PROXY, + false).apply(); + break; + } + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(R.string.use_tor_prompt) + .setPositiveButton(R.string.yes, dialogClickListener) + .setNegativeButton(R.string.no, dialogClickListener).show(); + + return true; + } else if (oh.isOrbotInstalled() & useProxy == true) { initializeTor(); return true; + } else { + mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, false); + mEditPrefs.apply(); + return false; } - - return false; } /* @@ -471,7 +507,7 @@ public class BrowserActivity extends Activity implements BrowserController { OrbotHelper oh = new OrbotHelper(this); if (!oh.isOrbotRunning()) oh.requestOrbotStart(this); - + WebkitProxy wkp = new WebkitProxy(); try { String host = mPreferences.getString( @@ -483,6 +519,7 @@ public class BrowserActivity extends Activity implements BrowserController { } catch (Exception e) { Log.d(Constants.LOGTAG, "error enabling web proxying", e); } + } /* @@ -587,7 +624,17 @@ public class BrowserActivity extends Activity implements BrowserController { } updateCookiePreference(); - + if (mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false)) { + initializeTor(); + } else { + try { + WebkitProxy.resetProxy("acr.browser.lightning.BrowserApp", + getApplicationContext()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } /* @@ -2415,7 +2462,7 @@ public class BrowserActivity extends Activity implements BrowserController { } } - //Override this, use finish() for Incognito, moveTaskToBack for Main + // Override this, use finish() for Incognito, moveTaskToBack for Main public void closeActivity() { finish(); } diff --git a/src/acr/browser/lightning/PreferenceConstants.java b/src/acr/browser/lightning/PreferenceConstants.java index 948a83d..b2f9844 100644 --- a/src/acr/browser/lightning/PreferenceConstants.java +++ b/src/acr/browser/lightning/PreferenceConstants.java @@ -35,4 +35,5 @@ public class PreferenceConstants { public static final String USE_PROXY = "useProxy"; public static final String USE_PROXY_HOST = "useProxyHost"; public static final String USE_PROXY_PORT = "useProxyPort"; + public static final String INITIAL_CHECK_FOR_TOR = "checkForTor"; } diff --git a/src/acr/browser/lightning/SettingsActivity.java b/src/acr/browser/lightning/SettingsActivity.java index a0f2e8a..ed8009a 100644 --- a/src/acr/browser/lightning/SettingsActivity.java +++ b/src/acr/browser/lightning/SettingsActivity.java @@ -3,6 +3,7 @@ */ package acr.browser.lightning; +import info.guardianproject.onionkit.ui.OrbotHelper; import android.net.Uri; import android.os.Bundle; import android.os.Environment; @@ -230,6 +231,7 @@ public class SettingsActivity extends Activity { } adblock.setChecked(mPreferences.getBoolean( PreferenceConstants.BLOCK_ADS, false)); + orbot.setChecked(mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false)); initSwitch(location, fullScreen, flash, adblock, orbot); clickListenerForSwitches(layoutLocation, layoutFullScreen, layoutFlash, @@ -361,8 +363,9 @@ public class SettingsActivity extends Activity { public void clickListenerForSwitches(RelativeLayout one, RelativeLayout two, RelativeLayout three, - RelativeLayout layoutBlockAds, RelativeLayout layoutOrbot, final Switch loc, final Switch full, - final Switch flash, final Switch adblock, final Switch orbot) { + RelativeLayout layoutBlockAds, RelativeLayout layoutOrbot, + final Switch loc, final Switch full, final Switch flash, + final Switch adblock, final Switch orbot) { layoutBlockAds.setOnClickListener(new OnClickListener() { @Override @@ -405,7 +408,12 @@ public class SettingsActivity extends Activity { @Override public void onClick(View v) { - orbot.setChecked(!orbot.isChecked()); + if (orbot.isEnabled()) { + orbot.setChecked(!orbot.isChecked()); + } else { + Utils.showToast(mContext, + getResources().getString(R.string.install_orbot)); + } } }); @@ -509,13 +517,17 @@ public class SettingsActivity extends Activity { } }); + OrbotHelper oh = new OrbotHelper(this); + if (!oh.isOrbotInstalled()) { + orbot.setEnabled(false); + } + orbot.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, - isChecked); + mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, isChecked); mEditPrefs.commit(); }