blob: 7cb91279b00aaa330d3c6c297c2a87ab22bf66c7 [file] [log] [blame]
Joe Onorato503007d2010-04-16 09:20:55 -07001/*
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 Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
Joe Onorato503007d2010-04-16 09:20:55 -070018
Christoph Studer37fe6932014-05-26 13:10:30 +020019import android.app.Notification;
Julia Reynoldsd9228f12015-10-20 10:37:27 -040020import android.content.Context;
Selim Cinekb18a20f2015-06-04 17:08:35 +020021import android.os.SystemClock;
Chris Wren3ad4e3a2014-09-02 17:23:51 -040022import android.service.notification.NotificationListenerService;
Christoph Studer37fe6932014-05-26 13:10:30 +020023import android.service.notification.NotificationListenerService.Ranking;
Christoph Studerd0694b62014-06-04 16:36:01 +020024import android.service.notification.NotificationListenerService.RankingMap;
John Spurlockde84f0e2013-06-12 12:41:00 -040025import android.service.notification.StatusBarNotification;
Christoph Studerc8db24b2014-07-25 17:50:30 +020026import android.util.ArrayMap;
Joe Onoratoe345fff2010-05-23 15:18:27 -040027import android.view.View;
Julia Reynoldsd9228f12015-10-20 10:37:27 -040028import android.widget.RemoteViews;
Joe Onorato503007d2010-04-16 09:20:55 -070029
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010030import com.android.systemui.statusbar.phone.NotificationGroupManager;
Selim Cinekfbe9a442015-04-13 16:09:49 -070031import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010032
Christoph Studerc8db24b2014-07-25 17:50:30 +020033import java.io.PrintWriter;
Joe Onoratoe345fff2010-05-23 15:18:27 -040034import java.util.ArrayList;
Christoph Studer37fe6932014-05-26 13:10:30 +020035import java.util.Collections;
John Spurlockde84f0e2013-06-12 12:41:00 -040036import java.util.Comparator;
Selim Cinek247fa012016-02-18 09:50:48 -080037import java.util.Objects;
Joe Onoratoe345fff2010-05-23 15:18:27 -040038
39/**
40 * The list of currently displaying notifications.
41 */
Joe Onorato503007d2010-04-16 09:20:55 -070042public class NotificationData {
Christoph Studerc8db24b2014-07-25 17:50:30 +020043
44 private final Environment mEnvironment;
Selim Cinekfbe9a442015-04-13 16:09:49 -070045 private HeadsUpManager mHeadsUpManager;
Christoph Studerc8db24b2014-07-25 17:50:30 +020046
Joe Onoratoe345fff2010-05-23 15:18:27 -040047 public static final class Entry {
Selim Cinekb18a20f2015-06-04 17:08:35 +020048 private static final long LAUNCH_COOLDOWN = 2000;
49 private static final long NOT_LAUNCHED_YET = -LAUNCH_COOLDOWN;
Christoph Studer71f18fd2014-05-20 17:02:04 +020050 public String key;
Joe Onoratoe345fff2010-05-23 15:18:27 -040051 public StatusBarNotification notification;
Joe Onorato66b4c5b2010-05-23 15:39:40 -040052 public StatusBarIconView icon;
Chris Wren51c75102013-07-16 20:49:17 -040053 public ExpandableNotificationRow row; // the outer expanded view
Chris Wrenf0048ce2013-08-07 16:43:43 -040054 private boolean interruption;
Jorim Jaggi36b15232014-06-10 17:24:20 +020055 public boolean autoRedacted; // whether the redacted notification was generated by us
56 public boolean legacy; // whether the notification has a legacy, dark background
Jorim Jaggia1eeade2014-09-08 22:34:39 +020057 public int targetSdk;
Selim Cinekb18a20f2015-06-04 17:08:35 +020058 private long lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET;
Julia Reynoldsd9228f12015-10-20 10:37:27 -040059 public RemoteViews cachedContentView;
60 public RemoteViews cachedBigContentView;
61 public RemoteViews cachedHeadsUpContentView;
62 public RemoteViews cachedPublicContentView;
Adrian Roos777ef562015-12-01 17:37:14 -080063 public CharSequence remoteInputText;
Jorim Jaggi36b15232014-06-10 17:24:20 +020064
Christoph Studer71f18fd2014-05-20 17:02:04 +020065 public Entry(StatusBarNotification n, StatusBarIconView ic) {
66 this.key = n.getKey();
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040067 this.notification = n;
68 this.icon = ic;
69 }
Chris Wrenf0048ce2013-08-07 16:43:43 -040070
71 public void setInterruption() {
72 interruption = true;
73 }
Chris Wrend04f6ce2014-06-11 17:37:28 -040074
75 public boolean hasInterrupted() {
76 return interruption;
77 }
Christoph Studer22f2ee52014-07-29 22:57:21 +020078
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 Studer22f2ee52014-07-29 22:57:21 +020085 autoRedacted = false;
86 legacy = false;
Selim Cinekb18a20f2015-06-04 17:08:35 +020087 lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET;
Christoph Studer22f2ee52014-07-29 22:57:21 +020088 if (row != null) {
89 row.reset();
90 }
91 }
Selim Cinek684a4422015-04-15 16:18:39 -070092
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 Cinekb18a20f2015-06-04 17:08:35 +0200108
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400109 public boolean cacheContentViews(Context ctx, Notification updatedNotification) {
Julia Reynolds6b531352015-11-18 11:12:53 -0500110 boolean applyInPlace = false;
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400111 if (updatedNotification != null) {
112 final Notification.Builder updatedNotificationBuilder
113 = Notification.Builder.recoverBuilder(ctx, updatedNotification);
Julia Reynolds3b848122016-02-26 10:45:32 -0500114 final RemoteViews newContentView = updatedNotificationBuilder.createContentView();
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400115 final RemoteViews newBigContentView =
Julia Reynolds3b848122016-02-26 10:45:32 -0500116 updatedNotificationBuilder.createBigContentView();
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400117 final RemoteViews newHeadsUpContentView =
Julia Reynolds3b848122016-02-26 10:45:32 -0500118 updatedNotificationBuilder.createHeadsUpContentView();
Selim Cinek624c02db2015-12-14 21:00:02 -0800119 final RemoteViews newPublicNotification
120 = updatedNotificationBuilder.makePublicContentView();
Julia Reynolds6b531352015-11-18 11:12:53 -0500121
Selim Cinek247fa012016-02-18 09:50:48 -0800122 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 Reynolds6b531352015-11-18 11:12:53 -0500127 applyInPlace = compareRemoteViews(cachedContentView, newContentView)
128 && compareRemoteViews(cachedBigContentView, newBigContentView)
129 && compareRemoteViews(cachedHeadsUpContentView, newHeadsUpContentView)
Selim Cinek247fa012016-02-18 09:50:48 -0800130 && compareRemoteViews(cachedPublicContentView, newPublicNotification)
131 && sameCustomView;
Selim Cinek624c02db2015-12-14 21:00:02 -0800132 cachedPublicContentView = newPublicNotification;
Julia Reynolds6b531352015-11-18 11:12:53 -0500133 cachedHeadsUpContentView = newHeadsUpContentView;
134 cachedBigContentView = newBigContentView;
135 cachedContentView = newContentView;
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400136 } else {
137 final Notification.Builder builder
138 = Notification.Builder.recoverBuilder(ctx, notification.getNotification());
139
Julia Reynolds3b848122016-02-26 10:45:32 -0500140 cachedContentView = builder.createContentView();
141 cachedBigContentView = builder.createBigContentView();
142 cachedHeadsUpContentView = builder.createHeadsUpContentView();
Selim Cinek624c02db2015-12-14 21:00:02 -0800143 cachedPublicContentView = builder.makePublicContentView();
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400144
Julia Reynolds6b531352015-11-18 11:12:53 -0500145 applyInPlace = false;
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400146 }
Julia Reynolds6b531352015-11-18 11:12:53 -0500147 return applyInPlace;
Julia Reynoldsd9228f12015-10-20 10:37:27 -0400148 }
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 Cinekb18a20f2015-06-04 17:08:35 +0200160 public void notifyFullScreenIntentLaunched() {
161 lastFullScreenIntentLaunchTime = SystemClock.elapsedRealtime();
162 }
163
164 public boolean hasJustLaunchedFullScreenIntent() {
165 return SystemClock.elapsedRealtime() < lastFullScreenIntentLaunchTime + LAUNCH_COOLDOWN;
166 }
Joe Onoratoe345fff2010-05-23 15:18:27 -0400167 }
Christoph Studer71f18fd2014-05-20 17:02:04 +0200168
Christoph Studerc8db24b2014-07-25 17:50:30 +0200169 private final ArrayMap<String, Entry> mEntries = new ArrayMap<>();
170 private final ArrayList<Entry> mSortedAndFiltered = new ArrayList<>();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100171
172 private NotificationGroupManager mGroupManager;
Christoph Studerc8db24b2014-07-25 17:50:30 +0200173
Christoph Studer1d599da2014-06-12 15:25:59 +0200174 private RankingMap mRankingMap;
175 private final Ranking mTmpRanking = new Ranking();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100176
Selim Cinekfbe9a442015-04-13 16:09:49 -0700177 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
178 mHeadsUpManager = headsUpManager;
179 }
180
Christoph Studer37fe6932014-05-26 13:10:30 +0200181 private final Comparator<Entry> mRankingComparator = new Comparator<Entry>() {
Christoph Studer1d599da2014-06-12 15:25:59 +0200182 private final Ranking mRankingA = new Ranking();
183 private final Ranking mRankingB = new Ranking();
184
Christoph Studer37fe6932014-05-26 13:10:30 +0200185 @Override
Daniel Sandler379020a2010-07-29 16:20:06 -0400186 public int compare(Entry a, Entry b) {
Christoph Studer14921162014-09-03 12:51:26 +0200187 final StatusBarNotification na = a.notification;
188 final StatusBarNotification nb = b.notification;
Chris Wrenbdf33762015-12-04 15:50:51 -0500189 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 Studer14921162014-09-03 12:51:26 +0200203
Dan Sandler4e787062015-06-17 15:09:48 -0400204 String mediaNotification = mEnvironment.getCurrentMediaNotificationKey();
205
Julia Reynoldsf0f629f2016-02-25 09:34:04 -0500206 // IMPORTANCE_MIN media streams are allowed to drift to the bottom
Dan Sandler4e787062015-06-17 15:09:48 -0400207 final boolean aMedia = a.key.equals(mediaNotification)
Julia Reynoldsf0f629f2016-02-25 09:34:04 -0500208 && aImportance > Ranking.IMPORTANCE_MIN;
Dan Sandler4e787062015-06-17 15:09:48 -0400209 final boolean bMedia = b.key.equals(mediaNotification)
Julia Reynoldsf0f629f2016-02-25 09:34:04 -0500210 && bImportance > Ranking.IMPORTANCE_MIN;
Dan Sandler4e787062015-06-17 15:09:48 -0400211
Chris Wrenbdf33762015-12-04 15:50:51 -0500212 boolean aSystemMax = aImportance >= Ranking.IMPORTANCE_MAX &&
Christoph Studer14921162014-09-03 12:51:26 +0200213 isSystemNotification(na);
Chris Wrenbdf33762015-12-04 15:50:51 -0500214 boolean bSystemMax = bImportance >= Ranking.IMPORTANCE_MAX &&
Christoph Studer14921162014-09-03 12:51:26 +0200215 isSystemNotification(nb);
Christoph Studer14921162014-09-03 12:51:26 +0200216
Selim Cinekfbe9a442015-04-13 16:09:49 -0700217 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 Wrenbdf33762015-12-04 15:50:51 -0500229 } else if (aRank != bRank) {
230 return aRank - bRank;
Chris Wrenf0048ce2013-08-07 16:43:43 -0400231 } else {
Christoph Studer37fe6932014-05-26 13:10:30 +0200232 return (int) (nb.getNotification().when - na.getNotification().when);
Chris Wrenf0048ce2013-08-07 16:43:43 -0400233 }
Daniel Sandler379020a2010-07-29 16:20:06 -0400234 }
235 };
Joe Onorato503007d2010-04-16 09:20:55 -0700236
Christoph Studerc8db24b2014-07-25 17:50:30 +0200237 public NotificationData(Environment environment) {
238 mEnvironment = environment;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100239 mGroupManager = environment.getGroupManager();
Joe Onoratoe345fff2010-05-23 15:18:27 -0400240 }
Joe Onorato503007d2010-04-16 09:20:55 -0700241
Christoph Studerc8db24b2014-07-25 17:50:30 +0200242 /**
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 Sandler0f0b11c2010-08-04 15:54:58 -0400253 }
254
Christoph Studerc8db24b2014-07-25 17:50:30 +0200255 public Entry get(String key) {
256 return mEntries.get(key);
Joe Onorato0e26dff2010-05-24 16:17:02 -0400257 }
258
Christoph Studerd0694b62014-06-04 16:36:01 +0200259 public void add(Entry entry, RankingMap ranking) {
Christoph Studerc8db24b2014-07-25 17:50:30 +0200260 mEntries.put(entry.notification.getKey(), entry);
Christoph Studer37fe6932014-05-26 13:10:30 +0200261 updateRankingAndSort(ranking);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100262 mGroupManager.onEntryAdded(entry);
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400263 }
264
Christoph Studerd0694b62014-06-04 16:36:01 +0200265 public Entry remove(String key, RankingMap ranking) {
Christoph Studerc8db24b2014-07-25 17:50:30 +0200266 Entry removed = mEntries.remove(key);
267 if (removed == null) return null;
Christoph Studer37fe6932014-05-26 13:10:30 +0200268 updateRankingAndSort(ranking);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100269 mGroupManager.onEntryRemoved(removed);
Christoph Studerc8db24b2014-07-25 17:50:30 +0200270 return removed;
Joe Onorato503007d2010-04-16 09:20:55 -0700271 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400272
Christoph Studerd0694b62014-06-04 16:36:01 +0200273 public void updateRanking(RankingMap ranking) {
Christoph Studer37fe6932014-05-26 13:10:30 +0200274 updateRankingAndSort(ranking);
275 }
276
277 public boolean isAmbient(String key) {
John Spurlockf079fc52014-08-09 11:10:03 -0400278 if (mRankingMap != null) {
279 mRankingMap.getRanking(key, mTmpRanking);
280 return mTmpRanking.isAmbient();
281 }
282 return false;
Christoph Studer37fe6932014-05-26 13:10:30 +0200283 }
284
Chris Wren3ad4e3a2014-09-02 17:23:51 -0400285 public int getVisibilityOverride(String key) {
286 if (mRankingMap != null) {
287 mRankingMap.getRanking(key, mTmpRanking);
288 return mTmpRanking.getVisibilityOverride();
289 }
Julia Reynoldsead00aa2015-12-07 08:23:48 -0500290 return Ranking.VISIBILITY_NO_OVERRIDE;
Chris Wren3ad4e3a2014-09-02 17:23:51 -0400291 }
292
Julia Reynoldsd5607292016-02-05 15:25:58 -0500293 public boolean shouldSuppressScreenOff(String key) {
Julia Reynoldsf612869ae2015-11-05 16:48:55 -0500294 if (mRankingMap != null) {
295 mRankingMap.getRanking(key, mTmpRanking);
296 return (mTmpRanking.getSuppressedVisualEffects()
Julia Reynoldsd5607292016-02-05 15:25:58 -0500297 & NotificationListenerService.SUPPRESSED_EFFECT_SCREEN_OFF) != 0;
Julia Reynoldsf612869ae2015-11-05 16:48:55 -0500298 }
299 return false;
300 }
301
Julia Reynolds61721582016-01-05 08:35:25 -0500302 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 Wrenbdf33762015-12-04 15:50:51 -0500311 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 Studerd0694b62014-06-04 16:36:01 +0200319 private void updateRankingAndSort(RankingMap ranking) {
Christoph Studer37fe6932014-05-26 13:10:30 +0200320 if (ranking != null) {
Christoph Studer1d599da2014-06-12 15:25:59 +0200321 mRankingMap = ranking;
Christoph Studer37fe6932014-05-26 13:10:30 +0200322 }
Christoph Studerc8db24b2014-07-25 17:50:30 +0200323 filterAndSort();
Christoph Studer37fe6932014-05-26 13:10:30 +0200324 }
325
Christoph Studerc8db24b2014-07-25 17:50:30 +0200326 // 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 Studerc8db24b2014-07-25 17:50:30 +0200331 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 Onorato9c1d8232010-05-24 20:02:53 -0400338 }
Christoph Studerc8db24b2014-07-25 17:50:30 +0200339
Christoph Studerc8db24b2014-07-25 17:50:30 +0200340 mSortedAndFiltered.add(entry);
341 }
342
Christoph Studerc8db24b2014-07-25 17:50:30 +0200343 Collections.sort(mSortedAndFiltered, mRankingComparator);
344 }
345
Christoph Studer2f9dbba2014-09-03 17:35:54 +0200346 boolean shouldFilterOut(StatusBarNotification sbn) {
Christoph Studerc8db24b2014-07-25 17:50:30 +0200347 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 Onorato9c1d8232010-05-24 20:02:53 -0400359 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100360
Selim Cinekb5605e52015-02-20 18:21:41 +0100361 if (!BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS
362 && mGroupManager.isChildInGroupWithSummary(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100363 return true;
364 }
Joe Onorato9c1d8232010-05-24 20:02:53 -0400365 return false;
Joe Onorato20da8f82010-05-24 16:39:29 -0400366 }
367
368 /**
Christoph Studerc8db24b2014-07-25 17:50:30 +0200369 * Return whether there are any clearable notifications (that aren't errors).
Joe Onorato20da8f82010-05-24 16:39:29 -0400370 */
Christoph Studerc8db24b2014-07-25 17:50:30 +0200371 public boolean hasActiveClearableNotifications() {
372 for (Entry e : mSortedAndFiltered) {
Selim Cinek684a4422015-04-15 16:18:39 -0700373 if (e.getContentView() != null) { // the view successfully inflated
Joe Onorato5dd11692010-09-27 15:34:04 -0700374 if (e.notification.isClearable()) {
Joe Onorato9c1d8232010-05-24 20:02:53 -0400375 return true;
376 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400377 }
378 }
379 return false;
380 }
Christoph Studerc8db24b2014-07-25 17:50:30 +0200381
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 Studer11840cd2014-08-21 16:41:45 +0200394 int active;
395 for (active = 0; active < N; active++) {
396 NotificationData.Entry e = mSortedAndFiltered.get(active);
397 dumpEntry(pw, indent, active, e);
Christoph Studerc8db24b2014-07-25 17:50:30 +0200398 }
399
400 int M = mEntries.size();
401 pw.print(indent);
Christoph Studer11840cd2014-08-21 16:41:45 +0200402 pw.println("inactive notifications: " + (M - active));
403 int inactiveCount = 0;
Christoph Studerc8db24b2014-07-25 17:50:30 +0200404 for (int i = 0; i < M; i++) {
405 Entry entry = mEntries.valueAt(i);
406 if (!mSortedAndFiltered.contains(entry)) {
Christoph Studer11840cd2014-08-21 16:41:45 +0200407 dumpEntry(pw, indent, inactiveCount, entry);
408 inactiveCount++;
Christoph Studerc8db24b2014-07-25 17:50:30 +0200409 }
410 }
411 }
412
413 private void dumpEntry(PrintWriter pw, String indent, int i, Entry e) {
Chris Wrenbdf33762015-12-04 15:50:51 -0500414 mRankingMap.getRanking(e.key, mTmpRanking);
Christoph Studerc8db24b2014-07-25 17:50:30 +0200415 pw.print(indent);
416 pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon);
417 StatusBarNotification n = e.notification;
418 pw.print(indent);
Chris Wrenbdf33762015-12-04 15:50:51 -0500419 pw.println(" pkg=" + n.getPackageName() + " id=" + n.getId() + " importance=" +
420 mTmpRanking.getImportance());
Christoph Studerc8db24b2014-07-25 17:50:30 +0200421 pw.print(indent);
422 pw.println(" notification=" + n.getNotification());
423 pw.print(indent);
424 pw.println(" tickerText=\"" + n.getNotification().tickerText + "\"");
425 }
426
Christoph Studer14921162014-09-03 12:51:26 +0200427 private static boolean isSystemNotification(StatusBarNotification sbn) {
428 String sbnPackage = sbn.getPackageName();
429 return "android".equals(sbnPackage) || "com.android.systemui".equals(sbnPackage);
430 }
431
Christoph Studerc8db24b2014-07-25 17:50:30 +0200432 /**
433 * Provides access to keyguard state and user settings dependent data.
434 */
435 public interface Environment {
Chris Wren3ad4e3a2014-09-02 17:23:51 -0400436 public boolean shouldHideSensitiveContents(int userid);
Christoph Studerc8db24b2014-07-25 17:50:30 +0200437 public boolean isDeviceProvisioned();
438 public boolean isNotificationForCurrentProfiles(StatusBarNotification sbn);
Christoph Studer2e731b52014-08-22 16:01:51 +0200439 public String getCurrentMediaNotificationKey();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100440 public NotificationGroupManager getGroupManager();
Christoph Studerc8db24b2014-07-25 17:50:30 +0200441 }
Joe Onorato503007d2010-04-16 09:20:55 -0700442}