Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit fb81d0f

Browse files
(chore) try to fix issue with cronet
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 7e1212a commit fb81d0f

5 files changed

Lines changed: 26 additions & 54 deletions

File tree

app/build.gradle.kts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ sentry {
304304
setOf(
305305
InstrumentationFeature.DATABASE,
306306
InstrumentationFeature.FILE_IO,
307-
InstrumentationFeature.OKHTTP,
308307
InstrumentationFeature.COMPOSE
309308
)
310309
)
@@ -367,7 +366,6 @@ configurations {
367366
// Access all imported libraries
368367
all {
369368
// Exclude all libraries with the following group and module
370-
exclude(group = "org.chromium.net", module = "cronet-api")
371369
exclude(group = "org.jetbrains", module = "annotations-java5")
372370
}
373371
}
@@ -397,11 +395,10 @@ dependencies {
397395
// logging interceptor
398396
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.10")
399397
// Chromium cronet from androidacy
400-
implementation("com.androidacy:cronet-common:112.0.5615.62")
401-
implementation("com.androidacy:cronet-native:112.0.5615.62")
402-
implementation("com.androidacy:cronet-api:112.0.5615.62")
398+
implementation("org.chromium.net:cronet-embedded:108.5359.79")
399+
403400
// protobuf - fixes a crash on some devices
404-
implementation("com.google.protobuf:protobuf-javalite:3.22.2")
401+
// implementation("com.google.protobuf:protobuf-javalite:3.22.2")
405402

406403
implementation("com.github.topjohnwu.libsu:io:5.0.5")
407404
implementation("com.github.Fox2Code:RosettaX:1.0.9")
@@ -466,12 +463,6 @@ android {
466463
}
467464
//noinspection GrDeprecatedAPIUsage
468465
buildToolsVersion = "34.0.0 rc3"
469-
@Suppress("DEPRECATION")
470-
packagingOptions {
471-
jniLibs {
472-
useLegacyPackaging = true
473-
}
474-
}
475466
}
476467

477468

app/proguard-rules.pro

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@
188188
}
189189

190190
# Keep all of Cronet API and google's internal classes
191-
-keep class org.chromium.net.** { *; }
192191
-keep class org.chromium.** { *; }
192+
-keep class org.chromium.net.** { *; }
193+
194+
-keepclassmembers class kotlin.SafePublicationLazyImpl {
195+
java.lang.Object _value;
196+
}
193197

194198
# Silence some warnings
195199
-dontwarn android.os.SystemProperties

