1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.dialer.notification.missedcalls;
17 
18 import android.content.Context;
19 import android.net.Uri;
20 import android.support.annotation.NonNull;
21 import android.support.annotation.Nullable;
22 import com.android.dialer.common.LogUtil;
23 import com.android.dialer.notification.DialerNotificationManager;
24 import com.android.dialer.notification.NotificationManagerUtils;
25 
26 /** Cancels missed calls notifications. */
27 public final class MissedCallNotificationCanceller {
28 
29   /** Cancels all missed call notifications. */
cancelAll(@onNull Context context)30   public static void cancelAll(@NonNull Context context) {
31     NotificationManagerUtils.cancelAllInGroup(context, MissedCallConstants.GROUP_KEY);
32   }
33 
34   /** Cancels a missed call notification for a single call. */
cancelSingle(@onNull Context context, @Nullable Uri callUri)35   public static void cancelSingle(@NonNull Context context, @Nullable Uri callUri) {
36     if (callUri == null) {
37       LogUtil.e(
38           "MissedCallNotificationCanceller.cancelSingle",
39           "unable to cancel notification, uri is null");
40       return;
41     }
42     // This will also dismiss the group summary if there are no more missed call notifications.
43     DialerNotificationManager.cancel(
44         context,
45         MissedCallNotificationTags.getNotificationTagForCallUri(callUri),
46         MissedCallConstants.NOTIFICATION_ID);
47   }
48 }
49