Daedalus: reformat things
This commit is contained in:
parent
a2d92d49aa
commit
000706a2ae
@ -58,7 +58,7 @@ dependencies {
|
|||||||
implementation 'androidx.cardview:cardview:1.0.0'
|
implementation 'androidx.cardview:cardview:1.0.0'
|
||||||
implementation 'com.google.android.material:material:1.2.0-alpha01'
|
implementation 'com.google.android.material:material:1.2.0-alpha01'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05'
|
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05'
|
||||||
implementation "androidx.preference:preference:1.1.0"
|
implementation 'androidx.preference:preference:1.1.0'
|
||||||
//DNS
|
//DNS
|
||||||
implementation 'org.pcap4j:pcap4j-core:1.8.2'
|
implementation 'org.pcap4j:pcap4j-core:1.8.2'
|
||||||
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.8.2'
|
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.8.2'
|
||||||
|
@ -16,10 +16,10 @@ import com.google.gson.GsonBuilder;
|
|||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import org.itxtech.daedalus.activity.MainActivity;
|
import org.itxtech.daedalus.activity.MainActivity;
|
||||||
import org.itxtech.daedalus.service.DaedalusVpnService;
|
|
||||||
import org.itxtech.daedalus.util.*;
|
|
||||||
import org.itxtech.daedalus.server.DnsServer;
|
import org.itxtech.daedalus.server.DnsServer;
|
||||||
import org.itxtech.daedalus.server.DnsServerHelper;
|
import org.itxtech.daedalus.server.DnsServerHelper;
|
||||||
|
import org.itxtech.daedalus.service.DaedalusVpnService;
|
||||||
|
import org.itxtech.daedalus.util.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -50,7 +50,7 @@ public class Daedalus extends Application {
|
|||||||
add(new DnsServer("dns.google/resolve", R.string.server_google_json));
|
add(new DnsServer("dns.google/resolve", R.string.server_google_json));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public static final List<Rule> RULES = new ArrayList<Rule>() {{
|
public static final ArrayList<Rule> RULES = new ArrayList<Rule>() {{
|
||||||
add(new Rule("googlehosts/hosts", "googlehosts.hosts", Rule.TYPE_HOSTS,
|
add(new Rule("googlehosts/hosts", "googlehosts.hosts", Rule.TYPE_HOSTS,
|
||||||
"https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts", false));
|
"https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts", false));
|
||||||
add(new Rule("vokins/yhosts", "vokins.hosts", Rule.TYPE_HOSTS,
|
add(new Rule("vokins/yhosts", "vokins.hosts", Rule.TYPE_HOSTS,
|
||||||
@ -62,7 +62,7 @@ public class Daedalus extends Application {
|
|||||||
"https://raw.githubusercontent.com/vokins/yhosts/master/dnsmasq/union.conf", false));
|
"https://raw.githubusercontent.com/vokins/yhosts/master/dnsmasq/union.conf", false));
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public static final String[] DEFAULT_TEST_DOMAINS = new String[]{
|
public static final String[] DEFAULT_TEST_DOMAINS = {
|
||||||
"google.com",
|
"google.com",
|
||||||
"twitter.com",
|
"twitter.com",
|
||||||
"youtube.com",
|
"youtube.com",
|
||||||
@ -71,12 +71,11 @@ public class Daedalus extends Application {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static Configurations configurations;
|
public static Configurations configurations;
|
||||||
|
public static String rulePath;
|
||||||
|
public static String logPath;
|
||||||
|
private static String configPath;
|
||||||
|
|
||||||
public static String rulePath = null;
|
private static Daedalus instance;
|
||||||
public static String logPath = null;
|
|
||||||
private static String configPath = null;
|
|
||||||
|
|
||||||
private static Daedalus instance = null;
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private Thread mResolver;
|
private Thread mResolver;
|
||||||
|
|
||||||
@ -85,12 +84,9 @@ public class Daedalus extends Application {
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
Logger.init();
|
Logger.init();
|
||||||
|
|
||||||
mResolver = new Thread(new RuleResolver());
|
mResolver = new Thread(new RuleResolver());
|
||||||
mResolver.start();
|
mResolver.start();
|
||||||
|
|
||||||
initData();
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,30 +127,30 @@ public class Daedalus extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void initRuleResolver() {
|
public static void initRuleResolver() {
|
||||||
ArrayList<String> pendingLoad = new ArrayList<>();
|
ArrayList<String> pendingLoad = new ArrayList<>();
|
||||||
ArrayList<Rule> usingRules = configurations.getUsingRules();
|
ArrayList<Rule> usingRules = configurations.getUsingRules();
|
||||||
if (usingRules != null && usingRules.size() > 0) {
|
if (usingRules != null && usingRules.size() > 0) {
|
||||||
for (Rule rule : usingRules) {
|
for (Rule rule : usingRules) {
|
||||||
if (rule.isUsing()) {
|
if (rule.isUsing()) {
|
||||||
pendingLoad.add(rulePath + rule.getFileName());
|
pendingLoad.add(rulePath + rule.getFileName());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (pendingLoad.size() > 0) {
|
}
|
||||||
String[] arr = new String[pendingLoad.size()];
|
if (pendingLoad.size() > 0) {
|
||||||
pendingLoad.toArray(arr);
|
String[] arr = new String[pendingLoad.size()];
|
||||||
switch (usingRules.get(0).getType()) {
|
pendingLoad.toArray(arr);
|
||||||
case Rule.TYPE_HOSTS:
|
switch (usingRules.get(0).getType()) {
|
||||||
RuleResolver.startLoadHosts(arr);
|
case Rule.TYPE_HOSTS:
|
||||||
break;
|
RuleResolver.startLoadHosts(arr);
|
||||||
case Rule.TYPE_DNAMASQ:
|
break;
|
||||||
RuleResolver.startLoadDnsmasq(arr);
|
case Rule.TYPE_DNAMASQ:
|
||||||
break;
|
RuleResolver.startLoadDnsmasq(arr);
|
||||||
}
|
break;
|
||||||
} else {
|
|
||||||
RuleResolver.clear();
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RuleResolver.clear();
|
RuleResolver.clear();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RuleResolver.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +44,10 @@ public class ConfigActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
ConfigFragment fragment;
|
ConfigFragment fragment;
|
||||||
switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) {
|
switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) {
|
||||||
case LAUNCH_FRAGMENT_DNS_SERVER:
|
|
||||||
fragment = new DnsServerConfigFragment();
|
|
||||||
break;
|
|
||||||
case LAUNCH_FRAGMENT_RULE:
|
case LAUNCH_FRAGMENT_RULE:
|
||||||
fragment = new RuleConfigFragment();
|
fragment = new RuleConfigFragment();
|
||||||
break;
|
break;
|
||||||
|
case LAUNCH_FRAGMENT_DNS_SERVER:
|
||||||
default://should never reach this
|
default://should never reach this
|
||||||
fragment = new DnsServerConfigFragment();
|
fragment = new DnsServerConfigFragment();
|
||||||
break;
|
break;
|
||||||
|
@ -50,8 +50,7 @@ public class DnsServersDetector {
|
|||||||
private static String[] getServersMethodConnectivityManager(Context context) {
|
private static String[] getServersMethodConnectivityManager(Context context) {
|
||||||
ArrayList<String> priorityServersArrayList = new ArrayList<>();
|
ArrayList<String> priorityServersArrayList = new ArrayList<>();
|
||||||
ArrayList<String> serversArrayList = new ArrayList<>();
|
ArrayList<String> serversArrayList = new ArrayList<>();
|
||||||
ConnectivityManager connectivityManager =
|
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
||||||
if (connectivityManager != null) {
|
if (connectivityManager != null) {
|
||||||
for (Network network : connectivityManager.getAllNetworks()) {
|
for (Network network : connectivityManager.getAllNetworks()) {
|
||||||
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
|
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
|
||||||
@ -83,15 +82,15 @@ public class DnsServersDetector {
|
|||||||
|
|
||||||
private static String[] getServersMethodSystemProperties() {
|
private static String[] getServersMethodSystemProperties() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
final String re1 = "^\\d+(\\.\\d+){3}$";
|
String re1 = "^\\d+(\\.\\d+){3}$";
|
||||||
final String re2 = "^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$";
|
String re2 = "^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$";
|
||||||
ArrayList<String> serversArrayList = new ArrayList<>();
|
ArrayList<String> serversArrayList = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
Class SystemProperties = Class.forName("android.os.SystemProperties");
|
Class SystemProperties = Class.forName("android.os.SystemProperties");
|
||||||
Method method = SystemProperties.getMethod("get", new Class[]{String.class});
|
Method method = SystemProperties.getMethod("get", new Class[]{String.class});
|
||||||
final String[] netdns = new String[]{"net.dns1", "net.dns2", "net.dns3", "net.dns4"};
|
String[] netdns = new String[]{"net.dns1", "net.dns2", "net.dns3", "net.dns4"};
|
||||||
for (int i = 0; i < netdns.length; i++) {
|
for (String dns : netdns) {
|
||||||
Object[] args = new Object[]{netdns[i]};
|
Object[] args = new Object[]{dns};
|
||||||
String v = (String) method.invoke(null, args);
|
String v = (String) method.invoke(null, args);
|
||||||
if (v != null && (v.matches(re1) || v.matches(re2)) && !serversArrayList.contains(v)) {
|
if (v != null && (v.matches(re1) || v.matches(re2)) && !serversArrayList.contains(v)) {
|
||||||
serversArrayList.add(v);
|
serversArrayList.add(v);
|
||||||
@ -100,7 +99,6 @@ public class DnsServersDetector {
|
|||||||
if (serversArrayList.size() > 0) {
|
if (serversArrayList.size() > 0) {
|
||||||
return serversArrayList.toArray(new String[0]);
|
return serversArrayList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.logException(ex);
|
Logger.logException(ex);
|
||||||
}
|
}
|
||||||
@ -125,7 +123,7 @@ public class DnsServersDetector {
|
|||||||
|
|
||||||
private static Set<String> methodExecParseProps(BufferedReader lineNumberReader) throws Exception {
|
private static Set<String> methodExecParseProps(BufferedReader lineNumberReader) throws Exception {
|
||||||
String line;
|
String line;
|
||||||
Set<String> serversSet = new HashSet<String>(10);
|
HashSet<String> serversSet = new HashSet<>();
|
||||||
while ((line = lineNumberReader.readLine()) != null) {
|
while ((line = lineNumberReader.readLine()) != null) {
|
||||||
int split = line.indexOf(METHOD_EXEC_PROP_DELIM);
|
int split = line.indexOf(METHOD_EXEC_PROP_DELIM);
|
||||||
if (split == -1) {
|
if (split == -1) {
|
||||||
@ -141,14 +139,16 @@ public class DnsServersDetector {
|
|||||||
if (value.isEmpty()) {
|
if (value.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (property.endsWith(".dns") || property.endsWith(".dns1") ||
|
if (property.endsWith(".dns") || property.endsWith(".dns1") || property.endsWith(".dns2") ||
|
||||||
property.endsWith(".dns2") || property.endsWith(".dns3") ||
|
property.endsWith(".dns3") || property.endsWith(".dns4")) {
|
||||||
property.endsWith(".dns4")) {
|
|
||||||
InetAddress ip = InetAddress.getByName(value);
|
InetAddress ip = InetAddress.getByName(value);
|
||||||
if (ip == null) continue;
|
if (ip == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
value = ip.getHostAddress();
|
value = ip.getHostAddress();
|
||||||
if (value == null) continue;
|
if (value == null || value.length() == 0) {
|
||||||
if (value.length() == 0) continue;
|
continue;
|
||||||
|
}
|
||||||
serversSet.add(value);
|
serversSet.add(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
<string name="settings_log_size">Log Size Limit</string>
|
<string name="settings_log_size">Log Size Limit</string>
|
||||||
<string name="settings_manual">Manual</string>
|
<string name="settings_manual">Manual</string>
|
||||||
<string name="settings_manual_summary">Visit GitHub wiki page.</string>
|
<string name="settings_manual_summary">Visit GitHub wiki page.</string>
|
||||||
<string name="settings_dont_build_cache">Don\'t cache ip for DNS servers</string>
|
<string name="settings_dont_build_cache">Don\'t cache IP for DNS servers</string>
|
||||||
<string name="settings_debug_output">Debug Output</string>
|
<string name="settings_debug_output">Debug Output</string>
|
||||||
<string name="settings_dark_theme">Use Dark Theme</string>
|
<string name="settings_dark_theme">Use Dark Theme</string>
|
||||||
<string name="settings_dns_query_method">DNS Query Method</string>
|
<string name="settings_dns_query_method">DNS Query Method</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user