• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 
17 package com.android.systemui.statusbar.notification.collection.coordinator;
18 
19 import static android.app.NotificationManager.IMPORTANCE_MIN;
20 
21 import android.app.Notification;
22 
23 import com.android.systemui.statusbar.notification.collection.ListEntry;
24 import com.android.systemui.statusbar.notification.collection.NotifPipeline;
25 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
26 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope;
27 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner;
28 import com.android.systemui.statusbar.notification.stack.NotificationPriorityBucketKt;
29 
30 import javax.inject.Inject;
31 
32 /**
33  * Handles sectioning for foreground service notifications.
34  *  Puts non-min colorized foreground service notifications into the FGS section. See
35  *  {@link NotifCoordinators} for section ordering priority.
36  */
37 @CoordinatorScope
38 public class ColorizedFgsCoordinator implements Coordinator {
39     private static final String TAG = "ColorizedCoordinator";
40 
41     @Inject
ColorizedFgsCoordinator()42     public ColorizedFgsCoordinator() {
43     }
44 
45     @Override
attach(NotifPipeline pipeline)46     public void attach(NotifPipeline pipeline) {
47     }
48 
getSectioner()49     public NotifSectioner getSectioner() {
50         return mNotifSectioner;
51     }
52 
53 
54     /**
55      * Puts colorized foreground service and call notifications into its own section.
56      */
57     private final NotifSectioner mNotifSectioner = new NotifSectioner("ColorizedSectioner",
58             NotificationPriorityBucketKt.BUCKET_FOREGROUND_SERVICE) {
59         @Override
60         public boolean isInSection(ListEntry entry) {
61             NotificationEntry notificationEntry = entry.getRepresentativeEntry();
62             if (notificationEntry != null) {
63                 return isColorizedForegroundService(notificationEntry) || isCall(notificationEntry);
64             }
65             return false;
66         }
67 
68         private boolean isColorizedForegroundService(NotificationEntry entry) {
69             Notification notification = entry.getSbn().getNotification();
70             return notification.isForegroundService()
71                     && notification.isColorized()
72                     && entry.getImportance() > IMPORTANCE_MIN;
73         }
74 
75         private boolean isCall(NotificationEntry entry) {
76             Notification notification = entry.getSbn().getNotification();
77             return entry.getImportance() > IMPORTANCE_MIN
78                     && notification.isStyle(Notification.CallStyle.class);
79         }
80     };
81 }
82