Skip to content

Address PR feedback #4481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
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)
enum class Property {
SOC_MODEL,
SOC_MANUFACTURER
}

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 {
fun get(key: Property, defaultValue: String = ""): String {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
when (key) {
SOC_MODEL -> Build.SOC_MODEL
SOC_MANUFACTURER -> Build.SOC_MANUFACTURER
else -> throw IllegalArgumentException("Unknown system property: $key")
Property.SOC_MODEL -> Build.SOC_MODEL
Property.SOC_MANUFACTURER -> Build.SOC_MANUFACTURER
}
} else {
defaultValue
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal class SimpleVideoEncoder(
val canvas = if (
Build.MANUFACTURER.contains("xiaomi", ignoreCase = true) ||
Build.MANUFACTURER.contains("motorola", ignoreCase = true) ||
SystemProperties.get(SystemProperties.SOC_MODEL).equals("T606", ignoreCase = true)
SystemProperties.get(SystemProperties.Property.SOC_MODEL).equals("T606", ignoreCase = true)
) {
surface?.lockCanvas(null)
} else {
Expand Down
Loading