yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.content.Context; |
| 22 | import android.content.res.Resources; |
Evan Laird | e1822fd | 2019-07-10 15:55:45 -0400 | [diff] [blame] | 23 | import android.graphics.Region; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 24 | import android.util.Pools; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 25 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 26 | import androidx.collection.ArraySet; |
| 27 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 28 | import com.android.internal.annotations.VisibleForTesting; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 29 | import com.android.systemui.Dumpable; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 30 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 31 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 32 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 33 | import com.android.systemui.statusbar.StatusBarState; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 34 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 35 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 36 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 37 | import com.android.systemui.statusbar.policy.ConfigurationController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 38 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 39 | import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; |
| 40 | |
| 41 | import java.io.FileDescriptor; |
| 42 | import java.io.PrintWriter; |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 43 | import java.util.ArrayList; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 44 | import java.util.HashSet; |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 45 | import java.util.List; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 46 | import java.util.Stack; |
| 47 | |
| 48 | /** |
| 49 | * A implementation of HeadsUpManager for phone and car. |
| 50 | */ |
| 51 | public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable, |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 52 | VisualStabilityManager.Callback, OnHeadsUpChangedListener { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 53 | private static final String TAG = "HeadsUpManagerPhone"; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 54 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 55 | @VisibleForTesting |
| 56 | final int mExtensionTime; |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 57 | private final KeyguardBypassController mBypassController; |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 58 | private final NotificationGroupManager mGroupManager; |
| 59 | private final List<OnHeadsUpPhoneListenerChange> mHeadsUpPhoneListeners = new ArrayList<>(); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 60 | private final int mAutoHeadsUpNotificationDecay; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 61 | private VisualStabilityManager mVisualStabilityManager; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 62 | private boolean mReleaseOnExpandFinish; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 63 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 64 | private boolean mTrackingHeadsUp; |
| 65 | private HashSet<String> mSwipedOutKeys = new HashSet<>(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 66 | private HashSet<NotificationEntry> mEntriesToRemoveAfterExpand = new HashSet<>(); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 67 | private HashSet<String> mKeysToRemoveWhenLeavingKeyguard = new HashSet<>(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 68 | private ArraySet<NotificationEntry> mEntriesToRemoveWhenReorderingAllowed |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 69 | = new ArraySet<>(); |
| 70 | private boolean mIsExpanded; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 71 | private boolean mHeadsUpGoingAway; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 72 | private int mStatusBarState; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 73 | private AnimationStateHandler mAnimationStateHandler; |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 74 | private int mHeadsUpInset; |
| 75 | |
| 76 | // Used for determining the region for touch interaction |
| 77 | private final Region mTouchableRegion = new Region(); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 78 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 79 | private final Pools.Pool<HeadsUpEntryPhone> mEntryPool = new Pools.Pool<HeadsUpEntryPhone>() { |
| 80 | private Stack<HeadsUpEntryPhone> mPoolObjects = new Stack<>(); |
| 81 | |
| 82 | @Override |
| 83 | public HeadsUpEntryPhone acquire() { |
| 84 | if (!mPoolObjects.isEmpty()) { |
| 85 | return mPoolObjects.pop(); |
| 86 | } |
| 87 | return new HeadsUpEntryPhone(); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public boolean release(@NonNull HeadsUpEntryPhone instance) { |
| 92 | mPoolObjects.push(instance); |
| 93 | return true; |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 98 | // Constructor: |
| 99 | |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 100 | public HeadsUpManagerPhone(@NonNull final Context context, |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 101 | StatusBarStateController statusBarStateController, |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 102 | KeyguardBypassController bypassController, |
| 103 | NotificationGroupManager groupManager, |
| 104 | ConfigurationController configurationController) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 105 | super(context); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 106 | Resources resources = mContext.getResources(); |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 107 | mExtensionTime = resources.getInteger(R.integer.ambient_notification_extension_time); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 108 | mAutoHeadsUpNotificationDecay = resources.getInteger( |
| 109 | R.integer.auto_heads_up_notification_decay); |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 110 | statusBarStateController.addCallback(mStatusBarStateListener); |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 111 | mBypassController = bypassController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 112 | mGroupManager = groupManager; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 113 | |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 114 | updateResources(); |
| 115 | configurationController.addCallback(new ConfigurationController.ConfigurationListener() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 116 | @Override |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 117 | public void onDensityOrFontScaleChanged() { |
| 118 | updateResources(); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void onOverlayChanged() { |
| 123 | updateResources(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 124 | } |
| 125 | }); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 128 | void setup(VisualStabilityManager visualStabilityManager) { |
| 129 | mVisualStabilityManager = visualStabilityManager; |
| 130 | } |
| 131 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 132 | public void setAnimationStateHandler(AnimationStateHandler handler) { |
| 133 | mAnimationStateHandler = handler; |
| 134 | } |
| 135 | |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 136 | private void updateResources() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 137 | Resources resources = mContext.getResources(); |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 138 | mHeadsUpInset = |
| 139 | resources.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height) |
| 140 | + resources.getDimensionPixelSize(R.dimen.heads_up_status_bar_padding); |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 141 | } |
| 142 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 143 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 144 | // Public methods: |
| 145 | |
| 146 | /** |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 147 | * Add a listener to receive callbacks onHeadsUpGoingAway |
| 148 | */ |
| 149 | void addHeadsUpPhoneListener(OnHeadsUpPhoneListenerChange listener) { |
| 150 | mHeadsUpPhoneListeners.add(listener); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Gets the touchable region needed for heads up notifications. Returns null if no touchable |
| 155 | * region is required (ie: no heads up notification currently exists). |
| 156 | */ |
| 157 | @Nullable Region getTouchableRegion() { |
| 158 | NotificationEntry topEntry = getTopEntry(); |
| 159 | |
| 160 | // This call could be made in an inconsistent state while the pinnedMode hasn't been |
| 161 | // updated yet, but callbacks leading out of the headsUp manager, querying it. Let's |
| 162 | // therefore also check if the topEntry is null. |
| 163 | if (!hasPinnedHeadsUp() || topEntry == null) { |
| 164 | return null; |
| 165 | } else { |
| 166 | if (topEntry.isChildInGroup()) { |
| 167 | final NotificationEntry groupSummary = |
| 168 | mGroupManager.getGroupSummary(topEntry.getSbn()); |
| 169 | if (groupSummary != null) { |
| 170 | topEntry = groupSummary; |
| 171 | } |
| 172 | } |
| 173 | ExpandableNotificationRow topRow = topEntry.getRow(); |
| 174 | int[] tmpArray = new int[2]; |
| 175 | topRow.getLocationOnScreen(tmpArray); |
| 176 | int minX = tmpArray[0]; |
| 177 | int maxX = tmpArray[0] + topRow.getWidth(); |
| 178 | int height = topRow.getIntrinsicHeight(); |
| 179 | mTouchableRegion.set(minX, 0, maxX, mHeadsUpInset + height); |
| 180 | return mTouchableRegion; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 185 | * Decides whether a click is invalid for a notification, i.e it has not been shown long enough |
| 186 | * that a user might have consciously clicked on it. |
| 187 | * |
| 188 | * @param key the key of the touched notification |
| 189 | * @return whether the touch is invalid and should be discarded |
| 190 | */ |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 191 | boolean shouldSwallowClick(@NonNull String key) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 192 | HeadsUpManager.HeadsUpEntry entry = getHeadsUpEntry(key); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 193 | return entry != null && mClock.currentTimeMillis() < entry.mPostTime; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | public void onExpandingFinished() { |
| 197 | if (mReleaseOnExpandFinish) { |
| 198 | releaseAllImmediately(); |
| 199 | mReleaseOnExpandFinish = false; |
| 200 | } else { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 201 | for (NotificationEntry entry : mEntriesToRemoveAfterExpand) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 202 | if (isAlerting(entry.getKey())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 203 | // Maybe the heads-up was removed already |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 204 | removeAlertEntry(entry.getKey()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | } |
| 208 | mEntriesToRemoveAfterExpand.clear(); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Sets the tracking-heads-up flag. If the flag is true, HeadsUpManager doesn't remove the entry |
| 213 | * from the list even after a Heads Up Notification is gone. |
| 214 | */ |
| 215 | public void setTrackingHeadsUp(boolean trackingHeadsUp) { |
| 216 | mTrackingHeadsUp = trackingHeadsUp; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Notify that the status bar panel gets expanded or collapsed. |
| 221 | * |
| 222 | * @param isExpanded True to notify expanded, false to notify collapsed. |
| 223 | */ |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 224 | void setIsPanelExpanded(boolean isExpanded) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 225 | if (isExpanded != mIsExpanded) { |
| 226 | mIsExpanded = isExpanded; |
| 227 | if (isExpanded) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 228 | mHeadsUpGoingAway = false; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 229 | } |
Selim Cinek | 91d0466 | 2019-06-24 17:13:06 -0700 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 233 | @Override |
| 234 | public boolean isEntryAutoHeadsUpped(String key) { |
| 235 | HeadsUpEntryPhone headsUpEntryPhone = getHeadsUpEntryPhone(key); |
| 236 | if (headsUpEntryPhone == null) { |
| 237 | return false; |
| 238 | } |
| 239 | return headsUpEntryPhone.isAutoHeadsUp(); |
| 240 | } |
| 241 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 242 | /** |
| 243 | * Set that we are exiting the headsUp pinned mode, but some notifications might still be |
| 244 | * animating out. This is used to keep the touchable regions in a sane state. |
| 245 | */ |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 246 | void setHeadsUpGoingAway(boolean headsUpGoingAway) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 247 | if (headsUpGoingAway != mHeadsUpGoingAway) { |
| 248 | mHeadsUpGoingAway = headsUpGoingAway; |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 249 | for (OnHeadsUpPhoneListenerChange listener : mHeadsUpPhoneListeners) { |
| 250 | listener.onHeadsUpGoingAwayStateChanged(headsUpGoingAway); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 251 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 255 | boolean isHeadsUpGoingAway() { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 256 | return mHeadsUpGoingAway; |
| 257 | } |
| 258 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 259 | /** |
| 260 | * Notifies that a remote input textbox in notification gets active or inactive. |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 261 | * |
| 262 | * @param entry The entry of the target notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 263 | * @param remoteInputActive True to notify active, False to notify inactive. |
| 264 | */ |
| 265 | public void setRemoteInputActive( |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 266 | @NonNull NotificationEntry entry, boolean remoteInputActive) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 267 | HeadsUpEntryPhone headsUpEntry = getHeadsUpEntryPhone(entry.getKey()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 268 | if (headsUpEntry != null && headsUpEntry.remoteInputActive != remoteInputActive) { |
| 269 | headsUpEntry.remoteInputActive = remoteInputActive; |
| 270 | if (remoteInputActive) { |
| 271 | headsUpEntry.removeAutoRemovalCallbacks(); |
| 272 | } else { |
| 273 | headsUpEntry.updateEntry(false /* updatePostTime */); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 278 | /** |
| 279 | * Sets whether an entry's menu row is exposed and therefore it should stick in the heads up |
| 280 | * area if it's pinned until it's hidden again. |
| 281 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 282 | public void setMenuShown(@NonNull NotificationEntry entry, boolean menuShown) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 283 | HeadsUpEntry headsUpEntry = getHeadsUpEntry(entry.getKey()); |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 284 | if (headsUpEntry instanceof HeadsUpEntryPhone && entry.isRowPinned()) { |
| 285 | ((HeadsUpEntryPhone) headsUpEntry).setMenuShownPinned(menuShown); |
| 286 | } |
| 287 | } |
| 288 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 289 | /** |
| 290 | * Extends the lifetime of the currently showing pulsing notification so that the pulse lasts |
| 291 | * longer. |
| 292 | */ |
| 293 | public void extendHeadsUp() { |
| 294 | HeadsUpEntryPhone topEntry = getTopHeadsUpEntryPhone(); |
| 295 | if (topEntry == null) { |
| 296 | return; |
| 297 | } |
| 298 | topEntry.extendPulse(); |
| 299 | } |
| 300 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 301 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 302 | // HeadsUpManager public methods overrides: |
| 303 | |
| 304 | @Override |
| 305 | public boolean isTrackingHeadsUp() { |
| 306 | return mTrackingHeadsUp; |
| 307 | } |
| 308 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 309 | @Override |
| 310 | public void snooze() { |
| 311 | super.snooze(); |
| 312 | mReleaseOnExpandFinish = true; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | public void addSwipedOutNotification(@NonNull String key) { |
| 316 | mSwipedOutKeys.add(key); |
| 317 | } |
| 318 | |
| 319 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 320 | // Dumpable overrides: |
| 321 | |
| 322 | @Override |
| 323 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 324 | pw.println("HeadsUpManagerPhone state:"); |
| 325 | dumpInternal(fd, pw, args); |
| 326 | } |
| 327 | |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 328 | @Override |
Selim Cinek | bd55909 | 2019-01-28 19:38:58 -0800 | [diff] [blame] | 329 | public boolean shouldExtendLifetime(NotificationEntry entry) { |
| 330 | // We should not defer the removal if reordering isn't allowed since otherwise |
| 331 | // these won't disappear until reordering is allowed again, which happens only once |
| 332 | // the notification panel is collapsed again. |
| 333 | return mVisualStabilityManager.isReorderingAllowed() && super.shouldExtendLifetime(entry); |
| 334 | } |
| 335 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 336 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 337 | // VisualStabilityManager.Callback overrides: |
| 338 | |
| 339 | @Override |
Selim Cinek | ba069ae | 2020-04-01 19:45:16 -0700 | [diff] [blame] | 340 | public void onChangeAllowed() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 341 | mAnimationStateHandler.setHeadsUpGoingAwayAnimationsAllowed(false); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 342 | for (NotificationEntry entry : mEntriesToRemoveWhenReorderingAllowed) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 343 | if (isAlerting(entry.getKey())) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 344 | // Maybe the heads-up was removed already |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 345 | removeAlertEntry(entry.getKey()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | mEntriesToRemoveWhenReorderingAllowed.clear(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 349 | mAnimationStateHandler.setHeadsUpGoingAwayAnimationsAllowed(true); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 353 | // HeadsUpManager utility (protected) methods overrides: |
| 354 | |
| 355 | @Override |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 356 | protected HeadsUpEntry createAlertEntry() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 357 | return mEntryPool.acquire(); |
| 358 | } |
| 359 | |
| 360 | @Override |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 361 | protected void onAlertEntryRemoved(AlertEntry alertEntry) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 362 | mKeysToRemoveWhenLeavingKeyguard.remove(alertEntry.mEntry.getKey()); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 363 | super.onAlertEntryRemoved(alertEntry); |
| 364 | mEntryPool.release((HeadsUpEntryPhone) alertEntry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 368 | protected boolean shouldHeadsUpBecomePinned(NotificationEntry entry) { |
Selim Cinek | d21232e | 2019-06-20 14:15:59 -0700 | [diff] [blame] | 369 | boolean pin = mStatusBarState == StatusBarState.SHADE && !mIsExpanded; |
| 370 | if (mBypassController.getBypassEnabled()) { |
| 371 | pin |= mStatusBarState == StatusBarState.KEYGUARD; |
| 372 | } |
| 373 | return pin || super.shouldHeadsUpBecomePinned(entry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Override |
| 377 | protected void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 378 | super.dumpInternal(fd, pw, args); |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 379 | pw.print(" mBarState="); |
| 380 | pw.println(mStatusBarState); |
Evan Laird | e1822fd | 2019-07-10 15:55:45 -0400 | [diff] [blame] | 381 | pw.print(" mTouchableRegion="); |
| 382 | pw.println(mTouchableRegion); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 386 | // Private utility methods: |
| 387 | |
| 388 | @Nullable |
| 389 | private HeadsUpEntryPhone getHeadsUpEntryPhone(@NonNull String key) { |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 390 | return (HeadsUpEntryPhone) mAlertEntries.get(key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | @Nullable |
| 394 | private HeadsUpEntryPhone getTopHeadsUpEntryPhone() { |
| 395 | return (HeadsUpEntryPhone) getTopHeadsUpEntry(); |
| 396 | } |
| 397 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 398 | @Override |
| 399 | protected boolean canRemoveImmediately(@NonNull String key) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 400 | if (mSwipedOutKeys.contains(key)) { |
| 401 | // We always instantly dismiss views being manually swiped out. |
| 402 | mSwipedOutKeys.remove(key); |
| 403 | return true; |
| 404 | } |
| 405 | |
| 406 | HeadsUpEntryPhone headsUpEntry = getHeadsUpEntryPhone(key); |
| 407 | HeadsUpEntryPhone topEntry = getTopHeadsUpEntryPhone(); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 408 | |
| 409 | return headsUpEntry == null || headsUpEntry != topEntry || super.canRemoveImmediately(key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 410 | } |
| 411 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 412 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 413 | // HeadsUpEntryPhone: |
| 414 | |
| 415 | protected class HeadsUpEntryPhone extends HeadsUpManager.HeadsUpEntry { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 416 | |
| 417 | private boolean mMenuShownPinned; |
| 418 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 419 | /** |
| 420 | * If the time this entry has been on was extended |
| 421 | */ |
| 422 | private boolean extended; |
| 423 | |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 424 | /** |
| 425 | * Was this entry received while on keyguard |
| 426 | */ |
| 427 | private boolean mIsAutoHeadsUp; |
| 428 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 429 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 430 | @Override |
| 431 | protected boolean isSticky() { |
| 432 | return super.isSticky() || mMenuShownPinned; |
| 433 | } |
| 434 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 435 | public void setEntry(@NonNull final NotificationEntry entry) { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 436 | Runnable removeHeadsUpRunnable = () -> { |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 437 | if (!mVisualStabilityManager.isReorderingAllowed() |
| 438 | // We don't want to allow reordering while pulsing, but headsup need to |
Selim Cinek | b57dd8a | 2019-06-14 12:27:58 -0700 | [diff] [blame] | 439 | // time out anyway |
| 440 | && !entry.showingPulsing()) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 441 | mEntriesToRemoveWhenReorderingAllowed.add(entry); |
Selim Cinek | 0260c75 | 2020-05-11 16:03:52 -0700 | [diff] [blame] | 442 | mVisualStabilityManager.addReorderingAllowedCallback(HeadsUpManagerPhone.this, |
| 443 | false /* persistent */); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 444 | } else if (mTrackingHeadsUp) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 445 | mEntriesToRemoveAfterExpand.add(entry); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 446 | } else if (mIsAutoHeadsUp && mStatusBarState == StatusBarState.KEYGUARD) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 447 | mKeysToRemoveWhenLeavingKeyguard.add(entry.getKey()); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 448 | } else { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 449 | removeAlertEntry(entry.getKey()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 450 | } |
| 451 | }; |
| 452 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 453 | setEntry(entry, removeHeadsUpRunnable); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | @Override |
| 457 | public void updateEntry(boolean updatePostTime) { |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 458 | mIsAutoHeadsUp = mEntry.isAutoHeadsUp(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 459 | super.updateEntry(updatePostTime); |
| 460 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 461 | if (mEntriesToRemoveAfterExpand.contains(mEntry)) { |
| 462 | mEntriesToRemoveAfterExpand.remove(mEntry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 463 | } |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 464 | if (mEntriesToRemoveWhenReorderingAllowed.contains(mEntry)) { |
| 465 | mEntriesToRemoveWhenReorderingAllowed.remove(mEntry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 466 | } |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 467 | mKeysToRemoveWhenLeavingKeyguard.remove(mEntry.getKey()); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | @Override |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 471 | public void setExpanded(boolean expanded) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 472 | if (this.expanded == expanded) { |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | this.expanded = expanded; |
| 477 | if (expanded) { |
| 478 | removeAutoRemovalCallbacks(); |
| 479 | } else { |
| 480 | updateEntry(false /* updatePostTime */); |
| 481 | } |
| 482 | } |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 483 | |
| 484 | public void setMenuShownPinned(boolean menuShownPinned) { |
| 485 | if (mMenuShownPinned == menuShownPinned) { |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | mMenuShownPinned = menuShownPinned; |
| 490 | if (menuShownPinned) { |
| 491 | removeAutoRemovalCallbacks(); |
| 492 | } else { |
| 493 | updateEntry(false /* updatePostTime */); |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public void reset() { |
| 499 | super.reset(); |
| 500 | mMenuShownPinned = false; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 501 | extended = false; |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 502 | mIsAutoHeadsUp = false; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | private void extendPulse() { |
| 506 | if (!extended) { |
| 507 | extended = true; |
| 508 | updateEntry(false); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | @Override |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 513 | public int compareTo(AlertEntry alertEntry) { |
| 514 | HeadsUpEntryPhone headsUpEntry = (HeadsUpEntryPhone) alertEntry; |
| 515 | boolean autoShown = isAutoHeadsUp(); |
| 516 | boolean otherAutoShown = headsUpEntry.isAutoHeadsUp(); |
| 517 | if (autoShown && !otherAutoShown) { |
| 518 | return 1; |
| 519 | } else if (!autoShown && otherAutoShown) { |
| 520 | return -1; |
| 521 | } |
| 522 | return super.compareTo(alertEntry); |
| 523 | } |
| 524 | |
| 525 | @Override |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 526 | protected long calculateFinishTime() { |
| 527 | return mPostTime + getDecayDuration() + (extended ? mExtensionTime : 0); |
| 528 | } |
| 529 | |
| 530 | private int getDecayDuration() { |
Lucas Dupin | d534c12 | 2019-07-16 18:48:59 -0700 | [diff] [blame] | 531 | if (isAutoHeadsUp()) { |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 532 | return getRecommendedHeadsUpTimeoutMs(mAutoHeadsUpNotificationDecay); |
| 533 | } else { |
| 534 | return getRecommendedHeadsUpTimeoutMs(mAutoDismissNotificationDecay); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | private boolean isAutoHeadsUp() { |
| 539 | return mIsAutoHeadsUp; |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 540 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 541 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 542 | |
| 543 | public interface AnimationStateHandler { |
| 544 | void setHeadsUpGoingAwayAnimationsAllowed(boolean allowed); |
| 545 | } |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * Listener to register for HeadsUpNotification Phone changes. |
| 549 | */ |
| 550 | public interface OnHeadsUpPhoneListenerChange { |
| 551 | /** |
| 552 | * Called when a heads up notification is 'going away' or no longer 'going away'. |
| 553 | * See {@link HeadsUpManagerPhone#setHeadsUpGoingAway}. |
| 554 | */ |
| 555 | void onHeadsUpGoingAwayStateChanged(boolean headsUpGoingAway); |
| 556 | } |
| 557 | |
| 558 | private final StateListener mStatusBarStateListener = new StateListener() { |
| 559 | @Override |
| 560 | public void onStateChanged(int newState) { |
| 561 | boolean wasKeyguard = mStatusBarState == StatusBarState.KEYGUARD; |
| 562 | boolean isKeyguard = newState == StatusBarState.KEYGUARD; |
| 563 | mStatusBarState = newState; |
| 564 | if (wasKeyguard && !isKeyguard && mKeysToRemoveWhenLeavingKeyguard.size() != 0) { |
| 565 | String[] keys = mKeysToRemoveWhenLeavingKeyguard.toArray(new String[0]); |
| 566 | for (String key : keys) { |
| 567 | removeAlertEntry(key); |
| 568 | } |
| 569 | mKeysToRemoveWhenLeavingKeyguard.clear(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | @Override |
| 574 | public void onDozingChanged(boolean isDozing) { |
| 575 | if (!isDozing) { |
| 576 | // Let's make sure all huns we got while dozing time out within the normal timeout |
| 577 | // duration. Otherwise they could get stuck for a very long time |
| 578 | for (AlertEntry entry : mAlertEntries.values()) { |
| 579 | entry.updateEntry(true /* updatePostTime */); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | }; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 584 | } |