app/src/main/java/com/fox2code/mmm/MainApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void onCreate() {
430430
// Update SSL Ciphers if update is possible
431431
GMSProviderInstaller.installIfNeeded(this);
432432
Http.ensureCacheDirs();
433-
Http.ensureURLHandler(this);
433+
Http.ensureURLHandler(getApplicationContext());
434434
Timber.d("Initializing FoxMMM");
435435
Timber.d("Started from background: %s", !isInForeground());
436436
Timber.d("FoxMMM is running in debug mode");

app/src/main/java/com/fox2code/mmm/utils/io/net/Http.java

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
import javax.net.ssl.SSLException;
5555

56-
import io.sentry.android.okhttp.SentryOkHttpInterceptor;
5756
import okhttp3.Cache;
5857
import okhttp3.Dns;
5958
import okhttp3.HttpUrl;
@@ -79,6 +78,7 @@ public enum Http {
7978
private static final boolean hasWebView;
8079
private static String needCaptchaAndroidacyHost;
8180
private static boolean doh;
81+
private static boolean urlFactoryInstalled;
8282

8383
static {
8484
MainApplication mainApplication = MainApplication.getINSTANCE();
@@ -90,8 +90,7 @@ public enum Http {
9090
System.err.flush();
9191
try {
9292
Os.kill(Os.getpid(), 9);
93-
} catch (
94-
ErrnoException e) {
93+
} catch (ErrnoException e) {
9594
System.exit(9);
9695
}
9796
throw error;
@@ -101,8 +100,7 @@ public enum Http {
101100
cookieManager = CookieManager.getInstance();
102101
cookieManager.setAcceptCookie(true);
103102
cookieManager.flush(); // Make sure the instance work
104-
} catch (
105-
Exception t) {
103+
} catch (Exception t) {
106104
cookieManager = null;
107105
Timber.e(t, "No WebView support!");
108106
// show a toast
@@ -148,9 +146,7 @@ public enum Http {
148146
WebkitCookieManagerProxy cookieJar = new WebkitCookieManagerProxy();
149147
httpclientBuilder.cookieJar(cookieJar);
150148
dns = new DnsOverHttps.Builder().client(httpclientBuilder.build()).url(Objects.requireNonNull(HttpUrl.parse("https://cloudflare-dns.com/dns-query"))).bootstrapDnsHosts(cloudflareBootstrap).resolvePrivateAddresses(true).build();
151-
} catch (
152-
UnknownHostException |
153-
RuntimeException e) {
149+
} catch (UnknownHostException | RuntimeException e) {
154150
Timber.e(e, "Failed to init DoH");
155151
}
156152
// User-Agent format was agreed on telegram
@@ -186,10 +182,6 @@ public enum Http {
186182
request.header("Sec-CH-UA-Bitness", Build.SUPPORTED_64_BIT_ABIS.length > 0 ? "64" : "32");
187183
return chain.proceed(request.build());
188184
});
189-
// add sentry interceptor
190-
if (MainApplication.isCrashReportingEnabled()) {
191-
httpclientBuilder.addInterceptor(new SentryOkHttpInterceptor());
192-
}
193185

194186
// for debug builds, add a logging interceptor
195187
// this spams the logcat, so it's disabled by default and hidden behind a build config flag
@@ -204,7 +196,7 @@ public enum Http {
204196
// init cronet
205197
try {
206198
// Load the cronet library
207-
CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication);
199+
CronetEngine.Builder builder = new CronetEngine.Builder(mainApplication.getApplicationContext());
208200
builder.enableBrotli(true);
209201
builder.enableHttp2(true);
210202
builder.enableQuic(true);
@@ -218,7 +210,6 @@ public enum Http {
218210
}
219211
builder.setStoragePath(mainApplication.getCacheDir().getAbsolutePath() + "/cronet");
220212
builder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_DISK_NO_HTTP, 10 * 1024 * 1024);
221-
builder.enableNetworkQualityEstimator(true);
222213
// Add quic hint
223214
builder.addQuicHint("github.com", 443, 443);
224215
builder.addQuicHint("githubusercontent.com", 443, 443);
@@ -227,8 +218,7 @@ public enum Http {
227218
builder.addQuicHint("sentry.io", 443, 443);
228219
CronetEngine engine = builder.build();
229220
httpclientBuilder.addInterceptor(CronetInterceptor.newBuilder(engine).build());
230-
} catch (
231-
Exception e) {
221+
} catch (Exception e) {
232222
Timber.e(e, "Failed to init cronet");
233223
// Gracefully fallback to okhttp
234224
}
@@ -249,8 +239,6 @@ public enum Http {
249239
doh = MainApplication.isDohEnabled();
250240
}
251241

252-
private static boolean urlFactoryInstalled;
253-
254242
private static OkHttpClient.Builder followRedirects(OkHttpClient.Builder builder, boolean followRedirects) {
255243
return builder.followRedirects(followRedirects).followSslRedirects(followRedirects);
256244
}
@@ -316,8 +304,7 @@ public static byte[] doHttpGet(String url, boolean allowCache) throws IOExceptio
316304
// Use cache api if used cached response
317305
if (response.code() == 304) {
318306
response = response.cacheResponse();
319-
if (response != null)
320-
responseBody = response.body();
307+
if (response != null) responseBody = response.body();
321308
}
322309
if (BuildConfig.DEBUG_HTTP) {
323310
Timber.d("doHttpGet: returning " + responseBody.contentLength() + " bytes");
@@ -347,8 +334,7 @@ private static Object doHttpPostRaw(String url, String data, boolean allowCache)
347334
// Use cache api if used cached response
348335
if (response.code() == 304) {
349336
response = response.cacheResponse();
350-
if (response != null)
351-
responseBody = response.body();
337+
if (response != null) responseBody = response.body();
352338
}
353339
return responseBody.bytes();
354340
}
@@ -377,8 +363,7 @@ public static byte[] doHttpGet(String url, ProgressListener progressListener) th
377363
progressListener.onUpdate(0, (int) (target / divider), false);
378364
while (true) {
379365
int read = inputStream.read(buff);
380-
if (read == -1)
381-
break;
366+
if (read == -1) break;
382367
byteArrayOutputStream.write(buff, 0, read);
383368
downloaded += read;
384369
currentUpdate = System.currentTimeMillis();
@@ -411,7 +396,7 @@ public static boolean hasWebView() {
411396
return hasWebView;
412397
}
413398

414-
public static void ensureCacheDirs() {
399+
public static void ensureCacheDirs() {
415400
try {
416401
FileUtils.forceMkdir(new File((MainApplication.getINSTANCE().getDataDir() + "/cache/WebView/Default/HTTP Cache/Code Cache/wasm").replaceAll("//", "/")));
417402
FileUtils.forceMkdir(new File((MainApplication.getINSTANCE().getDataDir() + "/cache/WebView/Default/HTTP Cache/Code Cache/js").replaceAll("//", "/")));
@@ -487,22 +472,19 @@ public FallBackDNS(Context context, Dns parent, String... fallbacks) {
487472

488473
@NonNull
489474
private static String toString(@NonNull List<InetAddress> inetAddresses) {
490-
if (inetAddresses.isEmpty())
491-
return "";
475+
if (inetAddresses.isEmpty()) return "";
492476
Iterator<InetAddress> inetAddressIterator = inetAddresses.iterator();
493477
StringBuilder stringBuilder = new StringBuilder();
494478
while (true) {
495479
stringBuilder.append(inetAddressIterator.next().getHostAddress());
496-
if (!inetAddressIterator.hasNext())
497-
return stringBuilder.toString();
480+
if (!inetAddressIterator.hasNext()) return stringBuilder.toString();
498481
stringBuilder.append("|");
499482
}
500483
}
501484

502485
@NonNull
503486
private static List<InetAddress> fromString(@NonNull String string) throws UnknownHostException {
504-
if (string.isEmpty())
505-
return Collections.emptyList();
487+
if (string.isEmpty()) return Collections.emptyList();
506488
String[] strings = string.split("\\|");
507489
ArrayList<InetAddress> inetAddresses = new ArrayList<>(strings.length);
508490
for (String address : strings) {
@@ -518,24 +500,20 @@ public List<InetAddress> lookup(@NonNull String s) throws UnknownHostException {
518500
List<InetAddress> addresses;
519501
synchronized (this.fallbackCache) {
520502
addresses = this.fallbackCache.get(s);
521-
if (addresses != null)
522-
return addresses;
503+
if (addresses != null) return addresses;
523504
try {
524505
addresses = this.parent.lookup(s);
525506
if (addresses.isEmpty() || addresses.get(0).isLoopbackAddress())
526507
throw new UnknownHostException(s);
527508
this.fallbackCache.put(s, addresses);
528509
this.sharedPreferences.edit().putString(s.replace('.', '_'), toString(addresses)).apply();
529-
} catch (
530-
UnknownHostException e) {
510+
} catch (UnknownHostException e) {
531511
String key = this.sharedPreferences.getString(s.replace('.', '_'), "");
532-
if (key.isEmpty())
533-
throw e;
512+
if (key.isEmpty()) throw e;
534513
try {
535514
addresses = fromString(key);
536515
this.fallbackCache.put(s, addresses);
537-
} catch (
538-
UnknownHostException e2) {
516+
} catch (UnknownHostException e2) {
539517
this.sharedPreferences.edit().remove(s.replace('.', '_')).apply();
540518
throw e;
541519
}

app/src/main/java/com/fox2code/mmm/utils/sentry/SentryMain.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ public static void initialize(final MainApplication mainApplication) {
8989
options.setAttachThreads(true);
9090
options.setAttachStacktrace(true);
9191
options.setEnableNdk(true);
92-
// Intercept okhttp requests to add sentry headers
9392
options.addInAppInclude("com.fox2code.mmm");
9493
options.addInAppInclude("com.fox2code.mmm.debug");
9594
options.addInAppInclude("com.fox2code.mmm.fdroid");

0 commit comments

Comments
 (0)