Skip to content

Commit 8849dcd

Browse files
authored
Address PR feedback (#4481)
* Address PR feeback * Cleanup
1 parent f269e08 commit 8849dcd

2 files changed

Lines changed: 10 additions & 23 deletions

File tree

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,21 @@
11
package io.sentry.android.replay.util
22

3-
import android.annotation.SuppressLint
43
import android.os.Build
5-
import java.lang.reflect.Method
64

75
internal object SystemProperties {
8-
// 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
9-
// these props are not available on API < 31 via Build, so we use reflection to access them
10-
const val SOC_MODEL = "ro.soc.model"
11-
const val SOC_MANUFACTURER = "ro.soc.manufacturer"
12-
13-
@delegate:SuppressLint("PrivateApi")
14-
private val getProperty: Method by lazy {
15-
val clazz = Class.forName("android.os.SystemProperties")
16-
clazz.getMethod("get", String::class.java)
6+
enum class Property {
7+
SOC_MODEL,
8+
SOC_MANUFACTURER
179
}
1810

19-
fun get(key: String, defaultValue: String = ""): String {
20-
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
21-
try {
22-
getProperty.invoke(null, key) as? String ?: defaultValue
23-
} catch (e: Throwable) {
24-
defaultValue
25-
}
26-
} else {
11+
fun get(key: Property, defaultValue: String = ""): String {
12+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
2713
when (key) {
28-
SOC_MODEL -> Build.SOC_MODEL
29-
SOC_MANUFACTURER -> Build.SOC_MANUFACTURER
30-
else -> throw IllegalArgumentException("Unknown system property: $key")
14+
Property.SOC_MODEL -> Build.SOC_MODEL
15+
Property.SOC_MANUFACTURER -> Build.SOC_MANUFACTURER
3116
}
17+
} else {
18+
defaultValue
3219
}
3320
}
3421
}

sentry-android-replay/src/main/java/io/sentry/android/replay/video/SimpleVideoEncoder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ internal class SimpleVideoEncoder(
169169
val canvas = if (
170170
Build.MANUFACTURER.contains("xiaomi", ignoreCase = true) ||
171171
Build.MANUFACTURER.contains("motorola", ignoreCase = true) ||
172-
SystemProperties.get(SystemProperties.SOC_MODEL).equals("T606", ignoreCase = true)
172+
SystemProperties.get(SystemProperties.Property.SOC_MODEL).equals("T606", ignoreCase = true)
173173
) {
174174
surface?.lockCanvas(null)
175175
} else {

0 commit comments

Comments
 (0)