feat(YouTube - Swipe controls): Change the setting name Enable watch panel gestures to Disable watch panel gestures, and change the setting name Enable swipe to change video to Disable swipe to change video

This commit is contained in:
inotia00 2024-12-21 13:38:12 +09:00
parent cd19073dd4
commit 1c06f2eee4
8 changed files with 101 additions and 37 deletions

View File

@ -20,15 +20,15 @@ public class SwipeControlsPatch {
/** /**
* Injection point. * Injection point.
*/ */
public static boolean enableSwipeToSwitchVideo() { public static boolean disableSwipeToSwitchVideo() {
return Settings.ENABLE_SWIPE_TO_SWITCH_VIDEO.get(); return !Settings.DISABLE_SWIPE_TO_SWITCH_VIDEO.get();
} }
/** /**
* Injection point. * Injection point.
*/ */
public static boolean enableWatchPanelGestures() { public static boolean disableWatchPanelGestures() {
return Settings.ENABLE_WATCH_PANEL_GESTURES.get(); return !Settings.DISABLE_WATCH_PANEL_GESTURES.get();
} }
/** /**

View File

@ -514,8 +514,8 @@ public class Settings extends BaseSettings {
*/ */
@Deprecated // Patch is obsolete and no longer works with 19.09+ @Deprecated // Patch is obsolete and no longer works with 19.09+
public static final BooleanSetting DISABLE_HDR_AUTO_BRIGHTNESS = new BooleanSetting("revanced_disable_hdr_auto_brightness", TRUE, true, parent(ENABLE_SWIPE_BRIGHTNESS)); public static final BooleanSetting DISABLE_HDR_AUTO_BRIGHTNESS = new BooleanSetting("revanced_disable_hdr_auto_brightness", TRUE, true, parent(ENABLE_SWIPE_BRIGHTNESS));
public static final BooleanSetting ENABLE_SWIPE_TO_SWITCH_VIDEO = new BooleanSetting("revanced_enable_swipe_to_switch_video", FALSE, true); public static final BooleanSetting DISABLE_SWIPE_TO_SWITCH_VIDEO = new BooleanSetting("revanced_disable_swipe_to_switch_video", FALSE, true);
public static final BooleanSetting ENABLE_WATCH_PANEL_GESTURES = new BooleanSetting("revanced_enable_watch_panel_gestures", FALSE, true); public static final BooleanSetting DISABLE_WATCH_PANEL_GESTURES = new BooleanSetting("revanced_disable_watch_panel_gestures", FALSE, true);
public static final BooleanSetting SWIPE_BRIGHTNESS_AUTO = new BooleanSetting("revanced_swipe_brightness_auto", TRUE, false, false); public static final BooleanSetting SWIPE_BRIGHTNESS_AUTO = new BooleanSetting("revanced_swipe_brightness_auto", TRUE, false, false);
public static final FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", -1.0f, false, false); public static final FloatSetting SWIPE_BRIGHTNESS_VALUE = new FloatSetting("revanced_swipe_brightness_value", -1.0f, false, false);

View File

@ -1,6 +1,7 @@
package app.revanced.patches.youtube.swipe.controls package app.revanced.patches.youtube.swipe.controls
import app.revanced.patches.youtube.utils.extension.Constants.EXTENSION_PATH import app.revanced.patches.youtube.utils.extension.Constants.EXTENSION_PATH
import app.revanced.patches.youtube.utils.resourceid.autoNavScrollCancelPadding
import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementOverlay import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementOverlay
import app.revanced.util.fingerprint.legacyFingerprint import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.or import app.revanced.util.or
@ -27,20 +28,29 @@ internal val swipeControlsHostActivityFingerprint = legacyFingerprint(
} }
) )
internal const val SWIPE_TO_SWITCH_VIDEO_FEATURE_FLAG = 45631116L
/** /**
* This fingerprint is compatible with YouTube v19.19.39+ * This fingerprint is compatible with YouTube v19.19.39+
*/ */
internal val swipeToSwitchVideoFingerprint = legacyFingerprint( internal val swipeToSwitchVideoFingerprint = legacyFingerprint(
name = "swipeToSwitchVideoFingerprint", name = "swipeToSwitchVideoFingerprint",
returnType = "V", returnType = "V",
literals = listOf(45631116L), literals = listOf(SWIPE_TO_SWITCH_VIDEO_FEATURE_FLAG),
) )
internal const val WATCH_PANEL_GESTURES_FEATURE_FLAG = 45372793L
/** /**
* This fingerprint is compatible with YouTube v18.29.38+ * This fingerprint is compatible with YouTube v18.29.38 ~ v19.34.42
*/ */
internal val watchPanelGesturesFingerprint = legacyFingerprint( internal val watchPanelGesturesFingerprint = legacyFingerprint(
name = "watchPanelGesturesFingerprint", name = "watchPanelGesturesFingerprint",
returnType = "V", returnType = "V",
literals = listOf(45372793L), literals = listOf(WATCH_PANEL_GESTURES_FEATURE_FLAG),
)
internal val watchPanelGesturesAlternativeFingerprint = legacyFingerprint(
name = "watchPanelGesturesAlternativeFingerprint",
literals = listOf(autoNavScrollCancelPadding),
) )

