From 985b30234397304dc30c8c579b47031930afc55c Mon Sep 17 00:00:00 2001 From: "Yevhen Babiichuk (DustDFG)" Date: Tue, 3 Feb 2026 20:43:01 +0200 Subject: [PATCH 1/2] Add brotli support to downloader --- app/build.gradle.kts | 2 +- app/src/main/java/org/schabi/newpipe/DownloaderImpl.java | 6 ++++++ gradle/libs.versions.toml | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e18826c1619..c7968104b53 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -132,7 +132,6 @@ ksp { arg("room.schemaLocation", "$projectDir/schemas") } - // Custom dependency configuration for ktlint val ktlint by configurations.creating @@ -256,6 +255,7 @@ dependencies { // HTTP client implementation(libs.squareup.okhttp) + implementation(libs.squareup.okhttp.brotli) // Media player implementation(libs.google.exoplayer.core) diff --git a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java index 74a2cab5176..5971f03b853 100644 --- a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java +++ b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java @@ -23,9 +23,12 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import okhttp3.CompressionInterceptor; +import okhttp3.Gzip; import okhttp3.OkHttpClient; import okhttp3.RequestBody; import okhttp3.ResponseBody; +import okhttp3.brotli.Brotli; public final class DownloaderImpl extends Downloader { public static final String USER_AGENT = @@ -44,6 +47,9 @@ private DownloaderImpl(final OkHttpClient.Builder builder) { .readTimeout(30, TimeUnit.SECONDS) // .cache(new Cache(new File(context.getExternalCacheDir(), "okhttp"), // 16 * 1024 * 1024)) + .addInterceptor(new CompressionInterceptor( + Brotli.INSTANCE, + Gzip.INSTANCE)) .build(); this.mCookies = new HashMap<>(); } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 73e9cad0815..ff63b2f8a0b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -128,6 +128,7 @@ squareup-leakcanary-core = { module = "com.squareup.leakcanary:leakcanary-androi squareup-leakcanary-plumber = { module = "com.squareup.leakcanary:plumber-android", version.ref = "leakcanary" } squareup-leakcanary-watcher = { module = "com.squareup.leakcanary:leakcanary-object-watcher-android", version.ref = "leakcanary" } squareup-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" } +squareup-okhttp-brotli = { module = "com.squareup.okhttp3:okhttp-brotli", version.ref = "okhttp" } zacsweers-autoservice-compiler = { module = "dev.zacsweers.autoservice:auto-service-ksp", version.ref = "autoservice-zacsweers" } [plugins] From facf576e0fcdc10c355a3e4ea08e0f93a2ced942 Mon Sep 17 00:00:00 2001 From: "Yevhen Babiichuk (DustDFG)" Date: Thu, 26 Feb 2026 10:51:46 +0200 Subject: [PATCH 2/2] Restrict brotli usage to devices with more than 2 physical cores For us it doesn't really matter amount of cores available for us. We need only physical cores count as we use it for filtering weak devices. _SC_NPROCESSORS_CONF - amount of physical cores (android devices doesn't have extrnal cpu cores hotplug). **Used** _SC_NPROCESSORS_ONLN - amount of cores available for OS right now. Often smaller than _SC_NPROCESSORS_CONF because OS can deactivate cores for powersave Runtime.getRuntime().availableProcessors() - a core count available to jvm. Has the same limitations as _SC_NPROCESSORS_ONLN but also can be decreased because some cores are allocated to other more priority processes (?) --- .../java/org/schabi/newpipe/DownloaderImpl.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java index 5971f03b853..41380bf0722 100644 --- a/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java +++ b/app/src/main/java/org/schabi/newpipe/DownloaderImpl.java @@ -1,6 +1,8 @@ package org.schabi.newpipe; import android.content.Context; +import android.system.Os; +import android.system.OsConstants; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -43,13 +45,20 @@ public final class DownloaderImpl extends Downloader { private final OkHttpClient client; private DownloaderImpl(final OkHttpClient.Builder builder) { + final CompressionInterceptor compressionInterceptor; + if (Os.sysconf(OsConstants._SC_NPROCESSORS_CONF) > 2) { + compressionInterceptor = new CompressionInterceptor( + Brotli.INSTANCE, + Gzip.INSTANCE); + } else { + compressionInterceptor = new CompressionInterceptor( + Gzip.INSTANCE); + } this.client = builder .readTimeout(30, TimeUnit.SECONDS) // .cache(new Cache(new File(context.getExternalCacheDir(), "okhttp"), // 16 * 1024 * 1024)) - .addInterceptor(new CompressionInterceptor( - Brotli.INSTANCE, - Gzip.INSTANCE)) + .addInterceptor(compressionInterceptor) .build(); this.mCookies = new HashMap<>(); }