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:
parent
7618e1529f
commit
68d7bdaa40
2 changed files with 25 additions and 9 deletions
|
@ -179,11 +179,15 @@ public class MainActivity extends AppCompatActivity
|
||||||
podUserProfile.setListener(this);
|
podUserProfile.setListener(this);
|
||||||
|
|
||||||
//Orbot integration
|
//Orbot integration
|
||||||
|
OrbotStatusReceiver.setMainActivity(this);
|
||||||
OrbotHelper.requestStartTor(this.getApplicationContext());
|
OrbotHelper.requestStartTor(this.getApplicationContext());
|
||||||
if(appSettings.isProxyOrbot()) {
|
if(appSettings.isProxyOrbot()) {
|
||||||
if(!OrbotHelper.isOrbotInstalled(this)) {
|
if(!OrbotHelper.isOrbotInstalled(this)) {
|
||||||
appSettings.setProxyOrbot(false);
|
appSettings.setProxyOrbot(false);
|
||||||
promptInstallOrbot();
|
promptInstallOrbot();
|
||||||
|
} else {
|
||||||
|
//precautionary set Proxy
|
||||||
|
OrbotStatusReceiver.setProxy(this.getApplicationContext(), OrbotStatusReceiver.defaultHost, OrbotStatusReceiver.defaultPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,11 @@ import info.guardianproject.netcipher.web.WebkitProxy;
|
||||||
*/
|
*/
|
||||||
public class OrbotStatusReceiver extends BroadcastReceiver {
|
public class OrbotStatusReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
public static final String defaultHost = "127.0.0.1";
|
||||||
|
public static final int defaultPort = 8118;
|
||||||
private Intent lastStatus;
|
private Intent lastStatus;
|
||||||
private Context lastContext;
|
private Context lastContext;
|
||||||
|
private static MainActivity mainActivity;
|
||||||
private AppSettings appSettings;
|
private AppSettings appSettings;
|
||||||
private static boolean proxySet = false;
|
private static boolean proxySet = false;
|
||||||
|
|
||||||
|
@ -63,6 +66,7 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
||||||
OrbotHelper.requestStartTor(context.getApplicationContext());
|
OrbotHelper.requestStartTor(context.getApplicationContext());
|
||||||
} else if(orbotStatus.equals(OrbotHelper.STATUS_STARTS_DISABLED)) {
|
} else if(orbotStatus.equals(OrbotHelper.STATUS_STARTS_DISABLED)) {
|
||||||
Log.d(App.TAG, "Warning: Orbot has background starts disabled.");
|
Log.d(App.TAG, "Warning: Orbot has background starts disabled.");
|
||||||
|
if(mainActivity != null) mainActivity.requestOrbotStart(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,21 +78,25 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
||||||
if(intent != null) {
|
if(intent != null) {
|
||||||
String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
|
String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
|
||||||
if(status.equals(OrbotHelper.STATUS_ON)) {
|
if(status.equals(OrbotHelper.STATUS_ON)) {
|
||||||
try {
|
setProxy(context, defaultHost, defaultPort);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(App.TAG, "OrbotStatusReceiver: lastStatus intent is null. Cannot set Proxy.");
|
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) {
|
public static void resetProxy(Context context) {
|
||||||
try {
|
try {
|
||||||
NetCipher.clearProxy();
|
NetCipher.clearProxy();
|
||||||
|
@ -108,4 +116,8 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
||||||
public static boolean isProxySet() {
|
public static boolean isProxySet() {
|
||||||
return proxySet;
|
return proxySet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setMainActivity(MainActivity main) {
|
||||||
|
mainActivity = main;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue