Skip to content

Commit 6be42d4

Browse files
ArnyminerZrfc2822
andauthored
Added timestamp to debug info (#1323)
* Added timestamp to debug info Signed-off-by: Arnau Mora <[email protected]> * Added timestamp to `DebugInfoActivity.IntentBuilder` Signed-off-by: Arnau Mora <[email protected]> * Show local time and UTC of timestamp --------- Signed-off-by: Arnau Mora <[email protected]> Co-authored-by: Ricki Hirner <[email protected]>
1 parent a56d42d commit 6be42d4

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

app/src/main/kotlin/at/bitfire/davdroid/ui/DebugInfoActivity.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import androidx.activity.compose.setContent
1212
import androidx.appcompat.app.AppCompatActivity
1313
import androidx.core.app.ShareCompat
1414
import androidx.core.content.FileProvider
15+
import androidx.core.content.IntentCompat
1516
import at.bitfire.davdroid.BuildConfig
1617
import at.bitfire.davdroid.R
1718
import com.google.common.base.Ascii
1819
import dagger.hilt.android.AndroidEntryPoint
1920
import okhttp3.HttpUrl
2021
import java.io.File
22+
import java.time.Instant
2123

2224
/**
2325
* Debug info activity. Provides verbose information for debugging and support. Should enable users
@@ -50,6 +52,9 @@ class DebugInfoActivity : AppCompatActivity() {
5052

5153
/** URL of remote resource related to the problem (plain-text [String]) */
5254
private const val EXTRA_REMOTE_RESOURCE = "remoteResource"
55+
56+
/** A timestamp of the moment at which the error took place. */
57+
private const val EXTRA_TIMESTAMP = "timestamp"
5358
}
5459

