Skip to content

Commit d6c4cab

Browse files
Migrated logging module from Java to Kotlin (commons-app#5972)
* Migrated logging module from Java to Kotlin * Rename .java to .kt --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
1 parent 1afff73 commit d6c4cab

11 files changed

+500
-508
lines changed

app/src/main/java/fr/free/nrw/commons/logging/CommonsLogSender.java

-105
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package fr.free.nrw.commons.logging
2+
3+
import android.content.Context
4+
5+
import android.os.Bundle
6+
import javax.inject.Inject
7+
import javax.inject.Singleton
8+
9+
import fr.free.nrw.commons.auth.SessionManager
10+
import fr.free.nrw.commons.utils.ConfigUtils
11+
import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha
12+
import fr.free.nrw.commons.utils.DeviceInfoUtil
13+
import org.acra.data.CrashReportData
14+
15+
16+
/**
17+
* Class responsible for sending logs to developers
18+
*/
19+
@Singleton
20+
class CommonsLogSender @Inject constructor(
21+
private val sessionManager: SessionManager,
22+
private val context: Context
23+
) : LogsSender(sessionManager) {
24+
25+
26+
companion object {
27+
private const val LOGS_PRIVATE_EMAIL = "commons-app-android-private@googlegroups.com"
28+
private const val LOGS_PRIVATE_EMAIL_SUBJECT = "Commons Android App (%s) Logs"
29+
private const val BETA_LOGS_PRIVATE_EMAIL_SUBJECT = "Commons Beta Android App (%s) Logs"
30+
}
31+
32+
init {
33+
val isBeta = ConfigUtils.isBetaFlavour
34+
logFileName = if (isBeta) "CommonsBetaAppLogs.zip" else "CommonsAppLogs.zip"
35+
val emailSubjectFormat = if (isBeta)
36+
BETA_LOGS_PRIVATE_EMAIL_SUBJECT
37+
else
38+
LOGS_PRIVATE_EMAIL_SUBJECT
39+
emailSubject = emailSubjectFormat.format(sessionManager.userName)
40+
emailBody = getExtraInfo()
41+
mailTo = LOGS_PRIVATE_EMAIL
42+
}
43+
44+
/**
45+
* Attach any extra meta information about the user or device that might help in debugging.
46+
* @return String with extra meta information useful for debugging.
47+
*/
48+
public override fun getExtraInfo(): String {
49+
return buildString {
50+
// Getting API Level
51+
append("API level: ")
52+
.append(DeviceInfoUtil.getAPILevel())
53+
.append("\n")
54+
55+
// Getting Android Version
56+
append("Android version: ")
57+
.append(DeviceInfoUtil.getAndroidVersion())
58+
.append("\n")
59+
60+
// Getting Device Manufacturer
61+
append("Device manufacturer: ")
62+
.append(DeviceInfoUtil.getDeviceManufacturer())
63+
.append("\n")
64+
65+
// Getting Device Model
66+
append("Device model: ")
67+
.append(DeviceInfoUtil.getDeviceModel())
68+
.append("\n")
69+
70+
// Getting Device Name
71+
append("Device: ")
72+
.append(DeviceInfoUtil.getDevice())
73+
.append("\n")
74+
75+
// Getting Network Type
76+
append("Network type: ")
77+
.append(DeviceInfoUtil.getConnectionType(context))
78+
.append("\n")
79+
80+
// Getting App Version
81+
append("App version name: ")
82+
.append(context.getVersionNameWithSha())
83+
.append("\n")
84+
85+
// Getting Username
86+
append("User name: ")
87+
.append(sessionManager.userName)
88+
.append("\n")
89+
}
90+
}
91+
92+
/**
93+
* Determines if the log sending process requires the app to be in the foreground.
94+
* @return False as it does not require foreground execution.
95+
*/
96+
override fun requiresForeground(): Boolean = false
97+
98+
/**
99+
* Sends logs to developers. Implementation can be extended.
100+
*/
101+
override fun send(
102+
context: Context,
103+
errorContent: CrashReportData,
104+
extras: Bundle) {
105+
// Add logic here if needed.
106+
}
107+
}

app/src/main/java/fr/free/nrw/commons/logging/FileLoggingTree.java

-145
This file was deleted.

0 commit comments

Comments
 (0)