View File

@ -3,6 +3,8 @@ package app.revanced.patches.youtube.swipe.controls
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable
import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patcher.util.smali.ExternalLabel
@ -13,6 +15,11 @@ import app.revanced.patches.youtube.utils.lockmodestate.lockModeStateHookPatch
import app.revanced.patches.youtube.utils.mainactivity.mainActivityResolvePatch import app.revanced.patches.youtube.utils.mainactivity.mainActivityResolvePatch
import app.revanced.patches.youtube.utils.patch.PatchList.SWIPE_CONTROLS import app.revanced.patches.youtube.utils.patch.PatchList.SWIPE_CONTROLS
import app.revanced.patches.youtube.utils.playertype.playerTypeHookPatch import app.revanced.patches.youtube.utils.playertype.playerTypeHookPatch
import app.revanced.patches.youtube.utils.playservice.is_19_09_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_23_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_36_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.resourceid.autoNavScrollCancelPadding
import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementOverlay import app.revanced.patches.youtube.utils.resourceid.fullScreenEngagementOverlay
import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
@ -23,12 +30,18 @@ import app.revanced.util.copyResources
import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall import app.revanced.util.fingerprint.injectLiteralInstructionBooleanCall
import app.revanced.util.fingerprint.methodOrThrow import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.fingerprint.mutableClassOrThrow import app.revanced.util.fingerprint.mutableClassOrThrow
import app.revanced.util.fingerprint.resolvable import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.indexOfFirstLiteralInstruction
import app.revanced.util.indexOfFirstLiteralInstructionOrThrow import app.revanced.util.indexOfFirstLiteralInstructionOrThrow
import app.revanced.util.transformMethods import app.revanced.util.transformMethods
import app.revanced.util.traverseClassHierarchy import app.revanced.util.traverseClassHierarchy
import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
import com.android.tools.smali.dexlib2.immutable.ImmutableMethod import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
private const val EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR = private const val EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR =
@ -47,6 +60,7 @@ val swipeControlsPatch = bytecodePatch(
playerTypeHookPatch, playerTypeHookPatch,
sharedResourceIdPatch, sharedResourceIdPatch,
settingsPatch, settingsPatch,
versionCheckPatch,
) )
execute { execute {
@ -91,14 +105,15 @@ val swipeControlsPatch = bytecodePatch(
// endregion // endregion
var settingArray = arrayOf( var settingArray = arrayOf(
"PREFERENCE_SCREEN: SWIPE_CONTROLS" "PREFERENCE_SCREEN: SWIPE_CONTROLS",
"SETTINGS: DISABLE_WATCH_PANEL_GESTURES"
) )
// region patch for disable HDR auto brightness // region patch for disable HDR auto brightness
// Since it does not support all versions, // Since it does not support all versions,
// add settings only if the patch is successful. // add settings only if the patch is successful.
if (hdrBrightnessFingerprint.resolvable()) { if (!is_19_09_or_greater) {
hdrBrightnessFingerprint.methodOrThrow().apply { hdrBrightnessFingerprint.methodOrThrow().apply {
addInstructionsWithLabels( addInstructionsWithLabels(
0, """ 0, """
@ -114,33 +129,60 @@ val swipeControlsPatch = bytecodePatch(
// endregion // endregion
// region patch for enable swipe to switch video // region patch for disable swipe to switch video
// Since it does not support all versions, if (is_19_23_or_greater) {
// add settings only if the patch is successful.
if (swipeToSwitchVideoFingerprint.resolvable()) {
swipeToSwitchVideoFingerprint.injectLiteralInstructionBooleanCall( swipeToSwitchVideoFingerprint.injectLiteralInstructionBooleanCall(
45631116L, SWIPE_TO_SWITCH_VIDEO_FEATURE_FLAG,
"$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->enableSwipeToSwitchVideo()Z" "$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableSwipeToSwitchVideo()Z"
) )
settingArray += "SETTINGS: ENABLE_SWIPE_TO_SWITCH_VIDEO" settingArray += "SETTINGS: DISABLE_SWIPE_TO_SWITCH_VIDEO"
} }
// endregion // endregion
// region patch for enable watch panel gestures // region patch for disable watch panel gestures
// Since it does not support all versions, if (!is_19_36_or_greater) {
// add settings only if the patch is successful.
if (watchPanelGesturesFingerprint.resolvable()) {
watchPanelGesturesFingerprint.injectLiteralInstructionBooleanCall( watchPanelGesturesFingerprint.injectLiteralInstructionBooleanCall(
45372793L, WATCH_PANEL_GESTURES_FEATURE_FLAG,
"$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->enableWatchPanelGestures()Z" "$EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z"
) )
} else {
watchPanelGesturesAlternativeFingerprint.methodOrThrow().apply {
val literalIndex = indexOfFirstLiteralInstruction(autoNavScrollCancelPadding)
val middleIndex = indexOfFirstInstructionOrThrow(literalIndex) {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "V" &&
reference.parameterTypes.size == 0
}
val targetIndex = indexOfFirstInstructionOrThrow(middleIndex + 1) {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "V" &&
reference.parameterTypes.size == 0
}
if (getInstruction(targetIndex - 1).opcode != Opcode.IGET_OBJECT) {
throw PatchException("Previous Opcode pattern does not match: ${getInstruction(targetIndex - 1).opcode}")
}
if (getInstruction(targetIndex + 1).opcode != Opcode.IF_EQZ) {
throw PatchException("Next Opcode pattern does not match: ${getInstruction(targetIndex + 1).opcode}")
}
val fieldReference = getInstruction<ReferenceInstruction>(targetIndex - 1).reference
val fieldInstruction = getInstruction<TwoRegisterInstruction>(targetIndex - 1)
settingArray += "SETTINGS: ENABLE_WATCH_PANEL_GESTURES" addInstructionsWithLabels(
targetIndex, """
invoke-static {}, $EXTENSION_SWIPE_CONTROLS_PATCH_CLASS_DESCRIPTOR->disableWatchPanelGestures()Z
move-result v${fieldInstruction.registerA}
if-eqz v${fieldInstruction.registerA}, :disable
iget-object v${fieldInstruction.registerA}, v${fieldInstruction.registerB}, $fieldReference
""", ExternalLabel("disable", getInstruction(targetIndex + 1))
)
removeInstruction(targetIndex - 1)
}
} }
// endregion // endregion

View File

@ -17,6 +17,10 @@ var is_18_49_or_greater = false
private set private set
var is_19_02_or_greater = false var is_19_02_or_greater = false
private set private set
var is_19_04_or_greater = false
private set
var is_19_09_or_greater = false
private set
var is_19_15_or_greater = false var is_19_15_or_greater = false
private set private set
var is_19_17_or_greater = false var is_19_17_or_greater = false
@ -68,6 +72,8 @@ val versionCheckPatch = resourcePatch(
is_18_42_or_greater = 234302000 <= playStoreServicesVersion is_18_42_or_greater = 234302000 <= playStoreServicesVersion
is_18_49_or_greater = 235000000 <= playStoreServicesVersion is_18_49_or_greater = 235000000 <= playStoreServicesVersion
is_19_02_or_greater = 240204000 < playStoreServicesVersion is_19_02_or_greater = 240204000 < playStoreServicesVersion
is_19_04_or_greater = 240502000 <= playStoreServicesVersion
is_19_09_or_greater = 241002000 <= playStoreServicesVersion
is_19_15_or_greater = 241602000 <= playStoreServicesVersion is_19_15_or_greater = 241602000 <= playStoreServicesVersion
is_19_17_or_greater = 241802000 <= playStoreServicesVersion is_19_17_or_greater = 241802000 <= playStoreServicesVersion
is_19_23_or_greater = 242402000 <= playStoreServicesVersion is_19_23_or_greater = 242402000 <= playStoreServicesVersion

View File

@ -28,6 +28,8 @@ var appRelatedEndScreenResults = -1L
private set private set
var autoNavPreviewStub = -1L var autoNavPreviewStub = -1L
private set private set
var autoNavScrollCancelPadding = -1L
private set
var autoNavToggle = -1L var autoNavToggle = -1L
private set private set
var backgroundCategory = -1L var backgroundCategory = -1L
@ -264,6 +266,10 @@ internal val sharedResourceIdPatch = resourcePatch(
ID, ID,
"autonav_preview_stub" "autonav_preview_stub"
] ]
autoNavScrollCancelPadding = resourceMappings[
DIMEN,
"autonav_scroll_cancel_padding"
]
autoNavToggle = resourceMappings[ autoNavToggle = resourceMappings[
ID, ID,
"autonav_toggle" "autonav_toggle"

View File

@ -1478,12 +1478,12 @@ Limitations:
<string name="revanced_disable_hdr_auto_brightness_title">Disable auto HDR brightness</string> <string name="revanced_disable_hdr_auto_brightness_title">Disable auto HDR brightness</string>
<string name="revanced_disable_hdr_auto_brightness_summary_on">Auto HDR brightness is disabled.</string> <string name="revanced_disable_hdr_auto_brightness_summary_on">Auto HDR brightness is disabled.</string>
<string name="revanced_disable_hdr_auto_brightness_summary_off">Auto HDR brightness is enabled.</string> <string name="revanced_disable_hdr_auto_brightness_summary_off">Auto HDR brightness is enabled.</string>
<string name="revanced_enable_watch_panel_gestures_title">Enable watch panel gestures</string> <string name="revanced_disable_watch_panel_gestures_title">Disable watch panel gestures</string>
<string name="revanced_enable_watch_panel_gestures_summary_on">Entering fullscreen when swiping down below the video player is enabled.</string> <string name="revanced_disable_watch_panel_gestures_summary_on">Entering fullscreen when swiping down below the video player is disabled.</string>
<string name="revanced_enable_watch_panel_gestures_summary_off">Entering fullscreen when swiping down below the video player is disabled.</string> <string name="revanced_disable_watch_panel_gestures_summary_off">Entering fullscreen when swiping down below the video player is enabled.</string>
<string name="revanced_enable_swipe_to_switch_video_title">Enable swipe to change video</string> <string name="revanced_disable_swipe_to_switch_video_title">Disable swipe to change video</string>
<string name="revanced_enable_swipe_to_switch_video_summary_on">Swiping up / down will play the next / previous video.</string> <string name="revanced_disable_swipe_to_switch_video_summary_on">Swiping up / down will not play the next / previous video.</string>
<string name="revanced_enable_swipe_to_switch_video_summary_off">Swiping up / down will not play the next / previous video.</string> <string name="revanced_disable_swipe_to_switch_video_summary_off">Swiping up / down will play the next / previous video.</string>
<string name="revanced_swipe_lowest_value_auto_brightness_overlay_text">Auto</string> <string name="revanced_swipe_lowest_value_auto_brightness_overlay_text">Auto</string>

View File

@ -667,11 +667,11 @@
<!-- SETTINGS: DISABLE_HDR_BRIGHTNESS <!-- SETTINGS: DISABLE_HDR_BRIGHTNESS
<SwitchPreference android:title="@string/revanced_disable_hdr_auto_brightness_title" android:key="revanced_disable_hdr_auto_brightness" android:summaryOn="@string/revanced_disable_hdr_auto_brightness_summary_on" android:summaryOff="@string/revanced_disable_hdr_auto_brightness_summary_off" />SETTINGS: DISABLE_HDR_BRIGHTNESS --> <SwitchPreference android:title="@string/revanced_disable_hdr_auto_brightness_title" android:key="revanced_disable_hdr_auto_brightness" android:summaryOn="@string/revanced_disable_hdr_auto_brightness_summary_on" android:summaryOff="@string/revanced_disable_hdr_auto_brightness_summary_off" />SETTINGS: DISABLE_HDR_BRIGHTNESS -->
<!-- SETTINGS: ENABLE_SWIPE_TO_SWITCH_VIDEO <!-- SETTINGS: DISABLE_SWIPE_TO_SWITCH_VIDEO
<SwitchPreference android:title="@string/revanced_enable_swipe_to_switch_video_title" android:key="revanced_enable_swipe_to_switch_video" android:summaryOn="@string/revanced_enable_swipe_to_switch_video_summary_on" android:summaryOff="@string/revanced_enable_swipe_to_switch_video_summary_off" />SETTINGS: ENABLE_SWIPE_TO_SWITCH_VIDEO --> <SwitchPreference android:title="@string/revanced_disable_swipe_to_switch_video_title" android:key="revanced_disable_swipe_to_switch_video" android:summaryOn="@string/revanced_disable_swipe_to_switch_video_summary_on" android:summaryOff="@string/revanced_disable_swipe_to_switch_video_summary_off" />SETTINGS: DISABLE_SWIPE_TO_SWITCH_VIDEO -->
<!-- SETTINGS: ENABLE_WATCH_PANEL_GESTURES <!-- SETTINGS: DISABLE_WATCH_PANEL_GESTURES
<SwitchPreference android:title="@string/revanced_enable_watch_panel_gestures_title" android:key="revanced_enable_watch_panel_gestures" android:summaryOn="@string/revanced_enable_watch_panel_gestures_summary_on" android:summaryOff="@string/revanced_enable_watch_panel_gestures_summary_off" />SETTINGS: ENABLE_WATCH_PANEL_GESTURES --> <SwitchPreference android:title="@string/revanced_disable_watch_panel_gestures_title" android:key="revanced_disable_watch_panel_gestures" android:summaryOn="@string/revanced_disable_watch_panel_gestures_summary_on" android:summaryOff="@string/revanced_disable_watch_panel_gestures_summary_off" />SETTINGS: DISABLE_WATCH_PANEL_GESTURES -->
<!-- PREFERENCE_SCREEN: SWIPE_CONTROLS <!-- PREFERENCE_SCREEN: SWIPE_CONTROLS
</PreferenceScreen>PREFERENCE_SCREEN: SWIPE_CONTROLS --> </PreferenceScreen>PREFERENCE_SCREEN: SWIPE_CONTROLS -->