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 |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | * limitations under the License |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 18 | |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 19 | import static android.app.Notification.CATEGORY_ALARM; |
| 20 | import static android.app.Notification.CATEGORY_CALL; |
| 21 | import static android.app.Notification.CATEGORY_EVENT; |
| 22 | import static android.app.Notification.CATEGORY_MESSAGE; |
| 23 | import static android.app.Notification.CATEGORY_REMINDER; |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 24 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT; |
| 25 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT; |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 26 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST; |
| 27 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK; |
| 28 | import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR; |
| 29 | |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 30 | import android.Manifest; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 31 | import android.annotation.NonNull; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 32 | import android.app.AppGlobals; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 33 | import android.app.Notification; |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 34 | import android.app.NotificationChannel; |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 35 | import android.app.NotificationManager; |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 36 | import android.app.Person; |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 37 | import android.content.Context; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 38 | import android.content.pm.IPackageManager; |
| 39 | import android.content.pm.PackageManager; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 40 | import android.graphics.drawable.Icon; |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 41 | import android.os.Bundle; |
| 42 | import android.os.Parcelable; |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 43 | import android.os.RemoteException; |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 44 | import android.os.SystemClock; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 45 | import android.service.notification.NotificationListenerService.Ranking; |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 46 | import android.service.notification.NotificationListenerService.RankingMap; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 47 | import android.service.notification.SnoozeCriterion; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 48 | import android.service.notification.StatusBarNotification; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 49 | import android.util.ArrayMap; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 50 | import android.util.ArraySet; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 51 | import android.view.View; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 52 | import android.widget.ImageView; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 53 | |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 54 | import androidx.annotation.Nullable; |
| 55 | |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 56 | import com.android.internal.annotations.VisibleForTesting; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 57 | import com.android.internal.statusbar.StatusBarIcon; |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 58 | import com.android.internal.util.ArrayUtils; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 59 | import com.android.internal.util.ContrastColorUtil; |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 60 | import com.android.systemui.Dependency; |
| 61 | import com.android.systemui.ForegroundServiceController; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 62 | import com.android.systemui.statusbar.InflationTask; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 63 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 64 | import com.android.systemui.statusbar.NotificationMediaManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 65 | import com.android.systemui.statusbar.StatusBarIconView; |
| 66 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 67 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 68 | import com.android.systemui.statusbar.phone.ShadeController; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.phone.StatusBar; |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 70 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 71 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 72 | import java.io.PrintWriter; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 73 | import java.util.ArrayList; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 74 | import java.util.Collections; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 75 | import java.util.Comparator; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 76 | import java.util.List; |
Selim Cinek | 247fa01 | 2016-02-18 09:50:48 -0800 | [diff] [blame] | 77 | import java.util.Objects; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * The list of currently displaying notifications. |
| 81 | */ |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 82 | public class NotificationData { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 83 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 84 | /** |
| 85 | * These dependencies are late init-ed |
| 86 | */ |
| 87 | private KeyguardEnvironment mEnvironment; |
| 88 | private ShadeController mShadeController; |
| 89 | private NotificationMediaManager mMediaManager; |
| 90 | private ForegroundServiceController mFsc; |
| 91 | private NotificationLockscreenUserManager mUserManager; |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 92 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 93 | private HeadsUpManager mHeadsUpManager; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 94 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 95 | public static final class Entry { |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 96 | private static final long LAUNCH_COOLDOWN = 2000; |
Selim Cinek | 1397ea3 | 2018-01-16 17:34:52 -0800 | [diff] [blame] | 97 | private static final long REMOTE_INPUT_COOLDOWN = 500; |
Aaron Heuckroth | 1dd67cb | 2018-06-14 14:28:08 -0400 | [diff] [blame] | 98 | private static final long INITIALIZATION_DELAY = 400; |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 99 | private static final long NOT_LAUNCHED_YET = -LAUNCH_COOLDOWN; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 100 | private static final int COLOR_INVALID = 1; |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 101 | public String key; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 102 | public StatusBarNotification notification; |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 103 | public NotificationChannel channel; |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 104 | public boolean audiblyAlerted; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 105 | public boolean noisy; |
| 106 | public int importance; |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 107 | public StatusBarIconView icon; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 108 | public StatusBarIconView expandedIcon; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 109 | public ExpandableNotificationRow row; // the outer expanded view |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 110 | private boolean interruption; |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 111 | public boolean autoRedacted; // whether the redacted notification was generated by us |
Jorim Jaggi | a1eeade | 2014-09-08 22:34:39 +0200 | [diff] [blame] | 112 | public int targetSdk; |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 113 | private long lastFullScreenIntentLaunchTime = NOT_LAUNCHED_YET; |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 114 | public CharSequence remoteInputText; |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 115 | public List<SnoozeCriterion> snoozeCriteria; |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 116 | public int userSentiment = Ranking.USER_SENTIMENT_NEUTRAL; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 117 | @NonNull |
| 118 | public List<Notification.Action> smartActions = Collections.emptyList(); |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 119 | public CharSequence[] smartReplies = new CharSequence[0]; |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 120 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 121 | private int mCachedContrastColor = COLOR_INVALID; |
| 122 | private int mCachedContrastColorIsFor = COLOR_INVALID; |
Selim Cinek | 67ff248 | 2017-05-25 10:27:28 -0700 | [diff] [blame] | 123 | private InflationTask mRunningTask = null; |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 124 | private Throwable mDebugThrowable; |
Selim Cinek | 1397ea3 | 2018-01-16 17:34:52 -0800 | [diff] [blame] | 125 | public CharSequence remoteInputTextWhenReset; |
| 126 | public long lastRemoteInputSent = NOT_LAUNCHED_YET; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 127 | public ArraySet<Integer> mActiveAppOps = new ArraySet<>(3); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 128 | public CharSequence headsUpStatusBarText; |
| 129 | public CharSequence headsUpStatusBarTextPublic; |
Aaron Heuckroth | 1dd67cb | 2018-06-14 14:28:08 -0400 | [diff] [blame] | 130 | |
| 131 | private long initializationTime = -1; |
| 132 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 133 | /** |
| 134 | * Whether or not this row represents a system notification. Note that if this is |
| 135 | * {@code null}, that means we were either unable to retrieve the info or have yet to |
| 136 | * retrieve the info. |
| 137 | */ |
| 138 | public Boolean mIsSystemNotification; |
Jorim Jaggi | 36b1523 | 2014-06-10 17:24:20 +0200 | [diff] [blame] | 139 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 140 | /** |
| 141 | * Has the user sent a reply through this Notification. |
| 142 | */ |
| 143 | private boolean hasSentReply; |
| 144 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 145 | public Entry(StatusBarNotification n) { |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 146 | this(n, null); |
| 147 | } |
| 148 | |
| 149 | public Entry(StatusBarNotification n, @Nullable Ranking ranking) { |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 150 | this.key = n.getKey(); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 151 | this.notification = n; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 152 | if (ranking != null) { |
| 153 | populateFromRanking(ranking); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | public void populateFromRanking(@NonNull Ranking ranking) { |
| 158 | channel = ranking.getChannel(); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 159 | audiblyAlerted = ranking.audiblyAlerted(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 160 | noisy = ranking.isNoisy(); |
| 161 | importance = ranking.getImportance(); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 162 | snoozeCriteria = ranking.getSnoozeCriteria(); |
| 163 | userSentiment = ranking.getUserSentiment(); |
| 164 | smartActions = ranking.getSmartActions() == null |
| 165 | ? Collections.emptyList() : ranking.getSmartActions(); |
Tony Mak | c9acf67 | 2018-07-20 13:58:24 +0200 | [diff] [blame] | 166 | smartReplies = ranking.getSmartReplies() == null |
| 167 | ? new CharSequence[0] |
| 168 | : ranking.getSmartReplies().toArray(new CharSequence[0]); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 169 | } |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 170 | |
| 171 | public void setInterruption() { |
| 172 | interruption = true; |
| 173 | } |
Chris Wren | d04f6ce | 2014-06-11 17:37:28 -0400 | [diff] [blame] | 174 | |
| 175 | public boolean hasInterrupted() { |
| 176 | return interruption; |
| 177 | } |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 178 | |
| 179 | /** |
| 180 | * Resets the notification entry to be re-used. |
| 181 | */ |
| 182 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 183 | if (row != null) { |
| 184 | row.reset(); |
| 185 | } |
| 186 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 187 | |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 188 | public void notifyFullScreenIntentLaunched() { |
Selim Cinek | da371df | 2017-07-21 16:18:21 -0700 | [diff] [blame] | 189 | setInterruption(); |
Selim Cinek | b18a20f | 2015-06-04 17:08:35 +0200 | [diff] [blame] | 190 | lastFullScreenIntentLaunchTime = SystemClock.elapsedRealtime(); |
| 191 | } |
| 192 | |
| 193 | public boolean hasJustLaunchedFullScreenIntent() { |
| 194 | return SystemClock.elapsedRealtime() < lastFullScreenIntentLaunchTime + LAUNCH_COOLDOWN; |
| 195 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 196 | |
Selim Cinek | 1397ea3 | 2018-01-16 17:34:52 -0800 | [diff] [blame] | 197 | public boolean hasJustSentRemoteInput() { |
| 198 | return SystemClock.elapsedRealtime() < lastRemoteInputSent + REMOTE_INPUT_COOLDOWN; |
| 199 | } |
| 200 | |
Aaron Heuckroth | 1dd67cb | 2018-06-14 14:28:08 -0400 | [diff] [blame] | 201 | public boolean hasFinishedInitialization() { |
| 202 | return initializationTime == -1 || |
| 203 | SystemClock.elapsedRealtime() > initializationTime + INITIALIZATION_DELAY; |
| 204 | } |
| 205 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 206 | /** |
| 207 | * Create the icons for a notification |
| 208 | * @param context the context to create the icons with |
| 209 | * @param sbn the notification |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 210 | * @throws InflationException |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 211 | */ |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 212 | public void createIcons(Context context, StatusBarNotification sbn) |
| 213 | throws InflationException { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 214 | Notification n = sbn.getNotification(); |
| 215 | final Icon smallIcon = n.getSmallIcon(); |
| 216 | if (smallIcon == null) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 217 | throw new InflationException("No small icon in notification from " |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 218 | + sbn.getPackageName()); |
| 219 | } |
| 220 | |
| 221 | // Construct the icon. |
| 222 | icon = new StatusBarIconView(context, |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 223 | sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()), sbn); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 224 | icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 225 | |
| 226 | // Construct the expanded icon. |
| 227 | expandedIcon = new StatusBarIconView(context, |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 228 | sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId()), sbn); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 229 | expandedIcon.setScaleType(ImageView.ScaleType.CENTER_INSIDE); |
| 230 | final StatusBarIcon ic = new StatusBarIcon( |
| 231 | sbn.getUser(), |
| 232 | sbn.getPackageName(), |
| 233 | smallIcon, |
| 234 | n.iconLevel, |
| 235 | n.number, |
| 236 | StatusBarIconView.contentDescForNotification(context, n)); |
| 237 | if (!icon.set(ic) || !expandedIcon.set(ic)) { |
| 238 | icon = null; |
| 239 | expandedIcon = null; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 240 | throw new InflationException("Couldn't create icon: " + ic); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 241 | } |
Selim Cinek | 6598974 | 2016-12-09 16:05:38 -0800 | [diff] [blame] | 242 | expandedIcon.setVisibility(View.INVISIBLE); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 243 | expandedIcon.setOnVisibilityChangedListener( |
| 244 | newVisibility -> { |
| 245 | if (row != null) { |
| 246 | row.setIconsVisible(newVisibility != View.VISIBLE); |
| 247 | } |
| 248 | }); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | public void setIconTag(int key, Object tag) { |
| 252 | if (icon != null) { |
| 253 | icon.setTag(key, tag); |
| 254 | expandedIcon.setTag(key, tag); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Update the notification icons. |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 260 | * |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 261 | * @param context the context to create the icons with. |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 262 | * @param sbn the notification to read the icon from. |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 263 | * @throws InflationException |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 264 | */ |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 265 | public void updateIcons(Context context, StatusBarNotification sbn) |
| 266 | throws InflationException { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 267 | if (icon != null) { |
| 268 | // Update the icon |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 269 | Notification n = sbn.getNotification(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 270 | final StatusBarIcon ic = new StatusBarIcon( |
| 271 | notification.getUser(), |
| 272 | notification.getPackageName(), |
| 273 | n.getSmallIcon(), |
| 274 | n.iconLevel, |
| 275 | n.number, |
| 276 | StatusBarIconView.contentDescForNotification(context, n)); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 277 | icon.setNotification(sbn); |
| 278 | expandedIcon.setNotification(sbn); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 279 | if (!icon.set(ic) || !expandedIcon.set(ic)) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 280 | throw new InflationException("Couldn't update icon: " + ic); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 285 | public int getContrastedColor(Context context, boolean isLowPriority, |
| 286 | int backgroundColor) { |
| 287 | int rawColor = isLowPriority ? Notification.COLOR_DEFAULT : |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 288 | notification.getNotification().color; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 289 | if (mCachedContrastColorIsFor == rawColor && mCachedContrastColor != COLOR_INVALID) { |
| 290 | return mCachedContrastColor; |
| 291 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 292 | final int contrasted = ContrastColorUtil.resolveContrastColor(context, rawColor, |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 293 | backgroundColor); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 294 | mCachedContrastColorIsFor = rawColor; |
| 295 | mCachedContrastColor = contrasted; |
| 296 | return mCachedContrastColor; |
| 297 | } |
Selim Cinek | 2630dc7 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 298 | |
| 299 | /** |
| 300 | * Abort all existing inflation tasks |
| 301 | */ |
Selim Cinek | 0f66a4c | 2017-04-28 19:26:28 -0700 | [diff] [blame] | 302 | public void abortTask() { |
Selim Cinek | 01d3da6 | 2017-04-28 15:03:48 -0700 | [diff] [blame] | 303 | if (mRunningTask != null) { |
| 304 | mRunningTask.abort(); |
| 305 | mRunningTask = null; |
Selim Cinek | 2630dc7 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
Selim Cinek | 67ff248 | 2017-05-25 10:27:28 -0700 | [diff] [blame] | 309 | public void setInflationTask(InflationTask abortableTask) { |
Selim Cinek | 01d3da6 | 2017-04-28 15:03:48 -0700 | [diff] [blame] | 310 | // abort any existing inflation |
Selim Cinek | 67ff248 | 2017-05-25 10:27:28 -0700 | [diff] [blame] | 311 | InflationTask existing = mRunningTask; |
Selim Cinek | 0f66a4c | 2017-04-28 19:26:28 -0700 | [diff] [blame] | 312 | abortTask(); |
| 313 | mRunningTask = abortableTask; |
Selim Cinek | 67ff248 | 2017-05-25 10:27:28 -0700 | [diff] [blame] | 314 | if (existing != null && mRunningTask != null) { |
| 315 | mRunningTask.supersedeTask(existing); |
| 316 | } |
Selim Cinek | 2630dc7 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 317 | } |
Selim Cinek | dc1231c | 2017-04-27 17:30:50 -0700 | [diff] [blame] | 318 | |
Selim Cinek | 01d3da6 | 2017-04-28 15:03:48 -0700 | [diff] [blame] | 319 | public void onInflationTaskFinished() { |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 320 | mRunningTask = null; |
Selim Cinek | dc1231c | 2017-04-27 17:30:50 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @VisibleForTesting |
Selim Cinek | 67ff248 | 2017-05-25 10:27:28 -0700 | [diff] [blame] | 324 | public InflationTask getRunningTask() { |
Selim Cinek | 01d3da6 | 2017-04-28 15:03:48 -0700 | [diff] [blame] | 325 | return mRunningTask; |
Selim Cinek | dc1231c | 2017-04-27 17:30:50 -0700 | [diff] [blame] | 326 | } |
Selim Cinek | 04be389 | 2017-08-08 10:58:32 -0700 | [diff] [blame] | 327 | |
| 328 | /** |
| 329 | * Set a throwable that is used for debugging |
| 330 | * |
| 331 | * @param debugThrowable the throwable to save |
| 332 | */ |
| 333 | public void setDebugThrowable(Throwable debugThrowable) { |
| 334 | mDebugThrowable = debugThrowable; |
| 335 | } |
| 336 | |
| 337 | public Throwable getDebugThrowable() { |
| 338 | return mDebugThrowable; |
| 339 | } |
Selim Cinek | 90d11a1 | 2018-01-17 16:24:36 -0800 | [diff] [blame] | 340 | |
| 341 | public void onRemoteInputInserted() { |
| 342 | lastRemoteInputSent = NOT_LAUNCHED_YET; |
| 343 | remoteInputTextWhenReset = null; |
| 344 | } |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 345 | |
| 346 | public void setHasSentReply() { |
| 347 | hasSentReply = true; |
| 348 | } |
| 349 | |
| 350 | public boolean isLastMessageFromReply() { |
| 351 | if (!hasSentReply) { |
| 352 | return false; |
| 353 | } |
| 354 | Bundle extras = notification.getNotification().extras; |
| 355 | CharSequence[] replyTexts = extras.getCharSequenceArray( |
| 356 | Notification.EXTRA_REMOTE_INPUT_HISTORY); |
| 357 | if (!ArrayUtils.isEmpty(replyTexts)) { |
| 358 | return true; |
| 359 | } |
| 360 | Parcelable[] messages = extras.getParcelableArray(Notification.EXTRA_MESSAGES); |
| 361 | if (messages != null && messages.length > 0) { |
| 362 | Parcelable message = messages[messages.length - 1]; |
| 363 | if (message instanceof Bundle) { |
| 364 | Notification.MessagingStyle.Message lastMessage = |
| 365 | Notification.MessagingStyle.Message.getMessageFromBundle( |
| 366 | (Bundle) message); |
| 367 | if (lastMessage != null) { |
| 368 | Person senderPerson = lastMessage.getSenderPerson(); |
| 369 | if (senderPerson == null) { |
| 370 | return true; |
| 371 | } |
| 372 | Person user = extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON); |
| 373 | return Objects.equals(user, senderPerson); |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | return false; |
| 378 | } |
Aaron Heuckroth | 1dd67cb | 2018-06-14 14:28:08 -0400 | [diff] [blame] | 379 | |
| 380 | public void setInitializationTime(long time) { |
| 381 | if (initializationTime == -1) { |
| 382 | initializationTime = time; |
| 383 | } |
| 384 | } |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 385 | } |
Christoph Studer | 71f18fd | 2014-05-20 17:02:04 +0200 | [diff] [blame] | 386 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 387 | private final ArrayMap<String, Entry> mEntries = new ArrayMap<>(); |
| 388 | private final ArrayList<Entry> mSortedAndFiltered = new ArrayList<>(); |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 389 | private final ArrayList<Entry> mFilteredForUser = new ArrayList<>(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 390 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 391 | private final NotificationGroupManager mGroupManager |
| 392 | = Dependency.get(NotificationGroupManager.class); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 393 | |
Christoph Studer | 1d599da | 2014-06-12 15:25:59 +0200 | [diff] [blame] | 394 | private RankingMap mRankingMap; |
| 395 | private final Ranking mTmpRanking = new Ranking(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 396 | |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 397 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 398 | mHeadsUpManager = headsUpManager; |
| 399 | } |
| 400 | |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 401 | private final Comparator<Entry> mRankingComparator = new Comparator<Entry>() { |
Christoph Studer | 1d599da | 2014-06-12 15:25:59 +0200 | [diff] [blame] | 402 | private final Ranking mRankingA = new Ranking(); |
| 403 | private final Ranking mRankingB = new Ranking(); |
| 404 | |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 405 | @Override |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 406 | public int compare(Entry a, Entry b) { |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 407 | final StatusBarNotification na = a.notification; |
| 408 | final StatusBarNotification nb = b.notification; |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 409 | int aImportance = NotificationManager.IMPORTANCE_DEFAULT; |
| 410 | int bImportance = NotificationManager.IMPORTANCE_DEFAULT; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 411 | int aRank = 0; |
| 412 | int bRank = 0; |
| 413 | |
| 414 | if (mRankingMap != null) { |
| 415 | // RankingMap as received from NoMan |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 416 | getRanking(a.key, mRankingA); |
| 417 | getRanking(b.key, mRankingB); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 418 | aImportance = mRankingA.getImportance(); |
| 419 | bImportance = mRankingB.getImportance(); |
| 420 | aRank = mRankingA.getRank(); |
| 421 | bRank = mRankingB.getRank(); |
| 422 | } |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 423 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 424 | String mediaNotification = getMediaManager().getMediaNotificationKey(); |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 425 | |
Julia Reynolds | f0f629f | 2016-02-25 09:34:04 -0500 | [diff] [blame] | 426 | // IMPORTANCE_MIN media streams are allowed to drift to the bottom |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 427 | final boolean aMedia = a.key.equals(mediaNotification) |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 428 | && aImportance > NotificationManager.IMPORTANCE_MIN; |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 429 | final boolean bMedia = b.key.equals(mediaNotification) |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 430 | && bImportance > NotificationManager.IMPORTANCE_MIN; |
Dan Sandler | 4e78706 | 2015-06-17 15:09:48 -0400 | [diff] [blame] | 431 | |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 432 | boolean aSystemMax = aImportance >= NotificationManager.IMPORTANCE_HIGH && |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 433 | isSystemNotification(na); |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 434 | boolean bSystemMax = bImportance >= NotificationManager.IMPORTANCE_HIGH && |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 435 | isSystemNotification(nb); |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 436 | |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 437 | boolean isHeadsUp = a.row.isHeadsUp(); |
| 438 | if (isHeadsUp != b.row.isHeadsUp()) { |
| 439 | return isHeadsUp ? -1 : 1; |
| 440 | } else if (isHeadsUp) { |
| 441 | // Provide consistent ranking with headsUpManager |
| 442 | return mHeadsUpManager.compare(a, b); |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 443 | } else if (a.row.isAmbientPulsing() != b.row.isAmbientPulsing()) { |
| 444 | return a.row.isAmbientPulsing() ? -1 : 1; |
Selim Cinek | fbe9a44 | 2015-04-13 16:09:49 -0700 | [diff] [blame] | 445 | } else if (aMedia != bMedia) { |
| 446 | // Upsort current media notification. |
| 447 | return aMedia ? -1 : 1; |
| 448 | } else if (aSystemMax != bSystemMax) { |
| 449 | // Upsort PRIORITY_MAX system notifications |
| 450 | return aSystemMax ? -1 : 1; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 451 | } else if (aRank != bRank) { |
| 452 | return aRank - bRank; |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 453 | } else { |
Ian Rogers | 31756df | 2016-06-06 14:49:30 -0700 | [diff] [blame] | 454 | return Long.compare(nb.getNotification().when, na.getNotification().when); |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 455 | } |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 456 | } |
| 457 | }; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 458 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 459 | private KeyguardEnvironment getEnvironment() { |
| 460 | if (mEnvironment == null) { |
| 461 | mEnvironment = Dependency.get(KeyguardEnvironment.class); |
| 462 | } |
| 463 | return mEnvironment; |
| 464 | } |
| 465 | |
| 466 | private ShadeController getShadeController() { |
| 467 | if (mShadeController == null) { |
| 468 | mShadeController = Dependency.get(ShadeController.class); |
| 469 | } |
| 470 | return mShadeController; |
| 471 | } |
| 472 | |
| 473 | private NotificationMediaManager getMediaManager() { |
| 474 | if (mMediaManager == null) { |
| 475 | mMediaManager = Dependency.get(NotificationMediaManager.class); |
| 476 | } |
| 477 | return mMediaManager; |
| 478 | } |
| 479 | |
| 480 | private ForegroundServiceController getFsc() { |
| 481 | if (mFsc == null) { |
| 482 | mFsc = Dependency.get(ForegroundServiceController.class); |
| 483 | } |
| 484 | return mFsc; |
| 485 | } |
| 486 | |
| 487 | private NotificationLockscreenUserManager getUserManager() { |
| 488 | if (mUserManager == null) { |
| 489 | mUserManager = Dependency.get(NotificationLockscreenUserManager.class); |
| 490 | } |
| 491 | return mUserManager; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 492 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 493 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 494 | /** |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 495 | * Returns the sorted list of active notifications (depending on {@link KeyguardEnvironment} |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 496 | * |
| 497 | * <p> |
| 498 | * This call doesn't update the list of active notifications. Call {@link #filterAndSort()} |
| 499 | * when the environment changes. |
| 500 | * <p> |
| 501 | * Don't hold on to or modify the returned list. |
| 502 | */ |
| 503 | public ArrayList<Entry> getActiveNotifications() { |
| 504 | return mSortedAndFiltered; |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 505 | } |
| 506 | |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 507 | public ArrayList<Entry> getNotificationsForCurrentUser() { |
| 508 | mFilteredForUser.clear(); |
| 509 | |
| 510 | synchronized (mEntries) { |
| 511 | final int N = mEntries.size(); |
| 512 | for (int i = 0; i < N; i++) { |
| 513 | Entry entry = mEntries.valueAt(i); |
| 514 | final StatusBarNotification sbn = entry.notification; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 515 | if (!getEnvironment().isNotificationForCurrentProfiles(sbn)) { |
Dieter Hsu | 36e1ebc | 2018-06-06 15:41:46 +0800 | [diff] [blame] | 516 | continue; |
| 517 | } |
| 518 | mFilteredForUser.add(entry); |
| 519 | } |
| 520 | } |
| 521 | return mFilteredForUser; |
| 522 | } |
| 523 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 524 | public Entry get(String key) { |
| 525 | return mEntries.get(key); |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 526 | } |
| 527 | |
Selim Cinek | 2630dc7 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 528 | public void add(Entry entry) { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 529 | synchronized (mEntries) { |
| 530 | mEntries.put(entry.notification.getKey(), entry); |
| 531 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 532 | mGroupManager.onEntryAdded(entry); |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 533 | |
Selim Cinek | 608a57a | 2017-04-28 16:50:41 -0700 | [diff] [blame] | 534 | updateRankingAndSort(mRankingMap); |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 537 | public Entry remove(String key, RankingMap ranking) { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 538 | Entry removed = null; |
| 539 | synchronized (mEntries) { |
| 540 | removed = mEntries.remove(key); |
| 541 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 542 | if (removed == null) return null; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 543 | mGroupManager.onEntryRemoved(removed); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 544 | updateRankingAndSort(ranking); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 545 | return removed; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 546 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 547 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 548 | public void updateRanking(RankingMap ranking) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 549 | updateRankingAndSort(ranking); |
| 550 | } |
| 551 | |
Julia Reynolds | 9159006 | 2018-04-02 16:24:11 -0400 | [diff] [blame] | 552 | public void updateAppOp(int appOp, int uid, String pkg, String key, boolean showIcon) { |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 553 | synchronized (mEntries) { |
| 554 | final int N = mEntries.size(); |
| 555 | for (int i = 0; i < N; i++) { |
| 556 | Entry entry = mEntries.valueAt(i); |
| 557 | if (uid == entry.notification.getUid() |
Julia Reynolds | 9159006 | 2018-04-02 16:24:11 -0400 | [diff] [blame] | 558 | && pkg.equals(entry.notification.getPackageName()) |
| 559 | && key.equals(entry.key)) { |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 560 | if (showIcon) { |
| 561 | entry.mActiveAppOps.add(appOp); |
| 562 | } else { |
| 563 | entry.mActiveAppOps.remove(appOp); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 570 | public boolean isAmbient(String key) { |
John Spurlock | f079fc5 | 2014-08-09 11:10:03 -0400 | [diff] [blame] | 571 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 572 | getRanking(key, mTmpRanking); |
John Spurlock | f079fc5 | 2014-08-09 11:10:03 -0400 | [diff] [blame] | 573 | return mTmpRanking.isAmbient(); |
| 574 | } |
| 575 | return false; |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 576 | } |
| 577 | |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 578 | public int getVisibilityOverride(String key) { |
| 579 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 580 | getRanking(key, mTmpRanking); |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 581 | return mTmpRanking.getVisibilityOverride(); |
| 582 | } |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 583 | return Ranking.VISIBILITY_NO_OVERRIDE; |
Chris Wren | 3ad4e3a | 2014-09-02 17:23:51 -0400 | [diff] [blame] | 584 | } |
| 585 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 586 | public boolean shouldSuppressFullScreenIntent(Entry entry) { |
| 587 | return shouldSuppressVisualEffect(entry, SUPPRESSED_EFFECT_FULL_SCREEN_INTENT); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 588 | } |
| 589 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 590 | public boolean shouldSuppressPeek(Entry entry) { |
| 591 | return shouldSuppressVisualEffect(entry, SUPPRESSED_EFFECT_PEEK); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 592 | } |
| 593 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 594 | public boolean shouldSuppressStatusBar(Entry entry) { |
| 595 | return shouldSuppressVisualEffect(entry, SUPPRESSED_EFFECT_STATUS_BAR); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 598 | public boolean shouldSuppressAmbient(Entry entry) { |
| 599 | return shouldSuppressVisualEffect(entry, SUPPRESSED_EFFECT_AMBIENT); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 602 | public boolean shouldSuppressNotificationList(Entry entry) { |
| 603 | return shouldSuppressVisualEffect(entry, SUPPRESSED_EFFECT_NOTIFICATION_LIST); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 606 | private boolean shouldSuppressVisualEffect(Entry entry, int effect) { |
| 607 | if (isExemptFromDndVisualSuppression(entry)) { |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 608 | return false; |
| 609 | } |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 610 | String key = entry.key; |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 611 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 612 | getRanking(key, mTmpRanking); |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 613 | return (mTmpRanking.getSuppressedVisualEffects() & effect) != 0; |
Julia Reynolds | f612869ae | 2015-11-05 16:48:55 -0500 | [diff] [blame] | 614 | } |
| 615 | return false; |
| 616 | } |
| 617 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 618 | protected boolean isExemptFromDndVisualSuppression(Entry entry) { |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 619 | if (isNotificationBlockedByPolicy(entry.notification.getNotification())) { |
| 620 | return false; |
| 621 | } |
| 622 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 623 | if ((entry.notification.getNotification().flags |
| 624 | & Notification.FLAG_FOREGROUND_SERVICE) != 0) { |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 625 | return true; |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 626 | } |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 627 | if (entry.notification.getNotification().isMediaNotification()) { |
| 628 | return true; |
| 629 | } |
| 630 | if (entry.mIsSystemNotification != null && entry.mIsSystemNotification) { |
Julia Reynolds | 5bbb6da | 2018-03-28 10:48:37 -0400 | [diff] [blame] | 631 | return true; |
Julia Reynolds | 6172158 | 2016-01-05 08:35:25 -0500 | [diff] [blame] | 632 | } |
| 633 | return false; |
| 634 | } |
| 635 | |
Julia Reynolds | 25926af | 2018-05-01 17:05:33 -0400 | [diff] [blame] | 636 | /** |
| 637 | * Categories that are explicitly called out on DND settings screens are always blocked, if |
| 638 | * DND has flagged them, even if they are foreground or system notifications that might |
| 639 | * otherwise visually bypass DND. |
| 640 | */ |
| 641 | protected boolean isNotificationBlockedByPolicy(Notification n) { |
| 642 | if (isCategory(CATEGORY_CALL, n) |
| 643 | || isCategory(CATEGORY_MESSAGE, n) |
| 644 | || isCategory(CATEGORY_ALARM, n) |
| 645 | || isCategory(CATEGORY_EVENT, n) |
| 646 | || isCategory(CATEGORY_REMINDER, n)) { |
| 647 | return true; |
| 648 | } |
| 649 | return false; |
| 650 | } |
| 651 | |
| 652 | private boolean isCategory(String category, Notification n) { |
| 653 | return Objects.equals(n.category, category); |
| 654 | } |
| 655 | |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 656 | public int getImportance(String key) { |
| 657 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 658 | getRanking(key, mTmpRanking); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 659 | return mTmpRanking.getImportance(); |
| 660 | } |
Julia Reynolds | 8576991 | 2016-10-25 09:08:57 -0400 | [diff] [blame] | 661 | return NotificationManager.IMPORTANCE_UNSPECIFIED; |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 662 | } |
| 663 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 664 | public String getOverrideGroupKey(String key) { |
| 665 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 666 | getRanking(key, mTmpRanking); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 667 | return mTmpRanking.getOverrideGroupKey(); |
| 668 | } |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 669 | return null; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 672 | public List<SnoozeCriterion> getSnoozeCriteria(String key) { |
| 673 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 674 | getRanking(key, mTmpRanking); |
Mady Mellor | 754d822 | 2017-01-25 15:29:39 -0800 | [diff] [blame] | 675 | return mTmpRanking.getSnoozeCriteria(); |
| 676 | } |
| 677 | return null; |
| 678 | } |
| 679 | |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 680 | public NotificationChannel getChannel(String key) { |
| 681 | if (mRankingMap != null) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 682 | getRanking(key, mTmpRanking); |
Julia Reynolds | 924eed1 | 2017-01-19 09:52:07 -0500 | [diff] [blame] | 683 | return mTmpRanking.getChannel(); |
| 684 | } |
| 685 | return null; |
| 686 | } |
| 687 | |
Dieter Hsu | d39f0d5 | 2018-04-14 02:08:30 +0800 | [diff] [blame] | 688 | public int getRank(String key) { |
| 689 | if (mRankingMap != null) { |
| 690 | getRanking(key, mTmpRanking); |
| 691 | return mTmpRanking.getRank(); |
| 692 | } |
| 693 | return 0; |
| 694 | } |
| 695 | |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 696 | public boolean shouldHide(String key) { |
| 697 | if (mRankingMap != null) { |
| 698 | getRanking(key, mTmpRanking); |
| 699 | return mTmpRanking.isSuspended(); |
| 700 | } |
| 701 | return false; |
| 702 | } |
| 703 | |
Christoph Studer | d0694b6 | 2014-06-04 16:36:01 +0200 | [diff] [blame] | 704 | private void updateRankingAndSort(RankingMap ranking) { |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 705 | if (ranking != null) { |
Christoph Studer | 1d599da | 2014-06-12 15:25:59 +0200 | [diff] [blame] | 706 | mRankingMap = ranking; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 707 | synchronized (mEntries) { |
| 708 | final int N = mEntries.size(); |
| 709 | for (int i = 0; i < N; i++) { |
| 710 | Entry entry = mEntries.valueAt(i); |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 711 | if (!getRanking(entry.key, mTmpRanking)) { |
| 712 | continue; |
| 713 | } |
Selim Cinek | 7f09ce1 | 2017-06-08 13:20:08 -0700 | [diff] [blame] | 714 | final StatusBarNotification oldSbn = entry.notification.cloneLight(); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 715 | final String overrideGroupKey = getOverrideGroupKey(entry.key); |
| 716 | if (!Objects.equals(oldSbn.getOverrideGroupKey(), overrideGroupKey)) { |
| 717 | entry.notification.setOverrideGroupKey(overrideGroupKey); |
| 718 | mGroupManager.onEntryUpdated(entry, oldSbn); |
| 719 | } |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 720 | entry.populateFromRanking(mTmpRanking); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 721 | } |
| 722 | } |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 723 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 724 | filterAndSort(); |
Christoph Studer | 37fe693 | 2014-05-26 13:10:30 +0200 | [diff] [blame] | 725 | } |
| 726 | |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 727 | /** |
| 728 | * Get the ranking from the current ranking map. |
| 729 | * |
| 730 | * @param key the key to look up |
| 731 | * @param outRanking the ranking to populate |
| 732 | * |
| 733 | * @return {@code true} if the ranking was properly obtained. |
| 734 | */ |
| 735 | @VisibleForTesting |
| 736 | protected boolean getRanking(String key, Ranking outRanking) { |
| 737 | return mRankingMap.getRanking(key, outRanking); |
| 738 | } |
| 739 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 740 | // TODO: This should not be public. Instead the Environment should notify this class when |
| 741 | // anything changed, and this class should call back the UI so it updates itself. |
| 742 | public void filterAndSort() { |
| 743 | mSortedAndFiltered.clear(); |
| 744 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 745 | synchronized (mEntries) { |
| 746 | final int N = mEntries.size(); |
| 747 | for (int i = 0; i < N; i++) { |
| 748 | Entry entry = mEntries.valueAt(i); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 749 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 750 | if (shouldFilterOut(entry)) { |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 751 | continue; |
| 752 | } |
| 753 | |
| 754 | mSortedAndFiltered.add(entry); |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 755 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 758 | Collections.sort(mSortedAndFiltered, mRankingComparator); |
| 759 | } |
| 760 | |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 761 | /** |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 762 | * @return true if this notification should NOT be shown right now |
| 763 | */ |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 764 | public boolean shouldFilterOut(Entry entry) { |
| 765 | final StatusBarNotification sbn = entry.notification; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 766 | if (!(getEnvironment().isDeviceProvisioned() || |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 767 | showNotificationEvenIfUnprovisioned(sbn))) { |
| 768 | return true; |
| 769 | } |
| 770 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 771 | if (!getEnvironment().isNotificationForCurrentProfiles(sbn)) { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 772 | return true; |
| 773 | } |
| 774 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 775 | if (getUserManager().isLockscreenPublicMode(sbn.getUserId()) && |
Julia Reynolds | 26fa8a5 | 2016-02-24 08:31:22 -0500 | [diff] [blame] | 776 | (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 777 | || getUserManager().shouldHideNotifications(sbn.getUserId()) |
| 778 | || getUserManager().shouldHideNotifications(sbn.getKey()))) { |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 779 | return true; |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 780 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 781 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 782 | if (getShadeController().isDozing() && shouldSuppressAmbient(entry)) { |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 783 | return true; |
| 784 | } |
| 785 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 786 | if (!getShadeController().isDozing() && shouldSuppressNotificationList(entry)) { |
Julia Reynolds | 24653c3 | 2018-03-02 13:16:37 -0500 | [diff] [blame] | 787 | return true; |
| 788 | } |
| 789 | |
Beverly | 5a20a5e | 2018-03-06 15:02:44 -0500 | [diff] [blame] | 790 | if (shouldHide(sbn.getKey())) { |
| 791 | return true; |
| 792 | } |
| 793 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 794 | if (!StatusBar.ENABLE_CHILD_NOTIFICATIONS |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 795 | && mGroupManager.isChildInGroupWithSummary(sbn)) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 796 | return true; |
| 797 | } |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 798 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 799 | if (getFsc().isDungeonNotification(sbn) |
| 800 | && !getFsc().isDungeonNeededForUser(sbn.getUserId())) { |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 801 | // this is a foreground-service disclosure for a user that does not need to show one |
| 802 | return true; |
| 803 | } |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 804 | if (getFsc().isSystemAlertNotification(sbn)) { |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 805 | final String[] apps = sbn.getNotification().extras.getStringArray( |
| 806 | Notification.EXTRA_FOREGROUND_APPS); |
| 807 | if (apps != null && apps.length >= 1) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 808 | if (!getFsc().isSystemAlertWarningNeeded(sbn.getUserId(), apps[0])) { |
Julia Reynolds | 3c7de11 | 2018-03-28 09:33:13 -0400 | [diff] [blame] | 809 | return true; |
| 810 | } |
| 811 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 812 | } |
Dan Sandler | 008cea7 | 2017-05-28 12:18:53 -0400 | [diff] [blame] | 813 | |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 814 | return false; |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 815 | } |
| 816 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 817 | // Q: What kinds of notifications should show during setup? |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 818 | // A: Almost none! Only things coming from packages with permission |
| 819 | // android.permission.NOTIFICATION_DURING_SETUP that also have special "kind" tags marking them |
| 820 | // as relevant for setup (see below). |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 821 | public static boolean showNotificationEvenIfUnprovisioned(StatusBarNotification sbn) { |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 822 | return showNotificationEvenIfUnprovisioned(AppGlobals.getPackageManager(), sbn); |
| 823 | } |
| 824 | |
| 825 | @VisibleForTesting |
| 826 | static boolean showNotificationEvenIfUnprovisioned(IPackageManager packageManager, |
| 827 | StatusBarNotification sbn) { |
| 828 | return checkUidPermission(packageManager, Manifest.permission.NOTIFICATION_DURING_SETUP, |
| 829 | sbn.getUid()) == PackageManager.PERMISSION_GRANTED |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 830 | && sbn.getNotification().extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP); |
| 831 | } |
| 832 | |
Maurice Lam | 132710e | 2017-03-03 19:13:42 -0800 | [diff] [blame] | 833 | private static int checkUidPermission(IPackageManager packageManager, String permission, |
| 834 | int uid) { |
| 835 | try { |
| 836 | return packageManager.checkUidPermission(permission, uid); |
| 837 | } catch (RemoteException e) { |
| 838 | throw e.rethrowFromSystemServer(); |
| 839 | } |
| 840 | } |
| 841 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 842 | public void dump(PrintWriter pw, String indent) { |
| 843 | int N = mSortedAndFiltered.size(); |
| 844 | pw.print(indent); |
| 845 | pw.println("active notifications: " + N); |
Christoph Studer | 11840cd | 2014-08-21 16:41:45 +0200 | [diff] [blame] | 846 | int active; |
| 847 | for (active = 0; active < N; active++) { |
| 848 | NotificationData.Entry e = mSortedAndFiltered.get(active); |
| 849 | dumpEntry(pw, indent, active, e); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 850 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame] | 851 | synchronized (mEntries) { |
| 852 | int M = mEntries.size(); |
| 853 | pw.print(indent); |
| 854 | pw.println("inactive notifications: " + (M - active)); |
| 855 | int inactiveCount = 0; |
| 856 | for (int i = 0; i < M; i++) { |
| 857 | Entry entry = mEntries.valueAt(i); |
| 858 | if (!mSortedAndFiltered.contains(entry)) { |
| 859 | dumpEntry(pw, indent, inactiveCount, entry); |
| 860 | inactiveCount++; |
| 861 | } |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | private void dumpEntry(PrintWriter pw, String indent, int i, Entry e) { |
Kensuke Matsui | efa1a74 | 2017-08-03 12:12:36 +0900 | [diff] [blame] | 867 | getRanking(e.key, mTmpRanking); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 868 | pw.print(indent); |
| 869 | pw.println(" [" + i + "] key=" + e.key + " icon=" + e.icon); |
| 870 | StatusBarNotification n = e.notification; |
| 871 | pw.print(indent); |
Chris Wren | bdf3376 | 2015-12-04 15:50:51 -0500 | [diff] [blame] | 872 | pw.println(" pkg=" + n.getPackageName() + " id=" + n.getId() + " importance=" + |
| 873 | mTmpRanking.getImportance()); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 874 | pw.print(indent); |
| 875 | pw.println(" notification=" + n.getNotification()); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Christoph Studer | 1492116 | 2014-09-03 12:51:26 +0200 | [diff] [blame] | 878 | private static boolean isSystemNotification(StatusBarNotification sbn) { |
| 879 | String sbnPackage = sbn.getPackageName(); |
| 880 | return "android".equals(sbnPackage) || "com.android.systemui".equals(sbnPackage); |
| 881 | } |
| 882 | |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 883 | /** |
| 884 | * Provides access to keyguard state and user settings dependent data. |
| 885 | */ |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 886 | public interface KeyguardEnvironment { |
| 887 | boolean isDeviceProvisioned(); |
| 888 | boolean isNotificationForCurrentProfiles(StatusBarNotification sbn); |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 889 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 890 | } |