Daedalus: reformat things

This commit is contained in:
PeratX 2019-10-23 15:48:02 +08:00
parent a2d92d49aa
commit 000706a2ae
5 changed files with 46 additions and 52 deletions

View File

@ -58,7 +58,7 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05'
implementation "androidx.preference:preference:1.1.0"
implementation 'androidx.preference:preference:1.1.0'
//DNS
implementation 'org.pcap4j:pcap4j-core:1.8.2'
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.8.2'

View File

@ -16,10 +16,10 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.stream.JsonReader;
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.DnsServerHelper;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.*;
import java.io.File;
import java.util.ArrayList;
@ -50,7 +50,7 @@ public class Daedalus extends Application {
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,
"https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts", false));
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));
}};
public static final String[] DEFAULT_TEST_DOMAINS = new String[]{
public static final String[] DEFAULT_TEST_DOMAINS = {
"google.com",
"twitter.com",
"youtube.com",
@ -71,12 +71,11 @@ public class Daedalus extends Application {
};
public static Configurations configurations;
public static String rulePath;
public static String logPath;
private static String configPath;
public static String rulePath = null;
public static String logPath = null;
private static String configPath = null;
private static Daedalus instance = null;
private static Daedalus instance;
private SharedPreferences prefs;
private Thread mResolver;
@ -85,12 +84,9 @@ public class Daedalus extends Application {
super.onCreate();
instance = this;
Logger.init();
mResolver = new Thread(new RuleResolver());
mResolver.start();
initData();
}

View File

@ -44,12 +44,10 @@ public class ConfigActivity extends AppCompatActivity {
ConfigFragment fragment;
switch (getIntent().getIntExtra(LAUNCH_ACTION_FRAGMENT, LAUNCH_FRAGMENT_DNS_SERVER)) {
case LAUNCH_FRAGMENT_DNS_SERVER:
fragment = new DnsServerConfigFragment();
break;
case LAUNCH_FRAGMENT_RULE:
fragment = new RuleConfigFragment();
break;
case LAUNCH_FRAGMENT_DNS_SERVER:
default://should never reach this
fragment = new DnsServerConfigFragment();
break;

View File

@ -50,8 +50,7 @@ public class DnsServersDetector {
private static String[] getServersMethodConnectivityManager(Context context) {
ArrayList<String> priorityServersArrayList = new ArrayList<>();
ArrayList<String> serversArrayList = new ArrayList<>();
ConnectivityManager connectivityManager =
(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
for (Network network : connectivityManager.getAllNetworks()) {
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
@ -83,15 +82,15 @@ public class DnsServersDetector {
private static String[] getServersMethodSystemProperties() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
final String re1 = "^\\d+(\\.\\d+){3}$";
final String re2 = "^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$";
String re1 = "^\\d+(\\.\\d+){3}$";
String re2 = "^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$";
ArrayList<String> serversArrayList = new ArrayList<>();
try {
Class SystemProperties = Class.forName("android.os.SystemProperties");
Method method = SystemProperties.getMethod("get", new Class[]{String.class});
final String[] netdns = new String[]{"net.dns1", "net.dns2", "net.dns3", "net.dns4"};
for (int i = 0; i < netdns.length; i++) {
Object[] args = new Object[]{netdns[i]};
String[] netdns = new String[]{"net.dns1", "net.dns2", "net.dns3", "net.dns4"};
for (String dns : netdns) {
Object[] args = new Object[]{dns};
String v = (String) method.invoke(null, args);
if (v != null && (v.matches(re1) || v.matches(re2)) && !serversArrayList.contains(v)) {
serversArrayList.add(v);
@ -100,7 +99,6 @@ public class DnsServersDetector {
if (serversArrayList.size() > 0) {
return serversArrayList.toArray(new String[0]);
}
} catch (Exception ex) {
Logger.logException(ex);
}
@ -125,7 +123,7 @@ public class DnsServersDetector {
private static Set<String> methodExecParseProps(BufferedReader lineNumberReader) throws Exception {
String line;
Set<String> serversSet = new HashSet<String>(10);
HashSet<String> serversSet = new HashSet<>();
while ((line = lineNumberReader.readLine()) != null) {
int split = line.indexOf(METHOD_EXEC_PROP_DELIM);
if (split == -1) {
@ -141,14 +139,16 @@ public class DnsServersDetector {
if (value.isEmpty()) {
continue;
}
if (property.endsWith(".dns") || property.endsWith(".dns1") ||
property.endsWith(".dns2") || property.endsWith(".dns3") ||
property.endsWith(".dns4")) {
if (property.endsWith(".dns") || property.endsWith(".dns1") || property.endsWith(".dns2") ||
property.endsWith(".dns3") || property.endsWith(".dns4")) {
InetAddress ip = InetAddress.getByName(value);
if (ip == null) continue;
if (ip == null) {
continue;
}
value = ip.getHostAddress();
if (value == null) continue;
if (value.length() == 0) continue;
if (value == null || value.length() == 0) {
continue;
}
serversSet.add(value);
}
}

View File

@ -60,7 +60,7 @@
<string name="settings_log_size">Log Size Limit</string>
<string name="settings_manual">Manual</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_dark_theme">Use Dark Theme</string>
<string name="settings_dns_query_method">DNS Query Method</string>