Improved advanced settings

This commit is contained in:
PeratX 2017-04-25 18:34:25 +08:00
parent 020a2bed90
commit a2c9dfe4ca
5 changed files with 75 additions and 25 deletions

View File

@ -38,6 +38,8 @@ public class SettingsFragment extends PreferenceFragment {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(DnsServer.getDnsServerById((String) newValue).getStringDescription(Daedalus.getInstance()));
Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
return true;
}
});
@ -50,6 +52,8 @@ public class SettingsFragment extends PreferenceFragment {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
preference.setSummary(DnsServer.getDnsServerById((String) newValue).getStringDescription(Daedalus.getInstance()));
Snackbar.make(view, R.string.notice_need_restart, Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
return true;
}
});
@ -72,6 +76,31 @@ public class SettingsFragment extends PreferenceFragment {
autoBoot.setChecked(false);
autoBoot.setEnabled(false);
}
SwitchPreference advanced = (SwitchPreference) findPreference("settings_advanced_switch");
advanced.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateAdvancedOptions((boolean) newValue);
return true;
}
});
updateAdvancedOptions(advanced.isChecked());
}
private void updateAdvancedOptions(boolean checked) {
PreferenceCategory category = (PreferenceCategory) findPreference("settings_advanced");
for (int i = 1; i < category.getPreferenceCount(); i++) {
Preference preference = category.getPreference(i);
if (checked) {
preference.setEnabled(true);
} else {
preference.setEnabled(false);
if (preference instanceof SwitchPreference) {
((SwitchPreference) preference).setChecked(false);
}
}
}
}
@Override

View File

