-
-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathSystemProperties.kt
More file actions
34 lines (30 loc) · 1.33 KB
/
SystemProperties.kt
File metadata and controls
34 lines (30 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package io.sentry.android.replay.util
import android.annotation.SuppressLint
import android.os.Build
import java.lang.reflect.Method
internal object SystemProperties {
// from https://cs.android.com/android/platform/superproject/main/+/main:out/soong/.intermediates/system/libsysprop/srcs/PlatformProperties/android_common/xref/srcjars.xref/android/sysprop/SocProperties.java;l=163-171
// these props are not available on API < 31 via Build, so we use reflection to access them
const val SOC_MODEL = "ro.soc.model"
const val SOC_MANUFACTURER = "ro.soc.manufacturer"
@delegate:SuppressLint("PrivateApi")
private val getProperty: Method by lazy {
val clazz = Class.forName("android.os.SystemProperties")
clazz.getMethod("get", String::class.java)
}
fun get(key: String, defaultValue: String = ""): String {
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
try {
getProperty.invoke(null, key) as? String ?: defaultValue
} catch (e: Throwable) {
defaultValue
}
} else {
when (key) {
SOC_MODEL -> Build.SOC_MODEL
SOC_MANUFACTURER -> Build.SOC_MANUFACTURER
else -> throw IllegalArgumentException("Unknown system property: $key")
}
}
}
}