(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(
InstrumentationFeature.DATABASE,
InstrumentationFeature.FILE_IO,
InstrumentationFeature.OKHTTP,
InstrumentationFeature.COMPOSE
)
)
@ -367,7 +366,6 @@ configurations {
// Access all imported libraries
all {
// Exclude all libraries with the following group and module
exclude(group = "org.chromium.net", module = "cronet-api")
exclude(group = "org.jetbrains", module = "annotations-java5")
}
}
@ -397,11 +395,10 @@ dependencies {
// logging interceptor
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.10")
// Chromium cronet from androidacy
implementation("com.androidacy:cronet-common:112.0.5615.62")
implementation("com.androidacy:cronet-native:112.0.5615.62")
implementation("com.androidacy:cronet-api:112.0.5615.62")
implementation("org.chromium.net:cronet-embedded:108.5359.79")
// 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.Fox2Code:RosettaX:1.0.9")
@ -466,12 +463,6 @@ android {
}
//noinspection GrDeprecatedAPIUsage
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 class org.chromium.net.** { *; }
-keep class org.chromium.** { *; }
-keep class org.chromium.net.** { *; }
-keepclassmembers class kotlin.SafePublicationLazyImpl {
java.lang.Object _value;
}
# Silence some warnings
-dontwarn android.os.SystemProperties

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

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

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

Loading…
Cancel
Save