diff options
| author | 2018-11-30 12:21:37 +0000 | |
|---|---|---|
| committer | 2018-11-30 12:21:37 +0000 | |
| commit | 0eca3fe5161dfc064a37487a7e75e8316f0ebf06 (patch) | |
| tree | 70118074250d793608f0c5452fb1552a42d920dd | |
| parent | 4e0a3ffac16a7c4bede635d05335c0ff46db4b1f (diff) | |
| parent | c98b163de0a35abb8b5de88b3e18db5ec56def59 (diff) | |
Merge "Avoid NPE when adding a smart action with a null icon."
| -rw-r--r-- | core/java/android/app/Notification.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 5002a8125d44..16d35802a9f6 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1693,11 +1693,30 @@ public class Notification implements Parcelable } /** + * Throws an NPE if we are building a contextual action missing one of the fields + * necessary to display the action. + */ + private void checkContextualActionNullFields() { + if (mSemanticAction != SEMANTIC_ACTION_CONTEXTUAL_SUGGESTION) return; + + if (mIcon == null) { + throw new NullPointerException("Contextual Actions must contain a valid icon"); + } + + if (mIntent == null) { + throw new NullPointerException( + "Contextual Actions must contain a valid PendingIntent"); + } + } + + /** * Combine all of the options that have been set and return a new {@link Action} * object. * @return the built action */ public Action build() { + checkContextualActionNullFields(); + ArrayList<RemoteInput> dataOnlyInputs = new ArrayList<>(); RemoteInput[] previousDataInputs = (RemoteInput[]) mExtras.getParcelableArray(EXTRA_DATA_ONLY_INPUTS); |