From e28edbadbf4097911979d88b964c89743f32e0b7 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Tue, 28 May 2024 23:38:57 +0400 Subject: [PATCH] fix(YouTube - Spoof client): Disable AV1 if not supported by spoofing an older iOS device (#644) --- .../patches/spoof/SpoofClientPatch.java | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofClientPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofClientPatch.java index fd1c8135..de411a66 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofClientPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/spoof/SpoofClientPatch.java @@ -1,6 +1,9 @@ package app.revanced.integrations.youtube.patches.spoof; +import android.media.MediaCodecInfo; +import android.media.MediaCodecList; import android.net.Uri; +import android.os.Build; import app.revanced.integrations.shared.Logger; import app.revanced.integrations.youtube.settings.Settings; @@ -29,7 +32,7 @@ public class SpoofClientPatch { String path = playerRequestUri.getPath(); if (path != null && path.contains("get_watch")) { - Logger.printDebug(() -> "Blocking: " + playerRequestUri + " by returning: " + UNREACHABLE_HOST_URI_STRING); + Logger.printDebug(() -> "Blocking: " + playerRequestUri + " by returning unreachable uri"); return UNREACHABLE_HOST_URI; } @@ -106,15 +109,32 @@ public class SpoofClientPatch { } private enum ClientType { - // https://dumps.tadiphone.dev/dumps/oculus/monterey/-/blob/vr_monterey-user-7.1.1-NGI77B-256550.6810.0-release-keys/system/system/build.prop?ref_type=heads + // https://dumps.tadiphone.dev/dumps/oculus/monterey/-/blob/vr_monterey-user-7.1.1-NGI77B-256550.6810.0-release-keys/system/system/build.prop + // version 1.37 is not the latest, but it works with livestream audio only playback. ANDROID_VR(28, "Quest", "1.37"), + // 11,4 = iPhone XS Max. // 16,2 = iPhone 15 Pro Max. + // Since the 15 supports AV1 hardware decoding, only spoof that device if this + // Android device also has hardware decoding. + // // Version number should be a valid iOS release. // https://www.ipa4fun.com/history/185230 - IOS(5, "iPhone16,2", "19.10.7"); + IOS(5, deviceHasAV1HardwareDecoding() ? "iPhone16,2" : "iPhone11,4", "19.10.7"); + /** + * YouTube + * client type + */ final int id; + + /** + * Device model, equivalent to {@link Build#MODEL} (System property: ro.product.model) + */ final String model; + + /** + * App version. + */ final String version; ClientType(int id, String model, String version) { @@ -123,4 +143,28 @@ public class SpoofClientPatch { this.version = version; } } + + private static boolean deviceHasAV1HardwareDecoding() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS); + + for (MediaCodecInfo codecInfo : codecList.getCodecInfos()) { + if (codecInfo.isHardwareAccelerated() && !codecInfo.isEncoder()) { + String[] supportedTypes = codecInfo.getSupportedTypes(); + for (String type : supportedTypes) { + if (type.equalsIgnoreCase("video/av01")) { + MediaCodecInfo.CodecCapabilities capabilities = codecInfo.getCapabilitiesForType(type); + if (capabilities != null) { + Logger.printDebug(() -> "Device supports AV1 hardware decoding."); + return true; + } + } + } + } + } + } + + Logger.printDebug(() -> "Device does not support AV1 hardware decoding."); + return false; + } }