willowtreeapps / Hyperion-Android

App Debugging & Inspection Tool for Android
MIT License
1.95k stars 144 forks source link

TransactionTooLargeException thrown when clicking on "SHARE" from Timber plugin #184

Open TylerMcCraw opened 5 years ago

TylerMcCraw commented 5 years ago

This exception was thrown when clicking on the "SHARE" button from the Hyperion Timber plugin. Our logs were 2172540 bytes (almost 2.2 MB), which isn't very large, but obviously is an accumulation of a decently significant amount of logging.

Using Hyperion version 0.9.27 Crash happened on Samsung Galaxy S9 (Android 9.0) and a Google Pixel 2 XL (Android 10.0).

Stacktrace:

Caused by android.os.TransactionTooLargeException: data parcel size 2172540 bytes
       at android.os.BinderProxy.transactNative(BinderProxy.java)
       at android.os.BinderProxy.transact + 510(BinderProxy.java:510)
       at android.app.IActivityTaskManager$Stub$Proxy.startActivity + 3847(IActivityTaskManager.java:3847)
       at android.app.Instrumentation.execStartActivity + 1712(Instrumentation.java:1712)
       at android.app.Activity.startActivityForResult + 5192(Activity.java:5192)
       at androidx.fragment.app.FragmentActivity.startActivityForResult + 676(FragmentActivity.java:676)
       at android.app.Activity.startActivityForResult + 5150(Activity.java:5150)
       at androidx.fragment.app.FragmentActivity.startActivityForResult + 663(FragmentActivity.java:663)
       at android.app.Activity.startActivity + 5521(Activity.java:5521)
       at android.app.Activity.startActivity + 5489(Activity.java:5489)
       at androidx.core.app.ShareCompat$IntentBuilder.startChooser + 357(ShareCompat.java:357)
       at com.willowtreeapps.hyperion.timber.list.TimberLogListActivity.collectLogs + 89(TimberLogListActivity.java:89)
       at com.willowtreeapps.hyperion.timber.list.TimberLogListActivity.onClick + 68(TimberLogListActivity.java:68)
       at android.view.View.performClick + 7140(View.java:7140)
       at android.view.View.performClickInternal + 7117(View.java:7117)
       at android.view.View.access$3500 + 801(View.java:801)
       at android.view.View$PerformClick.run + 27351(View.java:27351)
       at android.os.Handler.handleCallback + 883(Handler.java:883)
       at android.os.Handler.dispatchMessage + 100(Handler.java:100)
       at android.os.Looper.loop + 214(Looper.java:214)
       at android.app.ActivityThread.main + 7356(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 492(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main + 930(ZygoteInit.java:930)
Fatal Exception: java.lang.RuntimeException: Failure from system
       at android.app.Instrumentation.execStartActivity + 1718(Instrumentation.java:1718)
       at android.app.Activity.startActivityForResult + 5192(Activity.java:5192)
       at androidx.fragment.app.FragmentActivity.startActivityForResult + 676(FragmentActivity.java:676)
       at android.app.Activity.startActivityForResult + 5150(Activity.java:5150)
       at androidx.fragment.app.FragmentActivity.startActivityForResult + 663(FragmentActivity.java:663)
       at android.app.Activity.startActivity + 5521(Activity.java:5521)
       at android.app.Activity.startActivity + 5489(Activity.java:5489)
       at androidx.core.app.ShareCompat$IntentBuilder.startChooser + 357(ShareCompat.java:357)
       at com.willowtreeapps.hyperion.timber.list.TimberLogListActivity.collectLogs + 89(TimberLogListActivity.java:89)
       at com.willowtreeapps.hyperion.timber.list.TimberLogListActivity.onClick + 68(TimberLogListActivity.java:68)
       at android.view.View.performClick + 7140(View.java:7140)
       at android.view.View.performClickInternal + 7117(View.java:7117)
       at android.view.View.access$3500 + 801(View.java:801)
       at android.view.View$PerformClick.run + 27351(View.java:27351)
       at android.os.Handler.handleCallback + 883(Handler.java:883)
       at android.os.Handler.dispatchMessage + 100(Handler.java:100)
       at android.os.Looper.loop + 214(Looper.java:214)
       at android.app.ActivityThread.main + 7356(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 492(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main + 930(ZygoteInit.java:930)
TylerMcCraw commented 5 years ago

The issue is here: https://github.com/willowtreeapps/Hyperion-Android/blob/develop/hyperion-timber/src/main/java/com/willowtreeapps/hyperion/timber/list/TimberLogListActivity.java#L125

My guess is that the intent builder can't handle loading text that is this large.

Solution could be to instead pass a file containing the contents of the logs with the intent.

val logsFile = writeToFile(logs.toString())
val uriToLogs = FileProvider.getUriForFile(context, FILES_AUTHORITY, logsFile)
var shareIntent = ShareCompat.IntentBuilder.from(activity).setStream(uriToLogs).getIntent()
// Provide read access
shareIntent.setData(uriToImage)
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
ToxicBakery commented 5 years ago

Did you modify the circular buffer limit in your use case? The default is 200 messages so you're average over 10kB per message which is pretty hefty.

The file writing concept is sound though as an easy fix. If you wanted to create a PR for that, I wouldn't have any issues approving it.

TylerMcCraw commented 5 years ago

I did not modify the buffer limit. I think that it's possibly due to some of the individual messages being very large in size.

I'll try to get to a PR for that as soon as I can! Is there any concern about adding FileProvider authority with specific file paths for Hyperion? Are there any other Hyperion plugins that do this already?

ToxicBakery commented 5 years ago

Nothing comes to mind. @nishtahir you have any problems with this change?