|
|
|
@ -15,7 +15,6 @@ import org.purplei2p.lightning.BrowserApp;
@@ -15,7 +15,6 @@ import org.purplei2p.lightning.BrowserApp;
|
|
|
|
|
import org.purplei2p.lightning.constant.Constants; |
|
|
|
|
import org.purplei2p.lightning.dialog.BrowserDialog; |
|
|
|
|
import org.purplei2p.lightning.preference.PreferenceManager; |
|
|
|
|
import info.guardianproject.netcipher.proxy.OrbotHelper; |
|
|
|
|
import info.guardianproject.netcipher.webkit.WebkitProxy; |
|
|
|
|
|
|
|
|
|
@Singleton |
|
|
|
@ -30,71 +29,6 @@ public class ProxyUtils {
@@ -30,71 +29,6 @@ public class ProxyUtils {
|
|
|
|
|
BrowserApp.getAppComponent().inject(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* If Orbot/Tor or I2P is installed, prompt the user if they want to enable |
|
|
|
|
* proxying for this session |
|
|
|
|
*/ |
|
|
|
|
public void checkForProxy(@NonNull final Activity activity) { |
|
|
|
|
boolean useProxy = mPreferences.getUseProxy(); |
|
|
|
|
|
|
|
|
|
final boolean orbotInstalled = OrbotHelper.isOrbotInstalled(activity); |
|
|
|
|
boolean orbotChecked = mPreferences.getCheckedForTor(); |
|
|
|
|
boolean orbot = orbotInstalled && !orbotChecked; |
|
|
|
|
|
|
|
|
|
boolean i2pInstalled = true; |
|
|
|
|
boolean i2pChecked = mPreferences.getCheckedForI2P(); |
|
|
|
|
boolean i2p = i2pInstalled && !i2pChecked; |
|
|
|
|
|
|
|
|
|
// TODO Is the idea to show this per-session, or only once?
|
|
|
|
|
if (!useProxy && (orbot || i2p)) { |
|
|
|
|
if (orbot) mPreferences.setCheckedForTor(true); |
|
|
|
|
if (i2p) mPreferences.setCheckedForI2P(true); |
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity); |
|
|
|
|
|
|
|
|
|
if (orbotInstalled && i2pInstalled) { |
|
|
|
|
String[] proxyChoices = activity.getResources().getStringArray(R.array.proxy_choices_array); |
|
|
|
|
builder.setTitle(activity.getResources().getString(R.string.http_proxy)) |
|
|
|
|
.setSingleChoiceItems(proxyChoices, mPreferences.getProxyChoice(), |
|
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
mPreferences.setProxyChoice(which); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.setPositiveButton(activity.getResources().getString(R.string.action_ok), |
|
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
if (mPreferences.getUseProxy()) |
|
|
|
|
initializeProxy(activity); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
|
@Override |
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
switch (which) { |
|
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
|
mPreferences.setProxyChoice(orbotInstalled ? |
|
|
|
|
Constants.PROXY_ORBOT : Constants.PROXY_I2P); |
|
|
|
|
initializeProxy(activity); |
|
|
|
|
break; |
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
|
mPreferences.setProxyChoice(Constants.NO_PROXY); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
builder.setMessage(orbotInstalled ? R.string.use_tor_prompt : R.string.use_i2p_prompt) |
|
|
|
|
.setPositiveButton(R.string.yes, dialogClickListener) |
|
|
|
|
.setNegativeButton(R.string.no, dialogClickListener); |
|
|
|
|
} |
|
|
|
|
Dialog dialog = builder.show(); |
|
|
|
|
BrowserDialog.setDialogSize(activity, dialog); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* Initialize WebKit Proxying |
|
|
|
|
*/ |
|
|
|
@ -107,9 +41,6 @@ public class ProxyUtils {
@@ -107,9 +41,6 @@ public class ProxyUtils {
|
|
|
|
|
// We shouldn't be here
|
|
|
|
|
return; |
|
|
|
|
case Constants.PROXY_ORBOT: |
|
|
|
|
if (!OrbotHelper.isOrbotRunning(activity)) { |
|
|
|
|
OrbotHelper.requestStartTor(activity); |
|
|
|
|
} |
|
|
|
|
host = "localhost"; |
|
|
|
|
port = 8118; |
|
|
|
|
break; |
|
|
|
@ -117,17 +48,15 @@ public class ProxyUtils {
@@ -117,17 +48,15 @@ public class ProxyUtils {
|
|
|
|
|
host = "localhost"; |
|
|
|
|
port = 4444; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
host = mPreferences.getProxyHost(); |
|
|
|
|
port = mPreferences.getProxyPort(); |
|
|
|
|
break; |
|
|
|
|
case Constants.PROXY_MANUAL: |
|
|
|
|
default: |
|
|
|
|
host = mPreferences.getProxyHost(); |
|
|
|
|
port = mPreferences.getProxyPort(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
Log.i(TAG, "trying enable web proxying with host = " + host + " and port = " + port); |
|
|
|
|
WebkitProxy.setProxy(BrowserApp.class.getName(), activity.getApplicationContext(), null, host, port); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
Log.d(TAG, "error enabling web proxying", e); |
|
|
|
@ -155,10 +84,6 @@ public class ProxyUtils {
@@ -155,10 +84,6 @@ public class ProxyUtils {
|
|
|
|
|
public static int setProxyChoice(int choice, @NonNull Activity activity) { |
|
|
|
|
switch (choice) { |
|
|
|
|
case Constants.PROXY_ORBOT: |
|
|
|
|
if (!OrbotHelper.isOrbotInstalled(activity)) { |
|
|
|
|
choice = Constants.NO_PROXY; |
|
|
|
|
Utils.showSnackbar(activity, R.string.install_orbot); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case Constants.PROXY_I2P: |
|
|
|
|
break; |
|
|
|
|