Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
PublicAndroidApps
Nebulo
Commits
edbfb041
Commit
edbfb041
authored
Dec 09, 2019
by
Daniel Wolf
Browse files
Ignore all exceptions when creating the Sentry client, only try to access it if it is initialized
parent
127cf86e
Pipeline
#5984
passed with stage
in 2 minutes and 12 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/Logger.kt
View file @
edbfb041
...
...
@@ -94,7 +94,7 @@ fun Context.log(
}
fun
Context
.
log
(
e
:
Throwable
,
extras
:
Map
<
String
,
String
>?
=
null
)
{
logErrorSentry
(
e
,
extras
)
if
(
SmokeScreen
.
sentryReady
)
logErrorSentry
(
e
,
extras
)
getPreferences
().
lastCrashTimeStamp
=
System
.
currentTimeMillis
()
if
(
Logger
.
isEnabled
(
this
))
{
Logger
.
getInstance
(
this
).
log
(
e
)
...
...
app/src/main/java/com/frostnerd/smokescreen/SmokeScreen.kt
View file @
edbfb041
...
...
@@ -45,7 +45,10 @@ import kotlin.system.exitProcess
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class
SmokeScreen
:
Application
()
{
companion
object
{
var
sentryReady
:
Boolean
=
false
private
set
}
private
var
defaultUncaughtExceptionHandler
:
Thread
.
UncaughtExceptionHandler
?
=
null
val
customUncaughtExceptionHandler
=
EnrichableUncaughtExceptionHandler
()
private
fun
showCrashNotification
()
{
...
...
@@ -95,65 +98,77 @@ class SmokeScreen : Application() {
LeakSentry
.
watchIfEnabled
(
this
)
}
fun
closeSentry
()
{
Sentry
.
close
()
sentryReady
=
false
}
fun
initSentry
(
forceStatus
:
Status
=
Status
.
NONE
)
{
if
(!
BuildConfig
.
DEBUG
&&
BuildConfig
.
SENTRY_DSN
!=
"dummy"
)
{
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
val
hostName
=
InetAddress
.
getLocalHost
().
hostName
if
(!
hostName
.
startsWith
(
"mars-sandbox"
,
true
))
{
val
enabledType
=
getPreferences
().
crashreportingType
if
(
forceStatus
!=
Status
.
DATASAVING
&&
(
enabledType
==
Crashreporting
.
FULL
||
forceStatus
==
Status
.
ENABLED
))
{
// Enable Sentry in full mode
// This passes some device-related data, but nothing which allows user actions to be tracked across the app
// Info: Some data is attached by the AndroidEventBuilderHelper class, which is present by default
Sentry
.
init
(
BuildConfig
.
SENTRY_DSN
,
AndroidSentryClientFactory
(
this
@SmokeScreen
)
)
Sentry
.
getContext
().
user
=
User
(
getPreferences
().
crashReportingUUID
,
null
,
null
,
null
)
Sentry
.
getStoredClient
().
apply
{
addTag
(
"user.language"
,
Locale
.
getDefault
().
displayLanguage
)
addTag
(
"app.database_version"
,
AppDatabase
.
currentVersion
.
toString
())
addTag
(
"app.dns_server_name"
,
getPreferences
().
dnsServerConfig
.
name
)
addTag
(
"app.dns_server_primary"
,
getPreferences
().
dnsServerConfig
.
servers
[
0
].
address
.
formatToString
()
sentryReady
=
false
try
{
val
hostName
=
InetAddress
.
getLocalHost
().
hostName
if
(!
hostName
.
startsWith
(
"mars-sandbox"
,
true
))
{
val
enabledType
=
getPreferences
().
crashreportingType
if
(
forceStatus
!=
Status
.
DATASAVING
&&
(
enabledType
==
Crashreporting
.
FULL
||
forceStatus
==
Status
.
ENABLED
))
{
// Enable Sentry in full mode
// This passes some device-related data, but nothing which allows user actions to be tracked across the app
// Info: Some data is attached by the AndroidEventBuilderHelper class, which is present by default
Sentry
.
init
(
BuildConfig
.
SENTRY_DSN
,
AndroidSentryClientFactory
(
this
@SmokeScreen
)
)
addTag
(
"app.dns_server_secondary"
,
getPreferences
().
dnsServerConfig
.
servers
.
getOrNull
(
1
)
?.
address
?.
formatToString
()
)
addTag
(
"app.installer_package"
,
packageManager
.
getInstallerPackageName
(
packageName
)
Sentry
.
getContext
().
user
=
User
(
getPreferences
().
crashReportingUUID
,
null
,
null
,
null
)
Sentry
.
getStoredClient
().
apply
{
addTag
(
"user.language"
,
Locale
.
getDefault
().
displayLanguage
)
addTag
(
"app.database_version"
,
AppDatabase
.
currentVersion
.
toString
())
addTag
(
"app.dns_server_name"
,
getPreferences
().
dnsServerConfig
.
name
)
addTag
(
"app.dns_server_primary"
,
getPreferences
().
dnsServerConfig
.
servers
[
0
].
address
.
formatToString
()
)
addTag
(
"app.dns_server_secondary"
,
getPreferences
().
dnsServerConfig
.
servers
.
getOrNull
(
1
)
?.
address
?.
formatToString
()
)
addTag
(
"app.installer_package"
,
packageManager
.
getInstallerPackageName
(
packageName
)
)
addTag
(
"richdata"
,
"true"
)
addTag
(
"app.fromCi"
,
BuildConfig
.
FROM_CI
.
toString
())
addTag
(
"app.commit"
,
BuildConfig
.
COMMIT_HASH
)
}
sentryReady
=
true
}
else
if
(
enabledType
==
Crashreporting
.
MINIMAL
||
forceStatus
==
Status
.
DATASAVING
)
{
// Inits Sentry in datasaving mode
// Only data absolutely necessary is transmitted (Android version, app version).
// Only crashes will be reported, no regular events.
Sentry
.
init
(
BuildConfig
.
SENTRY_DSN
,
AndroidSentryClientFactory
(
this
@SmokeScreen
)
)
addTag
(
"richdata"
,
"true"
)
addTag
(
"app.fromCi"
,
BuildConfig
.
FROM_CI
.
toString
())
addTag
(
"app.commit"
,
BuildConfig
.
COMMIT_HASH
)
}
}
else
if
(
enabledType
==
Crashreporting
.
MINIMAL
||
forceStatus
==
Status
.
DATASAVING
)
{
// Inits Sentry in datasaving mode
// Only data absolutely necessary is transmitted (Android version, app version).
// Only crashes will be reported, no regular events.
Sentry
.
init
(
BuildConfig
.
SENTRY_DSN
,
AndroidSentryClientFactory
(
this
@SmokeScreen
)
)
Sentry
.
getContext
().
user
=
User
(
"anon-"
+
BuildConfig
.
VERSION_CODE
,
null
,
null
,
null
)
Sentry
.
getStoredClient
().
apply
{
addTag
(
"richdata"
,
"false"
)
addTag
(
"dist"
,
BuildConfig
.
VERSION_CODE
.
toString
())
addTag
(
"app.commit"
,
BuildConfig
.
COMMIT_HASH
)
addTag
(
"app.fromCi"
,
BuildConfig
.
FROM_CI
.
toString
())
addExtra
(
"dist"
,
BuildConfig
.
VERSION_CODE
)
this
.
builderHelpers
.
forEach
{
this
.
removeBuilderHelper
(
it
)
Sentry
.
getContext
().
user
=
User
(
"anon-"
+
BuildConfig
.
VERSION_CODE
,
null
,
null
,
null
)
Sentry
.
getStoredClient
().
apply
{
addTag
(
"richdata"
,
"false"
)
addTag
(
"dist"
,
BuildConfig
.
VERSION_CODE
.
toString
())
addTag
(
"app.commit"
,
BuildConfig
.
COMMIT_HASH
)
addTag
(
"app.fromCi"
,
BuildConfig
.
FROM_CI
.
toString
())
addExtra
(
"dist"
,
BuildConfig
.
VERSION_CODE
)
this
.
builderHelpers
.
forEach
{
this
.
removeBuilderHelper
(
it
)
}
this
.
addBuilderHelper
(
DatasavingSentryEventHelper
())
}
this
.
addBuilderHelper
(
DatasavingSentryEventHelper
())
sentryReady
=
true
}
}
}
catch
(
ex
:
Throwable
)
{
ex
.
printStackTrace
()
}
}
}
...
...
app/src/main/java/com/frostnerd/smokescreen/dialog/CrashReportingEnableDialog.kt
View file @
edbfb041
...
...
@@ -58,7 +58,7 @@ class CrashReportingEnableDialog(
)
{
dialog
,
_
->
context
.
getPreferences
().
crashreportingType
=
Crashreporting
.
OFF
context
.
getPreferences
().
crashReportingConsent
=
false
Sentry
.
close
()
(
context
.
applicationContext
as
SmokeScreen
).
close
Sentry
()
dialog
.
dismiss
()
}
setButton
(
DialogInterface
.
BUTTON_NEUTRAL
,
context
.
getString
(
R
.
string
.
dialog_crashreporting_neutral
))
{
_
,
_
->
...
...
app/src/main/java/com/frostnerd/smokescreen/fragment/SettingsFragment.kt
View file @
edbfb041
...
...
@@ -428,10 +428,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
false
}
else
{
if
(
newValue
==
Crashreporting
.
MINIMAL
.
value
)
{
Sentry
.
close
()
(
requireContext
().
applicationContext
as
SmokeScreen
).
close
Sentry
()
(
requireContext
().
applicationContext
as
SmokeScreen
).
initSentry
(
Status
.
DATASAVING
)
}
else
if
(
newValue
==
Crashreporting
.
OFF
.
value
)
{
Sentry
.
close
()
(
requireContext
().
applicationContext
as
SmokeScreen
).
close
Sentry
()
}
true
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment