Add log sending functionality

This commit is contained in:
charlag 2020-04-12 18:07:51 +02:00
parent d44eada140
commit 5a850805d3
No known key found for this signature in database
GPG Key ID: 0BF7E6B320588360
4 changed files with 98 additions and 3 deletions

View File

@ -1,8 +1,22 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky
import android.content.Intent
import android.os.Bundle
import androidx.annotation.StringRes
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.method.LinkMovementMethod
@ -10,8 +24,12 @@ import android.text.style.URLSpan
import android.text.util.Linkify
import android.view.MenuItem
import android.widget.TextView
import androidx.annotation.StringRes
import androidx.core.content.FileProvider
import androidx.core.net.toFile
import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.util.CustomURLSpan
import com.keylesspalace.tusky.util.LogReader
import com.keylesspalace.tusky.util.hide
import kotlinx.android.synthetic.main.activity_about.*
import kotlinx.android.synthetic.main.toolbar_basic.*
@ -32,7 +50,7 @@ class AboutActivity : BottomSheetActivity(), Injectable {
versionTextView.text = getString(R.string.about_app_version, getString(R.string.app_name), BuildConfig.VERSION_NAME)
if(BuildConfig.CUSTOM_INSTANCE.isBlank()) {
if (BuildConfig.CUSTOM_INSTANCE.isBlank()) {
aboutPoweredByTusky.hide()
}
@ -48,6 +66,9 @@ class AboutActivity : BottomSheetActivity(), Injectable {
startActivityWithSlideInAnimation(Intent(this, LicenseActivity::class.java))
}
sendLogsButton.setOnClickListener {
sendLogs()
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -60,6 +81,20 @@ class AboutActivity : BottomSheetActivity(), Injectable {
return super.onOptionsItemSelected(item)
}
private fun sendLogs() {
val logFileUri = LogReader.getLogFile(this)
val shareFileUri = FileProvider.getUriForFile(applicationContext,
"${BuildConfig.APPLICATION_ID}.fileprovider", logFileUri.toFile())
val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, shareFileUri)
type = "text/plain"
}
startActivity(Intent.createChooser(sendIntent,
getText(R.string.action_send_logs)))
}
}
private fun TextView.setClickableTextWithoutUnderlines(@StringRes textId: Int) {

View File

@ -0,0 +1,46 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.util
import android.content.Context
import android.net.Uri
import java.io.File
import java.io.IOException
object LogReader {
fun getLogFile(context: Context): Uri {
return try {
val logFile = File(context.cacheDir, "log.txt")
logFile.delete()
logFile.createNewFile()
// -d means print and exit, -T gets last lines, -f outputs to file
val process = Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-T", "1500", "-f", logFile.absolutePath))
try {
process.waitFor()
} catch (ignored: InterruptedException) {
}
if (process.exitValue() != 0) {
val error: String = process.errorStream.bufferedReader().readText()
throw RuntimeException("Reading logs failed: " + process.exitValue() + ", " + error)
}
Uri.fromFile(logFile)
} catch (e: IOException) {
throw RuntimeException(e)
}
}
}

View File

@ -39,7 +39,8 @@
android:textColor="?android:attr/textColorPrimary"
android:textIsSelectable="true"
android:textSize="24sp"
android:textStyle="bold" />
android:textStyle="bold"
tools:text="@string/app_name" />
<TextView
android:id="@+id/aboutPoweredByTusky"
@ -116,6 +117,18 @@
android:textAllCaps="false"
android:textSize="16sp" />
<Button
android:id="@+id/sendLogsButton"
style="@style/TuskyButton.Outlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:lineSpacingMultiplier="1.2"
android:text="@string/action_send_logs"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="16sp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@ -43,6 +43,7 @@
<string name="title_saved_toot">Drafts</string>
<string name="title_scheduled_toot">Scheduled toots</string>
<string name="title_licenses">Licenses</string>
<string name="action_send_logs">Send logs</string>
<string name="status_username_format">\@%s</string>
<string name="status_boosted_format">%s boosted</string>