From b1def70e00e0ece77234f4a8e1b2406d24e31efa Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Mon, 21 Jun 2021 16:37:56 -0400 Subject: [PATCH] Fix a security exception breaking notification inflation. Fixes: 188595459 Test: manual testing that snooze continues to work under basic circumstances. Change-Id: Ic1e2dcf3d70d5bc0174254c2f5acba25a459d62b --- core/java/android/app/Notification.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index ba0bc555eb57c..506dfe09f3fa0 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -5606,14 +5606,24 @@ public class Notification implements Parcelable final boolean snoozeEnabled = !hideSnoozeButton && mContext.getContentResolver() != null - && (Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1); + && isSnoozeSettingEnabled(); if (snoozeEnabled) { big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target, RemoteViews.MARGIN_BOTTOM, 0); } } + private boolean isSnoozeSettingEnabled() { + try { + return Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1; + } catch (SecurityException ex) { + // Most 3p apps can't access this snooze setting, so their NotificationListeners + // would be unable to create notification views if we propagated this exception. + return false; + } + } + /** * Returns the actions that are not contextual. */