Merge "Prevent ClassCastException" into sc-v2-dev am: c8f32a43b0 am: 570f42a60b

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

Change-Id: Ic8d3135c49411a63b7551060e3488925cd65306e