mirror of
https://github.com/BetterAndroid/Hikage.git
synced 2025-09-05 10:15:37 +08:00
fix: create XmlBlock on android 16
This commit is contained in:
@@ -120,7 +120,7 @@ internal object XmlBlockBypass {
|
|||||||
// Context may be loaded from the preview and other non-Android platforms, ignoring this.
|
// Context may be loaded from the preview and other non-Android platforms, ignoring this.
|
||||||
if (context.javaClass.name.endsWith("BridgeContext")) return
|
if (context.javaClass.name.endsWith("BridgeContext")) return
|
||||||
init(context.applicationContext.applicationInfo)
|
init(context.applicationContext.applicationInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize.
|
* Initialize.
|
||||||
@@ -148,9 +148,18 @@ internal object XmlBlockBypass {
|
|||||||
).apply { isAccessible = true }.invoke(null, sourceDir, false, false, false)
|
).apply { isAccessible = true }.invoke(null, sourceDir, false, false, false)
|
||||||
else -> error("Unsupported Android version.")
|
else -> error("Unsupported Android version.")
|
||||||
} as? Long? ?: error("Failed to create ApkAssets.")
|
} as? Long? ?: error("Failed to create ApkAssets.")
|
||||||
blockParser = HiddenApiBypass.getDeclaredConstructor(XmlBlockClass, AssetManagerClass, LongType)
|
blockParser = when {
|
||||||
.apply { isAccessible = true }
|
SystemVersion.isHighOrEqualsTo(36) ->
|
||||||
.newInstance(null, xmlBlock) as? AutoCloseable? ?: error("Failed to create XmlBlock\$Parser.")
|
// XmlBlock(@Nullable AssetManager assets, long xmlBlock, boolean usesFeatureFlags)
|
||||||
|
HiddenApiBypass.getDeclaredConstructor(XmlBlockClass, AssetManagerClass, LongType, BooleanType)
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
.newInstance(null, xmlBlock, false)
|
||||||
|
else ->
|
||||||
|
// XmlBlock(@Nullable AssetManager assets, long xmlBlock)
|
||||||
|
HiddenApiBypass.getDeclaredConstructor(XmlBlockClass, AssetManagerClass, LongType)
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
.newInstance(null, xmlBlock)
|
||||||
|
} as? AutoCloseable? ?: error("Failed to create XmlBlock\$Parser.")
|
||||||
isInitOnce = true
|
isInitOnce = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +175,7 @@ internal object XmlBlockBypass {
|
|||||||
* @return [XmlResourceParser]
|
* @return [XmlResourceParser]
|
||||||
*/
|
*/
|
||||||
fun createViewAttrs() = context.layoutInflater.inflateOrNull<HikageAttrsView>(R.layout.layout_hikage_attrs_view)?.attrs
|
fun createViewAttrs() = context.layoutInflater.inflateOrNull<HikageAttrsView>(R.layout.layout_hikage_attrs_view)?.attrs
|
||||||
as? XmlResourceParser? ?: error("Failed to create AttributeSet.")
|
as? XmlResourceParser? ?: error("Failed to create AttributeSet.")
|
||||||
return if (SystemVersion.isHighOrEqualsTo(SystemVersion.P)) {
|
return if (SystemVersion.isHighOrEqualsTo(SystemVersion.P)) {
|
||||||
if (!isInitOnce) return createViewAttrs()
|
if (!isInitOnce) return createViewAttrs()
|
||||||
require(blockParser != null) { "Hikage initialization failed." }
|
require(blockParser != null) { "Hikage initialization failed." }
|
||||||
|
Reference in New Issue
Block a user