5560
override fun onCreate(savedInstanceState: Bundle?) {
@@ -58,12 +63,13 @@ class DebugInfoActivity : AppCompatActivity() {
5863

5964
setContent {
6065
DebugInfoScreen(
61-
account = extras?.getParcelable(EXTRA_ACCOUNT),
66+
account = IntentCompat.getParcelableExtra(intent, EXTRA_ACCOUNT, Account::class.java),
6267
authority = extras?.getString(EXTRA_AUTHORITY),
63-
cause = extras?.getSerializable(EXTRA_CAUSE) as? Throwable,
68+
cause = IntentCompat.getParcelableExtra(intent, EXTRA_ACCOUNT, Throwable::class.java),
6469
localResource = extras?.getString(EXTRA_LOCAL_RESOURCE),
6570
remoteResource = extras?.getString(EXTRA_REMOTE_RESOURCE),
6671
logs = extras?.getString(EXTRA_LOGS),
72+
timestamp = extras?.getLong(EXTRA_TIMESTAMP),
6773
onShareZipFile = ::shareZipFile,
6874
onViewFile = ::viewFile,
6975
onNavUp = ::onSupportNavigateUp
@@ -132,6 +138,7 @@ class DebugInfoActivity : AppCompatActivity() {
132138
}
133139

134140
val intent = Intent(context, DebugInfoActivity::class.java)
141+
.putExtra(EXTRA_TIMESTAMP, Instant.now().epochSecond)
135142

136143
fun newTask(): IntentBuilder {
137144
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

app/src/main/kotlin/at/bitfire/davdroid/ui/DebugInfoGenerator.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ import dagger.hilt.android.qualifiers.ApplicationContext
5050
import org.dmfs.tasks.contract.TaskContract
5151
import java.io.PrintWriter
5252
import java.io.Writer
53+
import java.time.Instant
54+
import java.time.ZoneId
55+
import java.time.ZoneOffset
56+
import java.time.format.DateTimeFormatter
5357
import java.util.TimeZone
5458
import java.util.logging.Level
5559
import java.util.logging.Logger
5660
import javax.inject.Inject
57-
import kotlin.collections.filter
58-
import kotlin.collections.orEmpty
59-
import kotlin.text.removePrefix
6061
import kotlin.use
6162
import at.bitfire.ical4android.util.MiscUtils.asSyncAdapter as asCalendarSyncAdapter
6263
import at.bitfire.vcard4android.Utils.asSyncAdapter as asContactsSyncAdapter
@@ -79,12 +80,23 @@ class DebugInfoGenerator @Inject constructor(
7980
cause: Throwable?,
8081
localResource: String?,
8182
remoteResource: String?,
83+
timestamp: Long?,
8284
writer: PrintWriter
8385
) {
8486
writer.println("--- BEGIN DEBUG INFO ---")
8587
writer.println()
8688

87-
// begin with most specific information
89+
// begin with a timestamp to know when the error occurred
90+
if (timestamp != null) {
91+
val instant = Instant.ofEpochSecond(timestamp)
92+
writer.println("NOTIFICATION TIME")
93+
val iso = DateTimeFormatter.ISO_OFFSET_DATE_TIME
94+
writer.println("Local time: ${instant.atZone(ZoneId.systemDefault()).format(iso)}")
95+
writer.println("UTC: ${instant.atZone(ZoneOffset.UTC).format(iso)}")
96+
writer.println()
97+
}
98+
99+
// continue with most specific information
88100
if (syncAccount != null || syncAuthority != null) {
89101
writer.append("SYNCHRONIZATION INFO\n")
90102
if (syncAccount != null)

app/src/main/kotlin/at/bitfire/davdroid/ui/DebugInfoModel.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class DebugInfoModel @AssistedInject constructor(
4242
val cause: Throwable?,
4343
val localResource: String?,
4444
val remoteResource: String?,
45-
val logs: String?
45+
val logs: String?,
46+
val timestamp: Long?
4647
)
4748

4849
@AssistedFactory
@@ -102,7 +103,8 @@ class DebugInfoModel @AssistedInject constructor(
102103
syncAuthority = details.authority,
103104
cause = details.cause,
104105
localResource = details.localResource,
105-
remoteResource = details.remoteResource
106+
remoteResource = details.remoteResource,
107+
timestamp = details.timestamp
106108
)
107109
}
108110
}
@@ -112,7 +114,14 @@ class DebugInfoModel @AssistedInject constructor(
112114
*
113115
* Note: Part of this method and all of it's helpers (listed below) should probably be extracted in the future
114116
*/
115-
private fun generateDebugInfo(syncAccount: Account?, syncAuthority: String?, cause: Throwable?, localResource: String?, remoteResource: String?) {
117+
private fun generateDebugInfo(
118+
syncAccount: Account?,
119+
syncAuthority: String?,
120+
cause: Throwable?,
121+
localResource: String?,
122+
remoteResource: String?,
123+
timestamp: Long?
124+
) {
116125
val debugInfoFile = File(LogFileHandler.debugDir(context), FILE_DEBUG_INFO)
117126
debugInfoFile.printWriter().use { writer ->
118127
debugInfoGenerator(
@@ -121,6 +130,7 @@ class DebugInfoModel @AssistedInject constructor(
121130
cause = cause,
122131
localResource = localResource,
123132
remoteResource = remoteResource,
133+
timestamp = timestamp,
124134
writer = writer
125135
)
126136
}

app/src/main/kotlin/at/bitfire/davdroid/ui/DebugInfoScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ fun DebugInfoScreen(
5858
localResource: String?,
5959
remoteResource: String?,
6060
logs: String?,
61+
timestamp: Long?,
6162
onShareZipFile: (File) -> Unit,
6263
onViewFile: (File) -> Unit,
6364
onNavUp: () -> Unit
@@ -70,7 +71,8 @@ fun DebugInfoScreen(
7071
cause = cause,
7172
localResource = localResource,
7273
remoteResource = remoteResource,
73-
logs = logs
74+
logs = logs,
75+
timestamp = timestamp
7476
))
7577
}
7678
)

0 commit comments

Comments
 (0)