fix(ManifestPatcher): add vmSafeMode manifest attribute (#73)
On certain ROMs like GrapheneOS with agressive dexopt settings, the current method of deleting ART profiles upon startup does not work as dexopt runs right after app installation. This code cache would then be deletable only via ADB or root.
This commit is contained in:
parent
0271511e92
commit
6b3da4f07e
1 changed files with 15 additions and 4 deletions
|
|
@ -13,6 +13,7 @@ object ManifestPatcher {
|
|||
private const val ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android"
|
||||
private const val USES_CLEARTEXT_TRAFFIC = "usesCleartextTraffic"
|
||||
private const val DEBUGGABLE = "debuggable"
|
||||
private const val VM_SAFE_MODE = "vmSafeMode"
|
||||
private const val REQUEST_LEGACY_EXTERNAL_STORAGE = "requestLegacyExternalStorage"
|
||||
private const val NETWORK_SECURITY_CONFIG = "networkSecurityConfig"
|
||||
private const val LABEL = "label"
|
||||
|
|
@ -30,6 +31,13 @@ object ManifestPatcher {
|
|||
val writer = AxmlWriter()
|
||||
|
||||
reader.accept(object : AxmlVisitor(writer) {
|
||||
// Without this, decompiling the finished manifest has the android namespace
|
||||
// under an autogenerated name like axml_00 or something.
|
||||
override fun ns(prefix: String?, uri: String?, ln: Int) {
|
||||
val realUri = uri ?: ANDROID_NAMESPACE
|
||||
super.ns(prefix, realUri, ln)
|
||||
}
|
||||
|
||||
override fun child(ns: String?, name: String?) =
|
||||
object : ReplaceAttrsVisitor(
|
||||
super.child(ns, name),
|
||||
|
|
@ -88,14 +96,16 @@ object ManifestPatcher {
|
|||
) {
|
||||
private var addDebuggable = debuggable
|
||||
private var addLegacyStorage = true
|
||||
private var useVmSafeMode = true
|
||||
private var addUseClearTextTraffic = true
|
||||
|
||||
override fun attr(ns: String?, name: String, resourceId: Int, type: Int, value: Any?) {
|
||||
if (name == NETWORK_SECURITY_CONFIG) return
|
||||
super.attr(ns, name, resourceId, type, value)
|
||||
if (name == REQUEST_LEGACY_EXTERNAL_STORAGE) addLegacyStorage = false
|
||||
if (name == VM_SAFE_MODE) useVmSafeMode = false
|
||||
if (name == DEBUGGABLE) addDebuggable = false
|
||||
if (name == USES_CLEARTEXT_TRAFFIC) addUseClearTextTraffic = false
|
||||
super.attr(ns, name, resourceId, type, value)
|
||||
}
|
||||
|
||||
override fun child(ns: String?, name: String): NodeVisitor {
|
||||
|
|
@ -124,9 +134,10 @@ object ManifestPatcher {
|
|||
}
|
||||
|
||||
override fun end() {
|
||||
if (addLegacyStorage) super.attr(ANDROID_NAMESPACE, REQUEST_LEGACY_EXTERNAL_STORAGE, -1, TYPE_INT_BOOLEAN, 1)
|
||||
if (addDebuggable) super.attr(ANDROID_NAMESPACE, DEBUGGABLE, -1, TYPE_INT_BOOLEAN, 1)
|
||||
if (addUseClearTextTraffic) super.attr(ANDROID_NAMESPACE, USES_CLEARTEXT_TRAFFIC, -1, TYPE_INT_BOOLEAN, 1)
|
||||
if (addLegacyStorage && Build.VERSION.SDK_INT >= 29) super.attr(ANDROID_NAMESPACE, REQUEST_LEGACY_EXTERNAL_STORAGE, android.R.attr.requestLegacyExternalStorage, TYPE_INT_BOOLEAN, 1)
|
||||
if (useVmSafeMode) super.attr(ANDROID_NAMESPACE, VM_SAFE_MODE, android.R.attr.vmSafeMode, TYPE_INT_BOOLEAN, 1)
|
||||
if (addDebuggable) super.attr(ANDROID_NAMESPACE, DEBUGGABLE, android.R.attr.debuggable, TYPE_INT_BOOLEAN, 1)
|
||||
if (addUseClearTextTraffic) super.attr(ANDROID_NAMESPACE, USES_CLEARTEXT_TRAFFIC, android.R.attr.usesCleartextTraffic, TYPE_INT_BOOLEAN, 1)
|
||||
super.end()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue