Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a7ab8ff authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

855: setup Sentry telemetry.

parent 7cad75f4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ stages:
variables:
  MAPBOX_KEY: $MAPBOX_KEY_DEV
  MAPBOX_SECRET_KEY: $MAPBOX_SECRET_KEY_DEV
  SENTRY_DSN: $SENTRY_DSN

workflow:
  rules:
+3 −1
Original line number Diff line number Diff line
@@ -42,13 +42,14 @@ You can use any latest stable version of android studio to be able to build this
- Target SDK: 30 (Android R)

## API Keys
This project uses [Mapbox](https://docs.mapbox.com/android/maps/guides/install/) sdk for displaying maps. To download and use the mapbox sdk, you need to supply API key and secret and set them as follows:
This project uses [Sentry](https://sentry.io) for telemetry and crash reports,  [Mapbox](https://docs.mapbox.com/android/maps/guides/install/) sdk for displaying maps. To download and use the mapbox sdk, you need to supply API key and secret and set them as follows:

### For local build
You can set them in local.properties
```
MAPBOX_KEY=<insert mapbox public key>
MAPBOX_SECRET_KEY=<insert mapbox secret key>
SENTRY_DSN=<insert sentry dsn>
```
**IMP: Never add this file to version control.**

@@ -57,6 +58,7 @@ When building in CI environment, we don't have local.properties file. So the fol
```
export MAPBOX_KEY=<insert mapbox public key>
export MAPBOX_SECRET_KEY=<insert mapbox secret key>
export SENTRY_DSN=<insert sentry dsn>
```

## Code Style and Quality
+4 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ android {
        ]

        resValue("string", "mapbox_key", MAPBOX_KEY)
        buildConfigField("String", "SENTRY_DSN", "\"$SENTRY_DSN\"")
    }

    signingConfigs {
@@ -150,7 +151,9 @@ dependencies {
        Libs.Retrofit.scalars,

        Libs.MapBox.sdk,
        Libs.mpAndroidCharts
        Libs.mpAndroidCharts,

        Libs.sentry
    )

    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
+6 −1
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright  (C) 2022 ECORP
    Copyright  (C) 2022 ECORP, 2022 MURENA SAS

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -93,6 +93,11 @@
            android:launchMode="singleInstance"
            android:theme="@style/Theme.InvisibleActivity"
            />

        <meta-data
            android:name="io.sentry.auto-init"
            android:value="false"
            />
    </application>

</manifest>
 No newline at end of file
+20 −1
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 E FOUNDATION
 * Copyright (C) 2021 E FOUNDATION, 2022 MURENA SAS
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
@@ -18,7 +18,9 @@
package foundation.e.privacycentralapp

import android.app.Application
import android.provider.Settings
import com.mapbox.mapboxsdk.Mapbox
import io.sentry.android.core.SentryAndroid

class PrivacyCentralApplication : Application() {

@@ -27,8 +29,25 @@ class PrivacyCentralApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        initTelemetry()
        Mapbox.getTelemetry()?.setUserTelemetryRequestState(false)

        dependencyContainer.initBackgroundSingletons()
    }

    private fun initTelemetry() {
        val activateTelemetry = kotlin.runCatching {
            Settings.System.getInt(contentResolver, "telemetry") == 1
        }.getOrDefault(false)

        if (activateTelemetry) {
            SentryAndroid.init(this) { options ->
                options.setDsn(BuildConfig.SENTRY_DSN)
                options.setEnvironment(BuildConfig.BUILD_TYPE)
                options.setSampleRate(1.0)
                options.setEnableUserInteractionTracing(true)
                options.setProfilesSampleRate(1.0)
            }
        }
    }
}
Loading