/
Analytics.kt
68 lines (61 loc) · 2.23 KB
/
Analytics.kt
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package me.hufman.androidautoidrive
import android.content.Context
import io.sentry.Sentry
import io.sentry.android.AndroidSentryClientFactory
import io.sentry.event.Event
import io.sentry.event.EventBuilder
import io.sentry.event.interfaces.ExceptionInterface
import me.hufman.androidautoidrive.music.MusicAppInfo
object Analytics: AnalyticsProvider {
override fun init(context: Context) {
Sentry.init(AndroidSentryClientFactory(context))
}
override fun reportMusicAppProbe(appInfo: MusicAppInfo) {
val event = EventBuilder()
.withMessage("Probed music app")
.withTag("appId", appInfo.packageName)
.withTag("appName", appInfo.name)
.withTag("controllable", if (appInfo.controllable) "true" else "false")
.withTag("connectable", if (appInfo.connectable) "true" else "false")
.withTag("browseable", if (appInfo.browseable) "true" else "false")
.withTag("searchable", if (appInfo.searchable) "true" else "false")
.withTag("playsearchable", if (appInfo.playsearchable) "true" else "false")
.withLevel(Event.Level.DEBUG)
Sentry.capture(event)
}
override fun reportCarProbeFailure(port: Int, message: String?, throwable: Throwable?) {
val event = EventBuilder()
.withMessage("Failed to probe car: $message")
.withTag("port", port.toString())
.withLevel(Event.Level.WARNING)
if (throwable != null) {
val crash = event
.withSentryInterface(ExceptionInterface(throwable))
Sentry.capture(crash)
} else {
Sentry.capture(event)
}
}
override fun reportCarProbeDiscovered(port: Int?, vehicleType: String?, hmiType: String?) {
val event = EventBuilder()
.withMessage("Successfully probed to connect to car")
.withTag("vehicleType", vehicleType ?: "")
.withTag("hmiType", hmiType ?: "")
.withTag("port", port.toString())
.withLevel(Event.Level.DEBUG)
Sentry.capture(event)
}
override fun reportCarCapabilities(capabilities: Map<String, String?>) {
var event = EventBuilder()
.withMessage("Car capabilities")
.withLevel(Event.Level.DEBUG)
capabilities.keys.forEach { key ->
val value = capabilities[key]
if (value != null) {
val keyName = key.replace(Regex("[^a-zA-Z0-9_]"), "_")
event.withTag(keyName, value.toString())
}
}
Sentry.capture(event)
}
}