summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/notification/NotificationChannelManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/notification/NotificationChannelManager.java')
-rw-r--r--java/com/android/dialer/notification/NotificationChannelManager.java45
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);