This repository has been archived by the owner on Jun 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 553
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1351 from RocketChat/release/2.3.0-hotfix2
[RELEASE] 2.3.2 - HOTFIX
- Loading branch information
Showing
10 changed files
with
145 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/chat/rocket/android/infrastructure/CrashlyticsWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package chat.rocket.android.infrastructure | ||
|
||
import android.app.Application | ||
import chat.rocket.android.BuildConfig | ||
import chat.rocket.android.server.domain.AccountsRepository | ||
import chat.rocket.android.server.domain.GetCurrentServerInteractor | ||
import chat.rocket.android.server.domain.GetSettingsInteractor | ||
import chat.rocket.android.server.domain.SITE_URL | ||
import com.crashlytics.android.Crashlytics | ||
import kotlinx.coroutines.experimental.runBlocking | ||
|
||
fun installCrashlyticsWrapper(context: Application, | ||
currentServerInteractor: GetCurrentServerInteractor, | ||
settingsInteractor: GetSettingsInteractor, | ||
accountRepository: AccountsRepository, | ||
localRepository: LocalRepository) { | ||
if (isCrashlyticsEnabled()) { | ||
Thread.setDefaultUncaughtExceptionHandler(RocketChatUncaughtExceptionHandler(currentServerInteractor, | ||
settingsInteractor, accountRepository, localRepository)) | ||
} | ||
} | ||
|
||
private fun isCrashlyticsEnabled(): Boolean { | ||
return !BuildConfig.DEBUG | ||
} | ||
|
||
private class RocketChatUncaughtExceptionHandler( | ||
val currentServerInteractor: GetCurrentServerInteractor, | ||
val settingsInteractor: GetSettingsInteractor, | ||
val accountRepository: AccountsRepository, | ||
val localRepository: LocalRepository) | ||
: Thread.UncaughtExceptionHandler { | ||
|
||
val crashlyticsHandler: Thread.UncaughtExceptionHandler? = Thread.getDefaultUncaughtExceptionHandler() | ||
|
||
override fun uncaughtException(t: Thread, e: Throwable) { | ||
val currentServer = currentServerInteractor.get() ?: "<unknown>" | ||
Crashlytics.setString(KEY_CURRENT_SERVER, currentServer) | ||
runBlocking { | ||
val accounts = accountRepository.load() | ||
Crashlytics.setString(KEY_ACCOUNTS, accounts.toString()) | ||
} | ||
|
||
val settings = settingsInteractor.get(currentServer) | ||
Crashlytics.setInt(KEY_SETTINGS_SIZE, settings.size) | ||
val baseUrl = settings[SITE_URL]?.toString() | ||
Crashlytics.setString(KEY_SETTINGS_BASE_URL, baseUrl) | ||
|
||
val user = localRepository.getCurrentUser(currentServer) | ||
Crashlytics.setString(KEY_CURRENT_USER, user?.toString()) | ||
Crashlytics.setString(KEY_CURRENT_USERNAME, localRepository.username()) | ||
|
||
if (crashlyticsHandler != null) { | ||
crashlyticsHandler.uncaughtException(t, e) | ||
} else { | ||
throw RuntimeException("Missing default exception handler") | ||
} | ||
} | ||
} | ||
|
||
private const val KEY_CURRENT_SERVER = "CURRENT_SERVER" | ||
private const val KEY_CURRENT_USER = "CURRENT_USER" | ||
private const val KEY_CURRENT_USERNAME = "CURRENT_USERNAME" | ||
private const val KEY_ACCOUNTS = "ACCOUNTS" | ||
private const val KEY_SETTINGS_SIZE = "SETTINGS_SIZE" | ||
private const val KEY_SETTINGS_BASE_URL = "SETTINGS_BASE_URL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters