Fix TransactionTooLargeException

This commit is contained in:
Mygod
2018-02-21 21:24:03 -08:00
parent dea724ffb6
commit ca9398c04b
3 changed files with 40 additions and 22 deletions

View File

@@ -52,6 +52,16 @@
<action android:name="android.service.quicksettings.action.QS_TILE" /> <action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter> </intent-filter>
</service> </service>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="be.mygod.vpnhotspot.log"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/log_paths" />
</provider>
</application> </application>
</manifest> </manifest>

View File

@@ -6,13 +6,13 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.support.customtabs.CustomTabsIntent import android.support.customtabs.CustomTabsIntent
import android.support.v4.content.ContextCompat import android.support.v4.content.ContextCompat
import android.support.v4.content.FileProvider
import android.support.v4.content.LocalBroadcastManager import android.support.v4.content.LocalBroadcastManager
import android.widget.Toast import android.widget.Toast
import be.mygod.vpnhotspot.net.Routing import be.mygod.vpnhotspot.net.Routing
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers
import java.io.File
import java.io.IOException import java.io.IOException
import java.io.PrintWriter
import java.io.StringWriter
class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() { class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
private val customTabsIntent by lazy { private val customTabsIntent by lazy {
@@ -27,27 +27,31 @@ class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
true true
} }
findPreference("misc.logcat").setOnPreferenceClickListener { findPreference("misc.logcat").setOnPreferenceClickListener {
fun handle(e: IOException): String { val activity = activity!!
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show() val logDir = File(activity.cacheDir, "log")
val writer = StringWriter() logDir.mkdir()
e.printStackTrace(PrintWriter(writer)) val logFile = File.createTempFile("vpnhotspot-", ".log", logDir)
return writer.toString() logFile.printWriter().use { writer ->
writer.write("${BuildConfig.VERSION_CODE} is running on API ${Build.VERSION.SDK_INT}\n\n")
try {
writer.write(Runtime.getRuntime().exec(arrayOf("logcat", "-d"))
.inputStream.bufferedReader().readText())
} catch (e: IOException) {
e.printStackTrace(writer)
}
writer.write("\n")
try {
writer.write(Routing.dump())
} catch (e: IOException) {
e.printStackTrace(writer)
}
} }
val logcat = try { startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND)
Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.bufferedReader().readText() .setType("text/x-log")
} catch (e: IOException) { .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
handle(e) .putExtra(Intent.EXTRA_STREAM,
} FileProvider.getUriForFile(activity, "be.mygod.vpnhotspot.log", logFile)),
val debug = try { getString(R.string.abc_shareactionprovider_share_with)))
Routing.dump()
} catch (e: IOException) {
handle(e)
}
val intent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT,
"${BuildConfig.VERSION_CODE} running on ${Build.VERSION.SDK_INT}\n$logcat\n$debug")
startActivity(Intent.createChooser(intent, getString(R.string.abc_shareactionprovider_share_with)))
true true
} }
findPreference("misc.source").setOnPreferenceClickListener { findPreference("misc.source").setOnPreferenceClickListener {

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path name="log" path="log/"/>
</paths>