diff options
author | Jeff DeCew <jeffdq@google.com> | 2021-12-30 16:45:17 -0500 |
---|---|---|
committer | Jeff DeCew <jeffdq@google.com> | 2021-12-30 16:45:17 -0500 |
commit | a28572eb9da4208fa104f779ee6f0ff70c4743c0 (patch) | |
tree | 2b6b5cbe107f6a66ce7d80fa0e75de6790005890 /core | |
parent | b017001ae0f9f9cc3fbe6388eb33a67db26a54a0 (diff) |
Fix crash in RemoteViews w/ Bundle due to Parcel.allowSquashing
This fixes a failing CTS test, NotificationTemplateTest.
Fixes: 207741735
Bug: 212731590
Test: atest NotificationTemplateTest
Change-Id: Ide0241121d0824a2ba8c721c968e39f3c627f79d
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/widget/RemoteViews.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java index dfd853acaf0d..1784dcfc505f 100644 --- a/core/java/android/widget/RemoteViews.java +++ b/core/java/android/widget/RemoteViews.java @@ -301,6 +301,13 @@ public class RemoteViews implements Parcelable, Filter { public static final int FLAG_USE_LIGHT_BACKGROUND_LAYOUT = 4; /** + * A ReadWriteHelper which has the same behavior as ReadWriteHelper.DEFAULT, but which is + * intentionally a different instance in order to trick Bundle reader so that it doesn't allow + * lazy initialization. + */ + private static final Parcel.ReadWriteHelper ALTERNATIVE_DEFAULT = new Parcel.ReadWriteHelper(); + + /** * Used to restrict the views which can be inflated * * @see android.view.LayoutInflater.Filter#onLoadClass(java.lang.Class) @@ -1856,7 +1863,18 @@ public class RemoteViews implements Parcelable, Filter { this.value = in.readTypedObject(Bitmap.CREATOR); break; case BUNDLE: - this.value = in.readBundle(); + // Because we use Parcel.allowSquashing() when writing, and that affects + // how the contents of Bundles are written, we need to ensure the bundle is + // unparceled immediately, not lazily. Setting a custom ReadWriteHelper + // just happens to have that effect on Bundle.readFromParcel(). + // TODO(b/212731590): build this state tracking into Bundle + if (in.hasReadWriteHelper()) { + this.value = in.readBundle(); + } else { + in.setReadWriteHelper(ALTERNATIVE_DEFAULT); + this.value = in.readBundle(); + in.setReadWriteHelper(null); + } break; case INTENT: this.value = in.readTypedObject(Intent.CREATOR); |