From cd425eb8a5d91d2df760a8eb6318c258afaec3be Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Tue, 18 Apr 2017 21:12:44 +0800 Subject: [PATCH] Added manual edit dns test servers --- .../main/java/org/itxtech/daedalus/Daedalus.java | 16 +++++++++++++++- .../itxtech/daedalus/activity/MainActivity.java | 14 ++------------ .../daedalus/activity/ServerTestActivity.java | 11 ++++++++++- .../daedalus/receiver/BootBroadcastReceiver.java | 11 +++-------- app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/perf_settings.xml | 6 ++++++ 7 files changed, 38 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index 8aeff92..2809d9b 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -4,10 +4,12 @@ import android.app.ActivityManager; import android.app.Application; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.graphics.drawable.Icon; import android.os.Build; +import android.preference.PreferenceManager; import android.util.Log; import org.itxtech.daedalus.activity.MainActivity; import org.itxtech.daedalus.service.DaedalusVpnService; @@ -28,7 +30,7 @@ import java.util.List; * the Free Software Foundation, version 3. */ public class Daedalus extends Application { - public static final String SHORTCUT_ID_ACTIVATE = "activate"; + private static final String SHORTCUT_ID_ACTIVATE = "shortcut_activate"; public static final List DNS_SERVERS = new ArrayList() {{ add(new DnsServer("0", "113.107.249.56", R.string.server_north_china)); @@ -45,14 +47,26 @@ public class Daedalus extends Application { }; private static Daedalus instance = null; + private static SharedPreferences prefs; @Override public void onCreate() { super.onCreate(); + initConfig(); + instance = this; } + private void initConfig() { + PreferenceManager.setDefaultValues(this, R.xml.perf_settings, false); + prefs = PreferenceManager.getDefaultSharedPreferences(this); + } + + public static SharedPreferences getPrefs() { + return prefs; + } + @Override public void onTerminate() { super.onTerminate(); diff --git a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java index 28deee4..d07e26b 100644 --- a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java +++ b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java @@ -3,10 +3,8 @@ package org.itxtech.daedalus.activity; import android.app.ActivityManager; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.net.VpnService; import android.os.Bundle; -import android.preference.PreferenceManager; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; import android.util.Log; @@ -38,7 +36,6 @@ public class MainActivity extends AppCompatActivity { public static final int LAUNCH_ACTION_DEACTIVATE = 2; private static MainActivity instance = null; - private SharedPreferences prefs; public static MainActivity getInstance() { return instance; @@ -50,8 +47,6 @@ public class MainActivity extends AppCompatActivity { instance = this; - initConfig(); - setContentView(R.layout.activity_main); /*Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);*/ @@ -152,11 +147,6 @@ public class MainActivity extends AppCompatActivity { updateUserInterface(); } - private void initConfig() { - PreferenceManager.setDefaultValues(this, R.xml.perf_settings, false); - prefs = PreferenceManager.getDefaultSharedPreferences(this); - } - private void activateService() { Intent intent = VpnService.prepare(this); if (intent != null) { @@ -188,8 +178,8 @@ public class MainActivity extends AppCompatActivity { protected void onActivityResult(int request, int result, Intent data) { if (result == RESULT_OK) { - DaedalusVpnService.primaryServer = DnsServer.getDnsServerAddressById(prefs.getString("primary_server", "0")); - DaedalusVpnService.secondaryServer = DnsServer.getDnsServerAddressById(prefs.getString("secondary_server", "1")); + DaedalusVpnService.primaryServer = DnsServer.getDnsServerAddressById(Daedalus.getPrefs().getString("primary_server", "0")); + DaedalusVpnService.secondaryServer = DnsServer.getDnsServerAddressById(Daedalus.getPrefs().getString("secondary_server", "1")); startService(getServiceIntent().setAction(DaedalusVpnService.ACTION_ACTIVATE)); diff --git a/app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java index 2e78c84..da7b2ed 100644 --- a/app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java +++ b/app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java @@ -21,6 +21,7 @@ import org.itxtech.daedalus.R; import org.itxtech.daedalus.util.DnsServer; import java.net.InetAddress; +import java.util.ArrayList; import java.util.Random; import java.util.Set; @@ -84,7 +85,15 @@ public class ServerTestActivity extends AppCompatActivity { testDomain = Daedalus.DEFAULT_TEST_DOMAINS[0]; } StringBuilder testText = new StringBuilder(); - String[] dnsServers = {DnsServer.getDnsServerAddressByStringDescription(context, spinnerServerChoice.getSelectedItem().toString()), "114.114.114.114", "8.8.8.8"}; + ArrayList dnsServers = new ArrayList() {{ + add(DnsServer.getDnsServerAddressByStringDescription(context, spinnerServerChoice.getSelectedItem().toString())); + String servers = Daedalus.getPrefs().getString("dns_test_servers", ""); + if (!servers.equals("")) { + for (String server : servers.split(",")) { + add(server); + } + } + }}; DNSClient client = new DNSClient(null); for (String dnsServer : dnsServers) { testText = testServer(client, dnsServer, testDomain, testText); diff --git a/app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java b/app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java index de9f343..fdc51b8 100644 --- a/app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java +++ b/app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java @@ -3,12 +3,9 @@ package org.itxtech.daedalus.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.net.VpnService; -import android.preference.PreferenceManager; import android.util.Log; import org.itxtech.daedalus.Daedalus; -import org.itxtech.daedalus.R; import org.itxtech.daedalus.service.DaedalusVpnService; import org.itxtech.daedalus.util.DnsServer; @@ -25,17 +22,15 @@ import org.itxtech.daedalus.util.DnsServer; public class BootBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - PreferenceManager.setDefaultValues(context, R.xml.perf_settings, false); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - if (prefs.getBoolean("settings_boot", false)) { + if (Daedalus.getPrefs().getBoolean("settings_boot", false)) { Intent vIntent = VpnService.prepare(context); if (vIntent != null) { context.startActivity(vIntent); } - DaedalusVpnService.primaryServer = DnsServer.getDnsServerAddressById(prefs.getString("primary_server", "0")); - DaedalusVpnService.secondaryServer = DnsServer.getDnsServerAddressById(prefs.getString("secondary_server", "1")); + DaedalusVpnService.primaryServer = DnsServer.getDnsServerAddressById(Daedalus.getPrefs().getString("primary_server", "0")); + DaedalusVpnService.secondaryServer = DnsServer.getDnsServerAddressById(Daedalus.getPrefs().getString("secondary_server", "1")); context.startService((new Intent(context, DaedalusVpnService.class)).setAction(DaedalusVpnService.ACTION_ACTIVATE)); diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 84e21eb..6df0e02 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -37,4 +37,5 @@ 当前 Android API 无法支持所有功能。 提交反馈 前往 GitHub 提交问题反馈。 + DNS 测试服务器 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 791dbc8..e4bb276 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,4 +37,5 @@ The current Android API can not support all the features. Issue tracker Submit an issue in GitHub Issues page. + DNS test servers diff --git a/app/src/main/res/xml/perf_settings.xml b/app/src/main/res/xml/perf_settings.xml index 0761d27..502cd39 100644 --- a/app/src/main/res/xml/perf_settings.xml +++ b/app/src/main/res/xml/perf_settings.xml @@ -16,6 +16,12 @@ android:title="@string/secondary_server" android:defaultValue="1"> +