summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Louis Chang <louischang@google.com> 2022-10-13 10:06:31 +0000
committer Louis Chang <louischang@google.com> 2022-10-17 02:21:35 +0000
commitf17bbfbb722b803dc07de5605244111012df17c7 (patch)
tree07dfd7d959f9251c2abd6a2e466785cd732ad402
parentf2432024f9abbe99ad01ff1ec675ad58bbaa5fc8 (diff)
Embed the bundle states into exception message
... in order to help developers debug the binder transaction failure due to TransactionTooLargeException. Bug: 253942493 Test: verified locally Change-Id: I3c048cc31165de4a0e2fde1ffa7a58eab1d642f3
-rw-r--r--core/java/android/app/servertransaction/PendingTransactionActions.java44
1 files changed, 30 insertions, 14 deletions
diff --git a/core/java/android/app/servertransaction/PendingTransactionActions.java b/core/java/android/app/servertransaction/PendingTransactionActions.java
index a47fe821cd01..81747782cab2 100644
--- a/core/java/android/app/servertransaction/PendingTransactionActions.java
+++ b/core/java/android/app/servertransaction/PendingTransactionActions.java
@@ -25,11 +25,12 @@ import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.TransactionTooLargeException;
import android.util.Log;
-import android.util.LogWriter;
import android.util.Slog;
import com.android.internal.util.IndentingPrintWriter;
+import java.io.StringWriter;
+
/**
* Container that has data pending to be used at later stages of
* {@link android.app.servertransaction.ClientTransaction}.
@@ -134,6 +135,16 @@ public class PendingTransactionActions {
mDescription = description;
}
+ private String collectBundleStates() {
+ final StringWriter writer = new StringWriter();
+ final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
+ pw.println("Bundle stats:");
+ Bundle.dumpStats(pw, mState);
+ pw.println("PersistableBundle stats:");
+ Bundle.dumpStats(pw, mPersistentState);
+ return writer.toString().stripTrailing();
+ }
+
@Override
public void run() {
// Tell activity manager we have been stopped.
@@ -142,19 +153,24 @@ public class PendingTransactionActions {
// TODO(lifecycler): Use interface callback instead of AMS.
ActivityClient.getInstance().activityStopped(
mActivity.token, mState, mPersistentState, mDescription);
- } catch (RuntimeException ex) {
- // Dump statistics about bundle to help developers debug
- final LogWriter writer = new LogWriter(Log.WARN, TAG);
- final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ");
- pw.println("Bundle stats:");
- Bundle.dumpStats(pw, mState);
- pw.println("PersistableBundle stats:");
- Bundle.dumpStats(pw, mPersistentState);
-
- if (ex.getCause() instanceof TransactionTooLargeException
- && mActivity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) {
- Log.e(TAG, "App sent too much data in instance state, so it was ignored", ex);
- return;
+ } catch (RuntimeException runtimeException) {
+ // Collect the statistics about bundle
+ final String bundleStats = collectBundleStates();
+
+ RuntimeException ex = runtimeException;
+ if (ex.getCause() instanceof TransactionTooLargeException) {
+ // Embed the stats into exception message to help developers debug if the
+ // transaction size is too large.
+ final String message = ex.getMessage() + "\n" + bundleStats;
+ ex = new RuntimeException(message, ex.getCause());
+ if (mActivity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) {
+ Log.e(TAG, "App sent too much data in instance state, so it was ignored",
+ ex);
+ return;
+ }
+ } else {
+ // Otherwise, dump the stats anyway.
+ Log.w(TAG, bundleStats);
}
throw ex;
}