1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-24 13:22:08 +01:00

Precautionary set Orbot proxy, if configured to do so. Handle errors like Orbot not installed/running etc. afterwards.

This commit is contained in:
vanitasvitae 2016-06-06 11:50:04 +02:00
parent 7618e1529f
commit 68d7bdaa40
2 changed files with 25 additions and 9 deletions

View file

@ -179,11 +179,15 @@ public class MainActivity extends AppCompatActivity
podUserProfile.setListener(this);
//Orbot integration
OrbotStatusReceiver.setMainActivity(this);
OrbotHelper.requestStartTor(this.getApplicationContext());
if(appSettings.isProxyOrbot()) {
if(!OrbotHelper.isOrbotInstalled(this)) {
appSettings.setProxyOrbot(false);
promptInstallOrbot();
} else {
//precautionary set Proxy
OrbotStatusReceiver.setProxy(this.getApplicationContext(), OrbotStatusReceiver.defaultHost, OrbotStatusReceiver.defaultPort);
}
}

View file

@ -40,8 +40,11 @@ import info.guardianproject.netcipher.web.WebkitProxy;
*/
public class OrbotStatusReceiver extends BroadcastReceiver {
public static final String defaultHost = "127.0.0.1";
public static final int defaultPort = 8118;
private Intent lastStatus;
private Context lastContext;
private static MainActivity mainActivity;
private AppSettings appSettings;
private static boolean proxySet = false;
@ -63,6 +66,7 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
OrbotHelper.requestStartTor(context.getApplicationContext());
} else if(orbotStatus.equals(OrbotHelper.STATUS_STARTS_DISABLED)) {
Log.d(App.TAG, "Warning: Orbot has background starts disabled.");
if(mainActivity != null) mainActivity.requestOrbotStart(true);
}
}
} else {
@ -74,21 +78,25 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
if(intent != null) {
String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
if(status.equals(OrbotHelper.STATUS_ON)) {
try {
NetCipher.setProxy("127.0.0.1", 8118);
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), null, "127.0.0.1", 8118);
Log.d(App.TAG, "Proxy successfully set.");
proxySet = true;
} catch(Exception e) {
Log.e(App.TAG, "setProxy failed: ");
e.printStackTrace();
}
setProxy(context, defaultHost, defaultPort);
}
} else {
Log.e(App.TAG, "OrbotStatusReceiver: lastStatus intent is null. Cannot set Proxy.");
}
}
public static void setProxy(Context context, String host, int port) {
try {
NetCipher.setProxy(host, port);
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), null, host, port);
Log.d(App.TAG, "Proxy successfully set.");
proxySet = true;
} catch(Exception e) {
Log.e(App.TAG, "setProxy failed: ");
e.printStackTrace();
}
}
public static void resetProxy(Context context) {
try {
NetCipher.clearProxy();
@ -108,4 +116,8 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
public static boolean isProxySet() {
return proxySet;
}
public static void setMainActivity(MainActivity main) {
mainActivity = main;
}
}