diff options
author | Eric Erfanian <erfanian@google.com> | 2017-04-06 23:16:42 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-06 23:16:42 +0000 |
commit | 28188020060d1ad3304dfa0367486ff5bb35da62 (patch) | |
tree | 8d08d4f2292aa84dc435d455891e7ab633d95a25 /java/com/android/dialer/notification/NotificationChannelManager.java | |
parent | 34e183cfd77f68e0ade42d2080c76f54a319430d (diff) | |
parent | 01a86435499d66b267765f89b7dd9c83c158ddfe (diff) |
Update AOSP Dialer source from internal google3 repository at cl/152373142. am: d8046e520a
am: 01a8643549
Change-Id: Ib92542e6b88bc8d8906982280244661ed7dbca8f
Diffstat (limited to 'java/com/android/dialer/notification/NotificationChannelManager.java')
-rw-r--r-- | java/com/android/dialer/notification/NotificationChannelManager.java | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/java/com/android/dialer/notification/NotificationChannelManager.java b/java/com/android/dialer/notification/NotificationChannelManager.java index 5cae3d8c8..f23c02ad3 100644 --- a/java/com/android/dialer/notification/NotificationChannelManager.java +++ b/java/com/android/dialer/notification/NotificationChannelManager.java @@ -53,25 +53,15 @@ public class NotificationChannelManager { * Set the channel of notification appropriately. Will create the channel if it does not already * exist. Safe to call pre-O (will no-op). * - * <p>phoneAccount should only be null if channelName is {@link Channel#MISC}. + * <p>phoneAccount should only be null if channelName is {@link Channel#MISC} or {@link + * Channel#MISSED_CALL} since these do not have account-specific settings. */ public static void applyChannel( @NonNull Notification.Builder notification, @NonNull Context context, @Channel String channelName, @Nullable PhoneAccountHandle phoneAccount) { - if (phoneAccount == null) { - if (!Channel.MISC.equals(channelName)) { - IllegalArgumentException exception = - new IllegalArgumentException( - "Phone account handle must not be null unless on Channel.MISC"); - if (BuildType.get() >= BuildType.RELEASE) { - LogUtil.e("NotificationChannelManager.applyChannel", null, exception); - } else { - throw exception; - } - } - } + checkNullity(channelName, phoneAccount); if (BuildCompat.isAtLeastO()) { NotificationChannel channel = @@ -80,6 +70,33 @@ public class NotificationChannelManager { } } + private static void checkNullity( + @Channel String channelName, @Nullable PhoneAccountHandle phoneAccount) { + if (phoneAccount != null || channelAllowsNullPhoneAccountHandle(channelName)) { + return; + } + + // TODO (b/36568553): don't throw an exception once most cases have been identified + IllegalArgumentException exception = + new IllegalArgumentException( + "Phone account handle must not be null on channel " + channelName); + if (BuildType.get() == BuildType.RELEASE) { + LogUtil.e("NotificationChannelManager.applyChannel", null, exception); + } else { + throw exception; + } + } + + private static boolean channelAllowsNullPhoneAccountHandle(@Channel String channelName) { + switch (channelName) { + case Channel.MISC: + case Channel.MISSED_CALL: + return true; + default: + return false; + } + } + /** The base Channel IDs for {@link NotificationChannel} */ @Retention(RetentionPolicy.SOURCE) @StringDef({ @@ -136,7 +153,7 @@ public class NotificationChannelManager { (account == null) ? phoneAccountHandle.getId() : account.getLabel().toString()); getNotificationManager(context) .createNotificationChannelGroup(group); // No-op if already exists - } else if (!Channel.MISC.equals(channelName)) { + } else if (!channelAllowsNullPhoneAccountHandle(channelName)) { LogUtil.w( "NotificationChannelManager.createChannel", "Null PhoneAccountHandle with channel " + channelName); |