Upload crash logs to ctrl-v

This commit is contained in:
Suphon Thanakornpakapong committed 2022-05-13 16:33:15 +07:00
1 parent 24ff2efa8f
commit 42c5bc0282
6 files changed
+43 -5

No files matched your search

+2
View File
@@ -373,6 +373,8 @@ dependencies {
implementation 'me.xdrop:fuzzywuzzy:1.3.1'
implementation "com.patrykmichalik:preference-manager:1.0.4"
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
+1
View File
@@ -176,6 +176,7 @@
<string name="lawnchair_bug_report">Lawnchair Bug Report</string>
<string name="crash_report_notif_title">%1$s Crashed</string>
<string name="action_upload">Upload to Dogbin</string>
<string name="action_upload_crash_report">Upload Crash Log</string>
<string name="action_copy_link">Copy Link</string>
<string name="action_copy">Copy</string>
@@ -122,7 +122,7 @@ class BugReportReceiver : BroadcastReceiver() {
.putExtra("report", report)
val pendingUploadIntent = PendingIntent.getBroadcast(
context, notificationId, uploadIntent, FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE)
val uploadText = if (report.uploadError) R.string.action_upload_error else R.string.action_upload
val uploadText = if (report.uploadError) R.string.action_upload_error else R.string.action_upload_crash_report
val uploadIcon = Icon.createWithResource(context, R.drawable.ic_upload)
val uploadActionBuilder = Notification.Action.Builder(
uploadIcon, context.getString(uploadText), pendingUploadIntent)
@@ -0,0 +1,30 @@
package app.lawnchair.bugreport
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
interface CtrlVService {
@FormUrlEncoded
@POST("api")
suspend fun upload(
@Field("title") title: String,
@Field("content") content: String
): UploadResult
companion object {
fun create(): CtrlVService = Retrofit.Builder()
.baseUrl("https://api.ctrl-v.app/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create()
}
}
data class UploadResult(
val hash: String
)
@@ -36,8 +36,9 @@ class UploaderService : Service() {
while (uploadQueue.isNotEmpty()) {
val report = uploadQueue.poll()!!
try {
report.link = UploaderUtils.upload(report.contents)
report.link = UploaderUtils.upload(this, report)
} catch (e: Throwable) {
Log.d("UploaderService", "failed to upload bug report", e)
report.uploadError = true
} finally {
sendBroadcast(Intent(this, BugReportReceiver::class.java)
@@ -1,11 +1,15 @@
package app.lawnchair.bugreport
import android.content.Context
object UploaderUtils {
const val isAvailable = false
private val ctrlVService = CtrlVService.create()
const val isAvailable = true
@Suppress("BlockingMethodInNonBlockingContext")
suspend fun upload(content: String): String {
TODO("find an uploader service")
suspend fun upload(context: Context, report: BugReport): String {
val result = ctrlVService.upload(report.getTitle(context), report.contents)
return "https://ctrl-v.app/raw/${result.hash}"
}
}