mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-03-01 05:48:22 +03:00
BraveNewPipe: try to circumvent TransactionTooLargeException.
As workaround internally we use GZIP to reduce the amount of data that is put as in intent.putExtra(). It has to be tested if that compressing takes to much time and truncate here already. As later on if we share on the ErrorActivity we have to truncate the traces to around 100Kb as it otherwise crash there.
This commit is contained in:
parent
f44a2f594c
commit
83b691d01b
4 changed files with 81 additions and 1 deletions
|
@ -0,0 +1,33 @@
|
|||
package org.schabi.newpipe.error;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class BraveErrorActivityHelper {
|
||||
|
||||
private BraveErrorActivityHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip some traces as we might get TransactionTooLargeException exception.
|
||||
*
|
||||
* @param stackTraces the full stack traces
|
||||
* @return the truncated traces list that will not crash the Binder or whatever.
|
||||
*/
|
||||
public static List<String> truncateAsNeeded(final String[] stackTraces) {
|
||||
final int limit = 104857; // limit to around 100k
|
||||
|
||||
int size = 0;
|
||||
final List<String> finalList = new ArrayList<>();
|
||||
|
||||
for (final String trace : stackTraces) {
|
||||
if (limit < size) {
|
||||
finalList.add("BraveNewPipe TRUNCATED trace");
|
||||
break;
|
||||
}
|
||||
size += trace.length();
|
||||
finalList.add(trace);
|
||||
}
|
||||
return finalList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package org.schabi.newpipe.error
|
||||
|
||||
import android.os.Parcel
|
||||
import kotlinx.parcelize.Parceler
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.zip.GZIPInputStream
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
/**
|
||||
* The binder can not handle to much data and throws TransactionTooLargeException.
|
||||
*
|
||||
* This Parceler tries to skip this fact with temporary gzip the data. Seems to
|
||||
* work -- but sending over eMail still needs some truncating
|
||||
* see {@link BraveErrorActivityHelper}.
|
||||
*/
|
||||
object BraveErrorInfoTracesParceler : Parceler<Array<String>> {
|
||||
override fun create(parcel: Parcel): Array<String> {
|
||||
val byteArray = ByteArray(parcel.readInt())
|
||||
parcel.readByteArray(byteArray)
|
||||
val unzipped = ungzip(byteArray)
|
||||
|
||||
return unzipped.split(";").toTypedArray()
|
||||
}
|
||||
|
||||
override fun Array<String>.write(parcel: Parcel, flags: Int) {
|
||||
val result = this.reduce { result, nr -> "$result; $nr" }
|
||||
val zipped = gzip(result)
|
||||
parcel.writeInt(zipped.size)
|
||||
parcel.writeByteArray(zipped)
|
||||
}
|
||||
|
||||
private fun gzip(content: String): ByteArray {
|
||||
val byteOutputStream = ByteArrayOutputStream()
|
||||
GZIPOutputStream(byteOutputStream)
|
||||
.bufferedWriter(StandardCharsets.UTF_8).use { it.write(content) }
|
||||
|
||||
return byteOutputStream.toByteArray()
|
||||
}
|
||||
|
||||
private fun ungzip(content: ByteArray): String =
|
||||
GZIPInputStream(content.inputStream())
|
||||
.bufferedReader(StandardCharsets.UTF_8).use { it.readText() }
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.schabi.newpipe.error;
|
||||
|
||||
import static org.schabi.newpipe.error.BraveErrorActivityHelper.truncateAsNeeded;
|
||||
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
||||
|
||||
import android.app.Activity;
|
||||
|
@ -239,7 +240,7 @@ public class ErrorActivity extends AppCompatActivity {
|
|||
.value("version", BuildConfig.VERSION_NAME)
|
||||
.value("os", getOsString())
|
||||
.value("time", currentTimeStamp)
|
||||
.array("exceptions", Arrays.asList(errorInfo.getStackTraces()))
|
||||
.array("exceptions", truncateAsNeeded(errorInfo.getStackTraces()))
|
||||
.value("user_comment", activityErrorBinding.errorCommentBox.getText()
|
||||
.toString())
|
||||
.end()
|
||||
|
|
|
@ -5,6 +5,7 @@ import androidx.annotation.StringRes
|
|||
import com.google.android.exoplayer2.ExoPlaybackException
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import kotlinx.parcelize.TypeParceler
|
||||
import org.schabi.newpipe.R
|
||||
import org.schabi.newpipe.extractor.Info
|
||||
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
||||
|
@ -16,6 +17,7 @@ import org.schabi.newpipe.util.ServiceHelper
|
|||
|
||||
@Parcelize
|
||||
class ErrorInfo(
|
||||
@TypeParceler<Array<String>, BraveErrorInfoTracesParceler>()
|
||||
val stackTraces: Array<String>,
|
||||
val userAction: UserAction,
|
||||
val serviceName: String,
|
||||
|
|
Loading…
Add table
Reference in a new issue