1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-04 19:46:01 +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.SpannableString;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -166,7 +165,6 @@ public class MainActivity extends AppCompatActivity
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT >= 21) if (android.os.Build.VERSION.SDK_INT >= 21)
WebView.enableSlowWholeDocumentDraw(); WebView.enableSlowWholeDocumentDraw();

View file

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