fix(Reddit - Remove subreddit dialog): Navigation bar is not visible when Remove notification suggestion dialog setting is turned on (Reddit 2025.02+)

This commit is contained in:
inotia00
2025-01-22 12:52:50 +09:00
parent 2edd9cb2cd
commit e85a343c02
4 changed files with 73 additions and 63 deletions

View File

@ -3,11 +3,11 @@ package app.revanced.patches.reddit.layout.subredditdialog
import app.revanced.util.fingerprint.legacyFingerprint
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import app.revanced.util.indexOfFirstInstructionReversed
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.Method
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
internal val frequentUpdatesSheetScreenFingerprint = legacyFingerprint(
@ -26,38 +26,49 @@ internal val frequentUpdatesSheetScreenFingerprint = legacyFingerprint(
}
)
internal val frequentUpdatesSheetV2ScreenFingerprint = legacyFingerprint(
name = "frequentUpdatesSheetV2ScreenFingerprint",
returnType = "V",
internal val frequentUpdatesHandlerFingerprint = legacyFingerprint(
name = "frequentUpdatesHandlerFingerprint",
returnType = "Ljava/lang/Object;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
strings = listOf("subreddit_name"),
customFingerprint = { method, classDef ->
classDef.type == "Lcom/reddit/screens/pager/v2/FrequentUpdatesSheetV2Screen;"
classDef.type.startsWith("Lcom/reddit/screens/pager/FrequentUpdatesHandler${'$'}handleFrequentUpdates${'$'}") &&
method.name == "invokeSuspend" &&
listOfIsLoggedInInstruction(method).isNotEmpty()
}
)
internal val frequentUpdatesSheetV2ScreenInvokeFingerprint = legacyFingerprint(
name = "frequentUpdatesSheetV2ScreenInvokeFingerprint",
returnType = "V",
fun listOfIsLoggedInInstruction(method: Method) =
method.implementation?.instructions
?.withIndex()
?.filter { (_, instruction) ->
val reference = (instruction as? ReferenceInstruction)?.reference
instruction.opcode == Opcode.INVOKE_INTERFACE &&
reference is MethodReference &&
reference.name == "isLoggedIn" &&
reference.returnType == "Z"
}
?.map { (index, _) -> index }
?.reversed()
?: emptyList()
internal val nsfwAlertEmitFingerprint = legacyFingerprint(
name = "nsfwAlertEmitFingerprint",
returnType = "Ljava/lang/Object;",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.IGET_OBJECT,
Opcode.INVOKE_VIRTUAL,
Opcode.RETURN_VOID,
),
customFingerprint = { method, classDef ->
classDef.type.startsWith("Lcom/reddit/screens/pager/v2/FrequentUpdatesSheetV2Screen${'$'}SheetContent${'$'}") &&
method.name == "invoke" &&
indexOfDismissScreenInstruction(method) >= 0
strings = listOf("reddit://reddit/r/", "nsfwAlertDelegate"),
customFingerprint = { method, _ ->
method.name == "emit" &&
indexOfHasBeenVisitedInstruction(method) >= 0
}
)
fun indexOfDismissScreenInstruction(method: Method) =
method.indexOfFirstInstructionReversed {
fun indexOfHasBeenVisitedInstruction(method: Method) =
method.indexOfFirstInstruction {
val reference = getReference<MethodReference>()
opcode == Opcode.INVOKE_VIRTUAL &&
reference?.returnType == "V" &&
reference.parameterTypes.isEmpty()
reference?.name == "getHasBeenVisited" &&
reference.returnType == "Z"
}
internal val redditAlertDialogsFingerprint = legacyFingerprint(

View File

@ -8,10 +8,9 @@ import app.revanced.patches.reddit.utils.compatibility.Constants.COMPATIBLE_PACK
import app.revanced.patches.reddit.utils.extension.Constants.PATCHES_PATH
import app.revanced.patches.reddit.utils.patch.PatchList.REMOVE_SUBREDDIT_DIALOG
import app.revanced.patches.reddit.utils.settings.is_2024_41_or_greater
import app.revanced.patches.reddit.utils.settings.is_2025_01_or_greater
import app.revanced.patches.reddit.utils.settings.settingsPatch
import app.revanced.patches.reddit.utils.settings.updatePatchStatus
import app.revanced.util.addInstructionsAtControlFlowLabel
import app.revanced.util.findMethodOrThrow
import app.revanced.util.fingerprint.methodOrThrow
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
@ -19,7 +18,6 @@ import app.revanced.util.indexOfFirstInstructionReversedOrThrow
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction
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.reference.MethodReference
private const val EXTENSION_CLASS_DESCRIPTOR =
@ -36,6 +34,25 @@ val subRedditDialogPatch = bytecodePatch(
execute {
if (is_2024_41_or_greater) {
frequentUpdatesHandlerFingerprint
.methodOrThrow()
.apply {
listOfIsLoggedInInstruction(this)
.forEach { index ->
val register = getInstruction<OneRegisterInstruction>(index + 1).registerA
addInstructions(
index + 2, """
invoke-static {v$register}, $EXTENSION_CLASS_DESCRIPTOR->spoofLoggedInStatus(Z)Z
move-result v$register
"""
)
}
}
}
// Not used in latest Reddit client.
frequentUpdatesSheetScreenFingerprint.methodOrThrow().apply {
val index = indexOfFirstInstructionReversedOrThrow(Opcode.RETURN_OBJECT)
val register =
@ -43,39 +60,27 @@ val subRedditDialogPatch = bytecodePatch(
addInstruction(
index,
"invoke-static {v$register}, $EXTENSION_CLASS_DESCRIPTOR->onDialogCreated(Landroid/view/View;)V"
"invoke-static {v$register}, $EXTENSION_CLASS_DESCRIPTOR->dismissDialog(Landroid/view/View;)V"
)
}
if (is_2024_41_or_greater) {
val dismissReference = with (frequentUpdatesSheetV2ScreenInvokeFingerprint.methodOrThrow()) {
val index = indexOfDismissScreenInstruction(this)
getInstruction<ReferenceInstruction>(index).reference as MethodReference
if (is_2025_01_or_greater) {
nsfwAlertEmitFingerprint.methodOrThrow().apply {
val hasBeenVisitedIndex = indexOfHasBeenVisitedInstruction(this)
val hasBeenVisitedRegister =
getInstruction<OneRegisterInstruction>(hasBeenVisitedIndex + 1).registerA
addInstructions(
hasBeenVisitedIndex + 2, """
invoke-static {v$hasBeenVisitedRegister}, $EXTENSION_CLASS_DESCRIPTOR->spoofHasBeenVisitedStatus(Z)Z
move-result v$hasBeenVisitedRegister
"""
)
}
findMethodOrThrow(EXTENSION_CLASS_DESCRIPTOR) {
name == "dismissRedditDialogV2"
}.addInstructions(
0, """
check-cast p0, ${dismissReference.definingClass}
invoke-virtual {p0}, $dismissReference
"""
)
frequentUpdatesSheetV2ScreenFingerprint
.methodOrThrow()
.apply {
val targetIndex = indexOfFirstInstructionReversedOrThrow(Opcode.RETURN_VOID)
addInstructionsAtControlFlowLabel(
targetIndex,
"invoke-static {p0}, $EXTENSION_CLASS_DESCRIPTOR->dismissDialogV2(Ljava/lang/Object;)V"
)
}
}
// Not used in latest Reddit client.
redditAlertDialogsFingerprint.second.methodOrNull?.apply {
redditAlertDialogsFingerprint.methodOrThrow().apply {
val backgroundTintIndex = indexOfSetBackgroundTintListInstruction(this)
val insertIndex =
indexOfFirstInstructionOrThrow(backgroundTintIndex) {

View File

@ -37,6 +37,8 @@ var is_2024_26_or_greater = false
private set
var is_2024_41_or_greater = false
private set
var is_2025_01_or_greater = false
private set
private val settingsBytecodePatch = bytecodePatch(
description = "settingsBytecodePatch"
@ -59,6 +61,7 @@ private val settingsBytecodePatch = bytecodePatch(
is_2024_26_or_greater = 2024260 <= versionNumber
is_2024_41_or_greater = 2024410 <= versionNumber
is_2025_01_or_greater = 2025010 <= versionNumber
}
/**