1 /*
2  * Copyright (C) 2021 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.legacy;
18 
19 import android.service.notification.NotificationListenerService.Ranking;
20 import android.service.notification.NotificationListenerService.RankingMap;
21 
22 import androidx.annotation.NonNull;
23 import androidx.annotation.Nullable;
24 
25 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
26 
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Comparator;
30 import java.util.List;
31 
32 /**
33  * Stub implementation that we use until we get passed the "real" one in the form of
34  * {@link com.android.systemui.statusbar.notification.collection.NotificationRankingManager}
35  */
36 public class LegacyNotificationRankerStub implements LegacyNotificationRanker {
37     private RankingMap mRankingMap = new RankingMap(new Ranking[] {});
38 
39     @NonNull
40     @Override
updateRanking( @ullable RankingMap newRankingMap, @NonNull Collection<NotificationEntry> entries, @NonNull String reason)41     public List<NotificationEntry> updateRanking(
42             @Nullable RankingMap newRankingMap,
43             @NonNull Collection<NotificationEntry> entries,
44             @NonNull String reason) {
45         if (newRankingMap != null) {
46             mRankingMap = newRankingMap;
47         }
48         List<NotificationEntry> ranked = new ArrayList<>(entries);
49         ranked.sort(mEntryComparator);
50         return ranked;
51     }
52 
53     @Nullable
54     @Override
getRankingMap()55     public RankingMap getRankingMap() {
56         return mRankingMap;
57     }
58 
59     private final Comparator<NotificationEntry> mEntryComparator = Comparator.comparingLong(
60             o -> o.getSbn().getNotification().when);
61 
62     @Override
isNotificationForCurrentProfiles(@onNull NotificationEntry entry)63     public boolean isNotificationForCurrentProfiles(@NonNull NotificationEntry entry) {
64         return true;
65     }
66 }
67