Modify change the way of injectModuleAppResources

This commit is contained in:
2022-08-11 02:38:54 +08:00
parent f4166b61e2
commit b73187f714

View File

@@ -40,10 +40,7 @@ import android.content.res.Configuration
import android.content.res.Resources import android.content.res.Resources
import com.highcapable.yukihookapi.YukiHookAPI import com.highcapable.yukihookapi.YukiHookAPI
import com.highcapable.yukihookapi.annotation.YukiGenerateApi import com.highcapable.yukihookapi.annotation.YukiGenerateApi
import com.highcapable.yukihookapi.hook.factory.classOf import com.highcapable.yukihookapi.hook.factory.*
import com.highcapable.yukihookapi.hook.factory.field
import com.highcapable.yukihookapi.hook.factory.hasClass
import com.highcapable.yukihookapi.hook.factory.method
import com.highcapable.yukihookapi.hook.log.yLoggerE import com.highcapable.yukihookapi.hook.log.yLoggerE
import com.highcapable.yukihookapi.hook.log.yLoggerW import com.highcapable.yukihookapi.hook.log.yLoggerW
import com.highcapable.yukihookapi.hook.param.PackageParam import com.highcapable.yukihookapi.hook.param.PackageParam
@@ -341,16 +338,17 @@ object YukiHookBridge {
*/ */
internal fun injectModuleAppResources(hostResources: Resources) { internal fun injectModuleAppResources(hostResources: Resources) {
if (injectedHostResourcesHashCodes.contains(hostResources.hashCode())) return if (injectedHostResourcesHashCodes.contains(hostResources.hashCode())) return
injectedHostResourcesHashCodes.add(hostResources.hashCode()) if (hasXposedBridge) runCatching {
if (hasXposedBridge) hostResources.assets.current {
AssetManagerClass.method { method {
name = "addAssetPath" name = "addAssetPath"
param(StringType) param(StringType)
}.ignored().onNoSuchMethod { }.call(moduleAppFilePath)
runCatching { injectedHostResourcesHashCodes.remove(hostResources.hashCode()) } }
yLoggerE(msg = "Failed to inject module resources into [$hostResources]", e = it) injectedHostResourcesHashCodes.add(hostResources.hashCode())
}.get(hostResources.assets).call(moduleAppFilePath) }.onFailure {
else yLoggerW(msg = "You can only inject module resources in Xposed Environment") yLoggerE(msg = "Failed to inject module resources into [$hostResources]", e = it)
} else yLoggerW(msg = "You can only inject module resources in Xposed Environment")
} }
/** 刷新当前 Xposed 模块自身 [Resources] */ /** 刷新当前 Xposed 模块自身 [Resources] */