experimental clear display patch

This commit is contained in:
lbux 2026-03-01 15:24:11 -08:00
parent 6c2b836aa8
commit 84a73e730f
3 changed files with 94 additions and 31 deletions

View file

@ -4,10 +4,22 @@ import app.revanced.extension.tiktok.settings.Settings;
@SuppressWarnings("unused")
public class RememberClearDisplayPatch {
private static Boolean cachedState = null;
public static boolean getClearDisplayState() {
return Settings.CLEAR_DISPLAY.get();
if (cachedState == null) {
cachedState = Settings.CLEAR_DISPLAY.get();
}
return cachedState;
}
public static void rememberClearDisplayState(boolean newState) {
if (cachedState != null && cachedState == newState) {
return;
}
cachedState = newState;
Settings.CLEAR_DISPLAY.save(newState);
}
}
}

View file

@ -1,6 +1,7 @@
package app.revanced.patches.tiktok.interaction.cleardisplay
import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.AccessFlags
internal val onClearDisplayEventFingerprint = fingerprint {
custom { method, classDef ->
@ -8,3 +9,47 @@ internal val onClearDisplayEventFingerprint = fingerprint {
classDef.endsWith("/ClearModePanelComponent;") && method.name == "onClearModeEvent"
}
}
internal val clearModeLogCoreFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC, AccessFlags.FINAL)
returns("V")
parameters(
"Z",
"Ljava/lang/String;",
"Ljava/lang/String;",
"Lcom/ss/android/ugc/aweme/feed/model/Aweme;",
"Ljava/lang/String;",
"J",
"I"
)
}
internal val clearModeLogStateFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC, AccessFlags.FINAL)
returns("V")
parameters(
"Lcom/bytedance/common/utility/collection/WeakHandler;",
"Z",
"Ljava/lang/String;",
"Lcom/ss/android/ugc/aweme/feed/model/Aweme;",
"J"
"I",
"I"
)
}
internal val clearModeLogPlaytimeFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("V")
parameters(
"F",
"I",
"J",
"J",
"Lcom/ss/android/ugc/aweme/feed/model/Aweme;",
"Ljava/lang/String;",
"Ljava/lang/String;",
"Z",
"Z"
)
}

View file

@ -1,12 +1,11 @@
package app.revanced.patches.tiktok.interaction.cleardisplay
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.patch.bytecodePatch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.tiktok.shared.onRenderFirstFrameFingerprint
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.returnEarly
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
@ -21,9 +20,14 @@ val rememberClearDisplayPatch = bytecodePatch(
)
execute {
onClearDisplayEventFingerprint.method.let {
// region Hook the "Clear display" configuration save event to remember the state of clear display.
// kill loggers to prevent db from being constantly logged to
// might resolve crashing issue with this patch
clearModeLogCoreFingerprint.method.returnEarly()
clearModeLogStateFingerprint.method.returnEarly()
clearModeLogPlaytimeFingerprint.method.returnEarly()
onClearDisplayEventFingerprint.method.let {
// Hook the "Clear display" configuration save event to remember the state of clear display.
val isEnabledIndex = it.indexOfFirstInstructionOrThrow(Opcode.IGET_BOOLEAN) + 1
val isEnabledRegister = it.getInstruction<TwoRegisterInstruction>(isEnabledIndex - 1).registerA
@ -33,38 +37,40 @@ val rememberClearDisplayPatch = bytecodePatch(
"Lapp/revanced/extension/tiktok/cleardisplay/RememberClearDisplayPatch;->rememberClearDisplayState(Z)V",
)
// endregion
// region Override the "Clear display" configuration load event to load the state of clear display.
val clearDisplayEventClass = it.parameters[0].type
onRenderFirstFrameFingerprint.method.addInstructionsWithLabels(
onRenderFirstFrameFingerprint.method.addInstructions(
0,
"""
# Create a new clearDisplayEvent and post it to the EventBus (https://github.com/greenrobot/EventBus)
# Clear display type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc.
const/4 v1, 0x0
# Enter method (Such as "pinch", "swipe_exit", or an empty string (unknown, what it means)).
const-string v2, ""
# Name of the clear display type which is equivalent to the clear display type.
const-string v3, "long_press"
# The state of clear display.
# Get the saved state
invoke-static { }, Lapp/revanced/extension/tiktok/cleardisplay/RememberClearDisplayPatch;->getClearDisplayState()Z
move-result v4
if-eqz v4, :clear_display_disabled
move-result v1
# If false, jump past the event post
if-eqz v1, :clear_display_disabled
# Set up the other parameters
# Clear display type: 0 = LONG_PRESS
const/4 v2, 0x0
# Enter method
const-string v3, ""
# Name of the clear display type
const-string v4, "long_press"
# Create the event
new-instance v0, $clearDisplayEventClass
invoke-direct { v0, v1, v2, v3, v4 }, $clearDisplayEventClass-><init>(ILjava/lang/String;Ljava/lang/String;Z)V
# Call the constructor in order
invoke-direct { v0, v1, v2, v3, v4 }, $clearDisplayEventClass-><init>(ZILjava/lang/String;Ljava/lang/String;)V
# Post it to the EventBus
invoke-virtual { v0 }, $clearDisplayEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent;
""",
ExternalLabel("clear_display_disabled", onRenderFirstFrameFingerprint.method.getInstruction(0)),
)
// endregion
:clear_display_disabled
nop
"""
)
}
}
}
}