@ -173,6 +173,8 @@ public class DaedalusVpnService extends VpnService implements Runnable {
Daedalus.updateShortcut(getApplicationContext());
}
dnsQueryTimes = 0;
System.gc();
}
@ -201,23 +203,28 @@ public class DaedalusVpnService extends VpnService implements Runnable {
this.descriptor.close();
}
boolean statisticQuery = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("settings_count_query_times", false);
boolean advanced = Daedalus.getPrefs().getBoolean("settings_advanced_switch", false);
boolean statisticQuery = Daedalus.getPrefs().getBoolean("settings_count_query_times", false);
Log.d(TAG, "tun0 add " + format + " pServ " + primaryServer + " sServ " + secondaryServer);
Inet4Address primaryDNSServer = InetAddressUtil.ipv4From(primaryServer);
Inet4Address secondaryDNSServer = InetAddressUtil.ipv4From(secondaryServer);
builder.addDnsServer(primaryDNSServer);
builder.addDnsServer(secondaryDNSServer);
builder.setSession("Daedalus")
.addDnsServer(primaryDNSServer)
.addDnsServer(secondaryDNSServer)
.setConfigureIntent(PendingIntent.getActivity(this, 0,
new Intent(this, MainActivity.class).putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS),
PendingIntent.FLAG_ONE_SHOT));
if (statisticQuery) {
if (advanced) {
builder.addRoute(primaryDNSServer, primaryDNSServer.getAddress().length * 8)
.addRoute(secondaryDNSServer, secondaryDNSServer.getAddress().length * 8)
.setBlocking(true);
}
this.descriptor = builder.setSession("Daedalus").setConfigureIntent(PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class).putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS), PendingIntent.FLAG_ONE_SHOT)).establish();
this.descriptor = builder.establish();
if (statisticQuery) {
Log.d(TAG, "Starting count queries");
if (advanced) {
Log.d(TAG, "Starting advanced DNS proxy.");
FileDescriptor[] pipes = Os.pipe();
mInterruptFd = pipes[0];
mBlockFd = pipes[1];
@ -300,7 +307,9 @@ public class DaedalusVpnService extends VpnService implements Runnable {
}
}
updateUserInterface();
if (statisticQuery) {
updateUserInterface();
}
}
} else {
while (running) {

View File

@ -24,12 +24,7 @@
<string name="test_result_resolved">解析地址:</string>
<string name="test_failed">查询失败。超时或未知的主机。</string>
<string name="test_test_domain">google.com</string>
<string name="action_visit_cutedns">访问 CuteDNS!</string>
<string name="action_visit_github">访问 项目主页</string>
<string name="action_visit_itxtech">访问 iTXTech</string>
<string name="action_join_qqgroup">加入 CuteDNS! QQ群</string>
<string name="notice_join_group_failed">未安装手Q或当前版本不支持此操作。</string>
<string name="settings_notification">启用时显示通知</string>
<string name="settings_notification">显示通知</string>
<string name="settings_check_update">检查更新</string>
<string name="settings_update_summary">前往 GitHub 发布页面。</string>
<string name="settings_count_number_of_queries">统计 DNS 查询次数</string>
@ -54,4 +49,8 @@
<string name="server_neat_dns_cmcc">Neat DNS 中国移动</string>
<string name="server_neat_dns_china_telecom">Neat DNS 中国电信</string>
<string name="nav_github">GitHub</string>
<string name="settings_advanced">高级系统设置</string>
<string name="settings_advanced_on">开启</string>
<string name="settings_local_hosts_resolve">本地 hosts 解析 TODO</string>
<string name="notice_need_restart">重新启用 Daedalus 以应用设置。</string>
</resources>

View File

@ -23,13 +23,7 @@
<string name="test_result_resolved">Address:</string>
<string name="test_failed">DNS query failed. Timeout or unknown hostname.</string>
<string name="test_test_domain">google.com</string>
<string name="action_visit_itxtech">Visit iTXTech</string>
<string name="action_visit_cutedns">Visit CuteDNS!</string>
<string name="action_visit_github">Visit Project home</string>
<string name="action_join_qqgroup">Join QQ group</string>
<string name="notice_join_group_failed">QQ is not installed or current version does not support this operation.
</string>
<string name="settings_notification">Show notification when activated</string>
<string name="settings_notification">Show notification</string>
<string name="settings_check_update">Check update</string>
<string name="settings_update_summary">Visit GitHub releases page.</string>
<string name="settings_count_number_of_queries">Count DNS query times</string>
@ -54,4 +48,8 @@
<string name="server_neat_dns_cmcc">Neat DNS CMCC</string>
<string name="server_neat_dns_china_telecom">Neat DNS China Telecom</string>
<string name="nav_github">GitHub</string>
<string name="settings_advanced">Advanced system settings</string>
<string name="settings_advanced_on">On</string>
<string name="settings_local_hosts_resolve">Local hosts resolve (TODO)</string>
<string name="notice_need_restart">Re-activate Daedalus to make the settings take effect.</string>
</resources>

View File

@ -31,16 +31,31 @@
android:key="settings_boot"
android:title="@string/settings_boot"
android:defaultValue="false"/>
<SwitchPreference
android:key="settings_count_query_times"
android:title="@string/settings_count_number_of_queries"
android:defaultValue="false"/>
<SwitchPreference
android:key="settings_notification"
android:title="@string/settings_notification"
android:defaultValue="true"/>
</PreferenceCategory>
<PreferenceCategory
android:key="settings_advanced"
android:title="@string/settings_advanced">
<SwitchPreference
android:key="settings_advanced_switch"
android:title="@string/settings_advanced_on"
android:defaultValue="false"/>
<SwitchPreference
android:key="settings_count_query_times"
android:title="@string/settings_count_number_of_queries"
android:defaultValue="false"
android:enabled="false"/>
<SwitchPreference
android:key="settings_local_host_resolve"
android:title="@string/settings_count_number_of_queries"
android:defaultValue="false"
android:enabled="false"/>
</PreferenceCategory>
<PreferenceCategory
android:key="settings_help"
android:title="@string/settings_help_and_support">