(chore) try to fix issue with cronet

Signed-off-by: androidacy-user <opensource@androidacy.com>
master
androidacy-user 1 year ago
parent 7e1212aac2
commit fb81d0faa4

@ -304,7 +304,6 @@ sentry {
setOf( setOf(
InstrumentationFeature.DATABASE, InstrumentationFeature.DATABASE,
InstrumentationFeature.FILE_IO, InstrumentationFeature.FILE_IO,
InstrumentationFeature.OKHTTP,
InstrumentationFeature.COMPOSE InstrumentationFeature.COMPOSE
) )
) )
@ -367,7 +366,6 @@ configurations {
// Access all imported libraries // Access all imported libraries
all { all {
// Exclude all libraries with the following group and module // Exclude all libraries with the following group and module
exclude(group = "org.chromium.net", module = "cronet-api")
exclude(group = "org.jetbrains", module = "annotations-java5") exclude(group = "org.jetbrains", module = "annotations-java5")
} }
} }
@ -397,11 +395,10 @@ dependencies {
// logging interceptor // logging interceptor
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.10") implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.10")
// Chromium cronet from androidacy // Chromium cronet from androidacy
implementation("com.androidacy:cronet-common:112.0.5615.62") implementation("org.chromium.net:cronet-embedded:108.5359.79")
implementation("com.androidacy:cronet-native:112.0.5615.62")
implementation("com.androidacy:cronet-api:112.0.5615.62")
// protobuf - fixes a crash on some devices // protobuf - fixes a crash on some devices
implementation("com.google.protobuf:protobuf-javalite:3.22.2") // implementation("com.google.protobuf:protobuf-javalite:3.22.2")
implementation("com.github.topjohnwu.libsu:io:5.0.5") implementation("com.github.topjohnwu.libsu:io:5.0.5")
implementation("com.github.Fox2Code:RosettaX:1.0.9") implementation("com.github.Fox2Code:RosettaX:1.0.9")
@ -466,12 +463,6 @@ android {
} }
//noinspection GrDeprecatedAPIUsage //noinspection GrDeprecatedAPIUsage
buildToolsVersion = "34.0.0 rc3" buildToolsVersion = "34.0.0 rc3"
@Suppress("DEPRECATION")
packagingOptions {
jniLibs {
useLegacyPackaging = true
}
}
} }

@ -188,8 +188,12 @@
} }
# Keep all of Cronet API and google's internal classes # Keep all of Cronet API and google's internal classes
-keep class org.chromium.net.** { *; }
-keep class org.chromium.** { *; } -keep class org.chromium.** { *; }
-keep class org.chromium.net.** { *; }
-keepclassmembers class kotlin.SafePublicationLazyImpl {
java.lang.Object _value;
}
# Silence some warnings # Silence some warnings
-dontwarn android.os.SystemProperties -dontwarn android.os.SystemProperties

@ -430,7 +430,7 @@ public class MainApplication extends FoxApplication implements androidx.work.Con
// Update SSL Ciphers if update is possible // Update SSL Ciphers if update is possible
GMSProviderInstaller.installIfNeeded(this); GMSProviderInstaller.installIfNeeded(this);
Http.ensureCacheDirs(); Http.ensureCacheDirs();
Http.ensureURLHandler(this); Http.ensureURLHandler(getApplicationContext());
Timber.d("Initializing FoxMMM"); Timber.d("Initializing FoxMMM");
Timber.d("Started from background: %s", !isInForeground()); Timber.d("Started from background: %s", !isInForeground());
Timber.d("FoxMMM is running in debug mode"); Timber.d("FoxMMM is running in debug mode");

