mirror of
https://github.com/HighCapable/YukiHookAPI.git
synced 2025-09-06 10:45:47 +08:00
Fixed context-registered receivers
This commit is contained in:
@@ -208,11 +208,15 @@ class YukiHookDataChannel private constructor() {
|
|||||||
internal fun register(context: Context?, packageName: String = context?.packageName ?: "") {
|
internal fun register(context: Context?, packageName: String = context?.packageName ?: "") {
|
||||||
if (YukiHookAPI.Configs.isEnableDataChannel.not() || context == null) return
|
if (YukiHookAPI.Configs.isEnableDataChannel.not() || context == null) return
|
||||||
receiverContext = context
|
receiverContext = context
|
||||||
context.registerReceiver(
|
|
||||||
handlerReceiver, IntentFilter().apply {
|
val filter = IntentFilter().apply {
|
||||||
addAction(if (isXposedEnvironment) hostActionName(packageName) else moduleActionName(context))
|
addAction(if (isXposedEnvironment) hostActionName(packageName) else moduleActionName(context))
|
||||||
}
|
}
|
||||||
)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
context.registerReceiver(handlerReceiver, filter, Context.RECEIVER_EXPORTED)
|
||||||
|
|
||||||
|
} else context.registerReceiver(handlerReceiver, filter)
|
||||||
|
|
||||||
/** 排除模块环境下模块注册自身广播 */
|
/** 排除模块环境下模块注册自身广播 */
|
||||||
if (isXposedEnvironment.not()) return
|
if (isXposedEnvironment.not()) return
|
||||||
nameSpace(context, packageName).with {
|
nameSpace(context, packageName).with {
|
||||||
|
@@ -299,12 +299,16 @@ internal object AppParasitics {
|
|||||||
* @param result 回调 - ([Context] 当前实例, [Intent] 当前对象)
|
* @param result 回调 - ([Context] 当前实例, [Intent] 当前对象)
|
||||||
*/
|
*/
|
||||||
fun IntentFilter.registerReceiver(result: (Context, Intent) -> Unit) {
|
fun IntentFilter.registerReceiver(result: (Context, Intent) -> Unit) {
|
||||||
it.registerReceiver(object : BroadcastReceiver() {
|
val receiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context?, intent: Intent?) {
|
override fun onReceive(context: Context?, intent: Intent?) {
|
||||||
if (context == null || intent == null) return
|
if (context == null || intent == null) return
|
||||||
result(context, intent)
|
result(context, intent)
|
||||||
}
|
}
|
||||||
}, this)
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
it.registerReceiver(receiver, this, Context.RECEIVER_EXPORTED)
|
||||||
|
|
||||||
|
} else it.registerReceiver(receiver, this)
|
||||||
}
|
}
|
||||||
hostApplication = it
|
hostApplication = it
|
||||||
AppLifecycleCallback.onCreateCallback?.invoke(it)
|
AppLifecycleCallback.onCreateCallback?.invoke(it)
|
||||||
|
Reference in New Issue
Block a user