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);
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,9 +78,17 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
|||
if(intent != null) {
|
||||
String status = intent.getStringExtra(OrbotHelper.EXTRA_STATUS);
|
||||
if(status.equals(OrbotHelper.STATUS_ON)) {
|
||||
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("127.0.0.1", 8118);
|
||||
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), null, "127.0.0.1", 8118);
|
||||
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) {
|
||||
|
@ -84,10 +96,6 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.e(App.TAG, "OrbotStatusReceiver: lastStatus intent is null. Cannot set Proxy.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetProxy(Context context) {
|
||||
try {
|
||||
|
@ -108,4 +116,8 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
|
|||
public static boolean isProxySet() {
|
||||
return proxySet;
|
||||
}
|
||||
|
||||
public static void setMainActivity(MainActivity main) {
|
||||
mainActivity = main;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue