Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

add DNS Over HTTP setting #799

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Clover/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ android {
// of the format XXYYZZ, where XX is major, YY is minor, ZZ is patch
// (watch out for octal notation, never start with a 0)
versionCode 30002
multiDexEnabled true
}

compileOptions {
Expand Down Expand Up @@ -151,6 +152,7 @@ android {
}

dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
Expand All @@ -165,7 +167,8 @@ dependencies {
implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.7'

implementation 'com.android.volley:volley:1.1.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2'
implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:5.0.0-alpha.2'
//noinspection GradleDependency
implementation 'com.j256.ormlite:ormlite-core:4.48'
//noinspection GradleDependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ public String getKey() {
public static final BooleanSetting crashReporting;
public static final BooleanSetting useNewCaptchaWindow;

public static final BooleanSetting dnsOverHttps;

static {
SettingProvider p = new SharedPreferencesSettingProvider(AndroidUtils.getPreferences());

Expand Down Expand Up @@ -253,6 +255,8 @@ public String getKey() {
crashReporting = new BooleanSetting(p, "preference_crash_reporting", true);
useNewCaptchaWindow = new BooleanSetting(p, "use_new_captcha_window", true);

dnsOverHttps = new BooleanSetting(p, "dns_over_https", false);

// Old (but possibly still in some users phone)
// preference_board_view_mode default "list"
// preference_board_editor_filler default false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import org.floens.chan.core.di.UserAgentProvider;
import org.floens.chan.core.site.Site;
import org.floens.chan.core.site.SiteRequestModifier;
import org.floens.chan.utils.Logger;
import org.floens.chan.core.settings.ChanSettings;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

import java.util.concurrent.TimeUnit;

Expand All @@ -29,13 +34,15 @@

import okhttp3.OkHttpClient;
import okhttp3.Request;

import okhttp3.dnsoverhttps.DnsOverHttps;
import okhttp3.HttpUrl;
/**
* Manages the {@link HttpCall} executions.
*/
@Singleton
public class HttpCallManager {
private static final int TIMEOUT = 30000;
private static final String TAG = "HttpCallManager";

private UserAgentProvider userAgentProvider;
private OkHttpClient client;
Expand All @@ -48,6 +55,30 @@ public HttpCallManager(UserAgentProvider userAgentProvider) {
.readTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
.writeTimeout(TIMEOUT, TimeUnit.MILLISECONDS)
.build();
if (ChanSettings.dnsOverHttps.get()) {
try {
client = client.newBuilder()
.dns(new DnsOverHttps.Builder().client(client)
.url(HttpUrl.parse("https://cloudflare-dns.com/dns-query"))
.bootstrapDnsHosts(Arrays.asList(
InetAddress.getByName("162.159.36.1"),
InetAddress.getByName("162.159.46.1"),
InetAddress.getByName("1.1.1.1"),
InetAddress.getByName("1.0.0.1"),
InetAddress.getByName("162.159.132.53"),
InetAddress.getByName("2606:4700:4700::1111"),
InetAddress.getByName("2606:4700:4700::1001"),
InetAddress.getByName("2606:4700:4700::0064"),
InetAddress.getByName("2606:4700:4700::6400")
))
.build())
.build();

} catch (UnknownHostException e) {
Logger.e(TAG, "Error Dns over https", e);
e.printStackTrace();
}
}
}

public void makeHttpCall(HttpCall httpCall, HttpCall.HttpCallback<? extends HttpCall> callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ private void populatePreferences() {

groups.add(proxy);
}

// DNS Over HTTP Group
{
SettingsGroup doh = new SettingsGroup(R.string.setting_group_dns_over_https);

doh.add(new BooleanSettingView(this, ChanSettings.dnsOverHttps,
R.string.setting_group_dns_enable, R.string.setting_group_dns_enable_description));

groups.add(doh);
}
}

private void setupClearThreadHidesSetting(SettingsGroup post) {
Expand Down
4 changes: 4 additions & 0 deletions Clover/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ Crash reports do not collect any personally identifiable information."
<string name="setting_proxy_address">Proxy server address</string>
<string name="setting_proxy_port">Proxy server port</string>

<!-- Behavior DNS over HTTPS group -->
<string name="setting_group_dns_over_https">DNS over HTTPS</string>
<string name="setting_group_dns_enable">Enable DOH (Cloudflare)</string>
<string name="setting_group_dns_enable_description">Requires app restart to take effect</string>

<!-- Media -->
<string name="settings_screen_media">Media</string>
Expand Down