@ -53,7 +53,6 @@ import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException; import javax.net.ssl.SSLException;
import io.sentry.android.okhttp.SentryOkHttpInterceptor;
import okhttp3.Cache; import okhttp3.Cache;
import okhttp3.Dns; import okhttp3.Dns;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
@ -79,6 +78,7 @@ public enum Http {
private static final boolean hasWebView; private static final boolean hasWebView;
private static String needCaptchaAndroidacyHost; private static String needCaptchaAndroidacyHost;
private static boolean doh; private static boolean doh;
private static boolean urlFactoryInstalled;
static { static {
MainApplication mainApplication = MainApplication.getINSTANCE(); MainApplication mainApplication = MainApplication.getINSTANCE();
@ -90,8 +90,7 @@ public enum Http {
System.err.flush(); System.err.flush();
try { try {
Os.kill(Os.getpid(), 9); Os.kill(Os.getpid(), 9);
} catch ( } catch (ErrnoException e) {
ErrnoException e) {
System.exit(9); System.exit(9);
} }
throw error; throw error;
@ -101,8 +100,7 @@ public enum Http {
cookieManager = CookieManager.getInstance(); cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true); cookieManager.setAcceptCookie(true);
cookieManager.flush(); // Make sure the instance work cookieManager.flush(); // Make sure the instance work
} catch ( } catch (Exception t) {
Exception t) {
cookieManager = null; cookieManager = null;
Timber.e(t, "No WebView support!"); Timber.e(t, "No WebView support!");
// show a toast // show a toast
@ -148,9 +146,7 @@ public enum Http {
WebkitCookieManagerProxy cookieJar = new WebkitCookieManagerProxy(); WebkitCookieManagerProxy cookieJar = new WebkitCookieManagerProxy();
httpclientBuilder.cookieJar(cookieJar); httpclientBuilder.cookieJar(cookieJar);
dns = new DnsOverHttps.Builder().client(httpclientBuilder.build()).url(Objects.requireNonNull(HttpUrl.parse("https://cloudflare-dns.com/dns-query"))).bootstrapDnsHosts(cloudflareBootstrap).resolvePrivateAddresses(true).build(); dns = new DnsOverHttps.Builder().client(httpclientBuilder.build()).url(Objects.requireNonNull(HttpUrl.parse("https://cloudflare-dns.com/dns-query"))).bootstrapDnsHosts(cloudflareBootstrap).resolvePrivateAddresses(true).build();
} catch ( } catch (UnknownHostException | RuntimeException e) {
UnknownHostException |
RuntimeException e) {
Timber.e(e, "Failed to init DoH"); Timber.e(e, "Failed to init DoH");
} }
// User-Agent format was agreed on telegram // User-Agent format was agreed on telegram
@ -186,10 +182,6 @@ public enum Http {
request.header("Sec-CH-UA-Bitness", Build.SUPPORTED_64_BIT_ABIS.length > 0 ? "64" : "32"); request.header("Sec-CH-UA-Bitness", Build.SUPPORTED_64_BIT_ABIS.length > 0 ? "64" : "32");
return chain.proceed(request.build()); return chain.proceed(request.build());
}); });
// add sentry interceptor
if (MainApplication.isCrashReportingEnabled()) {
httpclientBuilder.addInterceptor(new SentryOkHttpInterceptor());
}
// for debug builds, add a logging interceptor // for debug builds, add a logging interceptor
// this spams the logcat, so it's disabled by default and hidden behind a build config flag // this spams the logcat, so it's disabled by default and hidden behind a build config flag
@ -204,7 +196,7 @@ public enum Http {
// init cronet // init cronet
try { try {
// Load the cronet library // Load the cronet library
CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication); CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication.getApplicationContext());
builder.enableBrotli(true); builder.enableBrotli(true);
builder.enableHttp2(true); builder.enableHttp2(true);
builder.enableQuic(true); builder.enableQuic(true);
@ -218,7 +210,6 @@ public enum Http {
} }
builder.setStoragePath(mainApplication.getCacheDir().getAbsolutePath() + "/cronet"); builder.setStoragePath(mainApplication.getCacheDir().getAbsolutePath() + "/cronet");
builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 10 * 1024 * 1024); builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 10 * 1024 * 1024);
builder.enableNetworkQualityEstimator(true);
// Add quic hint // Add quic hint
builder.addQuicHint("github.com", 443, 443); builder.addQuicHint("github.com", 443, 443);
builder.addQuicHint("githubusercontent.com", 443, 443); builder.addQuicHint("githubusercontent.com", 443, 443);
@ -227,8 +218,7 @@ public enum Http {
builder.addQuicHint("sentry.io", 443, 443); builder.addQuicHint("sentry.io", 443, 443);
CronetEngine engine = builder.build(); CronetEngine engine = builder.build();
httpclientBuilder.addInterceptor(CronetInterceptor.newBuilder(engine).build()); httpclientBuilder.addInterceptor(CronetInterceptor.newBuilder(engine).build());
} catch ( } catch (Exception e) {
Exception e) {
Timber.e(e, "Failed to init cronet"); Timber.e(e, "Failed to init cronet");
// Gracefully fallback to okhttp // Gracefully fallback to okhttp
} }
@ -249,8 +239,6 @@ public enum Http {
doh = MainApplication.isDohEnabled(); doh = MainApplication.isDohEnabled();
} }
private static boolean urlFactoryInstalled;
private static OkHttpClient.Builder followRedirects(OkHttpClient.Builder builder, boolean followRedirects) { private static OkHttpClient.Builder followRedirects(OkHttpClient.Builder builder, boolean followRedirects) {
return builder.followRedirects(followRedirects).followSslRedirects(followRedirects); return builder.followRedirects(followRedirects).followSslRedirects(followRedirects);
} }
@ -316,8 +304,7 @@ public enum Http {
// Use cache api if used cached response // Use cache api if used cached response
if (response.code() == 304) { if (response.code() == 304) {
response = response.cacheResponse(); response = response.cacheResponse();
if (response != null) if (response != null) responseBody = response.body();
responseBody = response.body();
} }
if (BuildConfig.DEBUG_HTTP) { if (BuildConfig.DEBUG_HTTP) {
Timber.d("doHttpGet: returning " + responseBody.contentLength() + " bytes"); Timber.d("doHttpGet: returning " + responseBody.contentLength() + " bytes");
@ -347,8 +334,7 @@ public enum Http {
// Use cache api if used cached response // Use cache api if used cached response
if (response.code() == 304) { if (response.code() == 304) {
response = response.cacheResponse(); response = response.cacheResponse();
if (response != null) if (response != null) responseBody = response.body();
responseBody = response.body();
} }
return responseBody.bytes(); return responseBody.bytes();
} }
@ -377,8 +363,7 @@ public enum Http {
progressListener.onUpdate(0, (int) (target / divider), false); progressListener.onUpdate(0, (int) (target / divider), false);
while (true) { while (true) {
int read = inputStream.read(buff); int read = inputStream.read(buff);
if (read == -1) if (read == -1) break;
break;
byteArrayOutputStream.write(buff, 0, read); byteArrayOutputStream.write(buff, 0, read);
downloaded += read; downloaded += read;
currentUpdate = System.currentTimeMillis(); currentUpdate = System.currentTimeMillis();
@ -411,7 +396,7 @@ public enum Http {
return hasWebView; return hasWebView;
} }
public static void ensureCacheDirs() { public static void ensureCacheDirs() {
try { try {
FileUtils.forceMkdir(new File((MainApplication.getINSTANCE().getDataDir() + "/cache/WebView/Default/HTTP Cache/Code Cache/wasm").replaceAll("//", "/"))); FileUtils.forceMkdir(new File((MainApplication.getINSTANCE().getDataDir() + "/cache/WebView/Default/HTTP Cache/Code Cache/wasm").replaceAll("//", "/")));
FileUtils.forceMkdir(new File((MainApplication.getINSTANCE().getDataDir() + "/cache/WebView/Default/HTTP Cache/Code Cache/js").replaceAll("//", "/"))); FileUtils.forceMkdir(new File((MainApplication.getINSTANCE().getDataDir() + "/cache/WebView/Default/HTTP Cache/Code Cache/js").replaceAll("//", "/")));
@ -487,22 +472,19 @@ public enum Http {
@NonNull @NonNull
private static String toString(@NonNull List<InetAddress> inetAddresses) { private static String toString(@NonNull List<InetAddress> inetAddresses) {
if (inetAddresses.isEmpty()) if (inetAddresses.isEmpty()) return "";
return "";
Iterator<InetAddress> inetAddressIterator = inetAddresses.iterator(); Iterator<InetAddress> inetAddressIterator = inetAddresses.iterator();
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
while (true) { while (true) {
stringBuilder.append(inetAddressIterator.next().getHostAddress()); stringBuilder.append(inetAddressIterator.next().getHostAddress());
if (!inetAddressIterator.hasNext()) if (!inetAddressIterator.hasNext()) return stringBuilder.toString();
return stringBuilder.toString();
stringBuilder.append("|"); stringBuilder.append("|");
} }
} }
@NonNull @NonNull
private static List<InetAddress> fromString(@NonNull String string) throws UnknownHostException { private static List<InetAddress> fromString(@NonNull String string) throws UnknownHostException {
if (string.isEmpty()) if (string.isEmpty()) return Collections.emptyList();
return Collections.emptyList();
String[] strings = string.split("\\|"); String[] strings = string.split("\\|");
ArrayList<InetAddress> inetAddresses = new ArrayList<>(strings.length); ArrayList<InetAddress> inetAddresses = new ArrayList<>(strings.length);
for (String address : strings) { for (String address : strings) {
@ -518,24 +500,20 @@ public enum Http {
List<InetAddress> addresses; List<InetAddress> addresses;
synchronized (this.fallbackCache) { synchronized (this.fallbackCache) {
addresses = this.fallbackCache.get(s); addresses = this.fallbackCache.get(s);
if (addresses != null) if (addresses != null) return addresses;
return addresses;
try { try {
addresses = this.parent.lookup(s); addresses = this.parent.lookup(s);
if (addresses.isEmpty() || addresses.get(0).isLoopbackAddress()) if (addresses.isEmpty() || addresses.get(0).isLoopbackAddress())
throw new UnknownHostException(s); throw new UnknownHostException(s);
this.fallbackCache.put(s, addresses); this.fallbackCache.put(s, addresses);
this.sharedPreferences.edit().putString(s.replace('.', '_'), toString(addresses)).apply(); this.sharedPreferences.edit().putString(s.replace('.', '_'), toString(addresses)).apply();
} catch ( } catch (UnknownHostException e) {
UnknownHostException e) {
String key = this.sharedPreferences.getString(s.replace('.', '_'), ""); String key = this.sharedPreferences.getString(s.replace('.', '_'), "");
if (key.isEmpty()) if (key.isEmpty()) throw e;
throw e;
try { try {
addresses = fromString(key); addresses = fromString(key);
this.fallbackCache.put(s, addresses); this.fallbackCache.put(s, addresses);
} catch ( } catch (UnknownHostException e2) {
UnknownHostException e2) {
this.sharedPreferences.edit().remove(s.replace('.', '_')).apply(); this.sharedPreferences.edit().remove(s.replace('.', '_')).apply();
throw e; throw e;
} }

@ -89,7 +89,6 @@ public class SentryMain {
options.setAttachThreads(true); options.setAttachThreads(true);
options.setAttachStacktrace(true); options.setAttachStacktrace(true);
options.setEnableNdk(true); options.setEnableNdk(true);
// Intercept okhttp requests to add sentry headers
options.addInAppInclude("com.fox2code.mmm"); options.addInAppInclude("com.fox2code.mmm");
options.addInAppInclude("com.fox2code.mmm.debug"); options.addInAppInclude("com.fox2code.mmm.debug");
options.addInAppInclude("com.fox2code.mmm.fdroid"); options.addInAppInclude("com.fox2code.mmm.fdroid");

Loading…
Cancel
Save