Skip to content

Commit dcf6178

Browse files
feat: Add Set target SDK version 34 patch (Disable edge-to-edge display) (#4780)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 065cc2a commit dcf6178

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

patches/api/patches.api

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public final class app/revanced/patches/all/misc/shortcut/sharetargets/RemoveSha
108108
public static final fun getRemoveShareTargetsPatch ()Lapp/revanced/patcher/patch/ResourcePatch;
109109
}
110110

111+
public final class app/revanced/patches/all/misc/targetSdk/SetTargetSdkVersion34Kt {
112+
public static final fun getSetTargetSdkVersion34 ()Lapp/revanced/patcher/patch/ResourcePatch;
113+
}
114+
111115
public abstract interface class app/revanced/patches/all/misc/transformation/IMethodCall {
112116
public abstract fun getDefinedClassName ()Ljava/lang/String;
113117
public abstract fun getMethodName ()Ljava/lang/String;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package app.revanced.patches.all.misc.targetSdk
2+
3+
import app.revanced.patcher.patch.resourcePatch
4+
import app.revanced.util.getNode
5+
import org.w3c.dom.Element
6+
import java.util.logging.Logger
7+
8+
@Suppress("unused")
9+
val setTargetSdkVersion34 = resourcePatch(
10+
name = "Set target SDK version 34",
11+
description = "Changes the target SDK to version 34 (Android 14). " +
12+
"For devices running Android 15+, this will disable edge-to-edge display.",
13+
use = false,
14+
) {
15+
execute {
16+
val targetSdkOverride = 34 // Android 14.
17+
18+
document("AndroidManifest.xml").use { document ->
19+
fun getLogger() = Logger.getLogger(this::class.java.name)
20+
21+
// Ideally, the override should only be applied if the existing target is higher.
22+
// But since ApkTool does not add targetSdkVersion to the decompiled AndroidManifest,
23+
// there is no way to check targetSdkVersion. Instead, check compileSdkVersion and print a warning.
24+
try {
25+
val manifestElement = document.getNode("manifest") as Element
26+
val compileSdkVersion = Integer.parseInt(
27+
manifestElement.getAttribute("android:compileSdkVersion")
28+
)
29+
if (compileSdkVersion <= targetSdkOverride) {
30+
getLogger().warning(
31+
"This app does not appear to use a target SDK above $targetSdkOverride: " +
32+
"(compileSdkVersion: $compileSdkVersion)"
33+
)
34+
}
35+
} catch (_: Exception) {
36+
getLogger().warning("Could not check compileSdkVersion")
37+
}
38+
39+
// Change targetSdkVersion to override value.
40+
document.getElementsByTagName("manifest").item(0).let {
41+
var element = it.ownerDocument.createElement("uses-sdk")
42+
element.setAttribute("android:targetSdkVersion", targetSdkOverride.toString())
43+
44+
it.appendChild(element)
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)