Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [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 | |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 19 | import static android.service.notification.NotificationListenerService.REASON_CLICK; |
| 20 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 21 | import static com.android.systemui.statusbar.phone.StatusBar.getActivityOptions; |
| 22 | |
| 23 | import android.app.ActivityManager; |
| 24 | import android.app.ActivityTaskManager; |
| 25 | import android.app.KeyguardManager; |
| 26 | import android.app.Notification; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 27 | import android.app.NotificationManager; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 28 | import android.app.PendingIntent; |
| 29 | import android.app.TaskStackBuilder; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
| 32 | import android.os.AsyncTask; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 33 | import android.os.Handler; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 34 | import android.os.Looper; |
| 35 | import android.os.RemoteException; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 36 | import android.os.UserHandle; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 37 | import android.service.dreams.IDreamManager; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 38 | import android.service.notification.StatusBarNotification; |
| 39 | import android.text.TextUtils; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 40 | import android.util.EventLog; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 41 | import android.util.Log; |
| 42 | import android.view.RemoteAnimationAdapter; |
| 43 | |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 44 | import com.android.internal.logging.MetricsLogger; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 45 | import com.android.internal.statusbar.IStatusBarService; |
| 46 | import com.android.internal.statusbar.NotificationVisibility; |
| 47 | import com.android.internal.widget.LockPatternUtils; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 48 | import com.android.systemui.ActivityIntentHelper; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 49 | import com.android.systemui.Dependency; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 50 | import com.android.systemui.EventLogTags; |
| 51 | import com.android.systemui.UiOffloadThread; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 52 | import com.android.systemui.assist.AssistManager; |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 53 | import com.android.systemui.bubbles.BubbleController; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 54 | import com.android.systemui.plugins.ActivityStarter; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 55 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 56 | import com.android.systemui.statusbar.CommandQueue; |
| 57 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 58 | import com.android.systemui.statusbar.NotificationPresenter; |
| 59 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 60 | import com.android.systemui.statusbar.RemoteInputController; |
| 61 | import com.android.systemui.statusbar.StatusBarState; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; |
| 63 | import com.android.systemui.statusbar.notification.NotificationActivityStarter; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 70 | import com.android.systemui.statusbar.policy.HeadsUpUtil; |
| 71 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Status bar implementation of {@link NotificationActivityStarter}. |
| 75 | */ |
| 76 | public class StatusBarNotificationActivityStarter implements NotificationActivityStarter { |
| 77 | |
| 78 | private static final String TAG = "NotificationClickHandler"; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 79 | protected static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 80 | |
Mark Renouf | 906a93f | 2019-03-15 16:04:58 -0400 | [diff] [blame] | 81 | private final AssistManager mAssistManager; |
| 82 | private final NotificationGroupManager mGroupManager; |
| 83 | private final StatusBarRemoteInputCallback mStatusBarRemoteInputCallback; |
| 84 | private final NotificationRemoteInputManager mRemoteInputManager; |
| 85 | private final NotificationLockscreenUserManager mLockscreenUserManager; |
| 86 | private final ShadeController mShadeController; |
| 87 | private final KeyguardMonitor mKeyguardMonitor; |
| 88 | private final ActivityStarter mActivityStarter; |
| 89 | private final NotificationEntryManager mEntryManager; |
| 90 | private final StatusBarStateController mStatusBarStateController; |
| 91 | private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider; |
| 92 | private final MetricsLogger mMetricsLogger; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 93 | private final Context mContext; |
| 94 | private final NotificationPanelView mNotificationPanel; |
| 95 | private final NotificationPresenter mPresenter; |
| 96 | private final LockPatternUtils mLockPatternUtils; |
| 97 | private final HeadsUpManagerPhone mHeadsUpManager; |
| 98 | private final KeyguardManager mKeyguardManager; |
| 99 | private final ActivityLaunchAnimator mActivityLaunchAnimator; |
| 100 | private final IStatusBarService mBarService; |
| 101 | private final CommandQueue mCommandQueue; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 102 | private final IDreamManager mDreamManager; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 103 | private final Handler mMainThreadHandler; |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 104 | private final Handler mBackgroundHandler; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 105 | private final ActivityIntentHelper mActivityIntentHelper; |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 106 | private final BubbleController mBubbleController; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 107 | |
| 108 | private boolean mIsCollapsingToShowActivityOverLockscreen; |
| 109 | |
| 110 | public StatusBarNotificationActivityStarter(Context context, |
Mark Renouf | 906a93f | 2019-03-15 16:04:58 -0400 | [diff] [blame] | 111 | CommandQueue commandQueue, |
| 112 | AssistManager assistManager, |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 113 | NotificationPanelView panel, |
| 114 | NotificationPresenter presenter, |
Mark Renouf | 906a93f | 2019-03-15 16:04:58 -0400 | [diff] [blame] | 115 | NotificationEntryManager entryManager, |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 116 | HeadsUpManagerPhone headsUpManager, |
Mark Renouf | 906a93f | 2019-03-15 16:04:58 -0400 | [diff] [blame] | 117 | ActivityStarter activityStarter, |
| 118 | ActivityLaunchAnimator activityLaunchAnimator, |
| 119 | IStatusBarService statusBarService, |
| 120 | StatusBarStateController statusBarStateController, |
| 121 | KeyguardManager keyguardManager, |
| 122 | IDreamManager dreamManager, |
| 123 | NotificationRemoteInputManager remoteInputManager, |
| 124 | StatusBarRemoteInputCallback remoteInputCallback, |
| 125 | NotificationGroupManager groupManager, |
| 126 | NotificationLockscreenUserManager lockscreenUserManager, |
| 127 | ShadeController shadeController, |
| 128 | KeyguardMonitor keyguardMonitor, |
| 129 | NotificationInterruptionStateProvider notificationInterruptionStateProvider, |
| 130 | MetricsLogger metricsLogger, |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 131 | LockPatternUtils lockPatternUtils, |
| 132 | Handler mainThreadHandler, |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 133 | Handler backgroundHandler, |
| 134 | ActivityIntentHelper activityIntentHelper, |
| 135 | BubbleController bubbleController) { |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 136 | mContext = context; |
| 137 | mNotificationPanel = panel; |
| 138 | mPresenter = presenter; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 139 | mHeadsUpManager = headsUpManager; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 140 | mActivityLaunchAnimator = activityLaunchAnimator; |
Mark Renouf | 906a93f | 2019-03-15 16:04:58 -0400 | [diff] [blame] | 141 | mBarService = statusBarService; |
| 142 | mCommandQueue = commandQueue; |
| 143 | mKeyguardManager = keyguardManager; |
| 144 | mDreamManager = dreamManager; |
| 145 | mRemoteInputManager = remoteInputManager; |
| 146 | mLockscreenUserManager = lockscreenUserManager; |
| 147 | mShadeController = shadeController; |
| 148 | mKeyguardMonitor = keyguardMonitor; |
| 149 | mActivityStarter = activityStarter; |
| 150 | mEntryManager = entryManager; |
| 151 | mStatusBarStateController = statusBarStateController; |
| 152 | mNotificationInterruptionStateProvider = notificationInterruptionStateProvider; |
| 153 | mMetricsLogger = metricsLogger; |
| 154 | mAssistManager = assistManager; |
| 155 | mGroupManager = groupManager; |
| 156 | mLockPatternUtils = lockPatternUtils; |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 157 | mBackgroundHandler = backgroundHandler; |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 158 | mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 159 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 160 | public void onPendingEntryAdded(NotificationEntry entry) { |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 161 | handleFullScreenIntent(entry); |
| 162 | } |
| 163 | }); |
Mark Renouf | 906a93f | 2019-03-15 16:04:58 -0400 | [diff] [blame] | 164 | mStatusBarRemoteInputCallback = remoteInputCallback; |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 165 | mMainThreadHandler = mainThreadHandler; |
| 166 | mActivityIntentHelper = activityIntentHelper; |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 167 | mBubbleController = bubbleController; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
| 171 | * Called when a notification is clicked. |
| 172 | * |
| 173 | * @param sbn notification that was clicked |
| 174 | * @param row row for that notification |
| 175 | */ |
| 176 | @Override |
| 177 | public void onNotificationClicked(StatusBarNotification sbn, ExpandableNotificationRow row) { |
| 178 | RemoteInputController controller = mRemoteInputManager.getController(); |
| 179 | if (controller.isRemoteInputActive(row.getEntry()) |
| 180 | && !TextUtils.isEmpty(row.getActiveRemoteInputText())) { |
| 181 | // We have an active remote input typed and the user clicked on the notification. |
| 182 | // this was probably unintentional, so we're closing the edit text instead. |
| 183 | controller.closeRemoteInputs(); |
| 184 | return; |
| 185 | } |
| 186 | Notification notification = sbn.getNotification(); |
| 187 | final PendingIntent intent = notification.contentIntent != null |
| 188 | ? notification.contentIntent |
| 189 | : notification.fullScreenIntent; |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 190 | final boolean isBubble = row.getEntry().isBubble(); |
| 191 | |
| 192 | // This code path is now executed for notification without a contentIntent. |
| 193 | // The only valid case is Bubble notifications. Guard against other cases |
| 194 | // entering here. |
| 195 | if (intent == null && !isBubble) { |
| 196 | Log.e(TAG, "onNotificationClicked called for non-clickable notification!"); |
| 197 | return; |
| 198 | } |
| 199 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 200 | final String notificationKey = sbn.getKey(); |
| 201 | |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 202 | boolean isActivityIntent = intent != null && intent.isActivity() && !isBubble; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 203 | final boolean afterKeyguardGone = isActivityIntent |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 204 | && mActivityIntentHelper.wouldLaunchResolverActivity(intent.getIntent(), |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 205 | mLockscreenUserManager.getCurrentUserId()); |
| 206 | final boolean wasOccluded = mShadeController.isOccluded(); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 207 | boolean showOverLockscreen = mKeyguardMonitor.isShowing() && intent != null |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 208 | && mActivityIntentHelper.wouldShowOverLockscreen(intent.getIntent(), |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 209 | mLockscreenUserManager.getCurrentUserId()); |
| 210 | ActivityStarter.OnDismissAction postKeyguardAction = |
| 211 | () -> handleNotificationClickAfterKeyguardDismissed( |
| 212 | sbn, row, controller, intent, notificationKey, |
| 213 | isActivityIntent, wasOccluded, showOverLockscreen); |
| 214 | if (showOverLockscreen) { |
| 215 | mIsCollapsingToShowActivityOverLockscreen = true; |
| 216 | postKeyguardAction.onDismiss(); |
| 217 | } else { |
| 218 | mActivityStarter.dismissKeyguardThenExecute( |
| 219 | postKeyguardAction, null /* cancel */, afterKeyguardGone); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | private boolean handleNotificationClickAfterKeyguardDismissed( |
| 224 | StatusBarNotification sbn, |
| 225 | ExpandableNotificationRow row, |
| 226 | RemoteInputController controller, |
| 227 | PendingIntent intent, |
| 228 | String notificationKey, |
| 229 | boolean isActivityIntent, |
| 230 | boolean wasOccluded, |
| 231 | boolean showOverLockscreen) { |
| 232 | // TODO: Some of this code may be able to move to NotificationEntryManager. |
| 233 | if (mHeadsUpManager != null && mHeadsUpManager.isAlerting(notificationKey)) { |
| 234 | // Release the HUN notification to the shade. |
| 235 | |
| 236 | if (mPresenter.isPresenterFullyCollapsed()) { |
| 237 | HeadsUpUtil.setIsClickedHeadsUpNotification(row, true); |
| 238 | } |
| 239 | // |
| 240 | // In most cases, when FLAG_AUTO_CANCEL is set, the notification will |
| 241 | // become canceled shortly by NoMan, but we can't assume that. |
| 242 | mHeadsUpManager.removeNotification(sbn.getKey(), |
| 243 | true /* releaseImmediately */); |
| 244 | } |
| 245 | StatusBarNotification parentToCancel = null; |
| 246 | if (shouldAutoCancel(sbn) && mGroupManager.isOnlyChildInGroup(sbn)) { |
| 247 | StatusBarNotification summarySbn = |
| 248 | mGroupManager.getLogicalGroupSummary(sbn).notification; |
| 249 | if (shouldAutoCancel(summarySbn)) { |
| 250 | parentToCancel = summarySbn; |
| 251 | } |
| 252 | } |
| 253 | final StatusBarNotification parentToCancelFinal = parentToCancel; |
| 254 | final Runnable runnable = () -> handleNotificationClickAfterPanelCollapsed( |
| 255 | sbn, row, controller, intent, notificationKey, |
| 256 | isActivityIntent, wasOccluded, parentToCancelFinal); |
| 257 | |
| 258 | if (showOverLockscreen) { |
| 259 | mShadeController.addPostCollapseAction(runnable); |
| 260 | mShadeController.collapsePanel(true /* animate */); |
| 261 | } else if (mKeyguardMonitor.isShowing() |
| 262 | && mShadeController.isOccluded()) { |
| 263 | mShadeController.addAfterKeyguardGoneRunnable(runnable); |
| 264 | mShadeController.collapsePanel(); |
| 265 | } else { |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 266 | mBackgroundHandler.postAtFrontOfQueue(runnable); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 267 | } |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 268 | return !mNotificationPanel.isFullyCollapsed(); |
| 269 | } |
| 270 | |
| 271 | private void handleNotificationClickAfterPanelCollapsed( |
| 272 | StatusBarNotification sbn, |
| 273 | ExpandableNotificationRow row, |
| 274 | RemoteInputController controller, |
| 275 | PendingIntent intent, |
| 276 | String notificationKey, |
| 277 | boolean isActivityIntent, |
| 278 | boolean wasOccluded, |
| 279 | StatusBarNotification parentToCancelFinal) { |
| 280 | try { |
| 281 | // The intent we are sending is for the application, which |
| 282 | // won't have permission to immediately start an activity after |
| 283 | // the user switches to home. We know it is safe to do at this |
| 284 | // point, so make sure new activity switches are now allowed. |
| 285 | ActivityManager.getService().resumeAppSwitches(); |
| 286 | } catch (RemoteException e) { |
| 287 | } |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 288 | // If we are launching a work activity and require to launch |
| 289 | // separate work challenge, we defer the activity action and cancel |
| 290 | // notification until work challenge is unlocked. |
| 291 | if (isActivityIntent) { |
| 292 | final int userId = intent.getCreatorUserHandle().getIdentifier(); |
| 293 | if (mLockPatternUtils.isSeparateProfileChallengeEnabled(userId) |
| 294 | && mKeyguardManager.isDeviceLocked(userId)) { |
| 295 | // TODO(b/28935539): should allow certain activities to |
| 296 | // bypass work challenge |
| 297 | if (mStatusBarRemoteInputCallback.startWorkChallengeIfNecessary(userId, |
| 298 | intent.getIntentSender(), notificationKey)) { |
| 299 | // Show work challenge, do not run PendingIntent and |
| 300 | // remove notification |
| 301 | collapseOnMainThread(); |
| 302 | return; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | Intent fillInIntent = null; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 307 | NotificationEntry entry = row.getEntry(); |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 308 | final boolean isBubble = entry.isBubble(); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 309 | CharSequence remoteInputText = null; |
| 310 | if (!TextUtils.isEmpty(entry.remoteInputText)) { |
| 311 | remoteInputText = entry.remoteInputText; |
| 312 | } |
| 313 | if (!TextUtils.isEmpty(remoteInputText) && !controller.isSpinning(entry.key)) { |
| 314 | fillInIntent = new Intent().putExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT, |
| 315 | remoteInputText.toString()); |
| 316 | } |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 317 | if (isBubble) { |
| 318 | expandBubbleStackOnMainThread(notificationKey); |
| 319 | } else { |
| 320 | startNotificationIntent(intent, fillInIntent, row, wasOccluded, isActivityIntent); |
| 321 | } |
| 322 | if (isActivityIntent || isBubble) { |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 323 | mAssistManager.hideAssist(); |
| 324 | } |
| 325 | if (shouldCollapse()) { |
| 326 | collapseOnMainThread(); |
| 327 | } |
| 328 | |
| 329 | final int count = |
| 330 | mEntryManager.getNotificationData().getActiveNotifications().size(); |
| 331 | final int rank = mEntryManager.getNotificationData().getRank(notificationKey); |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 332 | NotificationVisibility.NotificationLocation location = |
| 333 | NotificationLogger.getNotificationLocation( |
| 334 | mEntryManager.getNotificationData().get(notificationKey)); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 335 | final NotificationVisibility nv = NotificationVisibility.obtain(notificationKey, |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 336 | rank, count, true, location); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 337 | try { |
| 338 | mBarService.onNotificationClick(notificationKey, nv); |
| 339 | } catch (RemoteException ex) { |
| 340 | // system process is dead if we're here. |
| 341 | } |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 342 | if (!isBubble) { |
| 343 | if (parentToCancelFinal != null) { |
| 344 | removeNotification(parentToCancelFinal); |
| 345 | } |
| 346 | if (shouldAutoCancel(sbn) |
| 347 | || mRemoteInputManager.isNotificationKeptForRemoteInputHistory( |
| 348 | notificationKey)) { |
| 349 | // Automatically remove all notifications that we may have kept around longer |
| 350 | removeNotification(sbn); |
| 351 | } |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 352 | } |
| 353 | mIsCollapsingToShowActivityOverLockscreen = false; |
| 354 | } |
| 355 | |
Mark Renouf | fec45da | 2019-03-13 13:24:27 -0400 | [diff] [blame] | 356 | private void expandBubbleStackOnMainThread(String notificationKey) { |
| 357 | if (Looper.getMainLooper().isCurrentThread()) { |
| 358 | mBubbleController.expandStackAndSelectBubble(notificationKey); |
| 359 | } else { |
| 360 | mMainThreadHandler.post( |
| 361 | () -> mBubbleController.expandStackAndSelectBubble(notificationKey)); |
| 362 | } |
| 363 | } |
| 364 | |
Mark Renouf | 7bb6a24 | 2019-03-13 12:08:38 -0400 | [diff] [blame] | 365 | private void startNotificationIntent(PendingIntent intent, Intent fillInIntent, |
| 366 | ExpandableNotificationRow row, boolean wasOccluded, boolean isActivityIntent) { |
| 367 | RemoteAnimationAdapter adapter = mActivityLaunchAnimator.getLaunchAnimation(row, |
| 368 | wasOccluded); |
| 369 | try { |
| 370 | if (adapter != null) { |
| 371 | ActivityTaskManager.getService() |
| 372 | .registerRemoteAnimationForNextActivityStart( |
| 373 | intent.getCreatorPackage(), adapter); |
| 374 | } |
| 375 | int launchResult = intent.sendAndReturnResult(mContext, 0, fillInIntent, null, |
| 376 | null, null, getActivityOptions(adapter)); |
| 377 | mActivityLaunchAnimator.setLaunchResult(launchResult, isActivityIntent); |
| 378 | } catch (RemoteException | PendingIntent.CanceledException e) { |
| 379 | // the stack trace isn't very helpful here. |
| 380 | // Just log the exception message. |
| 381 | Log.w(TAG, "Sending contentIntent failed: " + e); |
| 382 | // TODO: Dismiss Keyguard. |
| 383 | } |
| 384 | } |
| 385 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 386 | @Override |
| 387 | public void startNotificationGutsIntent(final Intent intent, final int appUid, |
| 388 | ExpandableNotificationRow row) { |
| 389 | mActivityStarter.dismissKeyguardThenExecute(() -> { |
| 390 | AsyncTask.execute(() -> { |
| 391 | int launchResult = TaskStackBuilder.create(mContext) |
| 392 | .addNextIntentWithParentStack(intent) |
| 393 | .startActivities(getActivityOptions( |
| 394 | mActivityLaunchAnimator.getLaunchAnimation( |
| 395 | row, mShadeController.isOccluded())), |
| 396 | new UserHandle(UserHandle.getUserId(appUid))); |
| 397 | mActivityLaunchAnimator.setLaunchResult(launchResult, true /* isActivityIntent */); |
| 398 | if (shouldCollapse()) { |
| 399 | // Putting it back on the main thread, since we're touching views |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 400 | mMainThreadHandler.post(() -> mCommandQueue.animateCollapsePanels( |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 401 | CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL, true /* force */)); |
| 402 | } |
| 403 | }); |
| 404 | return true; |
| 405 | }, null, false /* afterKeyguardGone */); |
| 406 | } |
| 407 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 408 | private void handleFullScreenIntent(NotificationEntry entry) { |
Mady Mellor | 18cc097 | 2019-01-17 16:45:46 -0800 | [diff] [blame] | 409 | boolean isHeadsUped = mNotificationInterruptionStateProvider.shouldHeadsUp(entry); |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 410 | if (!isHeadsUped && entry.notification.getNotification().fullScreenIntent != null) { |
| 411 | if (shouldSuppressFullScreenIntent(entry)) { |
| 412 | if (DEBUG) { |
| 413 | Log.d(TAG, "No Fullscreen intent: suppressed by DND: " + entry.key); |
| 414 | } |
| 415 | } else if (entry.importance < NotificationManager.IMPORTANCE_HIGH) { |
| 416 | if (DEBUG) { |
| 417 | Log.d(TAG, "No Fullscreen intent: not important enough: " + entry.key); |
| 418 | } |
| 419 | } else { |
| 420 | // Stop screensaver if the notification has a fullscreen intent. |
| 421 | // (like an incoming phone call) |
| 422 | Dependency.get(UiOffloadThread.class).submit(() -> { |
| 423 | try { |
| 424 | mDreamManager.awaken(); |
| 425 | } catch (RemoteException e) { |
| 426 | e.printStackTrace(); |
| 427 | } |
| 428 | }); |
| 429 | |
| 430 | // not immersive & a fullscreen alert should be shown |
| 431 | if (DEBUG) { |
| 432 | Log.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent"); |
| 433 | } |
| 434 | try { |
| 435 | EventLog.writeEvent(EventLogTags.SYSUI_FULLSCREEN_NOTIFICATION, |
| 436 | entry.key); |
| 437 | entry.notification.getNotification().fullScreenIntent.send(); |
| 438 | entry.notifyFullScreenIntentLaunched(); |
| 439 | mMetricsLogger.count("note_fullscreen", 1); |
| 440 | } catch (PendingIntent.CanceledException e) { |
| 441 | // ignore |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 447 | @Override |
| 448 | public boolean isCollapsingToShowActivityOverLockscreen() { |
| 449 | return mIsCollapsingToShowActivityOverLockscreen; |
| 450 | } |
| 451 | |
| 452 | private static boolean shouldAutoCancel(StatusBarNotification sbn) { |
| 453 | int flags = sbn.getNotification().flags; |
| 454 | if ((flags & Notification.FLAG_AUTO_CANCEL) != Notification.FLAG_AUTO_CANCEL) { |
| 455 | return false; |
| 456 | } |
| 457 | if ((flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) { |
| 458 | return false; |
| 459 | } |
| 460 | return true; |
| 461 | } |
| 462 | |
| 463 | private void collapseOnMainThread() { |
| 464 | if (Looper.getMainLooper().isCurrentThread()) { |
| 465 | mShadeController.collapsePanel(); |
| 466 | } else { |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 467 | mMainThreadHandler.post(mShadeController::collapsePanel); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | |
| 471 | private boolean shouldCollapse() { |
| 472 | return mStatusBarStateController.getState() != StatusBarState.SHADE |
| 473 | || !mActivityLaunchAnimator.isAnimationPending(); |
| 474 | } |
| 475 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 476 | private boolean shouldSuppressFullScreenIntent(NotificationEntry entry) { |
Gus Prevas | d65c2db | 2018-12-18 17:13:38 -0500 | [diff] [blame] | 477 | if (mPresenter.isDeviceInVrMode()) { |
| 478 | return true; |
| 479 | } |
| 480 | |
| 481 | return entry.shouldSuppressFullScreenIntent(); |
| 482 | } |
| 483 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 484 | private void removeNotification(StatusBarNotification notification) { |
| 485 | // We have to post it to the UI thread for synchronization |
Mark Renouf | 6b2331c | 2019-03-21 13:40:08 -0400 | [diff] [blame] | 486 | mMainThreadHandler.post(() -> { |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 487 | Runnable removeRunnable = |
Mady Mellor | c2ff011 | 2019-03-28 14:18:06 -0700 | [diff] [blame] | 488 | () -> mEntryManager.performRemoveNotification(notification, REASON_CLICK); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 489 | if (mPresenter.isCollapsing()) { |
| 490 | // To avoid lags we're only performing the remove |
| 491 | // after the shade was collapsed |
| 492 | mShadeController.addPostCollapseAction(removeRunnable); |
| 493 | } else { |
| 494 | removeRunnable.run(); |
| 495 | } |
| 496 | }); |
| 497 | } |
| 498 | } |