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

Swap some method calls to harden proxy setting

This commit is contained in:
vanitasvitae 2016-06-06 19:12:50 +02:00
parent bb0bf6d93b
commit 523664487e
2 changed files with 11 additions and 12 deletions

View file

@ -52,7 +52,6 @@ import android.text.Html;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@ -166,7 +165,6 @@ public class MainActivity extends AppCompatActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= 21)
WebView.enableSlowWholeDocumentDraw();

View file

@ -111,13 +111,13 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
}
public static void setProxy(Context context, String host, int port) {
try {
OrbotStatusReceiver.host = host;
OrbotStatusReceiver.port = port;
NetCipher.setProxy(host, port);
try {
WebkitProxy.setProxy(MainActivity.class.getName(), context.getApplicationContext(), null, host, port);
Log.d(App.TAG, "Proxy successfully set.");
proxySet = true;
Log.d(App.TAG, "Proxy successfully set.");
} catch(Exception e) {
Log.e(App.TAG, "setProxy failed: ");
e.printStackTrace();
@ -126,15 +126,16 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
public static void resetProxy(Context context) {
promptOnBackgroundStart = true;
try {
OrbotStatusReceiver.host = "";
OrbotStatusReceiver.port = 0;
NetCipher.clearProxy();
try {
WebkitProxy.resetProxy(MainActivity.class.getName(), context.getApplicationContext());
proxySet = false;
Log.d(App.TAG, "Proxy reset");
} catch (Exception e) {
//Fails in any case on android 6. Ignore it and restart application.
}
proxySet = false;
//Restart application
Intent restartActivity = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 12374, restartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
@ -154,9 +155,9 @@ public class OrbotStatusReceiver extends BroadcastReceiver {
*/
public static boolean isInCorrectState(boolean orbotProxyActive) {
if(orbotProxyActive) {
return host != null && !host.equals("") && port > 0 && proxySet;
return host != null && !host.equals("") && port > 0 && isProxySet();
} else {
return (host.equals("") || host == null) && port < 1 && !proxySet;
return (host.equals("") || host == null) && port < 1 && !isProxySet();
}
}
}