From e1162241808ee6db5fefaab6cbb71448dcceed97 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 9 Feb 2020 23:20:29 +0800 Subject: [PATCH] Move DeviceInfo --- .../mamoe/mirai}/utils/SystemDeviceInfo.kt | 10 +++---- .../net.mamoe.mirai/utils/BotConfiguration.kt | 4 +++ .../net.mamoe.mirai}/utils/DeviceInfo.kt | 23 ++++++++-------- .../utils/SystemDeviceInfo.kt | 10 ++++--- .../mamoe/mirai}/utils/SystemDeviceInfo.kt | 27 ++++++++----------- 5 files changed, 38 insertions(+), 36 deletions(-) rename {mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid => mirai-core/src/androidMain/kotlin/net/mamoe/mirai}/utils/SystemDeviceInfo.kt (94%) rename {mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid => mirai-core/src/commonMain/kotlin/net.mamoe.mirai}/utils/DeviceInfo.kt (69%) rename {mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid => mirai-core/src/commonMain/kotlin/net.mamoe.mirai}/utils/SystemDeviceInfo.kt (60%) rename {mirai-core-qqandroid/src/jvmMain/kotlin/net/mamoe/mirai/qqandroid => mirai-core/src/jvmMain/kotlin/net/mamoe/mirai}/utils/SystemDeviceInfo.kt (65%) diff --git a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/SystemDeviceInfo.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt similarity index 94% rename from mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/SystemDeviceInfo.kt rename to mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt index 355dc9f26..b20ffbca2 100644 --- a/mirai-core-qqandroid/src/androidMain/kotlin/net/mamoe/mirai/qqandroid/utils/SystemDeviceInfo.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt @@ -7,22 +7,20 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -package net.mamoe.mirai.qqandroid.utils +package net.mamoe.mirai.utils import android.annotation.SuppressLint import android.net.wifi.WifiManager import android.os.Build import android.telephony.TelephonyManager import kotlinx.io.core.toByteArray -import net.mamoe.mirai.utils.Context -import net.mamoe.mirai.utils.localIpAddress -import net.mamoe.mirai.utils.md5 import java.io.File /** - * Delegated by [Build] + * 部分引用指向 [Build]. + * 部分需要权限, 若无权限则会使用默认值. */ -actual class SystemDeviceInfo actual constructor(context: Context) : DeviceInfo(context) { +actual open class SystemDeviceInfo actual constructor(context: Context) : DeviceInfo(context) { override val display: ByteArray get() = Build.DISPLAY.toByteArray() override val product: ByteArray get() = Build.PRODUCT.toByteArray() override val device: ByteArray get() = Build.DEVICE.toByteArray() diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt index df4024aff..cac2396d4 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/BotConfiguration.kt @@ -39,6 +39,10 @@ class BotConfiguration { * 日志记录器 */ var logger: MiraiLogger? = null + /** + * 设备信息覆盖 + */ + var deviceInfo: ((Context) -> DeviceInfo)? = null /** * 父 [CoroutineContext] diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt similarity index 69% rename from mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt rename to mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt index d584a32c0..89e76eabe 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/DeviceInfo.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt @@ -7,17 +7,17 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -package net.mamoe.mirai.qqandroid.utils +package net.mamoe.mirai.utils import kotlinx.serialization.SerialId import kotlinx.serialization.Serializable -import net.mamoe.mirai.qqandroid.io.serialization.ProtoBufWithNullableSupport -import net.mamoe.mirai.utils.Context +import kotlinx.serialization.protobuf.ProtoBuf import net.mamoe.mirai.utils.cryptor.contentToString -import net.mamoe.mirai.utils.getValue -import net.mamoe.mirai.utils.unsafeWeakRef -abstract class DeviceInfo( +/** + * 设备信息. 可通过继承 [SystemDeviceInfo] 来在默认的基础上修改 + */ +abstract class DeviceInfo internal constructor( context: Context ) { val context: Context by context.unsafeWeakRef() @@ -72,7 +72,7 @@ abstract class DeviceInfo( @SerialId(9) val innerVersion: ByteArray ) - return ProtoBufWithNullableSupport.dump( + return ProtoBuf.dump( DevInfo.serializer(), DevInfo( bootloader, procVersion, @@ -87,10 +87,6 @@ abstract class DeviceInfo( ) } - override fun toString(): String { // net.mamoe.mirai.utils.cryptor.ProtoKt.contentToString - return "DeviceInfo(display=${display.contentToString()}, product=${product.contentToString()}, device=${device.contentToString()}, board=${board.contentToString()}, brand=${brand.contentToString()}, model=${model.contentToString()}, bootloader=${bootloader.contentToString()}, fingerprint=${fingerprint.contentToString()}, bootId=${bootId.contentToString()}, procVersion=${procVersion.contentToString()}, baseBand=${baseBand.contentToString()}, version=$version, simInfo=${simInfo.contentToString()}, osType=${osType.contentToString()}, macAddress=${macAddress.contentToString()}, wifiBSSID=${wifiBSSID?.contentToString()}, wifiSSID=${wifiSSID?.contentToString()}, imsiMd5=${imsiMd5.contentToString()}, imei='$imei', ipAddress='$ipAddress', androidId=${androidId.contentToString()}, apn=${apn.contentToString()})" - } - interface Version { val incremental: ByteArray val release: ByteArray @@ -99,6 +95,11 @@ abstract class DeviceInfo( } } +/** + * Defaults "%4;7t>;28