Update Sentry usage
This commit is contained in:
1 parent
ea3aaf0e8a
commit
bd2ae618c1
5 files changed
+47
-32
No files matched your search
@@ -12,8 +12,10 @@ import io.sentry.Breadcrumb
|
||||
import io.sentry.IScope
|
||||
import io.sentry.Sentry
|
||||
import io.sentry.SentryLevel
|
||||
import io.sentry.android.core.SentryAndroid
|
||||
import io.sentry.compose.SentryModifier.sentryTag
|
||||
import io.sentry.compose.SentryTraced
|
||||
import androidx.core.content.edit
|
||||
|
||||
internal const val SENTRY_DSN =
|
||||
"https://39a6e220c97c585acd25ced5a6855b4d@o4508123221590016.ingest.de.sentry.io/4508123222704209"
|
||||
@@ -106,14 +108,15 @@ object Telemetry : ITelemetry {
|
||||
override val isStub: Boolean
|
||||
get() = false
|
||||
|
||||
override var enabled: Boolean
|
||||
override val enabled: Boolean
|
||||
get() = _enabled
|
||||
set(value) {
|
||||
sharedPrefs.edit().putBoolean(PREFS_ENABLED_KEY, value).apply()
|
||||
reinit(value)
|
||||
}
|
||||
|
||||
private fun reinit(enabled: Boolean) {
|
||||
override fun setEnabled(context: Context, enabled: Boolean) {
|
||||
sharedPrefs.edit { putBoolean(PREFS_ENABLED_KEY, enabled) }
|
||||
reinit(context, enabled)
|
||||
}
|
||||
|
||||
private fun reinit(context: Context, enabled: Boolean) {
|
||||
if (_enabled == enabled)
|
||||
return
|
||||
_enabled = enabled
|
||||
@@ -122,7 +125,7 @@ object Telemetry : ITelemetry {
|
||||
if (!enabled) {
|
||||
Sentry.close()
|
||||
} else {
|
||||
Sentry.init {
|
||||
SentryAndroid.init(context) {
|
||||
it.dsn = SENTRY_DSN
|
||||
it.isEnableUserInteractionTracing = true
|
||||
|
||||
@@ -130,14 +133,14 @@ object Telemetry : ITelemetry {
|
||||
it.environment = "debug"
|
||||
it.tracesSampleRate = DEBUG_SAMPLE_RATE
|
||||
it.profilesSampleRate = DEBUG_SAMPLE_RATE
|
||||
it.experimental.sessionReplay.sessionSampleRate = DEBUG_SAMPLE_RATE
|
||||
it.experimental.sessionReplay.onErrorSampleRate = DEBUG_ERROR_SAMPLE_RATE
|
||||
it.sessionReplay.sessionSampleRate = DEBUG_SAMPLE_RATE
|
||||
it.sessionReplay.onErrorSampleRate = DEBUG_ERROR_SAMPLE_RATE
|
||||
} else {
|
||||
it.environment = "production"
|
||||
it.tracesSampleRate = PROD_SAMPLE_RATE
|
||||
it.profilesSampleRate = PROD_SAMPLE_RATE
|
||||
it.experimental.sessionReplay.sessionSampleRate = PROD_SAMPLE_RATE
|
||||
it.experimental.sessionReplay.onErrorSampleRate = PROD_ERROR_SAMPLE_RATE
|
||||
it.sessionReplay.sessionSampleRate = PROD_SAMPLE_RATE
|
||||
it.sessionReplay.onErrorSampleRate = PROD_ERROR_SAMPLE_RATE
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +149,7 @@ object Telemetry : ITelemetry {
|
||||
override fun init(context: Context) {
|
||||
sharedPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
Log.i("Telemetry", "Enabled: ${sharedPrefs.getBoolean(PREFS_ENABLED_KEY, true)}")
|
||||
reinit(sharedPrefs.getBoolean(PREFS_ENABLED_KEY, true))
|
||||
reinit(context, sharedPrefs.getBoolean(PREFS_ENABLED_KEY, true))
|
||||
}
|
||||
|
||||
override fun Modifier.telemetryTag(tag: String): Modifier {
|
||||
@@ -162,10 +165,10 @@ object Telemetry : ITelemetry {
|
||||
content: @Composable (BoxScope.() -> Unit),
|
||||
) {
|
||||
SentryTraced(
|
||||
tag = tag,
|
||||
modifier = modifier,
|
||||
enableUserInteractionTracing = enableUserInteractionTracing,
|
||||
content = content
|
||||
tag = tag,
|
||||
modifier = modifier,
|
||||
enableUserInteractionTracing = enableUserInteractionTracing,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ private const val TRACE_IO = false
|
||||
*
|
||||
* @param msg The message to print if tracing is enabled.
|
||||
*/
|
||||
@JvmStatic
|
||||
private fun BlockDeviceInputStream.traceIo(msg: String) {
|
||||
if (TRACE_IO) println("ISTREAM: ${Thread.currentThread().name} time ${System.nanoTime()} pos $mCurrentOffset $msg")
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ private const val TRACE_IO = false
|
||||
*
|
||||
* @param msg The message to print if tracing is enabled.
|
||||
*/
|
||||
@JvmStatic
|
||||
private fun BlockDeviceOutputStream.traceIo(msg: String) {
|
||||
if (TRACE_IO) println("OSTREAM: ${Thread.currentThread().name} time ${System.nanoTime()} pos $mCurrentOffset $msg")
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import androidx.compose.ui.Modifier
|
||||
|
||||
interface ITelemetry {
|
||||
val isStub: Boolean
|
||||
var enabled: Boolean get() = !isStub; set(value) {}
|
||||
val enabled: Boolean get() = !isStub
|
||||
|
||||
fun setEnabled(context: Context, enabled: Boolean) {}
|
||||
|
||||
fun init(context: Context) {}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ class MainActivity : ActivityBase() {
|
||||
var telemetryDialogOpen by remember { mutableStateOf(false) }
|
||||
|
||||
fun setTelemetry(enabled: Boolean) {
|
||||
Telemetry.enabled = enabled
|
||||
Telemetry.setEnabled(this.applicationContext, enabled)
|
||||
mViewModel.setTelemetry(enabled)
|
||||
}
|
||||
|
||||
@@ -573,19 +573,24 @@ fun StartView(
|
||||
onClick = { setThemeMode(ThemeMode.SYSTEM) },
|
||||
text = { Text(stringResource(R.string.device_setting)) },
|
||||
leadingIcon = {
|
||||
RadioButton(modifier = Modifier.size(20.dp),
|
||||
RadioButton(
|
||||
modifier = Modifier.size(20.dp),
|
||||
selected = uiState.themeMode == ThemeMode.SYSTEM,
|
||||
onClick = { setThemeMode(ThemeMode.SYSTEM) })
|
||||
})
|
||||
DropdownMenuItem(onClick = { setThemeMode(ThemeMode.LIGHT) },
|
||||
DropdownMenuItem(
|
||||
onClick = { setThemeMode(ThemeMode.LIGHT) },
|
||||
text = { Text(stringResource(R.string.light)) }, leadingIcon = {
|
||||
RadioButton(modifier = Modifier.size(20.dp),
|
||||
RadioButton(
|
||||
modifier = Modifier.size(20.dp),
|
||||
selected = uiState.themeMode == ThemeMode.LIGHT,
|
||||
onClick = { setThemeMode(ThemeMode.LIGHT) })
|
||||
})
|
||||
DropdownMenuItem(onClick = { setThemeMode(ThemeMode.DARK) },
|
||||
DropdownMenuItem(
|
||||
onClick = { setThemeMode(ThemeMode.DARK) },
|
||||
text = { Text(stringResource(R.string.dark)) }, leadingIcon = {
|
||||
RadioButton(modifier = Modifier.size(20.dp),
|
||||
RadioButton(
|
||||
modifier = Modifier.size(20.dp),
|
||||
selected = uiState.themeMode == ThemeMode.DARK,
|
||||
onClick = { setThemeMode(ThemeMode.DARK) })
|
||||
})
|
||||
@@ -595,7 +600,8 @@ fun StartView(
|
||||
onClick = { setDynamicTheme(!uiState.dynamicColors) },
|
||||
text = { Text(stringResource(R.string.dynamic_colors)) },
|
||||
leadingIcon = {
|
||||
Checkbox(modifier = Modifier.size(20.dp),
|
||||
Checkbox(
|
||||
modifier = Modifier.size(20.dp),
|
||||
checked = uiState.dynamicColors,
|
||||
onCheckedChange = { setDynamicTheme(!uiState.dynamicColors) })
|
||||
})
|
||||
@@ -614,7 +620,8 @@ fun StartView(
|
||||
onClick = { toggleTelemetry() },
|
||||
text = { Text(stringResource(R.string.send_anonymous_data)) },
|
||||
leadingIcon = {
|
||||
Checkbox(modifier = Modifier.size(20.dp),
|
||||
Checkbox(
|
||||
modifier = Modifier.size(20.dp),
|
||||
checked = Telemetry.enabled,
|
||||
onCheckedChange = { toggleTelemetry() }
|
||||
)
|
||||
@@ -643,7 +650,8 @@ fun StartView(
|
||||
|
||||
HorizontalDivider()
|
||||
|
||||
DropdownMenuItem(onClick = { openAboutView() },
|
||||
DropdownMenuItem(
|
||||
onClick = { openAboutView() },
|
||||
text = { Text(stringResource(R.string.about)) }, leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.TwoTone.Info,
|
||||
@@ -1062,7 +1070,8 @@ fun WindowsAlertDialogPreview() {
|
||||
val viewModel = remember { MainActivityViewModel() }
|
||||
|
||||
MainView(viewModel) {
|
||||
WindowsImageAlertDialog(onDismissRequest = { /*TODO*/ }, onConfirm = { /*TODO*/ },
|
||||
WindowsImageAlertDialog(
|
||||
onDismissRequest = { /*TODO*/ }, onConfirm = { /*TODO*/ },
|
||||
onCancel = { /*TODO*/ })
|
||||
}
|
||||
}
|
||||
@@ -1073,7 +1082,8 @@ fun TelemetryAlertDialogPreview() {
|
||||
val viewModel = remember { MainActivityViewModel() }
|
||||
|
||||
MainView(viewModel) {
|
||||
TelemetryAlertDialog(onDismissRequest = { /*TODO*/ }, onOptOut = { /*TODO*/ },
|
||||
TelemetryAlertDialog(
|
||||
onDismissRequest = { /*TODO*/ }, onOptOut = { /*TODO*/ },
|
||||
onCancel = { /*TODO*/ })
|
||||
}
|
||||
}
|
||||
@@ -1092,7 +1102,8 @@ fun UsbDevicePickerBottomSheetPreview() {
|
||||
|
||||
MainView(viewModel) {
|
||||
Row(
|
||||
Modifier.toggleable(value = openBottomSheet, role = Role.Checkbox,
|
||||
Modifier.toggleable(
|
||||
value = openBottomSheet, role = Role.Checkbox,
|
||||
onValueChange = { checked -> openBottomSheet = checked })
|
||||
) {
|
||||
Checkbox(checked = openBottomSheet, onCheckedChange = null)
|
||||
@@ -1122,7 +1133,8 @@ fun EmptyUsbDevicePickerBottomSheetPreview() {
|
||||
|
||||
MainView(viewModel) {
|
||||
Row(
|
||||
Modifier.toggleable(value = openBottomSheet, role = Role.Checkbox,
|
||||
Modifier.toggleable(
|
||||
value = openBottomSheet, role = Role.Checkbox,
|
||||
onValueChange = { checked -> openBottomSheet = checked })
|
||||
) {
|
||||
Checkbox(checked = openBottomSheet, onCheckedChange = null)
|
||||
|
||||
Reference in new issue
Block a user