Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 18 | |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 19 | import android.app.Notification; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 20 | import android.content.Context; |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 21 | import android.os.SystemClock; |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 22 | import android.service.notification.NotificationListenerService; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 23 | import android.service.notification.NotificationListenerService.Ranking; |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 24 | import android.service.notification.NotificationListenerService.RankingMap; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 25 | import android.service.notification.StatusBarNotification; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 26 | import android.util.ArrayMap; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 27 | import android.view.View; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 28 | import android.widget.RemoteViews; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 29 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 30 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 31 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 32 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 33 | import java.io.PrintWriter; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 35 | import java.util.Collections; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 36 | import java.util.Comparator; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 37 | import java.util.Objects; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * The list of currently displaying notifications. |
| 41 | */ |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 42 | public class NotificationData { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 43 | |
| 44 | private final Environment mEnvironment; |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 45 | private HeadsUpManager mHeadsUpManager; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 46 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 47 | public static final class Entry { |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 48 | private static final long LAUNCH_COOLDOWN = 2000; |
| 49 | private static final long NOT_LAUNCHED_YET = -LAUNCH_COOLDOWN; |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 50 | public String key; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 51 | public StatusBarNotification notification; |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 52 | public StatusBarIconView icon; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 53 | public ExpandableNotificationRow row; // the outer expanded view |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 54 | private boolean interruption; |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 55 | public boolean autoRedacted; // whether the redacted notification was generated by us |
| 56 | public boolean legacy; // whether the notification has a legacy, dark background |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 57 | public int targetSdk; |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 58 | private long lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 59 | public RemoteViews cachedContentView; |
| 60 | public RemoteViews cachedBigContentView; |
| 61 | public RemoteViews cachedHeadsUpContentView; |
| 62 | public RemoteViews cachedPublicContentView; |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 63 | public CharSequence remoteInputText; |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 64 | |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 65 | public Entry(StatusBarNotification n, StatusBarIconView ic) { |
| 66 | this.key = n.getKey(); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 67 | this.notification = n; |
| 68 | this.icon = ic; |
| 69 | } |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 70 | |
| 71 | public void setInterruption() { |
| 72 | interruption = true; |
| 73 | } |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 74 | |
| 75 | public boolean hasInterrupted() { |
| 76 | return interruption; |
| 77 | } |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Resets the notification entry to be re-used. |
| 81 | */ |
| 82 | public void reset() { |
| 83 | // NOTE: Icon needs to be preserved for now. |
| 84 | // We should fix this at some point. |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 85 | autoRedacted = false; |
| 86 | legacy = false; |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 87 | lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET; |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 88 | if (row != null) { |
| 89 | row.reset(); |
| 90 | } |
| 91 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 92 | |
| 93 | public View getContentView() { |
| 94 | return row.getPrivateLayout().getContractedChild(); |
| 95 | } |
| 96 | |
| 97 | public View getExpandedContentView() { |
| 98 | return row.getPrivateLayout().getExpandedChild(); |
| 99 | } |
| 100 | |
| 101 | public View getHeadsUpContentView() { |
| 102 | return row.getPrivateLayout().getHeadsUpChild(); |
| 103 | } |
| 104 | |
| 105 | public View getPublicContentView() { |
| 106 | return row.getPublicLayout().getContractedChild(); |
| 107 | } |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 108 | |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 109 | public boolean cacheContentViews(Context ctx, Notification updatedNotification) { |
Julia Reynolds | 6b53135 | 2015-11-18 11:12:53 -0500 | [diff] [blame] | 110 | boolean applyInPlace = false; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 111 | if (updatedNotification != null) { |
| 112 | final Notification.Builder updatedNotificationBuilder |
| 113 | = Notification.Builder.recoverBuilder(ctx, updatedNotification); |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 114 | final RemoteViews newContentView = updatedNotificationBuilder.createContentView(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 115 | final RemoteViews newBigContentView = |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 116 | updatedNotificationBuilder.createBigContentView(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 117 | final RemoteViews newHeadsUpContentView = |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 118 | updatedNotificationBuilder.createHeadsUpContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 119 | final RemoteViews newPublicNotification |
| 120 | = updatedNotificationBuilder.makePublicContentView(); |
Julia Reynolds | 6b53135 | 2015-11-18 11:12:53 -0500 | [diff] [blame] | 121 | |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 122 | boolean sameCustomView = Objects.equals( |
| 123 | notification.getNotification().extras.getBoolean( |
| 124 | Notification.EXTRA_CONTAINS_CUSTOM_VIEW), |
| 125 | updatedNotification.extras.getBoolean( |
| 126 | Notification.EXTRA_CONTAINS_CUSTOM_VIEW)); |
Julia Reynolds | 6b53135 | 2015-11-18 11:12:53 -0500 | [diff] [blame] | 127 | applyInPlace = compareRemoteViews(cachedContentView, newContentView) |
| 128 | && compareRemoteViews(cachedBigContentView, newBigContentView) |
| 129 | && compareRemoteViews(cachedHeadsUpContentView, newHeadsUpContentView) |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 130 | && compareRemoteViews(cachedPublicContentView, newPublicNotification) |
| 131 | && sameCustomView; |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 132 | cachedPublicContentView = newPublicNotification; |
Julia Reynolds | 6b53135 | 2015-11-18 11:12:53 -0500 | [diff] [blame] | 133 | cachedHeadsUpContentView = newHeadsUpContentView; |
| 134 | cachedBigContentView = newBigContentView; |
| 135 | cachedContentView = newContentView; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 136 | } else { |
| 137 | final Notification.Builder builder |
| 138 | = Notification.Builder.recoverBuilder(ctx, notification.getNotification()); |
| 139 | |
Julia Reynolds | 3b84812 | 2016-02-26 10:45:32 -0500 | [diff] [blame] | 140 | cachedContentView = builder.createContentView(); |
| 141 | cachedBigContentView = builder.createBigContentView(); |
| 142 | cachedHeadsUpContentView = builder.createHeadsUpContentView(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 143 | cachedPublicContentView = builder.makePublicContentView(); |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 144 | |
Julia Reynolds | 6b53135 | 2015-11-18 11:12:53 -0500 | [diff] [blame] | 145 | applyInPlace = false; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 146 | } |
Julia Reynolds | 6b53135 | 2015-11-18 11:12:53 -0500 | [diff] [blame] | 147 | return applyInPlace; |
Julia Reynolds | d9228f1 | 2015-10-20 10:37:27 -0400 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | // Returns true if the RemoteViews are the same. |
| 151 | private boolean compareRemoteViews(final RemoteViews a, final RemoteViews b) { |
| 152 | return (a == null && b == null) || |
| 153 | (a != null && b != null |
| 154 | && b.getPackage() != null |
| 155 | && a.getPackage() != null |
| 156 | && a.getPackage().equals(b.getPackage()) |
| 157 | && a.getLayoutId() == b.getLayoutId()); |
| 158 | } |
| 159 | |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 160 | public void notifyFullScreenIntentLaunched() { |
| 161 | lastFullScreenIntentLaunchTime = SystemClock.elapsedRealtime(); |
| 162 | } |
| 163 | |
| 164 | public boolean hasJustLaunchedFullScreenIntent() { |
| 165 | return SystemClock.elapsedRealtime() < lastFullScreenIntentLaunchTime + LAUNCH_COOLDOWN; |
| 166 | } |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 167 | } |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 168 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 169 | private final ArrayMap<String, Entry> mEntries = new ArrayMap<>(); |
| 170 | private final ArrayList<Entry> mSortedAndFiltered = new ArrayList<>(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 171 | |
| 172 | private NotificationGroupManager mGroupManager; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 173 | |
Christoph Studer | 1d599da | 2014-06-12 15:25:59 +0200 | [diff] [blame] | 174 | private RankingMap mRankingMap; |
| 175 | private final Ranking mTmpRanking = new Ranking(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 176 | |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 177 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 178 | mHeadsUpManager = headsUpManager; |
| 179 | } |
| 180 | |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 181 | private final Comparator<Entry> mRankingComparator = new Comparator<Entry>() { |
Christoph Studer | 1d599da | 2014-06-12 15:25:59 +0200 | [diff] [blame] | 182 | private final Ranking mRankingA = new Ranking(); |
| 183 | private final Ranking mRankingB = new Ranking(); |
| 184 | |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 185 | @Override |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 186 | public int compare(Entry a, Entry b) { |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 187 | final StatusBarNotification na = a.notification; |
| 188 | final StatusBarNotification nb = b.notification; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 189 | int aImportance = Ranking.IMPORTANCE_DEFAULT; |
| 190 | int bImportance = Ranking.IMPORTANCE_DEFAULT; |
| 191 | int aRank = 0; |
| 192 | int bRank = 0; |
| 193 | |
| 194 | if (mRankingMap != null) { |
| 195 | // RankingMap as received from NoMan |
| 196 | mRankingMap.getRanking(a.key, mRankingA); |
| 197 | mRankingMap.getRanking(b.key, mRankingB); |
| 198 | aImportance = mRankingA.getImportance(); |
| 199 | bImportance = mRankingB.getImportance(); |
| 200 | aRank = mRankingA.getRank(); |
| 201 | bRank = mRankingB.getRank(); |
| 202 | } |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 203 | |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 204 | String mediaNotification = mEnvironment.getCurrentMediaNotificationKey(); |
| 205 | |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 206 | // IMPORTANCE_MIN media streams are allowed to drift to the bottom |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 207 | final boolean aMedia = a.key.equals(mediaNotification) |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 208 | && aImportance > Ranking.IMPORTANCE_MIN; |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 209 | final boolean bMedia = b.key.equals(mediaNotification) |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 210 | && bImportance > Ranking.IMPORTANCE_MIN; |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 211 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 212 | boolean aSystemMax = aImportance >= Ranking.IMPORTANCE_MAX && |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 213 | isSystemNotification(na); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 214 | boolean bSystemMax = bImportance >= Ranking.IMPORTANCE_MAX && |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 215 | isSystemNotification(nb); |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 216 | |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 217 | boolean isHeadsUp = a.row.isHeadsUp(); |
| 218 | if (isHeadsUp != b.row.isHeadsUp()) { |
| 219 | return isHeadsUp ? -1 : 1; |
| 220 | } else if (isHeadsUp) { |
| 221 | // Provide consistent ranking with headsUpManager |
| 222 | return mHeadsUpManager.compare(a, b); |
| 223 | } else if (aMedia != bMedia) { |
| 224 | // Upsort current media notification. |
| 225 | return aMedia ? -1 : 1; |
| 226 | } else if (aSystemMax != bSystemMax) { |
| 227 | // Upsort PRIORITY_MAX system notifications |
| 228 | return aSystemMax ? -1 : 1; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 229 | } else if (aRank != bRank) { |
| 230 | return aRank - bRank; |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 231 | } else { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 232 | return (int) (nb.getNotification().when - na.getNotification().when); |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 233 | } |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 234 | } |
| 235 | }; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 236 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 237 | public NotificationData(Environment environment) { |
| 238 | mEnvironment = environment; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 239 | mGroupManager = environment.getGroupManager(); |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 240 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 241 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 242 | /** |
| 243 | * Returns the sorted list of active notifications (depending on {@link Environment} |
| 244 | * |
| 245 | * <p> |
| 246 | * This call doesn't update the list of active notifications. Call {@link #filterAndSort()} |
| 247 | * when the environment changes. |
| 248 | * <p> |
| 249 | * Don't hold on to or modify the returned list. |
| 250 | */ |
| 251 | public ArrayList<Entry> getActiveNotifications() { |
| 252 | return mSortedAndFiltered; |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 255 | public Entry get(String key) { |
| 256 | return mEntries.get(key); |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 259 | public void add(Entry entry, RankingMap ranking) { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 260 | mEntries.put(entry.notification.getKey(), entry); |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 261 | updateRankingAndSort(ranking); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 262 | mGroupManager.onEntryAdded(entry); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 263 | } |
| 264 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 265 | public Entry remove(String key, RankingMap ranking) { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 266 | Entry removed = mEntries.remove(key); |
| 267 | if (removed == null) return null; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 268 | updateRankingAndSort(ranking); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 269 | mGroupManager.onEntryRemoved(removed); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 270 | return removed; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 271 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 272 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 273 | public void updateRanking(RankingMap ranking) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 274 | updateRankingAndSort(ranking); |
| 275 | } |
| 276 | |
| 277 | public boolean isAmbient(String key) { |
John Spurlock | f079fc5 | 2014-08-09 11:10:03 -0400 | [diff] [blame] | 278 | if (mRankingMap != null) { |
| 279 | mRankingMap.getRanking(key, mTmpRanking); |
| 280 | return mTmpRanking.isAmbient(); |
| 281 | } |
| 282 | return false; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 283 | } |
| 284 | |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 285 | public int getVisibilityOverride(String key) { |
| 286 | if (mRankingMap != null) { |
| 287 | mRankingMap.getRanking(key, mTmpRanking); |
| 288 | return mTmpRanking.getVisibilityOverride(); |
| 289 | } |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 290 | return Ranking.VISIBILITY_NO_OVERRIDE; |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 291 | } |
| 292 | |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 293 | public boolean shouldSuppressScreenOff(String key) { |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 294 | if (mRankingMap != null) { |
| 295 | mRankingMap.getRanking(key, mTmpRanking); |
| 296 | return (mTmpRanking.getSuppressedVisualEffects() |
Julia Reynolds | d560729 | 2016-02-05 15:25:58 -0500 | [diff] [blame] | 297 | & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) != 0; |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 298 | } |
| 299 | return false; |
| 300 | } |
| 301 | |
Julia Reynolds | 6172158 | 2016-01-05 08:35:25 -0500 | [diff] [blame] | 302 | public boolean shouldSuppressScreenOn(String key) { |
| 303 | if (mRankingMap != null) { |
| 304 | mRankingMap.getRanking(key, mTmpRanking); |
| 305 | return (mTmpRanking.getSuppressedVisualEffects() |
| 306 | & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_ON) != 0; |
| 307 | } |
| 308 | return false; |
| 309 | } |
| 310 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 311 | public int getImportance(String key) { |
| 312 | if (mRankingMap != null) { |
| 313 | mRankingMap.getRanking(key, mTmpRanking); |
| 314 | return mTmpRanking.getImportance(); |
| 315 | } |
| 316 | return Ranking.IMPORTANCE_UNSPECIFIED; |
| 317 | } |
| 318 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 319 | private void updateRankingAndSort(RankingMap ranking) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 320 | if (ranking != null) { |
Christoph Studer | 1d599da | 2014-06-12 15:25:59 +0200 | [diff] [blame] | 321 | mRankingMap = ranking; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 322 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 323 | filterAndSort(); |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 324 | } |
| 325 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 326 | // TODO: This should not be public. Instead the Environment should notify this class when |
| 327 | // anything changed, and this class should call back the UI so it updates itself. |
| 328 | public void filterAndSort() { |
| 329 | mSortedAndFiltered.clear(); |
| 330 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 331 | final int N = mEntries.size(); |
| 332 | for (int i = 0; i < N; i++) { |
| 333 | Entry entry = mEntries.valueAt(i); |
| 334 | StatusBarNotification sbn = entry.notification; |
| 335 | |
| 336 | if (shouldFilterOut(sbn)) { |
| 337 | continue; |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 338 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 339 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 340 | mSortedAndFiltered.add(entry); |
| 341 | } |
| 342 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 343 | Collections.sort(mSortedAndFiltered, mRankingComparator); |
| 344 | } |
| 345 | |
Christoph Studer | 2f9dbba | 2014-09-03 17:35:54 +0200 | [diff] [blame] | 346 | boolean shouldFilterOut(StatusBarNotification sbn) { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 347 | if (!(mEnvironment.isDeviceProvisioned() || |
| 348 | showNotificationEvenIfUnprovisioned(sbn))) { |
| 349 | return true; |
| 350 | } |
| 351 | |
| 352 | if (!mEnvironment.isNotificationForCurrentProfiles(sbn)) { |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | if (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET && |
| 357 | mEnvironment.shouldHideSensitiveContents(sbn.getUserId())) { |
| 358 | return true; |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 359 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 360 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 361 | if (!BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS |
| 362 | && mGroupManager.isChildInGroupWithSummary(sbn)) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 363 | return true; |
| 364 | } |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 365 | return false; |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /** |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 369 | * Return whether there are any clearable notifications (that aren't errors). |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 370 | */ |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 371 | public boolean hasActiveClearableNotifications() { |
| 372 | for (Entry e : mSortedAndFiltered) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 373 | if (e.getContentView() != null) { // the view successfully inflated |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 374 | if (e.notification.isClearable()) { |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 375 | return true; |
| 376 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | return false; |
| 380 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 381 | |
| 382 | // Q: What kinds of notifications should show during setup? |
| 383 | // A: Almost none! Only things coming from the system (package is "android") that also |
| 384 | // have special "kind" tags marking them as relevant for setup (see below). |
| 385 | public static boolean showNotificationEvenIfUnprovisioned(StatusBarNotification sbn) { |
| 386 | return "android".equals(sbn.getPackageName()) |
| 387 | && sbn.getNotification().extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP); |
| 388 | } |
| 389 | |
| 390 | public void dump(PrintWriter pw, String indent) { |
| 391 | int N = mSortedAndFiltered.size(); |
| 392 | pw.print(indent); |
| 393 | pw.println("active notifications: " + N); |
Christoph Studer | 11840cd | 2014-08-21 16:41:45 +0200 | [diff] [blame] | 394 | int active; |
| 395 | for (active = 0; active < N; active++) { |
| 396 | NotificationData.Entry e = mSortedAndFiltered.get(active); |
| 397 | dumpEntry(pw, indent, active, e); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | int M = mEntries.size(); |
| 401 | pw.print(indent); |
Christoph Studer | 11840cd | 2014-08-21 16:41:45 +0200 | [diff] [blame] | 402 | pw.println("inactive notifications: " + (M - active)); |
| 403 | int inactiveCount = 0; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 404 | for (int i = 0; i < M; i++) { |
| 405 | Entry entry = mEntries.valueAt(i); |
| 406 | if (!mSortedAndFiltered.contains(entry)) { |
Christoph Studer | 11840cd | 2014-08-21 16:41:45 +0200 | [diff] [blame] | 407 | dumpEntry(pw, indent, inactiveCount, entry); |
| 408 | inactiveCount++; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | private void dumpEntry(PrintWriter pw, String indent, int i, Entry e) { |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 414 | mRankingMap.getRanking(e.key, mTmpRanking); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 415 | pw.print(indent); |
| 416 | pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon); |
| 417 | StatusBarNotification n = e.notification; |
| 418 | pw.print(indent); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 419 | pw.println(" pkg=" + n.getPackageName() + " id=" + n.getId() + " importance=" + |
| 420 | mTmpRanking.getImportance()); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 421 | pw.print(indent); |
| 422 | pw.println(" notification=" + n.getNotification()); |
| 423 | pw.print(indent); |
| 424 | pw.println(" tickerText=\"" + n.getNotification().tickerText + "\""); |
| 425 | } |
| 426 | |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 427 | private static boolean isSystemNotification(StatusBarNotification sbn) { |
| 428 | String sbnPackage = sbn.getPackageName(); |
| 429 | return "android".equals(sbnPackage) || "com.android.systemui".equals(sbnPackage); |
| 430 | } |
| 431 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 432 | /** |
| 433 | * Provides access to keyguard state and user settings dependent data. |
| 434 | */ |
| 435 | public interface Environment { |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 436 | public boolean shouldHideSensitiveContents(int userid); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 437 | public boolean isDeviceProvisioned(); |
| 438 | public boolean isNotificationForCurrentProfiles(StatusBarNotification sbn); |
Christoph Studer | 2e731b5 | 2014-08-22 16:01:51 +0200 | [diff] [blame] | 439 | public String getCurrentMediaNotificationKey(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 440 | public NotificationGroupManager getGroupManager(); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 441 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 442 | } |