API: return String instead of printing out to logcat.

This commit is contained in:
Benoit Marty 2022-08-18 15:09:48 +02:00
parent ec3512fd5b
commit 4ffab7fc13
6 changed files with 22 additions and 19 deletions

View File

@ -28,7 +28,7 @@ interface DebugService {
fun getAllRealmConfigurations(): List<RealmConfiguration> fun getAllRealmConfigurations(): List<RealmConfiguration>
/** /**
* Prints out info on DB size to logcat. * Get info on DB size.
*/ */
fun logDbUsageInfo() fun getDbUsageInfo(): String
} }

View File

@ -323,9 +323,9 @@ interface Session {
fun getUiaSsoFallbackUrl(authenticationSessionId: String): String fun getUiaSsoFallbackUrl(authenticationSessionId: String): String
/** /**
* Debug API, will print out info on DB size to logcat. * Debug API, will return info about the DB.
*/ */
fun logDbUsageInfo() fun getDbUsageInfo(): String
/** /**
* Debug API, return the list of all RealmConfiguration used by this session. * Debug API, return the list of all RealmConfiguration used by this session.

View File

@ -19,16 +19,15 @@ package org.matrix.android.sdk.internal.database.tools
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration import io.realm.RealmConfiguration
import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.BuildConfig
import timber.log.Timber
internal class RealmDebugTools( internal class RealmDebugTools(
private val realmConfiguration: RealmConfiguration private val realmConfiguration: RealmConfiguration
) { ) {
/** /**
* Log info about the DB. * Get info about the DB.
*/ */
fun logInfo(baseName: String) { fun getInfo(baseName: String): String {
buildString { return buildString {
append("\n$baseName Realm located at : ${realmConfiguration.realmDirectory}/${realmConfiguration.realmFileName}") append("\n$baseName Realm located at : ${realmConfiguration.realmDirectory}/${realmConfiguration.realmFileName}")
if (BuildConfig.LOG_PRIVATE_DATA) { if (BuildConfig.LOG_PRIVATE_DATA) {
@ -54,7 +53,6 @@ internal class RealmDebugTools(
separator() separator()
} }
} }
.let { Timber.i(it) }
} }
private fun StringBuilder.separator() = append("\n==============================================") private fun StringBuilder.separator() = append("\n==============================================")

View File

@ -36,9 +36,9 @@ internal class DefaultDebugService @Inject constructor(
realmConfigurationGlobal realmConfigurationGlobal
} }
override fun logDbUsageInfo() { override fun getDbUsageInfo() = buildString {
RealmDebugTools(realmConfigurationAuth).logInfo("Auth") append(RealmDebugTools(realmConfigurationAuth).getInfo("Auth"))
RealmDebugTools(realmConfigurationGlobal).logInfo("Global") append(RealmDebugTools(realmConfigurationGlobal).getInfo("Global"))
sessionManager.getLastSession()?.logDbUsageInfo() append(sessionManager.getLastSession()?.getDbUsageInfo())
} }
} }

View File

@ -263,11 +263,11 @@ internal class DefaultSession @Inject constructor(
} }
} }
override fun logDbUsageInfo() { override fun getDbUsageInfo() = buildString {
RealmDebugTools(realmConfiguration).logInfo("Session") append(RealmDebugTools(realmConfiguration).getInfo("Session"))
RealmDebugTools(realmConfigurationCrypto).logInfo("Crypto") append(RealmDebugTools(realmConfigurationCrypto).getInfo("Crypto"))
RealmDebugTools(realmConfigurationIdentity).logInfo("Identity") append(RealmDebugTools(realmConfigurationIdentity).getInfo("Identity"))
RealmDebugTools(realmConfigurationContentScanner).logInfo("ContentScanner") append(RealmDebugTools(realmConfigurationContentScanner).getInfo("ContentScanner"))
} }
override fun getRealmConfigurations(): List<RealmConfiguration> { override fun getRealmConfigurations(): List<RealmConfiguration> {

View File

@ -499,10 +499,15 @@ class BugReporter @Inject constructor(
*/ */
fun openBugReportScreen(activity: FragmentActivity, reportType: ReportType = ReportType.BUG_REPORT) { fun openBugReportScreen(activity: FragmentActivity, reportType: ReportType = ReportType.BUG_REPORT) {
screenshot = takeScreenshot(activity) screenshot = takeScreenshot(activity)
matrix.debugService().logDbUsageInfo() logDbInfo()
activity.startActivity(BugReportActivity.intent(activity, reportType)) activity.startActivity(BugReportActivity.intent(activity, reportType))
} }
private fun logDbInfo() {
val dbInfo = matrix.debugService().getDbUsageInfo()
Timber.i(dbInfo)
}
private fun rageShakeAppNameForReport(reportType: ReportType): String { private fun rageShakeAppNameForReport(reportType: ReportType): String {
// As per https://github.com/matrix-org/rageshake // As per https://github.com/matrix-org/rageshake
// app: Identifier for the application (eg 'riot-web'). // app: Identifier for the application (eg 'riot-web').