Add Dns Over Https switch. (Close #5)

pull/55/head
Fox2Code 2 years ago
parent f3a1e63dce
commit 76e259e727

@ -106,6 +106,10 @@ public class MainApplication extends Application implements CompatActivity.Appli
return getSharedPreferences().getBoolean("pref_wrap_text", false); return getSharedPreferences().getBoolean("pref_wrap_text", false);
} }
public static boolean isDohEnabled() {
return getSharedPreferences().getBoolean("pref_dns_over_https", true);
}
public static boolean isDeveloper() { public static boolean isDeveloper() {
return BuildConfig.DEBUG || return BuildConfig.DEBUG ||
getSharedPreferences().getBoolean("developer", false); getSharedPreferences().getBoolean("developer", false);

@ -21,7 +21,6 @@ import java.util.zip.ZipFile;
interface NotificationTypeCst { interface NotificationTypeCst {
String TAG = "NotificationType"; String TAG = "NotificationType";
boolean ROOTLESS_TEST = true;
} }
public enum NotificationType implements NotificationTypeCst { public enum NotificationType implements NotificationTypeCst {
@ -110,7 +109,7 @@ public enum NotificationType implements NotificationTypeCst {
}, true) { }, true) {
@Override @Override
public boolean shouldRemove() { public boolean shouldRemove() {
return (!(ROOTLESS_TEST && BuildConfig.DEBUG)) && return !BuildConfig.DEBUG &&
(MainApplication.isShowcaseMode() || (MainApplication.isShowcaseMode() ||
InstallerInitializer.peekMagiskPath() == null); InstallerInitializer.peekMagiskPath() == null);
} }
@ -135,11 +134,13 @@ public enum NotificationType implements NotificationTypeCst {
this(textId, iconId, backgroundAttr, foregroundAttr, null); this(textId, iconId, backgroundAttr, foregroundAttr, null);
} }
NotificationType(@StringRes int textId, int iconId, int backgroundAttr, int foregroundAttr, View.OnClickListener onClickListener) { NotificationType(@StringRes int textId, int iconId, int backgroundAttr, int foregroundAttr,
this(textId, iconId, backgroundAttr, foregroundAttr, null, false); View.OnClickListener onClickListener) {
this(textId, iconId, backgroundAttr, foregroundAttr, onClickListener, false);
} }
NotificationType(@StringRes int textId, int iconId, int backgroundAttr, int foregroundAttr, View.OnClickListener onClickListener, boolean special) { NotificationType(@StringRes int textId, int iconId, int backgroundAttr, int foregroundAttr,
View.OnClickListener onClickListener, boolean special) {
this.textId = textId; this.textId = textId;
this.iconId = iconId; this.iconId = iconId;
this.backgroundAttr = backgroundAttr; this.backgroundAttr = backgroundAttr;

@ -107,6 +107,8 @@ public class AndroidacyRepoData extends RepoData {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
jsonObject = jsonArray.getJSONObject(i); jsonObject = jsonArray.getJSONObject(i);
String moduleId = jsonObject.getString("codename"); String moduleId = jsonObject.getString("codename");
// Deny remote modules ids shorter than 3 chars
if (moduleId.length() < 3) continue;
long lastUpdate = jsonObject.getLong("updated_at") * 1000; long lastUpdate = jsonObject.getLong("updated_at") * 1000;
lastLastUpdate = Math.max(lastLastUpdate, lastUpdate); lastLastUpdate = Math.max(lastLastUpdate, lastUpdate);
RepoModule repoModule = this.moduleHashMap.get(moduleId); RepoModule repoModule = this.moduleHashMap.get(moduleId);

@ -85,8 +85,8 @@ public class RepoData {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
JSONObject module = array.getJSONObject(i); JSONObject module = array.getJSONObject(i);
String moduleId = module.getString("id"); String moduleId = module.getString("id");
// Deny remote modules ids shorter than 3 chars long or that start with a digit // Deny remote modules ids shorter than 3 chars
if (moduleId.length() < 3 || Character.isDigit(moduleId.charAt(0))) continue; if (moduleId.length() < 3) continue;
long moduleLastUpdate = module.getLong("last_update"); long moduleLastUpdate = module.getLong("last_update");
String moduleNotesUrl = module.getString("notes_url"); String moduleNotesUrl = module.getString("notes_url");
String modulePropsUrl = module.getString("prop_url"); String modulePropsUrl = module.getString("prop_url");

@ -23,6 +23,7 @@ import com.fox2code.mmm.compat.CompatThemeWrapper;
import com.fox2code.mmm.installer.InstallerInitializer; import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.repo.RepoData; import com.fox2code.mmm.repo.RepoData;
import com.fox2code.mmm.repo.RepoManager; import com.fox2code.mmm.repo.RepoManager;
import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper; import com.fox2code.mmm.utils.IntentHelper;
import com.mikepenz.aboutlibraries.LibsBuilder; import com.mikepenz.aboutlibraries.LibsBuilder;
import com.topjohnwu.superuser.internal.UiThreadHandler; import com.topjohnwu.superuser.internal.UiThreadHandler;
@ -83,6 +84,10 @@ public class SettingsActivity extends CompatActivity {
} }
return true; return true;
}); });
findPreference("pref_dns_over_https").setOnPreferenceChangeListener((p, v) -> {
Http.setDoh((Boolean) v);
return true;
});
if ("dark".equals(themePreference.getValue())) { if ("dark".equals(themePreference.getValue())) {
findPreference("pref_force_dark_terminal").setEnabled(false); findPreference("pref_force_dark_terminal").setEnabled(false);
} }

@ -52,9 +52,12 @@ import okio.BufferedSink;
public class Http { public class Http {
private static final String TAG = "Http"; private static final String TAG = "Http";
private static final OkHttpClient httpClient; private static final OkHttpClient httpClient;
private static final OkHttpClient httpClientDoH;
private static final OkHttpClient httpClientWithCache; private static final OkHttpClient httpClientWithCache;
private static final OkHttpClient httpClientWithCacheDoH;
private static final FallBackDNS fallbackDNS; private static final FallBackDNS fallbackDNS;
private static final String androidacyUA; private static final String androidacyUA;
private static boolean doh;
static { static {
MainApplication mainApplication = MainApplication.getINSTANCE(); MainApplication mainApplication = MainApplication.getINSTANCE();
@ -131,26 +134,33 @@ public class Http {
return chain.proceed(request.build()); return chain.proceed(request.build());
}); });
// Fallback DNS cache responses in case request fail but already succeeded once in the past // Fallback DNS cache responses in case request fail but already succeeded once in the past
httpclientBuilder.dns(fallbackDNS = new FallBackDNS(mainApplication, dns, fallbackDNS = new FallBackDNS(mainApplication, dns,
"github.com", "api.github.com", "raw.githubusercontent.com", "github.com", "api.github.com", "raw.githubusercontent.com",
"camo.githubusercontent.com", "user-images.githubusercontent.com", "camo.githubusercontent.com", "user-images.githubusercontent.com",
"cdn.jsdelivr.net", "img.shields.io", "magisk-modules-repo.github.io", "cdn.jsdelivr.net", "img.shields.io", "magisk-modules-repo.github.io",
"www.androidacy.com", "api.androidacy.com")); "www.androidacy.com", "api.androidacy.com");
httpclientBuilder.cookieJar(new CDNCookieJar(true)); httpclientBuilder.cookieJar(new CDNCookieJar(true));
httpclientBuilder.dns(Dns.SYSTEM);
httpClient = httpclientBuilder.build(); httpClient = httpclientBuilder.build();
httpclientBuilder.dns(fallbackDNS);
httpClientDoH = httpclientBuilder.build();
httpclientBuilder.cache(new Cache( httpclientBuilder.cache(new Cache(
new File(mainApplication.getCacheDir(), "http_cache"), new File(mainApplication.getCacheDir(), "http_cache"),
16L * 1024L * 1024L)); // 16Mib of cache 16L * 1024L * 1024L)); // 16Mib of cache
httpclientBuilder.dns(Dns.SYSTEM);
httpClientWithCache = httpclientBuilder.build(); httpClientWithCache = httpclientBuilder.build();
httpclientBuilder.dns(fallbackDNS);
httpClientWithCacheDoH = httpclientBuilder.build();
Log.i(TAG, "Initialized Http successfully!"); Log.i(TAG, "Initialized Http successfully!");
doh = MainApplication.isDohEnabled();
} }
public static OkHttpClient getHttpClient() { public static OkHttpClient getHttpClient() {
return httpClient; return doh ? httpClientDoH : httpClient;
} }
public static OkHttpClient getHttpClientWithCache() { public static OkHttpClient getHttpClientWithCache() {
return httpClientWithCache; return doh ? httpClientWithCacheDoH : httpClientWithCache;
} }
public static byte[] doHttpGet(String url,boolean allowCache) throws IOException { public static byte[] doHttpGet(String url,boolean allowCache) throws IOException {
@ -241,6 +251,11 @@ public class Http {
return androidacyUA; return androidacyUA;
} }
public static void setDoh(boolean doh) {
Log.d(TAG, "DoH: " + Http.doh + " -> " + doh);
Http.doh = doh;
}
/** /**
* Cookie jar that allow CDN cookies, reset on app relaunch * Cookie jar that allow CDN cookies, reset on app relaunch
* Note: An argument can be made that it allow tracking but * Note: An argument can be made that it allow tracking but

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>

@ -74,7 +74,10 @@
and/or indicating poor module quality, disable at your own risk! and/or indicating poor module quality, disable at your own risk!
</string> </string>
<string name="dns_over_https_pref">Dns over https</string> <string name="dns_over_https_pref">Dns over https</string>
<string name="dns_over_https_desc">May fix connections issues in some cases.</string> <string name="dns_over_https_desc">
May fix connections issues in some cases.
(Does not apply to WebView)
</string>
<string name="disable_extensions_pref">Disable extensions</string> <string name="disable_extensions_pref">Disable extensions</string>
<string name="disable_extensions_desc"> <string name="disable_extensions_desc">
Disable Fox\'s Mmm extensions, this prevent modules from using Disable Fox\'s Mmm extensions, this prevent modules from using

@ -71,6 +71,14 @@
app:title="@string/use_magisk_install_command_pref" app:title="@string/use_magisk_install_command_pref"
app:summary="@string/use_magisk_install_command_desc" app:summary="@string/use_magisk_install_command_desc"
app:singleLineTitle="false" /> app:singleLineTitle="false" />
<SwitchPreferenceCompat
app:defaultValue="true"
app:key="pref_dns_over_https"
app:icon="@drawable/ic_baseline_security_24"
app:title="@string/dns_over_https_pref"
app:summary="@string/dns_over_https_desc"
app:singleLineTitle="false" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory

Loading…
Cancel
Save