Embed the bundle states into exception message am: f17bbfbb72

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20194892

Change-Id: I3f4fc7f9ba2e1f527222363b08c3781ef0288a89
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Louis Chang
2022-10-17 09:15:17 +00:00
committed by Automerger Merge Worker

View File

@@ -25,11 +25,12 @@ import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.os.TransactionTooLargeException; import android.os.TransactionTooLargeException;
import android.util.Log; import android.util.Log;
import android.util.LogWriter;
import android.util.Slog; import android.util.Slog;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import java.io.StringWriter;
/** /**
* Container that has data pending to be used at later stages of * Container that has data pending to be used at later stages of
* {@link android.app.servertransaction.ClientTransaction}. * {@link android.app.servertransaction.ClientTransaction}.
@@ -134,6 +135,16 @@ public class PendingTransactionActions {
mDescription = description; 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 @Override
public void run() { public void run() {
// Tell activity manager we have been stopped. // Tell activity manager we have been stopped.
@@ -142,20 +153,25 @@ public class PendingTransactionActions {
// TODO(lifecycler): Use interface callback instead of AMS. // TODO(lifecycler): Use interface callback instead of AMS.
ActivityClient.getInstance().activityStopped( ActivityClient.getInstance().activityStopped(
mActivity.token, mState, mPersistentState, mDescription); mActivity.token, mState, mPersistentState, mDescription);
} catch (RuntimeException ex) { } catch (RuntimeException runtimeException) {
// Dump statistics about bundle to help developers debug // Collect the statistics about bundle
final LogWriter writer = new LogWriter(Log.WARN, TAG); final String bundleStats = collectBundleStates();
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 RuntimeException ex = runtimeException;
&& mActivity.packageInfo.getTargetSdkVersion() < Build.VERSION_CODES.N) { if (ex.getCause() instanceof TransactionTooLargeException) {
Log.e(TAG, "App sent too much data in instance state, so it was ignored", ex); // 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; return;
} }
} else {
// Otherwise, dump the stats anyway.
Log.w(TAG, bundleStats);
}
throw ex; throw ex;
} }
} }