Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
9f7088d4
Commit
9f7088d4
authored
Apr 04, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid NPE from Android
parent
eb482a43
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
18 deletions
+21
-18
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt
.../kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt
+21
-18
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.android.kt
View file @
9f7088d4
...
@@ -57,13 +57,13 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
...
@@ -57,13 +57,13 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
@Transient
@Transient
final
override
lateinit
var
context
:
Context
final
override
lateinit
var
context
:
Context
override
val
display
:
ByteArray
get
()
=
Build
.
DISPLAY
.
toByteArray
()
override
val
display
:
ByteArray
get
()
=
Build
.
DISPLAY
.
orEmpty
().
toByteArray
()
override
val
product
:
ByteArray
get
()
=
Build
.
PRODUCT
.
toByteArray
()
override
val
product
:
ByteArray
get
()
=
Build
.
PRODUCT
.
orEmpty
().
toByteArray
()
override
val
device
:
ByteArray
get
()
=
Build
.
DEVICE
.
toByteArray
()
override
val
device
:
ByteArray
get
()
=
Build
.
DEVICE
.
orEmpty
().
toByteArray
()
override
val
board
:
ByteArray
get
()
=
Build
.
BOARD
.
toByteArray
()
override
val
board
:
ByteArray
get
()
=
Build
.
BOARD
.
orEmpty
().
toByteArray
()
override
val
brand
:
ByteArray
get
()
=
Build
.
BRAND
.
toByteArray
()
override
val
brand
:
ByteArray
get
()
=
Build
.
BRAND
.
orEmpty
().
toByteArray
()
override
val
model
:
ByteArray
get
()
=
Build
.
MODEL
.
toByteArray
()
override
val
model
:
ByteArray
get
()
=
Build
.
MODEL
.
orEmpty
().
toByteArray
()
override
val
bootloader
:
ByteArray
get
()
=
Build
.
BOOTLOADER
.
toByteArray
()
override
val
bootloader
:
ByteArray
get
()
=
Build
.
BOOTLOADER
.
orEmpty
().
toByteArray
()
override
val
baseBand
:
ByteArray
override
val
baseBand
:
ByteArray
@SuppressLint
(
"PrivateApi"
)
@SuppressLint
(
"PrivateApi"
)
...
@@ -72,17 +72,17 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
...
@@ -72,17 +72,17 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
Class
.
forName
(
"android.os.SystemProperties"
).
let
{
clazz
->
Class
.
forName
(
"android.os.SystemProperties"
).
let
{
clazz
->
clazz
.
getMethod
(
"get"
,
String
::
class
.
java
,
String
::
class
.
java
)
clazz
.
getMethod
(
"get"
,
String
::
class
.
java
,
String
::
class
.
java
)
.
invoke
(
clazz
.
newInstance
(),
"gsm.version.baseband"
,
"no message"
)
.
invoke
(
clazz
.
newInstance
(),
"gsm.version.baseband"
,
"no message"
)
?.
toString
()
?:
""
?.
toString
()
.
orEmpty
()
}
}
}.
getOrElse
{
""
}.
toByteArray
()
}.
getOrElse
{
""
}.
toByteArray
()
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
()
=
kotlin
.
runCatching
{
File
(
"/proc/version"
).
useLines
{
it
.
firstOrNull
()
?:
""
}.
toByteArray
()
}
get
()
=
kotlin
.
runCatching
{
File
(
"/proc/version"
).
useLines
{
it
.
firstOrNull
()
.
orEmpty
()
}.
toByteArray
()
}
.
getOrElse
{
byteArrayOf
()
}
.
getOrElse
{
byteArrayOf
()
}
override
val
bootId
:
ByteArray
override
val
bootId
:
ByteArray
get
()
=
kotlin
.
runCatching
{
get
()
=
kotlin
.
runCatching
{
File
(
"/proc/sys/kernel/random/boot_id"
).
useLines
{
it
.
firstOrNull
()
?:
""
}.
toByteArray
()
File
(
"/proc/sys/kernel/random/boot_id"
).
useLines
{
it
.
firstOrNull
()
.
orEmpty
()
}.
toByteArray
()
}.
getOrEmpty
()
}.
getOrEmpty
()
override
val
version
:
DeviceInfo
.
Version
get
()
=
Version
override
val
version
:
DeviceInfo
.
Version
get
()
=
Version
...
@@ -91,7 +91,7 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
...
@@ -91,7 +91,7 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
val
telephonyManager
=
val
telephonyManager
=
context
.
applicationContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
context
.
applicationContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
if
(
telephonyManager
.
simState
==
5
)
{
if
(
telephonyManager
.
simState
==
5
)
{
telephonyManager
.
simOperatorName
.
toByteArray
()
telephonyManager
.
simOperatorName
.
orEmpty
().
toByteArray
()
}
else
byteArrayOf
()
}
else
byteArrayOf
()
}.
getOrEmpty
()
}.
getOrEmpty
()
...
@@ -99,19 +99,22 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
...
@@ -99,19 +99,22 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
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
()
=
kotlin
.
runCatching
{
get
()
=
kotlin
.
runCatching
{
(
context
.
applicationContext
.
getSystemService
(
Context
.
WIFI_SERVICE
)
as
WifiManager
).
connectionInfo
.
bssid
.
toByteArray
()
(
context
.
applicationContext
.
getSystemService
(
Context
.
WIFI_SERVICE
)
as
WifiManager
).
connectionInfo
.
bssid
.
orEmpty
()
.
toByteArray
()
}.
getOrEmpty
()
}.
getOrEmpty
()
override
val
wifiSSID
:
ByteArray
?
override
val
wifiSSID
:
ByteArray
?
get
()
=
kotlin
.
runCatching
{
get
()
=
kotlin
.
runCatching
{
(
context
.
applicationContext
.
getSystemService
(
Context
.
WIFI_SERVICE
)
as
WifiManager
).
connectionInfo
.
ssid
.
toByteArray
()
(
context
.
applicationContext
.
getSystemService
(
Context
.
WIFI_SERVICE
)
as
WifiManager
).
connectionInfo
.
ssid
.
orEmpty
()
.
toByteArray
()
}.
getOrEmpty
()
}.
getOrEmpty
()
@OptIn
(
MiraiInternalAPI
::
class
)
@OptIn
(
MiraiInternalAPI
::
class
)
override
val
imsiMd5
:
ByteArray
override
val
imsiMd5
:
ByteArray
@SuppressLint
(
"HardwareIds"
)
@SuppressLint
(
"HardwareIds"
)
get
()
=
kotlin
.
runCatching
{
get
()
=
kotlin
.
runCatching
{
(
context
.
applicationContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
).
subscriberId
.
toByteArray
()
(
context
.
applicationContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
).
subscriberId
.
orEmpty
()
.
toByteArray
()
}.
getOrEmpty
().
md5
()
}.
getOrEmpty
().
md5
()
override
val
imei
:
String
override
val
imei
:
String
...
@@ -122,7 +125,7 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
...
@@ -122,7 +125,7 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
}
else
{
}
else
{
@Suppress
(
"DEPRECATION"
)
@Suppress
(
"DEPRECATION"
)
(
context
.
applicationContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
).
deviceId
(
context
.
applicationContext
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
)
as
TelephonyManager
).
deviceId
}
}
.
orEmpty
()
}.
getOrElse
{
""
}
}.
getOrElse
{
""
}
override
val
androidId
:
ByteArray
get
()
=
Build
.
ID
.
toByteArray
()
override
val
androidId
:
ByteArray
get
()
=
Build
.
ID
.
toByteArray
()
...
@@ -130,9 +133,9 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
...
@@ -130,9 +133,9 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
@Serializable
@Serializable
actual
object
Version
:
DeviceInfo
.
Version
{
actual
object
Version
:
DeviceInfo
.
Version
{
override
val
incremental
:
ByteArray
get
()
=
Build
.
VERSION
.
INCREMENTAL
.
toByteArray
()
override
val
incremental
:
ByteArray
get
()
=
Build
.
VERSION
.
INCREMENTAL
.
orEmpty
().
toByteArray
()
override
val
release
:
ByteArray
get
()
=
Build
.
VERSION
.
RELEASE
.
toByteArray
()
override
val
release
:
ByteArray
get
()
=
Build
.
VERSION
.
RELEASE
.
orEmpty
().
toByteArray
()
override
val
codename
:
ByteArray
get
()
=
Build
.
VERSION
.
CODENAME
.
toByteArray
()
override
val
codename
:
ByteArray
get
()
=
Build
.
VERSION
.
CODENAME
.
orEmpty
().
toByteArray
()
override
val
sdk
:
Int
get
()
=
Build
.
VERSION
.
SDK_INT
override
val
sdk
:
Int
get
()
=
Build
.
VERSION
.
SDK_INT
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment