Merge branch 'master' into api-31

# Conflicts:
#	app/build.gradle
#	build.gradle
This commit is contained in:
PeratX 2022-05-23 11:49:37 +08:00
commit 010096a4e3
53 changed files with 787 additions and 592 deletions

View File

@ -7,8 +7,8 @@ android:
components:
- tools
- platform-tools
- build-tools-28.0.3
- android-28
- build-tools-29.0.2
- android-29
- extra-android-support
- extra-google-m2repository
- extra-android-m2repository

View File

@ -1,6 +1,6 @@
# iTXTech Daedalus
[![Donate](https://img.shields.io/badge/alipay-donate-yellow.svg)](https://qr.alipay.com/a6x07022gffiehykicipv1a)
[![Donate](https://img.shields.io/badge/alipay-donate-yellow.svg)](https://qr.alipay.com/FKX04751EZDP0SQ0BOT137)
[![Build Status](https://travis-ci.org/iTXTech/Daedalus.svg?branch=master)](https://travis-ci.org/iTXTech/Daedalus)
[![Jenkins](https://img.shields.io/jenkins/s/http/dev.itxtech.org:10298/job/Daedalus.svg)](http://dev.itxtech.org:10298/job/Daedalus/)
@ -66,14 +66,13 @@ __Users must comply with local laws and regulations.__<br>
* __[ClearEditText](https://github.com/MrFuFuFu/ClearEditText)__ by *[Yuan Fu](https://github.com/MrFuFuFu)* - [APL 2.0](https://github.com/MrFuFuFu/ClearEditText)
* __[DNS66](https://github.com/julian-klode/dns66)__ by *[Julian Andres Klode](https://github.com/julian-klode)* - [GPLv3](https://github.com/julian-klode/dns66/blob/master/COPYING)
* __[Pcap4J](https://github.com/kaitoy/pcap4j)__ by *[Kaito Yamada](https://github.com/kaitoy)* - [MIT](https://github.com/kaitoy/pcap4j)
* __[MiniDNS](https://github.com/rtreffer/minidns)__ by *[Rene Treffer](https://github.com/rtreffer)* - [LGPLv2.1](https://github.com/rtreffer/minidns/blob/master/LICENCE_LGPL2.1)
* __[MiniDNS](https://github.com/MiniDNS/minidns)__ by *[MiniDNS](https://github.com/MiniDNS)* - [APL 2.0](https://github.com/MiniDNS/minidns/blob/master/LICENCE_APACHE)
* __[Gson](https://github.com/google/gson)__ by *[Google](https://github.com/google)* - [APL 2.0](https://github.com/google/gson/blob/master/LICENSE)
* __[Shadowsocks](https://github.com/shadowsocks/shadowsocks-android)__ by *[Shadowsocks](https://github.com/shadowsocks)* - [GPLv3](https://github.com/shadowsocks/shadowsocks-android/blob/master/LICENSE)
## Credits
* __[JetBrains](https://www.jetbrains.com/)__ - For providing free license for [IntelliJ IDEA](https://www.jetbrains.com/idea/)
* __[ShenniaoTech](https://www.sncidc.com/)__ - For supporting us with love
## License

View File

@ -58,6 +58,7 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.7.0-alpha01'
implementation 'androidx.recyclerview:recyclerview:1.3.0-alpha02'
implementation 'androidx.preference:preference:1.1.0'
//DNS
implementation 'org.pcap4j:pcap4j-core:1.7.6'
implementation 'org.pcap4j:pcap4j-packetfactory-static:1.7.6'

View File

@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18"/>

View File

@ -10,20 +10,20 @@ import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.VpnService;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import androidx.preference.PreferenceManager;
import com.google.gson.Gson;
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.server.AbstractDnsServer;
import org.itxtech.daedalus.server.DnsServer;
import org.itxtech.daedalus.server.DnsServerHelper;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.Configurations;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.Rule;
import org.itxtech.daedalus.util.RuleResolver;
import org.itxtech.daedalus.util.server.DNSServer;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import java.io.File;
import java.util.ArrayList;
@ -45,16 +45,16 @@ public class Daedalus extends Application {
private static final String SHORTCUT_ID_ACTIVATE = "shortcut_activate";
public static final List<DNSServer> DNS_SERVERS = new ArrayList<DNSServer>() {{
add(new DNSServer("101.101.101.101", R.string.server_twnic_primary));
add(new DNSServer("101.102.103.104", R.string.server_twnic_secondary));
add(new DNSServer("dns.rubyfish.cn/dns-query", R.string.server_rubyfish));
add(new DNSServer("cloudflare-dns.com/dns-query", R.string.server_cloudflare));
add(new DNSServer("dns.google/dns-query", R.string.server_google_ietf));
add(new DNSServer("dns.google/resolve", R.string.server_google_json));
public static final List<DnsServer> DNS_SERVERS = new ArrayList<DnsServer>() {{
add(new DnsServer("101.101.101.101", R.string.server_twnic_primary));
add(new DnsServer("101.102.103.104", R.string.server_twnic_secondary));
add(new DnsServer("rubyfish.cn/dns-query", R.string.server_rubyfish));
add(new DnsServer("cloudflare-dns.com/dns-query", R.string.server_cloudflare));
add(new DnsServer("dns.google/dns-query", R.string.server_google_ietf));
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,
@ -66,7 +66,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",
@ -75,12 +75,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;
@ -89,12 +88,9 @@ public class Daedalus extends Application {
super.onCreate();
instance = this;
Logger.init();
mResolver = new Thread(new RuleResolver());
mResolver.start();
initData();
}
@ -178,7 +174,6 @@ public class Daedalus extends Application {
@Override
public void onTerminate() {
Log.d("Daedalus", "onTerminate");
super.onTerminate();
instance = null;
@ -199,23 +194,38 @@ public class Daedalus extends Application {
deactivateService(instance);
return false;
} else {
activateService(instance);
prepareAndActivateService(instance);
return true;
}
}
public static boolean activateService(Context context) {
public static boolean prepareAndActivateService(Context context) {
Intent intent = VpnService.prepare(context);
if (intent != null) {
return false;
} else {
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
context.startService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
activateService(context);
return true;
}
}
public static void activateService(Context context) {
activateService(context, false);
}
public static void activateService(Context context, boolean forceForeground) {
DaedalusVpnService.primaryServer = (AbstractDnsServer) DnsServerHelper.getServerById(DnsServerHelper.getPrimary()).clone();
DaedalusVpnService.secondaryServer = (AbstractDnsServer) DnsServerHelper.getServerById(DnsServerHelper.getSecondary()).clone();
if ((getInstance().prefs.getBoolean("settings_foreground", false) || forceForeground)
&& Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
Logger.info("Starting foreground service");
context.startForegroundService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
} else {
Logger.info("Starting background service");
context.startService(Daedalus.getServiceIntent(context).setAction(DaedalusVpnService.ACTION_ACTIVATE));
}
}
public static void deactivateService(Context context) {
context.startService(getServiceIntent(context).setAction(DaedalusVpnService.ACTION_DEACTIVATE));
context.stopService(getServiceIntent(context));
@ -223,7 +233,7 @@ public class Daedalus extends Application {
public static void updateShortcut(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
Log.d("Daedalus", "Updating shortcut");
Logger.info("Updating shortcut");
boolean activate = DaedalusVpnService.isActivated();
String notice = activate ? context.getString(R.string.button_text_deactivate) : context.getString(R.string.button_text_activate);
ShortcutInfo info = new ShortcutInfo.Builder(context, Daedalus.SHORTCUT_ID_ACTIVATE)
@ -239,7 +249,7 @@ public class Daedalus extends Application {
}
public static void donate() {
openUri("https://qr.alipay.com/a6x07022gffiehykicipv1a");
openUri("https://qr.alipay.com/FKX04751EZDP0SQ0BOT137");
}
public static void openUri(String uri) {

View File

@ -40,7 +40,6 @@ import java.util.Objects;
* (at your option) any later version.
*/
public class AppFilterActivity extends AppCompatActivity {
private RecyclerViewAdapter adapter;
@Override
@ -78,7 +77,7 @@ public class AppFilterActivity extends AppCompatActivity {
adapter.notifyDataSetChanged();
}
private class AppObject {
private static class AppObject {
private String appName;
private String appPackageName;
private Drawable appIcon;
@ -111,13 +110,11 @@ public class AppFilterActivity extends AppCompatActivity {
void updateList(ArrayList<AppObject> appObjects) {
appList = appObjects;
for (int i = 0; i < appObjects.size(); i++) {
if (Daedalus.configurations.getAppObjects().contains(appObjects.get(i).appPackageName)) {
checkStatus.put(i, true);
}
}
runOnUiThread(this::notifyDataSetChanged);
}
@ -158,7 +155,7 @@ public class AppFilterActivity extends AppCompatActivity {
}
}
private class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private static class RecyclerViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private ImageView appIcon;
private TextView appName;
private CheckBox appCheck;
@ -172,7 +169,6 @@ public class AppFilterActivity extends AppCompatActivity {
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (appCheck.isChecked()) {

View File

@ -1,7 +1,5 @@
package org.itxtech.daedalus.activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@ -9,10 +7,12 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.fragment.ConfigFragment;
import org.itxtech.daedalus.fragment.DNSServerConfigFragment;
import org.itxtech.daedalus.fragment.DnsServerConfigFragment;
import org.itxtech.daedalus.fragment.RuleConfigFragment;
/**
@ -44,14 +44,12 @@ 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();
fragment = new DnsServerConfigFragment();
break;
}
@ -64,7 +62,7 @@ public class ConfigActivity extends AppCompatActivity {
toolbar.setOnMenuItemClickListener(fragment);
toolbar.inflateMenu(R.menu.custom_config);
FragmentManager manager = getFragmentManager();
FragmentManager manager = getSupportFragmentManager();
fragment.setIntent(getIntent());
FragmentTransaction fragmentTransaction = manager.beginTransaction();
fragmentTransaction.replace(R.id.id_config, fragment);

View File

@ -1,9 +1,7 @@
package org.itxtech.daedalus.activity;
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.VpnService;
import android.os.Bundle;
@ -26,7 +24,6 @@ import org.itxtech.daedalus.R;
import org.itxtech.daedalus.fragment.*;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.server.DNSServerHelper;
/**
* Daedalus Project
@ -100,8 +97,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
if (currentFragment == null || fragmentClass != currentFragment.getClass()) {
try {
ToolbarFragment fragment = (ToolbarFragment) fragmentClass.newInstance();
FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.id_content, fragment).commit();
getSupportFragmentManager().beginTransaction().replace(R.id.id_content, fragment).commit();
currentFragment = fragment;
} catch (Exception e) {
Logger.logException(e);
@ -153,22 +149,14 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
new AlertDialog.Builder(this)
.setTitle("觉得还不错?")
.setMessage("您的支持是我动力来源!\n请考虑为我买杯咖啡醒醒脑甚至其他…… ;)")
.setPositiveButton("为我买杯咖啡", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
.setPositiveButton("为我买杯咖啡", (dialog, which) -> {
Daedalus.donate();
new AlertDialog.Builder(MainActivity.this)
.setMessage("感谢您的支持!;)\n我会再接再厉")
.setPositiveButton("确认", null)
.show();
}
})
.setNeutralButton("不再显示", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Daedalus.configurations.setActivateCounter(-1);
}
})
.setNeutralButton("不再显示", (dialog, which) -> Daedalus.configurations.setActivateCounter(-1))
.setNegativeButton("取消", null)
.show();
}
@ -177,12 +165,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
public void onActivityResult(int request, int result, Intent data) {
super.onActivityResult(request, result, data);
if (result == Activity.RESULT_OK) {
DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary());
DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary());
Daedalus.getInstance().startService(Daedalus.getServiceIntent(getApplicationContext()).setAction(DaedalusVpnService.ACTION_ACTIVATE));
Daedalus.activateService(Daedalus.getInstance());
updateMainButton(R.string.button_text_deactivate);
Daedalus.updateShortcut(getApplicationContext());
}
super.onActivityResult(request, result, data);
}
private void updateMainButton(int id) {
@ -194,7 +181,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private void updateUserInterface(Intent intent) {
int launchAction = intent.getIntExtra(LAUNCH_ACTION, LAUNCH_ACTION_NONE);
Log.d(TAG, "Updating user interface with Launch Action " + String.valueOf(launchAction));
Log.d(TAG, "Updating user interface with Launch Action " + launchAction);
if (launchAction == LAUNCH_ACTION_ACTIVATE) {
this.activateService();
} else if (launchAction == LAUNCH_ACTION_DEACTIVATE) {
@ -227,10 +214,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
switchFragment(AboutFragment.class);
break;
case FRAGMENT_DNS_SERVERS:
switchFragment(DNSServersFragment.class);
switchFragment(DnsServersFragment.class);
break;
case FRAGMENT_DNS_TEST:
switchFragment(DNSTestFragment.class);
switchFragment(DnsTestFragment.class);
break;
case FRAGMENT_HOME:
switchFragment(HomeFragment.class);
@ -252,7 +239,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
switch (id) {
@ -260,10 +246,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
switchFragment(AboutFragment.class);
break;
case R.id.nav_dns_server:
switchFragment(DNSServersFragment.class);
switchFragment(DnsServersFragment.class);
break;
case R.id.nav_dns_test:
switchFragment(DNSTestFragment.class);
switchFragment(DnsTestFragment.class);
break;
case R.id.nav_github:
Daedalus.openUri("https://github.com/iTXTech/Daedalus");

View File

@ -13,6 +13,7 @@ import android.webkit.WebViewClient;
import org.itxtech.daedalus.BuildConfig;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.util.Logger;
import java.util.Locale;
@ -64,7 +65,7 @@ public class AboutFragment extends ToolbarFragment {
mWebView.loadUrl("javascript:changeColor('"+(Daedalus.isDarkTheme() ? "#FFFFFF" : "#000000")+"')");
mWebView.loadUrl("javascript:changeVersionInfo('" + Daedalus.getInstance().getPackageManager().getPackageInfo(Daedalus.getInstance().getPackageName(), 0).versionName + "', '" + BuildConfig.BUILD_TIME + "', '" + BuildConfig.GIT_COMMIT + "')");
} catch (Exception e) {
Log.e("DAboutActivity", e.toString());
Logger.logException(e);
}
}
});
@ -82,8 +83,6 @@ public class AboutFragment extends ToolbarFragment {
super.onDestroyView();
if (mWebView != null) {
Log.d("DAboutActivity", "onDestroy");
mWebView.removeAllViews();
mWebView.setWebViewClient(null);
((ViewGroup) mWebView.getParent()).removeView(mWebView);

View File

@ -1,8 +1,8 @@
package org.itxtech.daedalus.fragment;
import android.content.Intent;
import android.preference.PreferenceFragment;
import androidx.appcompat.widget.Toolbar;
import androidx.preference.PreferenceFragmentCompat;
/**
* Daedalus Project
@ -15,7 +15,7 @@ import androidx.appcompat.widget.Toolbar;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
abstract public class ConfigFragment extends PreferenceFragment implements Toolbar.OnMenuItemClickListener {
abstract public class ConfigFragment extends PreferenceFragmentCompat implements Toolbar.OnMenuItemClickListener {
protected Intent intent = null;
public void setIntent(Intent intent) {

View File

@ -2,7 +2,7 @@ package org.itxtech.daedalus.fragment;
import android.app.AlertDialog;
import android.os.Bundle;
import android.preference.EditTextPreference;
import androidx.preference.EditTextPreference;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -11,8 +11,8 @@ import com.google.android.material.snackbar.Snackbar;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.activity.ConfigActivity;
import org.itxtech.daedalus.util.server.CustomDNSServer;
import org.itxtech.daedalus.util.server.DNSServer;
import org.itxtech.daedalus.server.CustomDnsServer;
import org.itxtech.daedalus.server.DnsServer;
/**
* Daedalus Project
@ -25,12 +25,11 @@ import org.itxtech.daedalus.util.server.DNSServer;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class DNSServerConfigFragment extends ConfigFragment {
public class DnsServerConfigFragment extends ConfigFragment {
private int index;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.perf_server);
}
@ -38,19 +37,19 @@ public class DNSServerConfigFragment extends ConfigFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
EditTextPreference serverName = (EditTextPreference) findPreference("serverName");
EditTextPreference serverName = findPreference("serverName");
serverName.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
EditTextPreference serverAddress = (EditTextPreference) findPreference("serverAddress");
EditTextPreference serverAddress = findPreference("serverAddress");
serverAddress.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
EditTextPreference serverPort = (EditTextPreference) findPreference("serverPort");
EditTextPreference serverPort = findPreference("serverPort");
serverPort.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
@ -59,7 +58,7 @@ public class DNSServerConfigFragment extends ConfigFragment {
index = intent.getIntExtra(ConfigActivity.LAUNCH_ACTION_ID, ConfigActivity.ID_NONE);
if (index != ConfigActivity.ID_NONE) {
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(index);
CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(index);
serverName.setText(server.getName());
serverName.setSummary(server.getName());
serverAddress.setText(server.getAddress());
@ -69,7 +68,7 @@ public class DNSServerConfigFragment extends ConfigFragment {
} else {
serverName.setText("");
serverAddress.setText("");
String port = String.valueOf(DNSServer.DNS_SERVER_DEFAULT_PORT);
String port = String.valueOf(DnsServer.DNS_SERVER_DEFAULT_PORT);
serverPort.setText(port);
serverPort.setSummary(port);
}
@ -93,9 +92,9 @@ public class DNSServerConfigFragment extends ConfigFragment {
}
if (index == ConfigActivity.ID_NONE) {
Daedalus.configurations.getCustomDNSServers().add(new CustomDNSServer(serverName, serverAddress, Integer.parseInt(serverPort)));
Daedalus.configurations.getCustomDNSServers().add(new CustomDnsServer(serverName, serverAddress, Integer.parseInt(serverPort)));
} else {
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(index);
CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(index);
server.setName(serverName);
server.setAddress(serverAddress);
server.setPort(Integer.parseInt(serverPort));

View File

@ -15,8 +15,8 @@ import com.google.android.material.snackbar.Snackbar;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.activity.ConfigActivity;
import org.itxtech.daedalus.util.server.CustomDNSServer;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.CustomDnsServer;
import org.itxtech.daedalus.server.DnsServerHelper;
/**
* Daedalus Project
@ -29,9 +29,9 @@ import org.itxtech.daedalus.util.server.DNSServerHelper;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class DNSServersFragment extends ToolbarFragment {
public class DnsServersFragment extends ToolbarFragment {
private DNSServerAdapter adapter;
private CustomDNSServer server = null;
private CustomDnsServer server = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -47,7 +47,7 @@ public class DNSServersFragment extends ToolbarFragment {
if (viewHolder instanceof ViewHolder) {
int index = ((ViewHolder) viewHolder).getIndex();
if (index < Daedalus.configurations.getCustomDNSServers().size() &&
DNSServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
return 0;
}
}
@ -118,7 +118,7 @@ public class DNSServersFragment extends ToolbarFragment {
private class DNSServerAdapter extends RecyclerView.Adapter<ViewHolder> {
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
CustomDNSServer server = Daedalus.configurations.getCustomDNSServers().get(position);
CustomDnsServer server = Daedalus.configurations.getCustomDNSServers().get(position);
holder.setIndex(position);
holder.textViewName.setText(server.getName());
holder.textViewAddress.setText(server.getRealName());
@ -159,7 +159,7 @@ public class DNSServersFragment extends ToolbarFragment {
@Override
public void onClick(View v) {
if (!DNSServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
if (!DnsServerHelper.isInUsing(Daedalus.configurations.getCustomDNSServers().get(index))) {
Daedalus.getInstance().startActivity(new Intent(Daedalus.getInstance(), ConfigActivity.class)
.putExtra(ConfigActivity.LAUNCH_ACTION_ID, index)
.putExtra(ConfigActivity.LAUNCH_ACTION_FRAGMENT, ConfigActivity.LAUNCH_FRAGMENT_DNS_SERVER)

View File

@ -12,8 +12,8 @@ import android.widget.*;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.server.AbstractDNSServer;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.AbstractDnsServer;
import org.itxtech.daedalus.server.DnsServerHelper;
import org.minidns.dnsmessage.DnsMessage;
import org.minidns.dnsmessage.Question;
import org.minidns.record.Record;
@ -36,7 +36,7 @@ import java.util.Random;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class DNSTestFragment extends ToolbarFragment {
public class DnsTestFragment extends ToolbarFragment {
private class Type {
private Record.TYPE type;
private String name;
@ -67,9 +67,9 @@ public class DNSTestFragment extends ToolbarFragment {
final TextView textViewTestInfo = view.findViewById(R.id.textView_test_info);
final Spinner spinnerServerChoice = view.findViewById(R.id.spinner_server_choice);
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, DNSServerHelper.getAllServers());
ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, DnsServerHelper.getAllServers());
spinnerServerChoice.setAdapter(spinnerArrayAdapter);
spinnerServerChoice.setSelection(DNSServerHelper.getPosition(DNSServerHelper.getPrimary()));
spinnerServerChoice.setSelection(DnsServerHelper.getPosition(DnsServerHelper.getPrimary()));
ArrayList<Type> types = new ArrayList<Type>() {{
add(new Type("A", Record.TYPE.A));
@ -110,38 +110,38 @@ public class DNSTestFragment extends ToolbarFragment {
testDomain = Daedalus.DEFAULT_TEST_DOMAINS[0];
}
StringBuilder testText = new StringBuilder();
ArrayList<AbstractDNSServer> dnsServers = new ArrayList<AbstractDNSServer>() {{
add(((AbstractDNSServer) spinnerServerChoice.getSelectedItem()));
ArrayList<AbstractDnsServer> dnsServers = new ArrayList<AbstractDnsServer>() {{
add(((AbstractDnsServer) spinnerServerChoice.getSelectedItem()));
String servers = Daedalus.getPrefs().getString("dns_test_servers", "");
if (!servers.equals("")) {
for (String server : servers.split(",")) {
if (server.contains(".") && server.contains(":")) {//IPv4
String[] pieces = servers.split(":");
int port = AbstractDNSServer.DNS_SERVER_DEFAULT_PORT;
int port = AbstractDnsServer.DNS_SERVER_DEFAULT_PORT;
try {
port = Integer.parseInt(pieces[1]);
} catch (Exception e) {
Logger.logException(e);
}
add(new AbstractDNSServer(pieces[0], port));
add(new AbstractDnsServer(pieces[0], port));
} else if (!server.contains(".") && server.contains("|")) {//IPv6
String[] pieces = servers.split("\\|");
int port = AbstractDNSServer.DNS_SERVER_DEFAULT_PORT;
int port = AbstractDnsServer.DNS_SERVER_DEFAULT_PORT;
try {
port = Integer.parseInt(pieces[1]);
} catch (Exception e) {
Logger.logException(e);
}
add(new AbstractDNSServer(pieces[0], port));
add(new AbstractDnsServer(pieces[0], port));
} else {
add(new AbstractDNSServer(server, AbstractDNSServer.DNS_SERVER_DEFAULT_PORT));
add(new AbstractDnsServer(server, AbstractDnsServer.DNS_SERVER_DEFAULT_PORT));
}
}
}
}};
DnsQuery dnsQuery = new DnsQuery();
Record.TYPE type = ((Type) spinnerType.getSelectedItem()).getType();
for (AbstractDNSServer dnsServer : dnsServers) {
for (AbstractDnsServer dnsServer : dnsServers) {
testText = testServer(dnsQuery, type, dnsServer, testDomain, testText);
}
mHandler.obtainMessage(DnsTestHandler.MSG_TEST_DONE).sendToTarget();
@ -151,8 +151,7 @@ public class DNSTestFragment extends ToolbarFragment {
}
}
private StringBuilder testServer(DnsQuery dnsQuery, Record.TYPE type, AbstractDNSServer server, String domain, StringBuilder testText) {
private StringBuilder testServer(DnsQuery dnsQuery, Record.TYPE type, AbstractDnsServer server, String domain, StringBuilder testText) {
Logger.debug("Testing DNS server " + server.getRealName());
testText.append(getString(R.string.test_domain)).append(" ").append(domain).append("\n")
.append(getString(R.string.test_dns_server)).append(" ").append(server.getRealName());
@ -181,7 +180,7 @@ public class DNSTestFragment extends ToolbarFragment {
}
}
testText.append("\n").append(getString(R.string.test_time_used)).append(" ").
append(String.valueOf(endTime - startTime)).append(" ms");
append(endTime - startTime).append(" ms");
succ = true;
}
} catch (SocketTimeoutException ignored) {

View File

@ -2,12 +2,14 @@ package org.itxtech.daedalus.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.preference.*;
import androidx.preference.*;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
import org.itxtech.daedalus.activity.AppFilterActivity;
import org.itxtech.daedalus.activity.MainActivity;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.DnsServerHelper;
import java.util.ArrayList;
/**
* Daedalus Project
@ -20,52 +22,47 @@ import org.itxtech.daedalus.util.server.DNSServerHelper;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class GlobalConfigFragment extends PreferenceFragment {
public class GlobalConfigFragment extends PreferenceFragmentCompat {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Daedalus.getPrefs().edit()
.putString("primary_server", DNSServerHelper.getPrimary())
.putString("secondary_server", DNSServerHelper.getSecondary())
.putString("primary_server", DnsServerHelper.getPrimary())
.putString("secondary_server", DnsServerHelper.getSecondary())
.apply();
addPreferencesFromResource(R.xml.perf_settings);
ListPreference primaryServer = (ListPreference) findPreference("primary_server");
primaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
primaryServer.setEntryValues(DNSServerHelper.getIds());
primaryServer.setSummary(DNSServerHelper.getDescription(primaryServer.getValue(), Daedalus.getInstance()));
primaryServer.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary(DNSServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
boolean visible = !Daedalus.getPrefs().getBoolean("settings_use_system_dns", false);
for (String k : new ArrayList<String>() {{
add("primary_server");
add("secondary_server");
}}) {
ListPreference listPref = findPreference(k);
listPref.setEntries(DnsServerHelper.getNames(Daedalus.getInstance()));
listPref.setEntryValues(DnsServerHelper.getIds());
listPref.setSummary(DnsServerHelper.getDescription(listPref.getValue(), Daedalus.getInstance()));
listPref.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary(DnsServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
return true;
});
}
ListPreference secondaryServer = (ListPreference) findPreference("secondary_server");
secondaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance()));
secondaryServer.setEntryValues(DNSServerHelper.getIds());
secondaryServer.setSummary(DNSServerHelper.getDescription(secondaryServer.getValue(), Daedalus.getInstance()));
secondaryServer.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary(DNSServerHelper.getDescription((String) newValue, Daedalus.getInstance()));
return true;
});
EditTextPreference testDNSServers = (EditTextPreference) findPreference("dns_test_servers");
EditTextPreference testDNSServers = findPreference("dns_test_servers");
testDNSServers.setSummary(testDNSServers.getText());
testDNSServers.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
EditTextPreference logSize = (EditTextPreference) findPreference("settings_log_size");
EditTextPreference logSize = findPreference("settings_log_size");
logSize.setSummary(logSize.getText());
logSize.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
SwitchPreference darkTheme = (SwitchPreference) findPreference("settings_dark_theme");
SwitchPreference darkTheme = findPreference("settings_dark_theme");
darkTheme.setOnPreferenceChangeListener((preference, o) -> {
getActivity().startActivity(new Intent(Daedalus.getInstance(), MainActivity.class)
.putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS)
@ -73,13 +70,13 @@ public class GlobalConfigFragment extends PreferenceFragment {
return true;
});
SwitchPreference advanced = (SwitchPreference) findPreference("settings_advanced_switch");
SwitchPreference advanced = findPreference("settings_advanced_switch");
advanced.setOnPreferenceChangeListener((preference, newValue) -> {
updateOptions((boolean) newValue, "settings_advanced");
return true;
});
SwitchPreference appFilter = (SwitchPreference) findPreference("settings_app_filter_switch");
SwitchPreference appFilter = findPreference("settings_app_filter_switch");
appFilter.setOnPreferenceChangeListener((p, w) -> {
updateOptions((boolean) w, "settings_app_filter");
return true;
@ -115,7 +112,7 @@ public class GlobalConfigFragment extends PreferenceFragment {
}
private void updateOptions(boolean checked, String pref) {
PreferenceCategory category = (PreferenceCategory) findPreference(pref);
PreferenceCategory category = findPreference(pref);
for (int i = 1; i < category.getPreferenceCount(); i++) {
Preference preference = category.getPreference(i);
if (checked) {

View File

@ -49,16 +49,7 @@ public class HomeFragment extends ToolbarFragment {
updateUserInterface();
}
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
updateUserInterface();
}
}
private void updateUserInterface() {
Log.d("DMainFragment", "updateInterface");
Button but = getView().findViewById(R.id.button_activate);
if (DaedalusVpnService.isActivated()) {
but.setText(R.string.button_text_deactivate);

View File

@ -44,7 +44,7 @@ public class LogFragment extends ToolbarFragment implements Toolbar.OnMenuItemCl
private void export() {
try {
String file = Daedalus.logPath + String.valueOf(System.currentTimeMillis()) + ".log";
String file = Daedalus.logPath + System.currentTimeMillis() + ".log";
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(Logger.getLog());
fileWriter.close();

View File

@ -7,8 +7,8 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
@ -72,10 +72,8 @@ public class RuleConfigFragment extends ConfigFragment {
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.perf_rule);
}
@ -85,13 +83,13 @@ public class RuleConfigFragment extends ConfigFragment {
mHandler = new RuleConfigHandler().setView(view);
final EditTextPreference ruleName = (EditTextPreference) findPreference("ruleName");
final EditTextPreference ruleName = findPreference("ruleName");
ruleName.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
final ListPreference ruleType = (ListPreference) findPreference("ruleType");
final ListPreference ruleType = findPreference("ruleType");
final String[] entries = {"Hosts", "DNSMasq"};
String[] values = {"0", "1"};
ruleType.setEntries(entries);
@ -101,19 +99,19 @@ public class RuleConfigFragment extends ConfigFragment {
return true;
});
final EditTextPreference ruleDownloadUrl = (EditTextPreference) findPreference("ruleDownloadUrl");
final EditTextPreference ruleDownloadUrl = findPreference("ruleDownloadUrl");
ruleDownloadUrl.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
final EditTextPreference ruleFilename = (EditTextPreference) findPreference("ruleFilename");
final EditTextPreference ruleFilename = findPreference("ruleFilename");
ruleFilename.setOnPreferenceChangeListener((preference, newValue) -> {
preference.setSummary((String) newValue);
return true;
});
ClickPreference ruleSync = (ClickPreference) findPreference("ruleSync");
ClickPreference ruleSync = findPreference("ruleSync");
ruleSync.setOnPreferenceClickListener(preference -> {
save();
if (mThread == null) {
@ -167,7 +165,7 @@ public class RuleConfigFragment extends ConfigFragment {
return false;
});
ListPreference ruleImportBuildIn = (ListPreference) findPreference("ruleImportBuildIn");
ListPreference ruleImportBuildIn = findPreference("ruleImportBuildIn");
ruleImportBuildIn.setEntries(Rule.getBuildInRuleNames());
ruleImportBuildIn.setEntryValues(Rule.getBuildInRuleEntries());
ruleImportBuildIn.setOnPreferenceChangeListener((preference, newValue) -> {
@ -183,7 +181,7 @@ public class RuleConfigFragment extends ConfigFragment {
return true;
});
ClickPreference ruleImportExternal = (ClickPreference) findPreference("ruleImportExternal");
ClickPreference ruleImportExternal = findPreference("ruleImportExternal");
ruleImportExternal.setOnPreferenceClickListener(preference -> {
performFileSearch();
return false;

View File

@ -1,7 +1,5 @@
package org.itxtech.daedalus.fragment;
import android.app.FragmentManager;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -28,13 +26,7 @@ public class SettingsFragment extends ToolbarFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
FragmentManager fm;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
fm = getChildFragmentManager();
} else {
fm = getFragmentManager();
}
fm.beginTransaction().replace(R.id.settings_content, new GlobalConfigFragment()).commit();
getChildFragmentManager().beginTransaction().replace(R.id.settings_content, new GlobalConfigFragment()).commit();
}
@Override

View File

@ -1,10 +1,10 @@
package org.itxtech.daedalus.fragment;
import android.app.Fragment;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import com.google.android.material.navigation.NavigationView;
import org.itxtech.daedalus.R;

View File

@ -10,7 +10,7 @@ import okhttp3.OkHttpClient;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.DnsServerHelper;
import org.minidns.dnsmessage.DnsMessage;
import org.pcap4j.packet.IpPacket;
import org.pcap4j.packet.IpSelector;
@ -58,8 +58,8 @@ abstract public class HttpsProvider extends Provider {
.header("Accept", accept)
.build()))
.dns(hostname -> {
if (DNSServerHelper.domainCache.containsKey(hostname)) {
return DNSServerHelper.domainCache.get(hostname);
if (DnsServerHelper.domainCache.containsKey(hostname)) {
return DnsServerHelper.domainCache.get(hostname);
}
return Arrays.asList(InetAddress.getAllByName(hostname));
})
@ -138,7 +138,7 @@ abstract public class HttpsProvider extends Provider {
return;
String uri;
try {
uri = service.dnsServers.get(destAddr.getHostAddress());//https uri
uri = service.dnsServers.get(destAddr.getHostAddress()).getAddress();//https uri
} catch (Exception e) {
Logger.logException(e);
return;
@ -161,7 +161,7 @@ abstract public class HttpsProvider extends Provider {
return;
}
if (dnsMsg.getQuestion() == null) {
Log.i(TAG, "handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
Logger.debug("handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
return;
}

View File

@ -15,7 +15,7 @@ import org.itxtech.daedalus.service.DaedalusVpnService;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class ProviderPicker {
public abstract class ProviderPicker {
public static final int DNS_QUERY_METHOD_UDP = 0;
public static final int DNS_QUERY_METHOD_TCP = 1;
public static final int DNS_QUERY_METHOD_TLS = 2;
@ -40,6 +40,6 @@ public class ProviderPicker {
}
public static int getDnsQueryMethod() {
return Integer.valueOf(Daedalus.getPrefs().getString("settings_dns_query_method", "0"));
return Integer.parseInt(Daedalus.getPrefs().getString("settings_dns_query_method", "0"));
}
}

View File

@ -9,7 +9,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.AbstractDnsServer;
import org.pcap4j.packet.IpPacket;
import java.io.*;
@ -123,7 +123,7 @@ public class TcpProvider extends UdpProvider {
}
@Override
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) throws DaedalusVpnService.VpnNetworkException {
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket, AbstractDnsServer dnsServer) throws DaedalusVpnService.VpnNetworkException {
Socket dnsSocket;
try {
// Packets to be sent to the real DNS server will need to be protected from the VPN
@ -131,7 +131,7 @@ public class TcpProvider extends UdpProvider {
service.protect(dnsSocket);
SocketAddress address = new InetSocketAddress(outPacket.getAddress(), DNSServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
SocketAddress address = new InetSocketAddress(outPacket.getAddress(), dnsServer.getPort());
dnsSocket.connect(address, 5000);
dnsSocket.setSoTimeout(5000);
Logger.info("TcpProvider: Sending DNS query request");
@ -161,7 +161,7 @@ public class TcpProvider extends UdpProvider {
try {
DataInputStream stream = new DataInputStream(dnsSocket.getInputStream());
int length = stream.readUnsignedShort();
Log.d(TAG, "Reading length: " + String.valueOf(length));
Log.d(TAG, "Reading length: " + length);
byte[] data = new byte[length];
stream.read(data);
dnsSocket.close();

View File

@ -3,7 +3,7 @@ package org.itxtech.daedalus.provider;
import android.os.ParcelFileDescriptor;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.AbstractDnsServer;
import org.pcap4j.packet.IpPacket;
import javax.net.ssl.SSLContext;
@ -28,13 +28,12 @@ public class TlsProvider extends TcpProvider{
}
@Override
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) {
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket, AbstractDnsServer dnsServer) {
Socket dnsSocket;
try {
SSLContext context = SSLContext.getInstance("TLSv1.2");
context.init(null, null, null);
dnsSocket = context.getSocketFactory().createSocket(outPacket.getAddress(),
DNSServerHelper.getPortOrDefault(outPacket.getAddress(), outPacket.getPort()));
dnsSocket = context.getSocketFactory().createSocket(outPacket.getAddress(), dnsServer.getPort());
//Create TLS v1.2 socket
//TODO: SNI

View File

@ -9,7 +9,7 @@ import androidx.annotation.NonNull;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.service.DaedalusVpnService;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import org.itxtech.daedalus.server.AbstractDnsServer;
import org.minidns.dnsmessage.DnsMessage;
import org.pcap4j.packet.IpPacket;
import org.pcap4j.packet.IpSelector;
@ -118,7 +118,7 @@ public class UdpProvider extends Provider {
}
}
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket) throws DaedalusVpnService.VpnNetworkException {
protected void forwardPacket(DatagramPacket outPacket, IpPacket parsedPacket, AbstractDnsServer dnsServer) throws DaedalusVpnService.VpnNetworkException {
DatagramSocket dnsSocket;
try {
// Packets to be sent to the real DNS server will need to be protected from the VPN
@ -158,7 +158,6 @@ public class UdpProvider extends Provider {
*/
@Override
protected void handleDnsRequest(byte[] packetData) throws DaedalusVpnService.VpnNetworkException {
IpPacket parsedPacket;
try {
parsedPacket = (IpPacket) IpSelector.newPacket(packetData, 0, packetData.length);
@ -168,15 +167,21 @@ public class UdpProvider extends Provider {
}
if (!(parsedPacket.getPayload() instanceof UdpPacket)) {
Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload());
try {
Logger.debug("handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload());
} catch (Exception ignored) {
}
return;
}
InetAddress destAddr = parsedPacket.getHeader().getDstAddr();
if (destAddr == null)
if (destAddr == null) {
return;
}
AbstractDnsServer dnsServer;
try {
destAddr = InetAddress.getByName(service.dnsServers.get(destAddr.getHostAddress()));
dnsServer = service.dnsServers.get(destAddr.getHostAddress());
destAddr = InetAddress.getByName(dnsServer.getHostAddress());
} catch (Exception e) {
Logger.logException(e);
Logger.error("handleDnsRequest: DNS server alias query failed for " + destAddr.getHostAddress());
@ -191,9 +196,8 @@ public class UdpProvider extends Provider {
// Let's be nice to Firefox. Firefox uses an empty UDP packet to
// the gateway to reduce the RTT. For further details, please see
// https://bugzilla.mozilla.org/show_bug.cgi?id=888268
DatagramPacket outPacket = new DatagramPacket(new byte[0], 0, 0, destAddr,
DNSServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
forwardPacket(outPacket, null);
DatagramPacket outPacket = new DatagramPacket(new byte[0], 0, 0, destAddr, dnsServer.getPort());
forwardPacket(outPacket, null, dnsServer);
return;
}
@ -209,14 +213,13 @@ public class UdpProvider extends Provider {
return;
}
if (dnsMsg.getQuestion() == null) {
Log.i(TAG, "handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
Logger.debug("handleDnsRequest: Discarding DNS packet with no query " + dnsMsg);
return;
}
if (!resolve(parsedPacket, dnsMsg)) {
DatagramPacket outPacket = new DatagramPacket(dnsRawData, 0, dnsRawData.length, destAddr,
DNSServerHelper.getPortOrDefault(destAddr, parsedUdp.getHeader().getDstPort().valueAsInt()));
forwardPacket(outPacket, parsedPacket);
DatagramPacket outPacket = new DatagramPacket(dnsRawData, 0, dnsRawData.length, destAddr, dnsServer.getPort());
forwardPacket(outPacket, parsedPacket, dnsServer);
}
}

View File

@ -21,7 +21,7 @@ public class BootBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Daedalus.getPrefs().getBoolean("settings_boot", false)) {
Daedalus.activateService(context);
Daedalus.activateService(context, true);
Logger.info("Triggered boot receiver");
}
}

View File

@ -1,4 +1,6 @@
package org.itxtech.daedalus.util.server;
package org.itxtech.daedalus.server;
import androidx.annotation.NonNull;
/**
* Daedalus Project
@ -11,17 +13,26 @@ package org.itxtech.daedalus.util.server;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class AbstractDNSServer {
public class AbstractDnsServer implements Cloneable {
public static final int DNS_SERVER_DEFAULT_PORT = 53;
protected String address;
protected int port;
protected String hostAddress;
public AbstractDNSServer(String address, int port) {
public AbstractDnsServer(String address, int port) {
this.address = address;
this.port = port;
}
public void setHostAddress(String hostAddress) {
this.hostAddress = hostAddress;
}
public String getHostAddress() {
return hostAddress;
}
public void setAddress(String address) {
this.address = address;
}
@ -54,4 +65,14 @@ public class AbstractDNSServer {
public boolean isHttpsServer() {
return address.contains("/");
}
@NonNull
@Override
public Object clone() {
try {
return super.clone();
} catch (Exception ignored) {
}
return new AbstractDnsServer("", 0);
}
}

View File

@ -1,4 +1,4 @@
package org.itxtech.daedalus.util.server;
package org.itxtech.daedalus.server;
import org.itxtech.daedalus.Daedalus;
@ -13,11 +13,11 @@ import org.itxtech.daedalus.Daedalus;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class CustomDNSServer extends AbstractDNSServer {
public class CustomDnsServer extends AbstractDnsServer {
private String name;
private String id;
public CustomDNSServer(String name, String address, int port) {
public CustomDnsServer(String name, String address, int port) {
super(address, port);
this.name = name;
this.id = String.valueOf(Daedalus.configurations.getNextDnsId());

View File

@ -1,4 +1,4 @@
package org.itxtech.daedalus.util.server;
package org.itxtech.daedalus.server;
import android.content.Context;
import org.itxtech.daedalus.Daedalus;
@ -14,23 +14,27 @@ import org.itxtech.daedalus.Daedalus;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class DNSServer extends AbstractDNSServer {
public class DnsServer extends AbstractDnsServer {
private static int totalId = 0;
private String id;
private int description = 0;
private int description;
public DNSServer(String address, int description, int port) {
public DnsServer(String address, int description, int port) {
super(address, port);
this.id = String.valueOf(totalId++);
this.description = description;
}
public DNSServer(String address, int description) {
public DnsServer(String address, int description) {
this(address, description, DNS_SERVER_DEFAULT_PORT);
}
public DnsServer(String address) {
this(address, 0);
}
public String getId() {
return id;
}

View File

@ -1,4 +1,4 @@
package org.itxtech.daedalus.util.server;
package org.itxtech.daedalus.server;
import android.content.Context;
import android.net.Uri;
@ -25,31 +25,19 @@ import java.util.List;
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
public class DNSServerHelper {
private static HashMap<String, Integer> portCache = new HashMap<>();
public class DnsServerHelper {
public static HashMap<String, List<InetAddress>> domainCache = new HashMap<>();
public static void clearCache() {
portCache = new HashMap<>();
domainCache = new HashMap<>();
}
public static void buildCache() {
domainCache = new HashMap<>();
portCache = new HashMap<>();
if (ProviderPicker.getDnsQueryMethod() >= ProviderPicker.DNS_QUERY_METHOD_HTTPS_IETF &&
!Daedalus.getPrefs().getBoolean("settings_dont_build_doh_cache", false)) {
buildDomainCache(getAddressById(getPrimary()));
buildDomainCache(getAddressById(getSecondary()));
}
for (DNSServer server : Daedalus.DNS_SERVERS) {
portCache.put(server.getAddress(), server.getPort());
}
for (CustomDNSServer server : Daedalus.configurations.getCustomDNSServers()) {
portCache.put(server.getAddress(), server.getPort());
!Daedalus.getPrefs().getBoolean("settings_dont_build_cache", false)) {
buildDomainCache(getServerById(getPrimary()).getAddress());
buildDomainCache(getServerById(getSecondary()).getAddress());
}
}
@ -63,16 +51,6 @@ public class DNSServerHelper {
}
}
public static int getPortOrDefault(InetAddress address, int defaultPort) {
String hostAddress = address.getHostAddress();
if (portCache.containsKey(hostAddress)) {
return portCache.get(hostAddress);
}
return defaultPort;
}
public static int getPosition(String id) {
int intId = Integer.parseInt(id);
if (intId < Daedalus.DNS_SERVERS.size()) {
@ -88,18 +66,18 @@ public class DNSServerHelper {
}
public static String getPrimary() {
return String.valueOf(DNSServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("primary_server", "0"))));
return String.valueOf(DnsServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("primary_server", "0"))));
}
public static String getSecondary() {
return String.valueOf(DNSServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("secondary_server", "1"))));
return String.valueOf(DnsServerHelper.checkServerId(Integer.parseInt(Daedalus.getPrefs().getString("secondary_server", "1"))));
}
private static int checkServerId(int id) {
if (id < Daedalus.DNS_SERVERS.size()) {
return id;
}
for (CustomDNSServer server : Daedalus.configurations.getCustomDNSServers()) {
for (CustomDnsServer server : Daedalus.configurations.getCustomDNSServers()) {
if (server.getId().equals(String.valueOf(id))) {
return id;
}
@ -107,26 +85,26 @@ public class DNSServerHelper {
return 0;
}
public static String getAddressById(String id) {
for (DNSServer server : Daedalus.DNS_SERVERS) {
public static AbstractDnsServer getServerById(String id) {
for (DnsServer server : Daedalus.DNS_SERVERS) {
if (server.getId().equals(id)) {
return server.getAddress();
return server;
}
}
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
if (customDNSServer.getId().equals(id)) {
return customDNSServer.getAddress();
return customDNSServer;
}
}
return Daedalus.DNS_SERVERS.get(0).getAddress();
return Daedalus.DNS_SERVERS.get(0);
}
public static String[] getIds() {
ArrayList<String> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
for (DNSServer server : Daedalus.DNS_SERVERS) {
for (DnsServer server : Daedalus.DNS_SERVERS) {
servers.add(server.getId());
}
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
servers.add(customDNSServer.getId());
}
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
@ -135,30 +113,30 @@ public class DNSServerHelper {
public static String[] getNames(Context context) {
ArrayList<String> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
for (DNSServer server : Daedalus.DNS_SERVERS) {
for (DnsServer server : Daedalus.DNS_SERVERS) {
servers.add(server.getStringDescription(context));
}
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
servers.add(customDNSServer.getName());
}
String[] stringServers = new String[Daedalus.DNS_SERVERS.size()];
return servers.toArray(stringServers);
}
public static ArrayList<AbstractDNSServer> getAllServers() {
ArrayList<AbstractDNSServer> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
public static ArrayList<AbstractDnsServer> getAllServers() {
ArrayList<AbstractDnsServer> servers = new ArrayList<>(Daedalus.DNS_SERVERS.size());
servers.addAll(Daedalus.DNS_SERVERS);
servers.addAll(Daedalus.configurations.getCustomDNSServers());
return servers;
}
public static String getDescription(String id, Context context) {
for (DNSServer server : Daedalus.DNS_SERVERS) {
for (DnsServer server : Daedalus.DNS_SERVERS) {
if (server.getId().equals(id)) {
return server.getStringDescription(context);
}
}
for (CustomDNSServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
for (CustomDnsServer customDNSServer : Daedalus.configurations.getCustomDNSServers()) {
if (customDNSServer.getId().equals(id)) {
return customDNSServer.getName();
}
@ -166,7 +144,7 @@ public class DNSServerHelper {
return Daedalus.DNS_SERVERS.get(0).getStringDescription(context);
}
public static boolean isInUsing(CustomDNSServer server) {
public static boolean isInUsing(CustomDnsServer server) {
return DaedalusVpnService.isActivated() && (server.getId().equals(getPrimary()) || server.getId().equals(getSecondary()));
}
}

View File

@ -4,14 +4,18 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.VpnService;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.system.OsConstants;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.NotificationCompat;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.R;
@ -19,9 +23,12 @@ import org.itxtech.daedalus.activity.MainActivity;
import org.itxtech.daedalus.provider.Provider;
import org.itxtech.daedalus.provider.ProviderPicker;
import org.itxtech.daedalus.receiver.StatusBarBroadcastReceiver;
import org.itxtech.daedalus.server.AbstractDnsServer;
import org.itxtech.daedalus.server.DnsServer;
import org.itxtech.daedalus.server.DnsServerHelper;
import org.itxtech.daedalus.util.DnsServersDetector;
import org.itxtech.daedalus.util.Logger;
import org.itxtech.daedalus.util.RuleResolver;
import org.itxtech.daedalus.util.server.DNSServerHelper;
import java.net.Inet4Address;
import java.net.Inet6Address;
@ -51,22 +58,21 @@ public class DaedalusVpnService extends VpnService implements Runnable {
private static final String CHANNEL_ID = "daedalus_channel_1";
private static final String CHANNEL_NAME = "daedalus_channel";
public static String primaryServer;
public static String secondaryServer;
public static AbstractDnsServer primaryServer;
public static AbstractDnsServer secondaryServer;
private static InetAddress aliasPrimary;
private static InetAddress aliasSecondary;
private NotificationCompat.Builder notification = null;
private boolean running = false;
private long lastUpdate = 0;
private boolean statisticQuery;
private Provider provider;
private ParcelFileDescriptor descriptor;
private Thread mThread = null;
public HashMap<String, String> dnsServers;
public HashMap<String, AbstractDnsServer> dnsServers;
private static boolean activated = false;
private static BroadcastReceiver receiver;
public static boolean isActivated() {
return activated;
@ -75,6 +81,44 @@ public class DaedalusVpnService extends VpnService implements Runnable {
@Override
public void onCreate() {
super.onCreate();
if (Daedalus.getPrefs().getBoolean("settings_use_system_dns", false)) {
registerReceiver(receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateUpstreamServers(context);
}
}, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
}
private static void updateUpstreamServers(Context context) {
String[] servers = DnsServersDetector.getServers(context);
if (servers != null) {
if (servers.length >= 2 && (aliasPrimary == null || !aliasPrimary.getHostAddress().equals(servers[0])) &&
(aliasSecondary == null || !aliasSecondary.getHostAddress().equals(servers[0])) &&
(aliasPrimary == null || !aliasPrimary.getHostAddress().equals(servers[1])) &&
(aliasSecondary == null || !aliasSecondary.getHostAddress().equals(servers[1]))) {
primaryServer.setAddress(servers[0]);
primaryServer.setPort(DnsServer.DNS_SERVER_DEFAULT_PORT);
secondaryServer.setAddress(servers[1]);
secondaryServer.setPort(DnsServer.DNS_SERVER_DEFAULT_PORT);
} else if ((aliasPrimary == null || !aliasPrimary.getHostAddress().equals(servers[0])) &&
(aliasSecondary == null || !aliasSecondary.getHostAddress().equals(servers[0]))) {
primaryServer.setAddress(servers[0]);
primaryServer.setPort(DnsServer.DNS_SERVER_DEFAULT_PORT);
secondaryServer.setAddress(servers[0]);
secondaryServer.setPort(DnsServer.DNS_SERVER_DEFAULT_PORT);
} else {
StringBuilder buf = new StringBuilder();
for (String server : servers) {
buf.append(server).append(" ");
}
Logger.error("Invalid upstream DNS " + buf);
}
Logger.info("Upstream DNS updated: " + primaryServer.getAddress() + " " + secondaryServer.getAddress());
} else {
Logger.error("Cannot obtain upstream DNS server!");
}
}
@Override
@ -84,7 +128,6 @@ public class DaedalusVpnService extends VpnService implements Runnable {
case ACTION_ACTIVATE:
activated = true;
if (Daedalus.getPrefs().getBoolean("settings_notification", true)) {
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder;
@ -126,12 +169,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
}
Daedalus.initRuleResolver();
if (this.mThread == null) {
this.mThread = new Thread(this, "DaedalusVpn");
this.running = true;
this.mThread.start();
}
startThread();
Daedalus.updateShortcut(getApplicationContext());
if (MainActivity.getInstance() != null) {
MainActivity.getInstance().startActivity(new Intent(getApplicationContext(), MainActivity.class)
@ -146,9 +184,21 @@ public class DaedalusVpnService extends VpnService implements Runnable {
return START_NOT_STICKY;
}
private void startThread() {
if (this.mThread == null) {
this.mThread = new Thread(this, "DaedalusVpn");
this.running = true;
this.mThread.start();
}
}
@Override
public void onDestroy() {
stopThread();
if (receiver != null) {
unregisterReceiver(receiver);
receiver = null;
}
}
private void stopThread() {
@ -185,7 +235,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
if (shouldRefresh) {
RuleResolver.clear();
DNSServerHelper.clearCache();
DnsServerHelper.clearCache();
Logger.info("Daedalus VPN service has stopped");
}
@ -202,27 +252,30 @@ public class DaedalusVpnService extends VpnService implements Runnable {
stopThread();
}
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, String addr) throws UnknownHostException {
private InetAddress addDnsServer(Builder builder, String format, byte[] ipv6Template, AbstractDnsServer addr)
throws UnknownHostException {
int size = dnsServers.size();
size++;
if (addr.contains("/")) {//https uri
if (addr.getAddress().contains("/")) {//https uri
String alias = String.format(format, size + 1);
dnsServers.put(alias, addr);
builder.addRoute(alias, 32);
return InetAddress.getByName(alias);
}
InetAddress address = InetAddress.getByName(addr);
InetAddress address = InetAddress.getByName(addr.getAddress());
if (address instanceof Inet6Address && ipv6Template == null) {
Log.i(TAG, "addDnsServer: Ignoring DNS server " + address);
} else if (address instanceof Inet4Address) {
String alias = String.format(format, size + 1);
dnsServers.put(alias, address.getHostAddress());
addr.setHostAddress(address.getHostAddress());
dnsServers.put(alias, addr);
builder.addRoute(alias, 32);
return InetAddress.getByName(alias);
} else if (address instanceof Inet6Address) {
ipv6Template[ipv6Template.length - 1] = (byte) (size + 1);
InetAddress i6addr = Inet6Address.getByAddress(ipv6Template);
dnsServers.put(i6addr.getHostAddress(), address.getHostAddress());
addr.setHostAddress(address.getHostAddress());
dnsServers.put(i6addr.getHostAddress(), addr);
return i6addr;
}
return null;
@ -231,14 +284,13 @@ public class DaedalusVpnService extends VpnService implements Runnable {
@Override
public void run() {
try {
DNSServerHelper.buildCache();
DnsServerHelper.buildCache();
Builder builder = new Builder()
.setSession("Daedalus")
.setConfigureIntent(PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class).putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS),
PendingIntent.FLAG_ONE_SHOT));
//Set App Filter
if (Daedalus.getPrefs().getBoolean("settings_app_filter_switch", false)) {
ArrayList<String> apps = Daedalus.configurations.getAppObjects();
if (apps.size() > 0) {
@ -275,7 +327,6 @@ public class DaedalusVpnService extends VpnService implements Runnable {
statisticQuery = Daedalus.getPrefs().getBoolean("settings_count_query_times", false);
byte[] ipv6Template = new byte[]{32, 1, 13, (byte) (184 & 0xFF), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (primaryServer.contains(":") || secondaryServer.contains(":")) {//IPv6
try {
InetAddress addr = Inet6Address.getByAddress(ipv6Template);
Log.d(TAG, "configure: Adding IPv6 address" + addr);
@ -285,26 +336,19 @@ public class DaedalusVpnService extends VpnService implements Runnable {
ipv6Template = null;
}
} else {
ipv6Template = null;
}
InetAddress aliasPrimary;
InetAddress aliasSecondary;
if (advanced) {
dnsServers = new HashMap<>();
aliasPrimary = addDnsServer(builder, format, ipv6Template, primaryServer);
aliasSecondary = addDnsServer(builder, format, ipv6Template, secondaryServer);
} else {
aliasPrimary = InetAddress.getByName(primaryServer);
aliasSecondary = InetAddress.getByName(secondaryServer);
aliasPrimary = InetAddress.getByName(primaryServer.getAddress());
aliasSecondary = InetAddress.getByName(secondaryServer.getAddress());
}
InetAddress primaryDNSServer = aliasPrimary;
InetAddress secondaryDNSServer = aliasSecondary;
Logger.info("Daedalus VPN service is listening on " + primaryServer + " as " + primaryDNSServer.getHostAddress());
Logger.info("Daedalus VPN service is listening on " + secondaryServer + " as " + secondaryDNSServer.getHostAddress());
builder.addDnsServer(primaryDNSServer).addDnsServer(secondaryDNSServer);
Logger.info("Daedalus VPN service is listening on " + primaryServer.getAddress() + " as " + aliasPrimary.getHostAddress());
Logger.info("Daedalus VPN service is listening on " + secondaryServer.getAddress() + " as " + aliasSecondary.getHostAddress());
builder.addDnsServer(aliasPrimary).addDnsServer(aliasSecondary);
if (advanced) {
builder.setBlocking(true);
@ -324,13 +368,17 @@ public class DaedalusVpnService extends VpnService implements Runnable {
Thread.sleep(1000);
}
}
} catch (
InterruptedException ignored) {
} catch (
Exception e) {
} catch (InterruptedException ignored) {
} catch (Exception e) {
MainActivity.getInstance().runOnUiThread(() ->
new AlertDialog.Builder(MainActivity.getInstance())
.setTitle(R.string.error_occurred)
.setMessage(Logger.getExceptionMessage(e))
.setPositiveButton(android.R.string.ok, (d, id) -> {
})
.show());
Logger.logException(e);
} finally {
Log.d(TAG, "quit");
stopThread();
}
}
@ -346,14 +394,13 @@ public class DaedalusVpnService extends VpnService implements Runnable {
if (time - lastUpdate >= 1000) {
lastUpdate = time;
if (notification != null) {
notification.setContentTitle(getResources().getString(R.string.notice_queries) + " " + String.valueOf(provider.getDnsQueryTimes()));
notification.setContentTitle(getResources().getString(R.string.notice_queries) + " " + provider.getDnsQueryTimes());
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_ACTIVATED, notification.build());
}
}
}
public static class VpnNetworkException extends Exception {
public VpnNetworkException(String s) {
super(s);
@ -362,7 +409,5 @@ public class DaedalusVpnService extends VpnService implements Runnable {
public VpnNetworkException(String s, Throwable t) {
super(s, t);
}
}
}

View File

@ -3,7 +3,7 @@ package org.itxtech.daedalus.util;
import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import org.itxtech.daedalus.Daedalus;
import org.itxtech.daedalus.util.server.CustomDNSServer;
import org.itxtech.daedalus.server.CustomDnsServer;
import java.io.File;
import java.io.FileReader;
@ -27,7 +27,7 @@ public class Configurations {
private static File file;
private ArrayList<CustomDNSServer> customDNSServers;
private ArrayList<CustomDnsServer> customDNSServers;
private ArrayList<String> appObjects;
private ArrayList<Rule> hostsRules;
@ -60,7 +60,7 @@ public class Configurations {
this.activateCounter = activateCounter;
}
public ArrayList<CustomDNSServer> getCustomDNSServers() {
public ArrayList<CustomDnsServer> getCustomDNSServers() {
if (customDNSServers == null) {
customDNSServers = new ArrayList<>();
}

View File

@ -0,0 +1,166 @@
package org.itxtech.daedalus.util;
import android.content.Context;
import android.net.*;
import android.os.Build;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Daedalus Project
*
* @author iTX Technologies
* @link https://itxtech.org
* <p>
* 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, either version 3 of the License, or
* (at your option) any later version.
*/
public class DnsServersDetector {
//https://stackoverflow.com/a/48973823
private static final String METHOD_EXEC_PROP_DELIM = "]: [";
public static String[] getServers(Context context) {
String[] result;
result = getServersMethodSystemProperties();
if (result != null && result.length > 0) {
return result;
}
result = getServersMethodConnectivityManager(context);
if (result != null && result.length > 0) {
return result;
}
result = getServersMethodExec();
if (result != null && result.length > 0) {
return result;
}
return null;
}
private static String[] getServersMethodConnectivityManager(Context context) {
ArrayList<String> priorityServersArrayList = new ArrayList<>();
ArrayList<String> serversArrayList = new ArrayList<>();
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
for (Network network : connectivityManager.getAllNetworks()) {
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
if (networkInfo.isConnected()) {
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
List<InetAddress> dnsServersList = linkProperties.getDnsServers();
if (linkPropertiesHasDefaultRoute(linkProperties)) {
for (InetAddress element : dnsServersList) {
String dnsHost = element.getHostAddress();
priorityServersArrayList.add(dnsHost);
}
} else {
for (InetAddress element : dnsServersList) {
String dnsHost = element.getHostAddress();
serversArrayList.add(dnsHost);
}
}
}
}
}
if (priorityServersArrayList.isEmpty()) {
priorityServersArrayList.addAll(serversArrayList);
}
if (priorityServersArrayList.size() > 0) {
return priorityServersArrayList.toArray(new String[0]);
}
return null;
}
private static String[] getServersMethodSystemProperties() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
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});
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);
}
}
if (serversArrayList.size() > 0) {
return serversArrayList.toArray(new String[0]);
}
} catch (Exception ex) {
Logger.logException(ex);
}
}
return null;
}
private static String[] getServersMethodExec() {
try {
Process process = Runtime.getRuntime().exec("getprop");
InputStream inputStream = process.getInputStream();
LineNumberReader lineNumberReader = new LineNumberReader(new InputStreamReader(inputStream));
Set<String> serversSet = methodExecParseProps(lineNumberReader);
if (serversSet.size() > 0) {
return serversSet.toArray(new String[0]);
}
} catch (Exception ex) {
Logger.logException(ex);
}
return null;
}
private static Set<String> methodExecParseProps(BufferedReader lineNumberReader) throws Exception {
String line;
HashSet<String> serversSet = new HashSet<>();
while ((line = lineNumberReader.readLine()) != null) {
int split = line.indexOf(METHOD_EXEC_PROP_DELIM);
if (split == -1) {
continue;
}
String property = line.substring(1, split);
int valueStart = split + METHOD_EXEC_PROP_DELIM.length();
int valueEnd = line.length() - 1;
if (valueEnd < valueStart) {
continue;
}
String value = line.substring(valueStart, valueEnd);
if (value.isEmpty()) {
continue;
}
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;
}
value = ip.getHostAddress();
if (value == null || value.length() == 0) {
continue;
}
serversSet.add(value);
}
}
return serversSet;
}
private static boolean linkPropertiesHasDefaultRoute(LinkProperties linkProperties) {
for (RouteInfo route : linkProperties.getRoutes()) {
if (route.isDefaultRoute()) {
return true;
}
}
return false;
}
}

View File

@ -1,7 +1,7 @@
package org.itxtech.daedalus.widget;
import android.content.Context;
import android.preference.ListPreference;
import androidx.preference.ListPreference;
import android.util.AttributeSet;
/**

View File

@ -25,7 +25,6 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</androidx.recyclerview.widget.RecyclerView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -9,15 +9,13 @@
android:layout_width="46dp"
android:layout_height="46dp"
android:paddingEnd="10dp"
android:paddingLeft="14dp"
android:paddingRight="10dp"
android:paddingStart="14dp" />
android:paddingStart="14dp"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/app_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
android:layout_weight="1.0"/>
<androidx.appcompat.widget.AppCompatCheckBox
android:id="@+id/app_check"
@ -25,8 +23,6 @@
android:layout_height="wrap_content"
android:clickable="false"
android:paddingEnd="6dp"
android:paddingLeft="2dp"
android:paddingRight="6dp"
android:paddingStart="2dp" />
android:paddingStart="2dp"/>
</LinearLayout>

View File

@ -14,18 +14,13 @@
app:cardPreventCornerOverlap="true"
android:id="@+id/cardView_indicator">
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:orientation="vertical"
android:background="?android:attr/selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_small"
android:layout_marginLeft="@dimen/margin_small">
android:background="?android:attr/selectableItemBackground"
android:layout_marginStart="@dimen/margin_small">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -33,7 +28,6 @@
android:id="@+id/textView_rule_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="match_parent"
@ -43,18 +37,16 @@
android:id="@+id/textView_rule_detail"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView android:id="@+id/textView_rule_size"
<TextView
android:id="@+id/textView_rule_size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:padding="@dimen/margin_small"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</FrameLayout>

View File

@ -5,6 +5,7 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="true"
@ -23,7 +24,6 @@
android:id="@+id/textView_custom_dns_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:layout_width="match_parent"
@ -34,7 +34,6 @@
android:id="@+id/textView_custom_dns_address"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>

View File

@ -11,7 +11,6 @@
android:layout_height="match_parent"
android:scrollbars="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton

View File

@ -41,15 +41,12 @@
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"
android:id="@+id/button_start_test"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"/>
android:layout_alignParentEnd="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_start_test"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:id="@+id/textView_test_info"
android:textIsSelectable="true"

View File

@ -13,7 +13,6 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="org.itxtech.daedalus.fragment.HomeFragment">
<ImageView
android:contentDescription="icon"
android:id="@+id/imageView_icon"
android:layout_width="0dp"
android:layout_height="0dp"
@ -21,7 +20,7 @@
app:srcCompat="@mipmap/ic_launcher"
app:layout_widthPercent="40%"
app:layout_heightPercent="20%"
app:layout_marginTopPercent="5%"
app:layout_marginTopPercent="10%"
android:layout_alignParentTop="true" android:layout_centerHorizontal="true"/>
<TextView
android:text="@string/app_name"
@ -33,21 +32,12 @@
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:fontFamily="sans-serif"
android:layout_centerHorizontal="true" android:id="@+id/textView_app_name"/>
<TextView
android:text="@string/notice_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_notice"
app:layout_marginTopPercent="5%"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:fontFamily="sans-serif"
android:layout_below="@+id/textView_app_name" android:layout_centerHorizontal="true"/>
<Button
android:text="@string/button_text_activate"
android:textSize="15sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button_activate"
app:layout_marginTopPercent="10%"
android:layout_alignTop="@+id/textView_notice" android:layout_centerHorizontal="true"/>
app:layout_marginTopPercent="15%"
android:layout_alignTop="@+id/textView_app_name" android:layout_centerHorizontal="true"/>
</androidx.percentlayout.widget.PercentRelativeLayout>

View File

@ -11,7 +11,6 @@
android:layout_height="match_parent"
android:scrollbars="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton

View File

@ -1,20 +0,0 @@
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>
<style name="AppTheme.NoActionBar.TransparentStatusBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="AppTheme.Dark.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>
<style name="AppTheme.Dark.NoActionBar.TransparentStatusBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@ -3,7 +3,6 @@
<string name="app_name">Daedalus</string>
<string name="quick_toggle">开关</string>
<string name="notice_main">世界很大,我要去看看。</string>
<string name="notice_activated">已启用 iTXTech Daedalus。</string>
<string name="notice_start_test">正在测试指定的 DNS 服务器……</string>
<string name="notice_queries">DNS 查询次数:</string>
@ -63,9 +62,11 @@
<string name="settings_manual_summary">访问 GitHub wiki 页面。</string>
<string name="settings_log_size">日志大小限制</string>
<string name="settings_debug_output">调试输出</string>
<string name="settings_dont_build_doh_cache">不缓存 DoH DNS 的 IP地址</string>
<string name="settings_dont_build_cache">不缓存 DNS 的 IP地址</string>
<string name="settings_dark_theme">使用暗主题</string>
<string name="settings_dns_query_method">DNS 查询方式</string>
<string name="settings_foreground">运行前台服务</string>
<string name="settings_use_system_dns">使用系統DNS作為上游DNS</string>
<string name="settings_rule_name">规则名称</string>
<string name="settings_rule_type">规则类型</string>
@ -103,4 +104,6 @@
<string name="test_test_domain">google.com</string>
<string name="nav_version">版本:</string>
<string name="error_occurred">启动时出现了一个错误</string>
</resources>

View File

@ -3,7 +3,6 @@
<string name="app_name">Daedalus</string>
<string name="quick_toggle">开关</string>
<string name="notice_main">世界很大,我要去看看。</string>
<string name="notice_activated">已啟動 iTXTech Daedalus。</string>
<string name="notice_start_test">正在測試指定的 DNS 伺服器……</string>
<string name="notice_queries">DNS 查詢次數:</string>
@ -63,7 +62,7 @@
<string name="settings_manual_summary">造訪 GitHub wiki 頁面。</string>
<string name="settings_log_size">紀錄檔大小限制</string>
<string name="settings_debug_output">调试输出 TODO</string>
<string name="settings_dont_build_doh_cache">不緩存 DoH DNS 的 IP地址</string>
<string name="settings_dont_build_cache">不緩存 DNS 的 IP地址</string>
<string name="settings_dark_theme">使用暗主题</string>
<string name="settings_rule_name">規則名稱</string>
@ -76,6 +75,7 @@
<string name="settings_rule_import_built_in">内置</string>
<string name="settings_rule_import_external">外部</string>
<string name="settings_dns_query_method">DNS 查询方式</string>
<string name="settings_foreground">運行前臺服務</string>
<string name="settings_server_name">伺服器名稱</string>
<string name="settings_server_address">伺服器網址</string>
@ -101,4 +101,6 @@
<string name="test_test_domain">google.com</string>
<string name="nav_version">版本:</string>
<string name="error_occurred">啟動時出現了一個錯誤</string>
</resources>

View File

@ -2,7 +2,6 @@
<string name="app_name">Daedalus</string>
<string name="quick_toggle">Toggle</string>
<string name="notice_main">See the world outside.</string>
<string name="notice_activated">iTXTech Daedalus is activated.</string>
<string name="notice_start_test">Testing specified DNS server…</string>
<string name="notice_queries">DNS query times:</string>
@ -61,10 +60,12 @@
<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_doh_cache">Don\'t build DNS Cache for DoH DNS</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>
<string name="settings_foreground">Run service in Foreground</string>
<string name="settings_use_system_dns">Use System DNS as upstream DNS</string>
<string name="settings_dns_tcp">TCP</string>
<string name="settings_dns_udp">UDP</string>
@ -111,4 +112,6 @@
<string name="nav_version">Version:</string>
<string name="nav_git_commit">Git commit:</string>
<string name="nav_github">GitHub</string>
<string name="error_occurred">An error occurred at startup</string>
</resources>

View File

@ -1,8 +1,5 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
@ -12,15 +9,25 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimaryLight</item>
</style>
<style name="AppTheme.NoActionBar">
<style name="AppTheme.NoActionBar" parent="AppTheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>
<style name="AppTheme.Dark.NoActionBar">
<style name="AppTheme.Dark.NoActionBar" parent="AppTheme.Dark">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:navigationBarColor">@color/colorPrimaryDark</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="AppTheme.NoActionBar.TransparentStatusBar" parent="AppTheme.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
<style name="AppTheme.Dark.NoActionBar.TransparentStatusBar" parent="AppTheme.Dark.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>

View File

@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:key="ruleName"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/settings_rule_name"/>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="rulSettings"
android:title="@string/settings_rule">
<ListPreference
@ -27,7 +30,9 @@
android:key="ruleSync"
android:title="@string/settings_rule_sync"/>
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="Import"
android:title="@string/settings_rule_import">
<ListPreference
@ -37,4 +42,4 @@
android:key="ruleImportExternal"
android:title="@string/settings_rule_import_external"/>
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:key="serverName"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/settings_server_name"/>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="serverSettings"
android:title="@string/settings_server">
<EditTextPreference
@ -20,4 +23,4 @@
android:numeric="integer"
android:title="@string/settings_server_port"/>
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="settingsServer"
android:title="@string/settings_server">
@ -10,7 +11,6 @@
android:title="@string/primary_server"
android:defaultValue="0">
</ListPreference>
<ListPreference
android:key="secondary_server"
android:title="@string/secondary_server"
@ -23,7 +23,9 @@
android:singleLine="true"
android:title="@string/settings_dns_test_servers"/>
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="settings_system"
android:title="@string/settings_system">
@ -39,6 +41,10 @@
android:key="settings_dark_theme"
android:title="@string/settings_dark_theme"
android:defaultValue="false"/>
<SwitchPreference
android:key="settings_foreground"
android:title="@string/settings_foreground"
android:defaultValue="false"/>
<EditTextPreference
android:key="settings_log_size"
android:selectAllOnFocus="false"
@ -49,6 +55,7 @@
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="settings_app_filter"
android:title="@string/settings_app_filter">
<SwitchPreference
@ -68,6 +75,7 @@
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="settings_advanced"
android:title="@string/settings_advanced">
<SwitchPreference
@ -80,10 +88,14 @@
android:defaultValue="false"
android:enabled="false"/>
<SwitchPreference
android:key="settings_dont_build_doh_cache"
android:title="@string/settings_dont_build_doh_cache"
android:key="settings_dont_build_cache"
android:title="@string/settings_dont_build_cache"
android:defaultValue="false"
android:enabled="false"/>
<SwitchPreference
android:key="settings_use_system_dns"
android:title="@string/settings_use_system_dns"
android:defaultValue="false"/>
<ListPreference
android:key="settings_dns_query_method"
android:title="@string/settings_dns_query_method"
@ -100,6 +112,7 @@
</PreferenceCategory>
<PreferenceCategory
app:iconSpaceReserved="false"
android:key="settings_help"
android:title="@string/settings_help_and_support">
<org.itxtech.daedalus.widget.ClickPreference
@ -118,4 +131,4 @@
android:title="@string/settings_manual"
android:summary="@string/settings_manual_summary"/>
</PreferenceCategory>
</PreferenceScreen>
</androidx.preference.PreferenceScreen>

Binary file not shown.

View File

@ -1,6 +1,5 @@
#Wed Aug 23 01:02:45 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-5.5.1-bin.zip

125
gradlew vendored
View File

@ -1,5 +1,21 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
@ -10,34 +26,34 @@
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
while [ -h "$PRG" ]; do
ls=$(ls -ld "$PRG")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' >/dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
PRG=$(dirname "$PRG")"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
SAVED="$(pwd)"
cd "$(dirname \"$PRG\")/" >/dev/null
APP_HOME="$(pwd -P)"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
APP_BASE_NAME=$(basename "$0")
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
warn() {
echo "$*"
}
die ( ) {
die() {
echo
echo "$*"
echo
@ -49,17 +65,17 @@ cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
case "$(uname)" in
CYGWIN*)
cygwin=true
;;
Darwin* )
Darwin*)
darwin=true
;;
MINGW* )
MINGW*)
msys=true
;;
NONSTOP* )
NONSTOP*)
nonstop=true
;;
esac
@ -67,14 +83,14 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
if [ -n "$JAVA_HOME" ]; then
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
if [ ! -x "$JAVACMD" ]; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
@ -89,14 +105,14 @@ location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ]; then
MAX_FD_LIMIT=$(ulimit -H -n)
if [ $? -eq 0 ]; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
if [ $? -ne 0 ]; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
@ -109,54 +125,54 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ]; then
APP_HOME=$(cygpath --path --mixed "$APP_HOME")
CLASSPATH=$(cygpath --path --mixed "$CLASSPATH")
JAVACMD=$(cygpath --unix "$JAVACMD")
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
ROOTDIRSRAW=$(find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null)
SEP=""
for dir in $ROOTDIRSRAW ; do
for dir in $ROOTDIRSRAW; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
if [ "$GRADLE_CYGPATTERN" != "" ]; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
for arg in "$@"; do
CHECK=$(echo "$arg" | egrep -c "$OURCYGPATTERN" -)
CHECK2=$(echo "$arg" | egrep -c "^-") ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ]; then ### Added a condition
eval $(echo args$i)=$(cygpath --path --ignore --mixed "$arg")
else
eval `echo args$i`="\"$arg\""
eval $(echo args$i)="\"$arg\""
fi
i=$((i+1))
i=$(expr $i + 1)
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save ( ) {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
save() {
for i; do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"; done
echo " "
}
APP_ARGS=$(save "$@")
@ -164,9 +180,4 @@ APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"

18
gradlew.bat vendored
View File

@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome