diff --git a/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt index ce7d7294a..7f01d76f6 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AboutActivity.kt @@ -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 . */ + 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) { diff --git a/app/src/main/java/com/keylesspalace/tusky/util/LogReader.kt b/app/src/main/java/com/keylesspalace/tusky/util/LogReader.kt new file mode 100644 index 000000000..5925ec089 --- /dev/null +++ b/app/src/main/java/com/keylesspalace/tusky/util/LogReader.kt @@ -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 . */ + +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) + } + } +} diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 2d55b693e..8b04fa466 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -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" /> +