From b7c4ff98500594616ef946b4dc057a19b5e524ed Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Mon, 16 Sep 2019 09:33:23 +0800 Subject: [PATCH 01/14] app: update dependencies --- .travis.yml | 4 ++-- app/build.gradle | 14 +++++++------- build.gradle | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0420c20..a25a745 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/app/build.gradle b/app/build.gradle index e36e0d9..72df18e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,12 +4,12 @@ apply plugin: 'io.fabric' def gitCommit = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() android { - compileSdkVersion 28 - buildToolsVersion "28.0.3" + compileSdkVersion 29 + buildToolsVersion "29.0.2" defaultConfig { applicationId "org.itxtech.daedalus" minSdkVersion 21 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 20 versionName "1.14.1" @@ -52,12 +52,12 @@ configurations { dependencies { //Support - implementation 'androidx.appcompat:appcompat:1.1.0-rc01' + implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.percentlayout:percentlayout:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'com.google.android.material:material:1.1.0-alpha08' - implementation 'androidx.recyclerview:recyclerview:1.1.0-beta01' + implementation 'com.google.android.material:material:1.1.0-alpha10' + implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04' //DNS implementation 'org.pcap4j:pcap4j-core:1.7.6' implementation 'org.pcap4j:pcap4j-packetfactory-static:1.7.6' @@ -66,7 +66,7 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp:3.14.1' //Analytics - googleReleaseImplementation 'com.google.firebase:firebase-core:17.0.1' + googleReleaseImplementation 'com.google.firebase:firebase-core:17.2.0' googleReleaseImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' } diff --git a/build.gradle b/build.gradle index 49925bf..f553388 100644 --- a/build.gradle +++ b/build.gradle @@ -9,8 +9,8 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.4.2' - classpath 'com.google.gms:google-services:4.3.0' + classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.google.gms:google-services:4.3.2' classpath 'io.fabric.tools:gradle:1.28.1' } } From d207a416356df056bbd98ee6b3b84ead8233bc1c Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Thu, 10 Oct 2019 10:09:36 +0800 Subject: [PATCH 02/14] androidx: move to new libs --- app/build.gradle | 11 ++++---- .../java/org/itxtech/daedalus/Daedalus.java | 2 +- .../daedalus/activity/ConfigActivity.java | 6 ++--- .../daedalus/activity/MainActivity.java | 27 +++++++------------ .../daedalus/fragment/ConfigFragment.java | 4 +-- .../fragment/DNSServerConfigFragment.java | 11 ++++---- .../fragment/GlobalConfigFragment.java | 24 ++++++++--------- .../daedalus/fragment/RuleConfigFragment.java | 22 +++++++-------- .../daedalus/fragment/SettingsFragment.java | 10 +------ .../daedalus/fragment/ToolbarFragment.java | 2 +- .../daedalus/provider/UdpProvider.java | 5 +++- .../daedalus/widget/ClickPreference.java | 2 +- build.gradle | 4 +-- 13 files changed, 56 insertions(+), 74 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 72df18e..040344c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,14 +56,15 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.percentlayout:percentlayout:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'com.google.android.material:material:1.1.0-alpha10' - implementation 'androidx.recyclerview:recyclerview:1.1.0-beta04' + implementation 'com.google.android.material:material:1.1.0-beta01' + implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05' + 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' + implementation 'org.pcap4j:pcap4j-core:1.8.2' + implementation 'org.pcap4j:pcap4j-packetfactory-static:1.8.2' implementation 'org.minidns:minidns-client:0.3.4' implementation 'com.google.code.gson:gson:2.8.5' - implementation 'com.squareup.okhttp3:okhttp:3.14.1' + implementation 'com.squareup.okhttp3:okhttp:4.2.0' //Analytics googleReleaseImplementation 'com.google.firebase:firebase-core:17.2.0' diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index d7cd117..8d86bb5 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -10,8 +10,8 @@ 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; diff --git a/app/src/main/java/org/itxtech/daedalus/activity/ConfigActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/ConfigActivity.java index 500a669..78bda50 100644 --- a/app/src/main/java/org/itxtech/daedalus/activity/ConfigActivity.java +++ b/app/src/main/java/org/itxtech/daedalus/activity/ConfigActivity.java @@ -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,6 +7,8 @@ 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; @@ -64,7 +64,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); diff --git a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java index 5797891..23bf3c4 100644 --- a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java +++ b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java @@ -1,7 +1,6 @@ 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; @@ -100,8 +99,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 +151,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) { - 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); - } + .setPositiveButton("为我买杯咖啡", (dialog, which) -> { + Daedalus.donate(); + new AlertDialog.Builder(MainActivity.this) + .setMessage("感谢您的支持!;)\n我会再接再厉!") + .setPositiveButton("确认", null) + .show(); }) + .setNeutralButton("不再显示", (dialog, which) -> Daedalus.configurations.setActivateCounter(-1)) .setNegativeButton("取消", null) .show(); } @@ -182,6 +172,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On updateMainButton(R.string.button_text_deactivate); Daedalus.updateShortcut(getApplicationContext()); } + super.onActivityResult(request, result, data); } private void updateMainButton(int id) { diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/ConfigFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/ConfigFragment.java index 33a54e2..9f08c2c 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/ConfigFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/ConfigFragment.java @@ -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) { diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/DNSServerConfigFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/DNSServerConfigFragment.java index 411eaed..06b0bb2 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DNSServerConfigFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DNSServerConfigFragment.java @@ -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; @@ -29,8 +29,7 @@ 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; diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java index 79353b9..6864fe0 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java @@ -2,7 +2,7 @@ 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; @@ -20,12 +20,10 @@ 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()) @@ -33,7 +31,7 @@ public class GlobalConfigFragment extends PreferenceFragment { addPreferencesFromResource(R.xml.perf_settings); - ListPreference primaryServer = (ListPreference) findPreference("primary_server"); + ListPreference primaryServer = findPreference("primary_server"); primaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance())); primaryServer.setEntryValues(DNSServerHelper.getIds()); primaryServer.setSummary(DNSServerHelper.getDescription(primaryServer.getValue(), Daedalus.getInstance())); @@ -42,7 +40,7 @@ public class GlobalConfigFragment extends PreferenceFragment { return true; }); - ListPreference secondaryServer = (ListPreference) findPreference("secondary_server"); + ListPreference secondaryServer = findPreference("secondary_server"); secondaryServer.setEntries(DNSServerHelper.getNames(Daedalus.getInstance())); secondaryServer.setEntryValues(DNSServerHelper.getIds()); secondaryServer.setSummary(DNSServerHelper.getDescription(secondaryServer.getValue(), Daedalus.getInstance())); @@ -51,21 +49,21 @@ public class GlobalConfigFragment extends PreferenceFragment { 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 +71,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 +113,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) { diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java index 860c83c..d02bddf 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/RuleConfigFragment.java @@ -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; diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java index 41e1620..28419ac 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/SettingsFragment.java @@ -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 diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/ToolbarFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/ToolbarFragment.java index 7c8ff05..adfa8de 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/ToolbarFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/ToolbarFragment.java @@ -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; diff --git a/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java b/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java index c51f5d3..6e08604 100644 --- a/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java +++ b/app/src/main/java/org/itxtech/daedalus/provider/UdpProvider.java @@ -168,7 +168,10 @@ public class UdpProvider extends Provider { } if (!(parsedPacket.getPayload() instanceof UdpPacket)) { - Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload()); + try { + Log.i(TAG, "handleDnsRequest: Discarding unknown packet type " + parsedPacket.getPayload()); + } catch (Exception ignored) { + } return; } diff --git a/app/src/main/java/org/itxtech/daedalus/widget/ClickPreference.java b/app/src/main/java/org/itxtech/daedalus/widget/ClickPreference.java index 432bc04..4640abf 100644 --- a/app/src/main/java/org/itxtech/daedalus/widget/ClickPreference.java +++ b/app/src/main/java/org/itxtech/daedalus/widget/ClickPreference.java @@ -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; /** diff --git a/build.gradle b/build.gradle index f553388..da4865c 100644 --- a/build.gradle +++ b/build.gradle @@ -9,9 +9,9 @@ buildscript { } } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:3.5.1' classpath 'com.google.gms:google-services:4.3.2' - classpath 'io.fabric.tools:gradle:1.28.1' + classpath 'io.fabric.tools:gradle:1.31.0' } } From 99cc306ded4e3e98bc9cb4ecdc38930c8d2ce863 Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Thu, 10 Oct 2019 10:59:10 +0800 Subject: [PATCH 03/14] server: add foreground service option. close #112 --- .../java/org/itxtech/daedalus/Daedalus.java | 21 +++++++--- .../daedalus/activity/MainActivity.java | 4 +- app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/perf_rule.xml | 9 +++- app/src/main/res/xml/perf_server.xml | 7 +++- app/src/main/res/xml/perf_settings.xml | 42 ++++++++++++------- 8 files changed, 58 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index 8d86bb5..97f3e5a 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -199,23 +199,34 @@ 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) { + DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary()); + DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary()); + if (getInstance().prefs.getBoolean("settings_foreground", false) + && 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)); diff --git a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java index 23bf3c4..f8b22c3 100644 --- a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java +++ b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java @@ -166,9 +166,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On public void onActivityResult(int request, int result, Intent 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()); } diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index db68622..884fb2d 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -66,6 +66,7 @@ 不缓存 DoH DNS 的 IP地址 使用暗主题 DNS 查询方式 + 运行前台服务 规则名称 规则类型 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 2d0bedc..965dbe9 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -76,6 +76,7 @@ 内置 外部 DNS 查询方式 + 運行前臺服務 伺服器名稱 伺服器網址 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9c1de0f..d85f09d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -65,6 +65,7 @@ Debug Output Use Dark Theme DNS Query Method + Run service in Foreground TCP UDP diff --git a/app/src/main/res/xml/perf_rule.xml b/app/src/main/res/xml/perf_rule.xml index 5e24c80..8753372 100644 --- a/app/src/main/res/xml/perf_rule.xml +++ b/app/src/main/res/xml/perf_rule.xml @@ -1,11 +1,14 @@ - + + + - + diff --git a/app/src/main/res/xml/perf_server.xml b/app/src/main/res/xml/perf_server.xml index 2453e8b..0ec3b11 100644 --- a/app/src/main/res/xml/perf_server.xml +++ b/app/src/main/res/xml/perf_server.xml @@ -1,11 +1,14 @@ - + + - \ No newline at end of file + diff --git a/app/src/main/res/xml/perf_settings.xml b/app/src/main/res/xml/perf_settings.xml index 5540e8c..cb4ed66 100644 --- a/app/src/main/res/xml/perf_settings.xml +++ b/app/src/main/res/xml/perf_settings.xml @@ -1,7 +1,8 @@ - - + @@ -23,7 +24,9 @@ android:singleLine="true" android:title="@string/settings_dns_test_servers"/> + @@ -39,6 +42,10 @@ android:key="settings_dark_theme" android:title="@string/settings_dark_theme" android:defaultValue="false"/> + + app:iconSpaceReserved="false" + android:key="settings_app_filter" + android:title="@string/settings_app_filter"> + android:key="settings_app_filter_switch" + android:title="@string/settings_app_filter" + android:defaultValue="false"/> + android:key="settings_app_filter_mode_switch" + android:title="@string/settings_app_filter_mode" + android:defaultValue="false" + android:enabled="false"/> + android:key="settings_app_filter_list" + android:title="@string/settings_app_filter_list" + android:summary="@string/settings_app_filter_list_summary" + android:enabled="false"/> - + From 77c7ce21351e09db9988bd7b6c1f047bfced0f5f Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Thu, 10 Oct 2019 17:19:16 +0800 Subject: [PATCH 04/14] README: update --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3c10d2e..4e8984a 100644 --- a/README.md +++ b/README.md @@ -66,14 +66,13 @@ __Users must comply with local laws and regulations.__
* __[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 From 37fa7963030de9119a849163cb4f36f2dd0f3143 Mon Sep 17 00:00:00 2001 From: PeratX <1215714524@qq.com> Date: Tue, 22 Oct 2019 18:11:08 +0800 Subject: [PATCH 05/14] DNS: add Use System DNS as upstream DNS. close #113 --- app/src/main/AndroidManifest.xml | 1 + .../java/org/itxtech/daedalus/Daedalus.java | 16 +- .../fragment/GlobalConfigFragment.java | 41 +++-- .../daedalus/service/DaedalusVpnService.java | 5 +- .../daedalus/util/DnsServersDetector.java | 166 ++++++++++++++++++ app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/perf_settings.xml | 5 +- 8 files changed, 210 insertions(+), 26 deletions(-) create mode 100644 app/src/main/java/org/itxtech/daedalus/util/DnsServersDetector.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4000d81..c6f3837 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,7 @@ + diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index 97f3e5a..066a836 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -18,10 +18,7 @@ import com.google.gson.JsonParseException; import com.google.gson.stream.JsonReader; import org.itxtech.daedalus.activity.MainActivity; import org.itxtech.daedalus.service.DaedalusVpnService; -import org.itxtech.daedalus.util.Configurations; -import org.itxtech.daedalus.util.Logger; -import org.itxtech.daedalus.util.Rule; -import org.itxtech.daedalus.util.RuleResolver; +import org.itxtech.daedalus.util.*; import org.itxtech.daedalus.util.server.DNSServer; import org.itxtech.daedalus.util.server.DNSServerHelper; @@ -217,6 +214,17 @@ public class Daedalus extends Application { public static void activateService(Context context) { DaedalusVpnService.primaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getPrimary()); DaedalusVpnService.secondaryServer = DNSServerHelper.getAddressById(DNSServerHelper.getSecondary()); + if (getPrefs().getBoolean("settings_use_system_dns", false)) { + String[] servers = DnsServersDetector.getServers(context); + if (servers != null) { + if (servers.length >= 2) { + DaedalusVpnService.primaryServer = servers[0]; + DaedalusVpnService.secondaryServer = servers[1]; + } else { + DaedalusVpnService.primaryServer = DaedalusVpnService.secondaryServer = servers[0]; + } + } + } if (getInstance().prefs.getBoolean("settings_foreground", false) && Build.VERSION.SDK_INT > Build.VERSION_CODES.O) { Logger.info("Starting foreground service"); diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java index 6864fe0..53f917e 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/GlobalConfigFragment.java @@ -9,6 +9,8 @@ import org.itxtech.daedalus.activity.AppFilterActivity; import org.itxtech.daedalus.activity.MainActivity; import org.itxtech.daedalus.util.server.DNSServerHelper; +import java.util.ArrayList; + /** * Daedalus Project * @@ -31,23 +33,21 @@ public class GlobalConfigFragment extends PreferenceFragmentCompat { addPreferencesFromResource(R.xml.perf_settings); - ListPreference primaryServer = 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())); - return true; - }); - - ListPreference secondaryServer = 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; - }); + boolean visible = !Daedalus.getPrefs().getBoolean("settings_use_system_dns", false); + for (String k : new ArrayList() {{ + add("primary_server"); + add("secondary_server"); + }}) { + ListPreference listPref = findPreference(k); + listPref.setVisible(visible); + 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; + }); + } EditTextPreference testDNSServers = findPreference("dns_test_servers"); testDNSServers.setSummary(testDNSServers.getText()); @@ -110,6 +110,13 @@ public class GlobalConfigFragment extends PreferenceFragmentCompat { updateOptions(advanced.isChecked(), "settings_advanced"); updateOptions(appFilter.isChecked(), "settings_app_filter"); + + findPreference("settings_use_system_dns").setOnPreferenceChangeListener((preference, newValue) -> { + boolean vis = !(boolean) newValue; + findPreference("primary_server").setVisible(vis); + findPreference("secondary_server").setVisible(vis); + return true; + }); } private void updateOptions(boolean checked, String pref) { diff --git a/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java b/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java index ccae93f..7d3e54e 100644 --- a/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java +++ b/app/src/main/java/org/itxtech/daedalus/service/DaedalusVpnService.java @@ -346,7 +346,7 @@ 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()); } @@ -358,11 +358,8 @@ public class DaedalusVpnService extends VpnService implements Runnable { public VpnNetworkException(String s) { super(s); } - public VpnNetworkException(String s, Throwable t) { super(s, t); } - } - } diff --git a/app/src/main/java/org/itxtech/daedalus/util/DnsServersDetector.java b/app/src/main/java/org/itxtech/daedalus/util/DnsServersDetector.java new file mode 100644 index 0000000..cace002 --- /dev/null +++ b/app/src/main/java/org/itxtech/daedalus/util/DnsServersDetector.java @@ -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 + *

+ * 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 priorityServersArrayList = new ArrayList<>(); + ArrayList 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 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) { + final String re1 = "^\\d+(\\.\\d+){3}$"; + final String re2 = "^[0-9a-f]+(:[0-9a-f]*)+:[0-9a-f]+$"; + ArrayList serversArrayList = new ArrayList<>(); + try { + Class SystemProperties = Class.forName("android.os.SystemProperties"); + Method method = SystemProperties.getMethod("get", new Class[]{String.class}); + final String[] netdns = new String[]{"net.dns1", "net.dns2", "net.dns3", "net.dns4"}; + for (int i = 0; i < netdns.length; i++) { + Object[] args = new Object[]{netdns[i]}; + String 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 serversSet = methodExecParseProps(lineNumberReader); + if (serversSet.size() > 0) { + return serversSet.toArray(new String[0]); + } + } catch (Exception ex) { + Logger.logException(ex); + } + return null; + } + + private static Set methodExecParseProps(BufferedReader lineNumberReader) throws Exception { + String line; + Set serversSet = new HashSet(10); + 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) continue; + if (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; + } +} diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 884fb2d..3a7b0b9 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -67,6 +67,7 @@ 使用暗主题 DNS 查询方式 运行前台服务 + 使用系統DNS作為上游DNS 规则名称 规则类型 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d85f09d..84be857 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,6 +66,7 @@ Use Dark Theme DNS Query Method Run service in Foreground + Use System DNS as upstream DNS TCP UDP diff --git a/app/src/main/res/xml/perf_settings.xml b/app/src/main/res/xml/perf_settings.xml index cb4ed66..10320a6 100644 --- a/app/src/main/res/xml/perf_settings.xml +++ b/app/src/main/res/xml/perf_settings.xml @@ -6,12 +6,15 @@ android:key="settingsServer" android:title="@string/settings_server"> + - Date: Wed, 23 Oct 2019 12:34:17 +0800 Subject: [PATCH 06/14] Home: remove notice_main --- app/build.gradle | 3 +-- app/src/main/java/org/itxtech/daedalus/Daedalus.java | 3 +-- .../java/org/itxtech/daedalus/activity/MainActivity.java | 3 +-- .../org/itxtech/daedalus/fragment/DNSTestFragment.java | 2 +- .../java/org/itxtech/daedalus/fragment/HomeFragment.java | 8 -------- .../java/org/itxtech/daedalus/fragment/LogFragment.java | 2 +- .../java/org/itxtech/daedalus/provider/TcpProvider.java | 2 +- .../java/org/itxtech/daedalus/util/RuleResolver.java | 4 ++-- .../java/org/itxtech/daedalus/util/server/DNSServer.java | 2 +- app/src/main/res/layout/fragment_main.xml | 9 --------- app/src/main/res/values-zh-rCN/strings.xml | 1 - app/src/main/res/values-zh-rTW/strings.xml | 1 - app/src/main/res/values/strings.xml | 1 - 13 files changed, 9 insertions(+), 32 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 040344c..7f93c67 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,7 +56,7 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.percentlayout:percentlayout:1.0.0' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'com.google.android.material:material:1.1.0-beta01' + implementation 'com.google.android.material:material:1.2.0-alpha01' implementation 'androidx.recyclerview:recyclerview:1.1.0-beta05' implementation "androidx.preference:preference:1.1.0" //DNS @@ -65,7 +65,6 @@ dependencies { implementation 'org.minidns:minidns-client:0.3.4' implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.squareup.okhttp3:okhttp:4.2.0' - //Analytics googleReleaseImplementation 'com.google.firebase:firebase-core:17.2.0' googleReleaseImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1' diff --git a/app/src/main/java/org/itxtech/daedalus/Daedalus.java b/app/src/main/java/org/itxtech/daedalus/Daedalus.java index 066a836..8cc9453 100644 --- a/app/src/main/java/org/itxtech/daedalus/Daedalus.java +++ b/app/src/main/java/org/itxtech/daedalus/Daedalus.java @@ -175,7 +175,6 @@ public class Daedalus extends Application { @Override public void onTerminate() { - Log.d("Daedalus", "onTerminate"); super.onTerminate(); instance = null; @@ -242,7 +241,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) diff --git a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java index f8b22c3..78f1ef8 100644 --- a/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java +++ b/app/src/main/java/org/itxtech/daedalus/activity/MainActivity.java @@ -182,7 +182,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) { @@ -240,7 +240,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) { diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java index 79157d9..3d44e6f 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/DNSTestFragment.java @@ -181,7 +181,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) { diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/HomeFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/HomeFragment.java index 91803a8..82702f3 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/HomeFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/HomeFragment.java @@ -49,14 +49,6 @@ 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); diff --git a/app/src/main/java/org/itxtech/daedalus/fragment/LogFragment.java b/app/src/main/java/org/itxtech/daedalus/fragment/LogFragment.java index dc8880d..0a418b0 100644 --- a/app/src/main/java/org/itxtech/daedalus/fragment/LogFragment.java +++ b/app/src/main/java/org/itxtech/daedalus/fragment/LogFragment.java @@ -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(); diff --git a/app/src/main/java/org/itxtech/daedalus/provider/TcpProvider.java b/app/src/main/java/org/itxtech/daedalus/provider/TcpProvider.java index 3768ea5..183efc9 100644 --- a/app/src/main/java/org/itxtech/daedalus/provider/TcpProvider.java +++ b/app/src/main/java/org/itxtech/daedalus/provider/TcpProvider.java @@ -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(); diff --git a/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java b/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java index d52806f..d6638a7 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java +++ b/app/src/main/java/org/itxtech/daedalus/util/RuleResolver.java @@ -129,7 +129,7 @@ public class RuleResolver implements Runnable { dataIO.close(); stream.close(); - Logger.info("Loaded " + String.valueOf(count) + " rules"); + Logger.info("Loaded " + count + " rules"); } } } else if (mode == MODE_DNSMASQ) { @@ -162,7 +162,7 @@ public class RuleResolver implements Runnable { dataIO.close(); stream.close(); - Logger.info("Loaded " + String.valueOf(count) + " rules"); + Logger.info("Loaded " + count + " rules"); } } } diff --git a/app/src/main/java/org/itxtech/daedalus/util/server/DNSServer.java b/app/src/main/java/org/itxtech/daedalus/util/server/DNSServer.java index e6e8be9..865d07b 100644 --- a/app/src/main/java/org/itxtech/daedalus/util/server/DNSServer.java +++ b/app/src/main/java/org/itxtech/daedalus/util/server/DNSServer.java @@ -19,7 +19,7 @@ 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) { super(address, port); diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index 9ada810..30b23a1 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -33,15 +33,6 @@ android:textAppearance="@android:style/TextAppearance.DeviceDefault" android:fontFamily="sans-serif" android:layout_centerHorizontal="true" android:id="@+id/textView_app_name"/> -