Revert "putIfAbsent" method in YukiMemberHookCreater、YukiResourcesHookCreater、PackageParam

This commit is contained in:
2022-05-26 02:15:23 +08:00
parent bc1ca9cdb0
commit 670a6b39ee
4 changed files with 3 additions and 23 deletions

View File

@@ -42,7 +42,6 @@ import com.highcapable.yukihookapi.hook.param.HookParam
import com.highcapable.yukihookapi.hook.param.PackageParam
import com.highcapable.yukihookapi.hook.param.type.HookEntryType
import com.highcapable.yukihookapi.hook.param.wrapper.HookParamWrapper
import com.highcapable.yukihookapi.hook.utils.putIfAbsentCompat
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge
import java.lang.reflect.Field
import java.lang.reflect.Member
@@ -100,8 +99,7 @@ class YukiMemberHookCreater(@PublishedApi internal val packageParam: PackagePara
* @return [MemberHookCreater.Result]
*/
inline fun injectMember(priority: Int = PRIORITY_DEFAULT, tag: String = "Default", initiate: MemberHookCreater.() -> Unit) =
MemberHookCreater(priority, tag, packageParam.exhibitName)
.apply(initiate).apply { preHookMembers.putIfAbsentCompat(toString(), this) }.build()
MemberHookCreater(priority, tag, packageParam.exhibitName).apply(initiate).apply { preHookMembers[toString()] = this }.build()
/**
* Hook 执行入口

View File

@@ -36,7 +36,6 @@ import com.highcapable.yukihookapi.hook.log.yLoggerE
import com.highcapable.yukihookapi.hook.log.yLoggerI
import com.highcapable.yukihookapi.hook.param.PackageParam
import com.highcapable.yukihookapi.hook.param.type.HookEntryType
import com.highcapable.yukihookapi.hook.utils.putIfAbsentCompat
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge
import com.highcapable.yukihookapi.hook.xposed.bridge.dummy.YukiResources
@@ -59,7 +58,7 @@ class YukiResourcesHookCreater(private val packageParam: PackageParam, @Publishe
* @return [ResourcesHookCreater.Result]
*/
inline fun injectResource(tag: String = "Default", initiate: ResourcesHookCreater.() -> Unit) =
ResourcesHookCreater(tag).apply(initiate).apply { preHookResources.putIfAbsentCompat(toString(), this) }.build()
ResourcesHookCreater(tag).apply(initiate).apply { preHookResources[toString()] = this }.build()
/**
* Hook 执行入口

View File

@@ -47,7 +47,6 @@ import com.highcapable.yukihookapi.hook.factory.hasClass
import com.highcapable.yukihookapi.hook.factory.hookClass
import com.highcapable.yukihookapi.hook.param.type.HookEntryType
import com.highcapable.yukihookapi.hook.param.wrapper.PackageParamWrapper
import com.highcapable.yukihookapi.hook.utils.putIfAbsentCompat
import com.highcapable.yukihookapi.hook.utils.value
import com.highcapable.yukihookapi.hook.xposed.bridge.YukiHookBridge
import com.highcapable.yukihookapi.hook.xposed.bridge.dummy.YukiModuleResources
@@ -467,8 +466,7 @@ open class PackageParam internal constructor(@PublishedApi internal var wrapper:
* @param initiate 回调 - ([Context] 当前上下文,[Intent] 当前 Intent)
*/
fun registerReceiver(vararg action: String, initiate: (context: Context, intent: Intent) -> Unit) {
if (action.isNotEmpty())
YukiHookBridge.AppLifecycleCallback.onReceiversCallback.putIfAbsentCompat(action.value(), Pair(action, initiate))
if (action.isNotEmpty()) YukiHookBridge.AppLifecycleCallback.onReceiversCallback[action.value()] = Pair(action, initiate)
}
/** 设置创建生命周期监听回调 */

View File

@@ -27,7 +27,6 @@
*/
package com.highcapable.yukihookapi.hook.utils
import android.os.Build
import com.highcapable.yukihookapi.annotation.YukiPrivateApi
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
@@ -60,20 +59,6 @@ inline fun <reified T> Array<out T>.value() = if (isNotEmpty()) {
"[${value.trim().let { it.substring(0, it.lastIndex) }}]"
} else "[]"
/**
* 不重复写入 [HashMap]
*
* 兼容旧版本 Android
* @param key Key
* @param value Value
*/
@YukiPrivateApi
inline fun <reified K, V> HashMap<K, V>.putIfAbsentCompat(key: K, value: V) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
putIfAbsent(key, value)
else get(key) ?: put(key, value)
}
/**
* 计算方法执行耗时
* @param block 方法块