feat(YouTube): Add Hide accessibility controls dialog patch

This commit is contained in:
inotia00 2025-01-31 20:40:46 +09:00
parent e72ff471ae
commit 1c2e85b7eb
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package app.revanced.patches.youtube.misc.accessibility
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.patch.PatchList.HIDE_ACCESSIBILITY_CONTROLS_DIALOG
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.findMethodOrThrow
import app.revanced.util.fingerprint.mutableClassOrThrow
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import app.revanced.util.or
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@Suppress("unused")
val accessibilityPatch = bytecodePatch(
HIDE_ACCESSIBILITY_CONTROLS_DIALOG.title,
HIDE_ACCESSIBILITY_CONTROLS_DIALOG.summary,
) {
compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(settingsPatch)
execute {
playerAccessibilitySettingsEduControllerParentFingerprint
.mutableClassOrThrow()
.methods
.first { method -> method.name == "<init>" }
.apply {
val lifecycleObserverIndex = indexOfFirstInstructionReversedOrThrow(Opcode.NEW_INSTANCE)
val lifecycleObserverClass = getInstruction<ReferenceInstruction>(lifecycleObserverIndex).reference.toString()
findMethodOrThrow(lifecycleObserverClass) {
accessFlags == AccessFlags.PUBLIC or AccessFlags.FINAL &&
parameterTypes.size == 1 &&
indexOfFirstInstruction(Opcode.INVOKE_DIRECT) >= 0
}.returnEarly()
}
addPreference(HIDE_ACCESSIBILITY_CONTROLS_DIALOG)
}
}

View File

@ -0,0 +1,49 @@
package app.revanced.patches.youtube.misc.accessibility
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.or
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
/**
* The name of the class to find is 'Lcom/google/android/apps/youtube/app/player/overlay/accessibility/PlayerAccessibilitySettingsEduController$LifecycleObserver;'.
* It is one of the types of fields in the class.
* This class name has been obfuscated since YouTube 18.25.40.
* This class is always the same structure despite not a synthetic class.
* (Same field and method, checked in YouTube 17.34.36 ~ 20.02.41).
*/
internal val playerAccessibilitySettingsEduControllerParentFingerprint = legacyFingerprint(
name = "playerAccessibilitySettingsEduControllerParentFingerprint",
returnType = "V",
accessFlags = AccessFlags.STATIC or AccessFlags.CONSTRUCTOR,
parameters = emptyList(),
opcodes = listOf(
Opcode.SGET_OBJECT,
Opcode.CONST_WIDE_16,
Opcode.INVOKE_VIRTUAL,
Opcode.MOVE_RESULT_WIDE,
Opcode.SPUT_WIDE,
Opcode.RETURN_VOID,
),
customFingerprint = custom@{ method, classDef ->
// The number of fields is always 12.
if (classDef.fields.count() != 12) {
return@custom false
}
// The number of methods is always 2 or 3.
if (classDef.methods.count() > 3) {
return@custom false
}
val implementation = method.implementation
?: return@custom false
val instructions = implementation.instructions
val instructionCount = instructions.count()
if (instructionCount != 6) {
return@custom false
}
((instructions.elementAt(0) as? ReferenceInstruction)?.reference as? FieldReference)?.toString() == "Ljava/util/concurrent/TimeUnit;->DAYS:Ljava/util/concurrent/TimeUnit;"
}
)

View File

@ -113,6 +113,10 @@ internal enum class PatchList(
"GmsCore support",
"Allows patched Google apps to run without root and under a different package name by using GmsCore instead of Google Play Services."
),
HIDE_ACCESSIBILITY_CONTROLS_DIALOG(
"Hide accessibility controls dialog",
"Removes, at compile time, accessibility controls dialog 'Turn on accessibility controls for the video player?'."
),
HIDE_SHORTS_DIMMING(
"Hide Shorts dimming",
"Removes, at compile time, the dimming effect at the top and bottom of Shorts videos."

View File

@ -980,6 +980,7 @@
<Preference android:title="Custom double tap length" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Custom Shorts action buttons" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="GmsCore support" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide accessibility controls dialog" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide Shorts dimming" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide shortcuts" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Icon" android:summary="@string/revanced_icon_default" android:selectable="false"/>