From d1419824a9a2dc35df5bf8414bc5a807dd33f65b Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 10 Jan 2020 23:09:04 +0800 Subject: [PATCH] weakRef context --- .../net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt | 3 ++- .../kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt index 521cf5b85..ea9d053e8 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidClient.kt @@ -32,7 +32,7 @@ import net.mamoe.mirai.utils.unsafeWeakRef @PublishedApi internal open class QQAndroidClient( - val context: Context, + context: Context, @MiraiInternalAPI("Be careful. Do not use the id in BotAccount. use client.uin instead") val account: BotAccount, @@ -40,6 +40,7 @@ internal open class QQAndroidClient( val device: DeviceInfo = SystemDeviceInfo(context), bot: QQAndroidBot ) { + val context by context.unsafeWeakRef() val bot: QQAndroidBot by bot.unsafeWeakRef() val tgtgtKey: ByteArray = ByteArray(16) // generateTgtgtKey(device.guid) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt index a42a0747d..f34b559a3 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt @@ -3,10 +3,13 @@ package net.mamoe.mirai.qqandroid.utils import kotlinx.serialization.SerialId import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoBuf +import net.mamoe.mirai.utils.unsafeWeakRef abstract class DeviceInfo( - val context: Context + context: Context ) { + val context: Context by context.unsafeWeakRef() + abstract val display: ByteArray abstract val product: ByteArray abstract val device: ByteArray @@ -34,7 +37,6 @@ abstract class DeviceInfo( abstract val imsiMd5: ByteArray abstract val imei: String - abstract val ksid: String abstract val ipAddress: String