From 800ca4ac0c8405bdfd73a88d3398085a25d6770b Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 6 Jul 2018 12:02:38 -0400 Subject: [PATCH] Add boolean to check never occurring zen schedule rule validity Bug: 111167252 Test: manual Change-Id: If105898ae4299b1b24dfeb8476f8c35ff4b33ba4 --- .../service/notification/ZenModeConfig.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 5546e803342bd..df88e642a9707 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -1007,6 +1007,24 @@ public class ZenModeConfig implements Parcelable { return true; } + /** + * Returns whether the conditionId is a valid ScheduleCondition. + * If allowNever is true, this will return true even if the ScheduleCondition never occurs. + */ + public static boolean isValidScheduleConditionId(Uri conditionId, boolean allowNever) { + ScheduleInfo info; + try { + info = tryParseScheduleConditionId(conditionId); + } catch (NullPointerException | ArrayIndexOutOfBoundsException e) { + return false; + } + + if (info == null || (!allowNever && (info.days == null || info.days.length == 0))) { + return false; + } + return true; + } + public static ScheduleInfo tryParseScheduleConditionId(Uri conditionId) { final boolean isSchedule = conditionId != null && conditionId.getScheme().equals(Condition.SCHEME)