+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ */
+public class Daedalus extends Application {
+ public static final List
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- */
-class DnsServers {
- static String getDnsServerAddress(String id) {
- switch (id) {
- case "0":
- return "113.107.249.56";
- case "1":
- return "120.27.103.230";
- case "2":
- return "123.206.61.167";
- default:
- return "123.206.61.167";
- }
- }
-}
diff --git a/app/src/main/java/org/itxtech/daedalus/SettingsFragment.java b/app/src/main/java/org/itxtech/daedalus/SettingsFragment.java
deleted file mode 100644
index 72e7da4..0000000
--- a/app/src/main/java/org/itxtech/daedalus/SettingsFragment.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.itxtech.daedalus;
-
-import android.os.Bundle;
-import android.preference.PreferenceFragment;
-
-/**
- * Daedalus Project
- *
- * @author iTXTech
- * @link https://itxtech.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 3.
- */
-public class SettingsFragment extends PreferenceFragment {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.perf_settings);
- }
-}
diff --git a/app/src/main/java/org/itxtech/daedalus/AboutActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/AboutActivity.java
similarity index 97%
rename from app/src/main/java/org/itxtech/daedalus/AboutActivity.java
rename to app/src/main/java/org/itxtech/daedalus/activity/AboutActivity.java
index 0437366..42c5361 100644
--- a/app/src/main/java/org/itxtech/daedalus/AboutActivity.java
+++ b/app/src/main/java/org/itxtech/daedalus/activity/AboutActivity.java
@@ -1,4 +1,4 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.activity;
import android.annotation.SuppressLint;
import android.content.Intent;
@@ -12,6 +12,8 @@ import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
+import org.itxtech.daedalus.BuildConfig;
+import org.itxtech.daedalus.R;
import java.util.Locale;
diff --git a/app/src/main/java/org/itxtech/daedalus/MainActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java
similarity index 91%
rename from app/src/main/java/org/itxtech/daedalus/MainActivity.java
rename to app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java
index 149d407..88e3b7c 100644
--- a/app/src/main/java/org/itxtech/daedalus/MainActivity.java
+++ b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java
@@ -1,4 +1,4 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.activity;
import android.app.ActivityManager;
import android.app.NotificationManager;
@@ -15,6 +15,9 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.service.DaedalusVpnService;
+import org.itxtech.daedalus.util.DnsServer;
/**
* Daedalus Project
@@ -30,7 +33,7 @@ public class MainActivity extends AppCompatActivity {
private static MainActivity instance = null;
private SharedPreferences prefs;
- static MainActivity getInstance() {
+ public static MainActivity getInstance() {
return instance;
}
@@ -124,8 +127,8 @@ public class MainActivity extends AppCompatActivity {
protected void onActivityResult(int request, int result, Intent data) {
if (result == RESULT_OK) {
- DaedalusVpnService.primaryServer = DnsServers.getDnsServerAddress(prefs.getString("primary_server", "0"));
- DaedalusVpnService.secondaryServer = DnsServers.getDnsServerAddress(prefs.getString("secondary_server", "1"));
+ DaedalusVpnService.primaryServer = DnsServer.getDnsServerAddressById(prefs.getString("primary_server", "0"));
+ DaedalusVpnService.secondaryServer = DnsServer.getDnsServerAddressById(prefs.getString("secondary_server", "1"));
startService(getServiceIntent().setAction(DaedalusVpnService.ACTION_ACTIVATE));
diff --git a/app/src/main/java/org/itxtech/daedalus/ServerTestActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java
similarity index 86%
rename from app/src/main/java/org/itxtech/daedalus/ServerTestActivity.java
rename to app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java
index 871505e..c77e0f6 100644
--- a/app/src/main/java/org/itxtech/daedalus/ServerTestActivity.java
+++ b/app/src/main/java/org/itxtech/daedalus/activity/ServerTestActivity.java
@@ -1,4 +1,4 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.activity;
import android.content.Context;
import android.os.Bundle;
@@ -16,11 +16,23 @@ import de.measite.minidns.Question;
import de.measite.minidns.Record;
import de.measite.minidns.record.A;
import de.measite.minidns.util.InetAddressUtil;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.util.DnsServer;
import java.net.InetAddress;
import java.util.Random;
import java.util.Set;
+/**
+ * Daedalus Project
+ *
+ * @author iTXTech
+ * @link https://itxtech.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ */
public class ServerTestActivity extends AppCompatActivity {
private static final int MSG_DISPLAY_STATUS = 0;
private static final int MSG_TEST_DONE = 1;
@@ -37,10 +49,14 @@ public class ServerTestActivity extends AppCompatActivity {
final TextView textViewTestInfo = (TextView) findViewById(R.id.textView_test_info);
final Spinner spinnerServerChoice = (Spinner) findViewById(R.id.spinner_server_choice);
+ ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, DnsServer.getDnsServerNames(this));
+ spinnerServerChoice.setAdapter(spinnerArrayAdapter);
final AutoCompleteTextView textViewTestUrl = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView_test_url);
- ArrayAdapter arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.default_test_urls));
- textViewTestUrl.setAdapter(arrayAdapter);
+ ArrayAdapter autoCompleteArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.default_test_urls));
+ textViewTestUrl.setAdapter(autoCompleteArrayAdapter);
+
+ final Context context = this;
final Button startTestBut = (Button) findViewById(R.id.button_start_test);
startTestBut.setOnClickListener(new View.OnClickListener() {
@@ -65,7 +81,7 @@ public class ServerTestActivity extends AppCompatActivity {
testUrl = getResources().getStringArray(R.array.default_test_urls)[0];
}
String testText = "";
- String[] dnsServers = {DnsServers.getDnsServerAddress(String.valueOf(spinnerServerChoice.getSelectedItemId())), "114.114.114.114", "8.8.8.8"};
+ String[] dnsServers = {DnsServer.getDnsServerAddressByStringDesription(context, spinnerServerChoice.getSelectedItem().toString()), "114.114.114.114", "8.8.8.8"};
DNSClient client = new DNSClient(null);
for (String dnsServer : dnsServers) {
testText = testServer(client, dnsServer, testUrl, testText);
diff --git a/app/src/main/java/org/itxtech/daedalus/SettingsActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/SettingsActivity.java
similarity index 87%
rename from app/src/main/java/org/itxtech/daedalus/SettingsActivity.java
rename to app/src/main/java/org/itxtech/daedalus/activity/SettingsActivity.java
index 2d3f6f6..d7ebf65 100644
--- a/app/src/main/java/org/itxtech/daedalus/SettingsActivity.java
+++ b/app/src/main/java/org/itxtech/daedalus/activity/SettingsActivity.java
@@ -1,8 +1,10 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.activity;
import android.app.FragmentManager;
-import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.fragment.SettingsFragment;
/**
* Daedalus Project
diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java
new file mode 100644
index 0000000..8575335
--- /dev/null
+++ b/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java
@@ -0,0 +1,36 @@
+package org.itxtech.daedalus.fragment;
+
+import android.os.Bundle;
+import android.preference.ListPreference;
+import android.preference.PreferenceFragment;
+import org.itxtech.daedalus.Daedalus;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.util.DnsServer;
+
+/**
+ * Daedalus Project
+ *
+ * @author iTXTech
+ * @link https://itxtech.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ */
+public class SettingsFragment extends PreferenceFragment {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.perf_settings);
+
+ ListPreference primaryServer = (ListPreference) findPreference("primary_server");
+ primaryServer.setEntries(DnsServer.getDnsServerNames(Daedalus.getInstance()));
+ primaryServer.setEntryValues(DnsServer.getDnsServerIds());
+ primaryServer.setDefaultValue(Daedalus.DNS_SERVERS.get(0).getId());
+
+ ListPreference secondaryServer = (ListPreference) findPreference("secondary_server");
+ secondaryServer.setEntries(DnsServer.getDnsServerNames(Daedalus.getInstance()));
+ secondaryServer.setEntryValues(DnsServer.getDnsServerIds());
+ primaryServer.setDefaultValue(Daedalus.DNS_SERVERS.get(1).getId());
+ }
+}
diff --git a/app/src/main/java/org/itxtech/daedalus/BootBroadcastReceiver.java b/app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java
similarity index 74%
rename from app/src/main/java/org/itxtech/daedalus/BootBroadcastReceiver.java
rename to app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java
index 540228f..1e768d6 100644
--- a/app/src/main/java/org/itxtech/daedalus/BootBroadcastReceiver.java
+++ b/app/src/main/java/org/itxtech/daedalus/receiver/BootBroadcastReceiver.java
@@ -1,4 +1,4 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -7,6 +7,9 @@ import android.content.SharedPreferences;
import android.net.VpnService;
import android.preference.PreferenceManager;
import android.util.Log;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.service.DaedalusVpnService;
+import org.itxtech.daedalus.util.DnsServer;
/**
* Daedalus Project
@@ -30,8 +33,8 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
context.startActivity(vIntent);
}
- DaedalusVpnService.primaryServer = DnsServers.getDnsServerAddress(prefs.getString("primary_server", "0"));
- DaedalusVpnService.secondaryServer = DnsServers.getDnsServerAddress(prefs.getString("secondary_server", "1"));
+ DaedalusVpnService.primaryServer = DnsServer.getDnsServerAddressById(prefs.getString("primary_server", "0"));
+ DaedalusVpnService.secondaryServer = DnsServer.getDnsServerAddressById(prefs.getString("secondary_server", "1"));
context.startService((new Intent(context, DaedalusVpnService.class)).setAction(DaedalusVpnService.ACTION_ACTIVATE));
diff --git a/app/src/main/java/org/itxtech/daedalus/StatusBarBroadcastReceiver.java b/app/src/main/java/org/itxtech/daedalus/receiver/StatusBarBroadcastReceiver.java
similarity index 75%
rename from app/src/main/java/org/itxtech/daedalus/StatusBarBroadcastReceiver.java
rename to app/src/main/java/org/itxtech/daedalus/receiver/StatusBarBroadcastReceiver.java
index 93c18ee..9eace5d 100644
--- a/app/src/main/java/org/itxtech/daedalus/StatusBarBroadcastReceiver.java
+++ b/app/src/main/java/org/itxtech/daedalus/receiver/StatusBarBroadcastReceiver.java
@@ -1,10 +1,14 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Button;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.activity.MainActivity;
+import org.itxtech.daedalus.activity.SettingsActivity;
+import org.itxtech.daedalus.service.DaedalusVpnService;
import java.lang.reflect.Method;
@@ -19,8 +23,8 @@ import java.lang.reflect.Method;
* the Free Software Foundation, version 3.
*/
public class StatusBarBroadcastReceiver extends BroadcastReceiver {
- static String STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION = "org.itxtech.daedalus.StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION";
- static String STATUS_BAR_BTN_SETTINGS_CLICK_ACTION = "org.itxtech.daedalus.StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION";
+ public static String STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION = "org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION";
+ public static String STATUS_BAR_BTN_SETTINGS_CLICK_ACTION = "org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION";
@Override
public void onReceive(Context context, Intent intent) {
@@ -31,7 +35,6 @@ public class StatusBarBroadcastReceiver extends BroadcastReceiver {
if (MainActivity.getInstance() != null) {
((Button) MainActivity.getInstance().findViewById(R.id.button_activate)).setText(R.string.button_text_activate);
}
-
}
if (intent.getAction().equals(STATUS_BAR_BTN_SETTINGS_CLICK_ACTION)) {
Intent settingsIntent = new Intent(context, SettingsActivity.class);
diff --git a/app/src/main/java/org/itxtech/daedalus/DaedalusVpnService.java b/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java
similarity index 82%
rename from app/src/main/java/org/itxtech/daedalus/DaedalusVpnService.java
rename to app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java
index fd112d8..87a11d6 100644
--- a/app/src/main/java/org/itxtech/daedalus/DaedalusVpnService.java
+++ b/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java
@@ -1,4 +1,4 @@
-package org.itxtech.daedalus;
+package org.itxtech.daedalus.service;
import android.app.Notification;
import android.app.NotificationManager;
@@ -10,6 +10,9 @@ import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.support.v7.app.NotificationCompat;
import android.util.Log;
+import org.itxtech.daedalus.R;
+import org.itxtech.daedalus.activity.MainActivity;
+import org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver;
/**
* Daedalus Project
@@ -22,11 +25,11 @@ import android.util.Log;
* the Free Software Foundation, version 3.
*/
public class DaedalusVpnService extends VpnService implements Runnable {
- static final String ACTION_ACTIVATE = "org.itxtech.daedalus.DaedalusVpnService.ACTION_ACTIVATE";
- static final String ACTION_DEACTIVATE = "org.itxtech.daedalus.DaedalusVpnService.ACTION_DEACTIVATE";
+ public static final String ACTION_ACTIVATE = "org.itxtech.daedalus.service.DaedalusVpnService.ACTION_ACTIVATE";
+ public static final String ACTION_DEACTIVATE = "org.itxtech.daedalus.service.DaedalusVpnService.ACTION_DEACTIVATE";
- static String primaryServer;
- static String secondaryServer;
+ public static String primaryServer;
+ public static String secondaryServer;
private Thread mThread = null;
private static int ip = 0;
@@ -57,8 +60,12 @@ public class DaedalusVpnService extends VpnService implements Runnable {
.setAutoCancel(true)
.setOngoing(true)
.setContentIntent(pIntent)
- .addAction(R.mipmap.ic_launcher, getResources().getString(R.string.button_text_deactivate), PendingIntent.getBroadcast(this, 0, new Intent(StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION), 0))
- .addAction(R.mipmap.ic_launcher, getResources().getString(R.string.action_settings), PendingIntent.getBroadcast(this, 0, new Intent(StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION), 0));
+ .addAction(R.mipmap.ic_launcher, getResources().getString(R.string.button_text_deactivate),
+ PendingIntent.getBroadcast(this, 0,
+ new Intent(StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION), 0))
+ .addAction(R.mipmap.ic_launcher, getResources().getString(R.string.action_settings),
+ PendingIntent.getBroadcast(this, 0,
+ new Intent(StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION), 0));
Notification notification = builder.build();
notification.flags = Notification.FLAG_NO_CLEAR;
diff --git a/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java b/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java
new file mode 100644
index 0000000..199a05a
--- /dev/null
+++ b/app/src/main/java/org/itxtech/daedalus/util/DnsServer.java
@@ -0,0 +1,80 @@
+package org.itxtech.daedalus.util;
+
+import android.content.Context;
+import org.itxtech.daedalus.Daedalus;
+
+import java.util.ArrayList;
+
+/**
+ * Daedalus Project
+ *
+ * @author iTXTech
+ * @link https://itxtech.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ */
+public class DnsServer {
+ private String id;
+ private String address;
+ private int description;
+
+ public DnsServer(String id, String address, int description) {
+ this.id = id;
+ this.address = address;
+ this.description = description;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public int getDescription() {
+ return description;
+ }
+
+ public String getStringDescription(Context context) {
+ return context.getResources().getString(description);
+ }
+
+ public static String getDnsServerAddressById(String id) {
+ for (DnsServer server : Daedalus.DNS_SERVERS) {
+ if (server.getId().equals(id)) {
+ return server.getAddress();
+ }
+ }
+ return Daedalus.DNS_SERVERS.get(0).getAddress();
+ }
+
+ public static String getDnsServerAddressByStringDesription(Context context, String description) {
+ for (DnsServer server : Daedalus.DNS_SERVERS) {
+ if (server.getStringDescription(context).equals(description)) {
+ return server.getAddress();
+ }
+ }
+ return Daedalus.DNS_SERVERS.get(0).getAddress();
+ }
+
+ public static String[] getDnsServerIds() {
+ ArrayList