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:
parent
bb0bf6d93b
commit
523664487e
2 changed files with 11 additions and 12 deletions
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
try {
|
|
||||||
OrbotStatusReceiver.host = host;
|
OrbotStatusReceiver.host = host;
|
||||||
OrbotStatusReceiver.port = port;
|
OrbotStatusReceiver.port = port;
|
||||||
NetCipher.setProxy(host, port);
|
NetCipher.setProxy(host, port);
|
||||||
|
try {
|
||||||
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;
|
||||||
try {
|
|
||||||
OrbotStatusReceiver.host = "";
|
OrbotStatusReceiver.host = "";
|
||||||
OrbotStatusReceiver.port = 0;
|
OrbotStatusReceiver.port = 0;
|
||||||
NetCipher.clearProxy();
|
NetCipher.clearProxy();
|
||||||
|
try {
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue