Commit 4fd579a7 authored by Him188's avatar Him188

Add default values

parent 42828cbe
package net.mamoe.mirai.qqandroid.utils package net.mamoe.mirai.qqandroid.utils
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.net.wifi.WifiManager
import android.os.Build import android.os.Build
import android.telephony.TelephonyManager import android.telephony.TelephonyManager
import kotlinx.io.core.toByteArray import kotlinx.io.core.toByteArray
...@@ -33,16 +34,15 @@ actual class SystemDeviceInfo actual constructor(context: Context) : DeviceInfo( ...@@ -33,16 +34,15 @@ actual class SystemDeviceInfo actual constructor(context: Context) : DeviceInfo(
override val fingerprint: ByteArray get() = Build.FINGERPRINT.toByteArray() override val fingerprint: ByteArray get() = Build.FINGERPRINT.toByteArray()
override val procVersion: ByteArray override val procVersion: ByteArray
get() = File("/proc/version").useLines { it.firstOrNull() ?: "" }.toByteArray() get() = kotlin.runCatching { File("/proc/version").useLines { it.firstOrNull() ?: "" }.toByteArray() }.getOrElse { byteArrayOf() }
override val bootId: ByteArray override val bootId: ByteArray
get() = File("/proc/sys/kernel/random/boot_id").useLines { it.firstOrNull() ?: "" }.toByteArray() get() = File("/proc/sys/kernel/random/boot_id").useLines { it.firstOrNull() ?: "" }.toByteArray()
override val version: DeviceInfo.Version get() = Version override val version: DeviceInfo.Version get() = Version
override val simInfo: ByteArray override val simInfo: ByteArray
@SuppressLint("WrongConstant")
get() { get() {
return kotlin.runCatching { return kotlin.runCatching {
val telephonyManager = context.getSystemService("phone") as TelephonyManager val telephonyManager = context.applicationContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
if (telephonyManager.simState == 5) { if (telephonyManager.simState == 5) {
telephonyManager.simOperatorName.toByteArray() telephonyManager.simOperatorName.toByteArray()
} else byteArrayOf() } else byteArrayOf()
...@@ -52,26 +52,21 @@ actual class SystemDeviceInfo actual constructor(context: Context) : DeviceInfo( ...@@ -52,26 +52,21 @@ actual class SystemDeviceInfo actual constructor(context: Context) : DeviceInfo(
override val osType: ByteArray = "android".toByteArray() override val osType: ByteArray = "android".toByteArray()
override val macAddress: ByteArray get() = "02:00:00:00:00:00".toByteArray() override val macAddress: ByteArray get() = "02:00:00:00:00:00".toByteArray()
override val wifiBSSID: ByteArray? override val wifiBSSID: ByteArray?
get() = TODO("not implemented") get() = kotlin.runCatching {
(context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager).connectionInfo.bssid.toByteArray()
}.getOrElse { byteArrayOf() }
override val wifiSSID: ByteArray? override val wifiSSID: ByteArray?
get() = TODO("not implemented") get() = kotlin.runCatching {
override val imsiMd5: ByteArray // null due to permission READ_PHONE_STATE required (context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager).connectionInfo.ssid.toByteArray()
get() = md5(byteArrayOf())/*{ }.getOrElse { byteArrayOf() }
val telephonyManager = context.getSystemService("phone") as TelephonyManager
if (telephonyManager != null) { override val imsiMd5: ByteArray
val subscriberId = telephonyManager.subscriberId @SuppressLint("HardwareIds")
if (subscriberId != null) { get() = md5(kotlin.runCatching {
return subscriberId.toByteArray() (context.applicationContext.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager).subscriberId.toByteArray()
} }.getOrElse { byteArrayOf() })
} override val ipAddress: String get() = localIpAddress()
return kotlin.runCatching {
val telephonyManager = context.getSystemService("phone") as TelephonyManager
if (telephonyManager != null) {
telephonyManager.subscriberId.toByteArray()
} else byteArrayOf()
}.getOrElse { byteArrayOf() }
}*/
override val ipAddress: ByteArray get() = localIpAddress().toByteArray()
override val androidId: ByteArray get() = Build.ID.toByteArray() override val androidId: ByteArray get() = Build.ID.toByteArray()
override val apn: ByteArray get() = "wifi".toByteArray() override val apn: ByteArray get() = "wifi".toByteArray()
......
package net.mamoe.mirai.qqandroid.utils
/**
* 连接类型
*/
inline class NetworkType(val value: Int) {
companion object {
/**
* 移动网络
*/
val MOBILE = NetworkType(1)
/**
* Wifi
*/
val WIFI = NetworkType(2)
/**
* 其他任何类型
*/
val OTHER = NetworkType(0)
}
}
\ No newline at end of file
...@@ -28,7 +28,9 @@ actual val Http: HttpClient ...@@ -28,7 +28,9 @@ actual val Http: HttpClient
/** /**
* Localhost 解析 * Localhost 解析
*/ */
actual fun localIpAddress(): String = InetAddress.getLocalHost().hostAddress actual fun localIpAddress(): String = runCatching {
InetAddress.getLocalHost().hostAddress
}.getOrElse { "192.168.1.123" }
/** /**
* MD5 算法 * MD5 算法
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment