Refactor optimize code in YukiHookDataChannel, AppParasitics

This commit is contained in:
2023-08-29 20:03:23 +08:00
parent f02e512ad8
commit a88e88786e
2 changed files with 14 additions and 7 deletions

View File

@@ -73,10 +73,13 @@ object YukiHookAPI {
/** 标识是否从自定义 Hook API 装载 */
internal var isLoadedFromBaseContext = false
/** 获取当前 [YukiHookAPI] 的版本 */
// TODO
const val TAG = ""
/** 版本名称 */
const val API_VERSION_NAME = BuildConfig.API_VERSION_NAME
/** 获取当前 [YukiHookAPI] 的版本号 */
/** 版本号 */
const val API_VERSION_CODE = BuildConfig.API_VERSION_CODE
/**

View File

@@ -299,16 +299,20 @@ internal object AppParasitics {
* @param result 回调 - ([Context] 当前实例, [Intent] 当前对象)
*/
fun IntentFilter.registerReceiver(result: (Context, Intent) -> Unit) {
val receiver = object : BroadcastReceiver() {
object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (context == null || intent == null) return
result(context, intent)
}
}.also { receiver ->
/**
* 从 Android 14 (及预览版) 开始
* 外部广播必须声明 [Context.RECEIVER_EXPORTED]
*/
if (Build.VERSION.SDK_INT >= 33)
it.registerReceiver(receiver, this, Context.RECEIVER_EXPORTED)
else it.registerReceiver(receiver, this)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
it.registerReceiver(receiver, this, Context.RECEIVER_EXPORTED)
} else it.registerReceiver(receiver, this)
}
hostApplication = it
AppLifecycleCallback.onCreateCallback?.invoke(it)