Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.statusbar.phone; |
| 16 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 17 | import static com.android.systemui.statusbar.phone.StatusBar.CLOSE_PANEL_WHEN_EMPTIED; |
| 18 | import static com.android.systemui.statusbar.phone.StatusBar.DEBUG; |
| 19 | import static com.android.systemui.statusbar.phone.StatusBar.MULTIUSER_DEBUG; |
| 20 | import static com.android.systemui.statusbar.phone.StatusBar.SPEW; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 21 | |
Ned Burns | 1dd6b40 | 2019-01-02 15:25:23 -0500 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 23 | import android.app.KeyguardManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 24 | import android.content.Context; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 25 | import android.os.RemoteException; |
| 26 | import android.os.ServiceManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 27 | import android.service.notification.StatusBarNotification; |
| 28 | import android.service.vr.IVrManager; |
| 29 | import android.service.vr.IVrStateCallbacks; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 30 | import android.util.Log; |
| 31 | import android.util.Slog; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 32 | import android.view.View; |
| 33 | import android.view.ViewGroup; |
| 34 | import android.view.accessibility.AccessibilityManager; |
| 35 | import android.widget.TextView; |
| 36 | |
| 37 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 38 | import com.android.internal.statusbar.IStatusBarService; |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 39 | import com.android.internal.statusbar.NotificationVisibility; |
Selim Cinek | 9ba78f1 | 2018-12-07 14:37:33 -0800 | [diff] [blame] | 40 | import com.android.internal.widget.MessagingGroup; |
| 41 | import com.android.internal.widget.MessagingMessage; |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 42 | import com.android.keyguard.KeyguardUpdateMonitor; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 43 | import com.android.systemui.Dependency; |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 44 | import com.android.systemui.ForegroundServiceNotificationListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 45 | import com.android.systemui.InitController; |
| 46 | import com.android.systemui.R; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 47 | import com.android.systemui.plugins.ActivityStarter; |
| 48 | import com.android.systemui.plugins.ActivityStarter.OnDismissAction; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 49 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 50 | import com.android.systemui.statusbar.CommandQueue; |
Heemin Seog | 98df697 | 2019-12-05 13:01:38 -0800 | [diff] [blame] | 51 | import com.android.systemui.statusbar.KeyguardIndicationController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 52 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 53 | import com.android.systemui.statusbar.NotificationMediaManager; |
| 54 | import com.android.systemui.statusbar.NotificationPresenter; |
| 55 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 56 | import com.android.systemui.statusbar.NotificationViewHierarchyManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 57 | import com.android.systemui.statusbar.StatusBarState; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 58 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 59 | import com.android.systemui.statusbar.notification.AboveShelfObserver; |
| 60 | import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 61 | import com.android.systemui.statusbar.notification.DynamicPrivacyController; |
Gus Prevas | 26bc59b | 2018-12-19 11:26:39 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Ned Burns | 012048d | 2020-01-08 19:57:30 -0500 | [diff] [blame] | 66 | import com.android.systemui.statusbar.notification.collection.inflation.NotificationRowBinderImpl; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.interruption.NotificationInterruptStateProvider; |
| 68 | import com.android.systemui.statusbar.notification.interruption.NotificationInterruptSuppressor; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.row.ActivatableNotificationView; |
| 70 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 71 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
| 72 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager.OnSettingsClickListener; |
| 73 | import com.android.systemui.statusbar.notification.row.NotificationInfo.CheckSaveListener; |
| 74 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
Selim Cinek | 9ba78f1 | 2018-12-07 14:37:33 -0800 | [diff] [blame] | 75 | import com.android.systemui.statusbar.policy.ConfigurationController; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 76 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 77 | |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 78 | import java.util.List; |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 79 | |
Selim Cinek | 9ba78f1 | 2018-12-07 14:37:33 -0800 | [diff] [blame] | 80 | public class StatusBarNotificationPresenter implements NotificationPresenter, |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 81 | ConfigurationController.ConfigurationListener, |
Beverly | ea2010c | 2019-11-04 09:55:29 -0500 | [diff] [blame] | 82 | NotificationRowBinderImpl.BindRowCallback, |
| 83 | CommandQueue.Callbacks { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 84 | |
| 85 | private final LockscreenGestureLogger mLockscreenGestureLogger = |
| 86 | Dependency.get(LockscreenGestureLogger.class); |
| 87 | |
| 88 | private static final String TAG = "StatusBarNotificationPresenter"; |
| 89 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 90 | private final ActivityStarter mActivityStarter = Dependency.get(ActivityStarter.class); |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 91 | private final KeyguardStateController mKeyguardStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 92 | private final NotificationViewHierarchyManager mViewHierarchyManager = |
| 93 | Dependency.get(NotificationViewHierarchyManager.class); |
| 94 | private final NotificationLockscreenUserManager mLockscreenUserManager = |
| 95 | Dependency.get(NotificationLockscreenUserManager.class); |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 96 | private final SysuiStatusBarStateController mStatusBarStateController = |
| 97 | (SysuiStatusBarStateController) Dependency.get(StatusBarStateController.class); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 98 | private final NotificationEntryManager mEntryManager = |
| 99 | Dependency.get(NotificationEntryManager.class); |
| 100 | private final NotificationMediaManager mMediaManager = |
| 101 | Dependency.get(NotificationMediaManager.class); |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 102 | private final VisualStabilityManager mVisualStabilityManager = |
| 103 | Dependency.get(VisualStabilityManager.class); |
Ned Burns | 1016d96 | 2019-01-08 16:52:39 -0500 | [diff] [blame] | 104 | private final NotificationGutsManager mGutsManager = |
| 105 | Dependency.get(NotificationGutsManager.class); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 106 | |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 107 | private final NotificationPanelViewController mNotificationPanel; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 108 | private final HeadsUpManagerPhone mHeadsUpManager; |
| 109 | private final AboveShelfObserver mAboveShelfObserver; |
| 110 | private final DozeScrimController mDozeScrimController; |
| 111 | private final ScrimController mScrimController; |
| 112 | private final Context mContext; |
Heemin Seog | 98df697 | 2019-12-05 13:01:38 -0800 | [diff] [blame] | 113 | private final KeyguardIndicationController mKeyguardIndicationController; |
Heemin Seog | bd9bcbf | 2019-12-04 17:07:32 -0800 | [diff] [blame] | 114 | private final StatusBar mStatusBar; |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 115 | private final ShadeController mShadeController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 116 | private final CommandQueue mCommandQueue; |
| 117 | |
| 118 | private final AccessibilityManager mAccessibilityManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 119 | private final KeyguardManager mKeyguardManager; |
| 120 | private final ActivityLaunchAnimator mActivityLaunchAnimator; |
| 121 | private final int mMaxAllowedKeyguardNotifications; |
| 122 | private final IStatusBarService mBarService; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 123 | private final DynamicPrivacyController mDynamicPrivacyController; |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 124 | private boolean mReinflateNotificationsOnUserSwitched; |
| 125 | private boolean mDispatchUiModeChangeOnUserSwitched; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 126 | private TextView mNotificationPanelDebugText; |
| 127 | |
| 128 | protected boolean mVrMode; |
| 129 | private int mMaxKeyguardNotifications; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 130 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 131 | public StatusBarNotificationPresenter(Context context, |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 132 | NotificationPanelViewController panel, |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 133 | HeadsUpManagerPhone headsUp, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 134 | NotificationShadeWindowView statusBarWindow, |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 135 | ViewGroup stackScroller, |
| 136 | DozeScrimController dozeScrimController, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 137 | ScrimController scrimController, |
Gus Prevas | 0b8174a | 2018-12-07 11:35:53 -0500 | [diff] [blame] | 138 | ActivityLaunchAnimator activityLaunchAnimator, |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 139 | DynamicPrivacyController dynamicPrivacyController, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 140 | KeyguardStateController keyguardStateController, |
Heemin Seog | 98df697 | 2019-12-05 13:01:38 -0800 | [diff] [blame] | 141 | KeyguardIndicationController keyguardIndicationController, |
Heemin Seog | bd9bcbf | 2019-12-04 17:07:32 -0800 | [diff] [blame] | 142 | StatusBar statusBar, |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 143 | ShadeController shadeController, |
Dave Mankoff | 71fca1a | 2019-12-19 14:16:32 -0500 | [diff] [blame] | 144 | CommandQueue commandQueue, |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 145 | InitController initController, |
| 146 | NotificationInterruptStateProvider notificationInterruptStateProvider) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 147 | mContext = context; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 148 | mKeyguardStateController = keyguardStateController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 149 | mNotificationPanel = panel; |
| 150 | mHeadsUpManager = headsUp; |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 151 | mDynamicPrivacyController = dynamicPrivacyController; |
Heemin Seog | 98df697 | 2019-12-05 13:01:38 -0800 | [diff] [blame] | 152 | mKeyguardIndicationController = keyguardIndicationController; |
Heemin Seog | bd9bcbf | 2019-12-04 17:07:32 -0800 | [diff] [blame] | 153 | // TODO: use KeyguardStateController#isOccluded to remove this dependency |
| 154 | mStatusBar = statusBar; |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 155 | mShadeController = shadeController; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 156 | mCommandQueue = commandQueue; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 157 | mAboveShelfObserver = new AboveShelfObserver(stackScroller); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 158 | mActivityLaunchAnimator = activityLaunchAnimator; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 159 | mAboveShelfObserver.setListener(statusBarWindow.findViewById( |
| 160 | R.id.notification_container_parent)); |
| 161 | mAccessibilityManager = context.getSystemService(AccessibilityManager.class); |
| 162 | mDozeScrimController = dozeScrimController; |
| 163 | mScrimController = scrimController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 164 | mKeyguardManager = context.getSystemService(KeyguardManager.class); |
| 165 | mMaxAllowedKeyguardNotifications = context.getResources().getInteger( |
| 166 | R.integer.keyguard_max_notification_count); |
| 167 | mBarService = IStatusBarService.Stub.asInterface( |
| 168 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 169 | |
| 170 | if (MULTIUSER_DEBUG) { |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 171 | mNotificationPanelDebugText = mNotificationPanel.getHeaderDebugInfo(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 172 | mNotificationPanelDebugText.setVisibility(View.VISIBLE); |
| 173 | } |
| 174 | |
| 175 | IVrManager vrManager = IVrManager.Stub.asInterface(ServiceManager.getService( |
| 176 | Context.VR_SERVICE)); |
| 177 | if (vrManager != null) { |
| 178 | try { |
| 179 | vrManager.registerListener(mVrStateCallbacks); |
| 180 | } catch (RemoteException e) { |
| 181 | Slog.e(TAG, "Failed to register VR mode state listener: " + e); |
| 182 | } |
| 183 | } |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 184 | NotificationRemoteInputManager remoteInputManager = |
| 185 | Dependency.get(NotificationRemoteInputManager.class); |
| 186 | remoteInputManager.setUpWithCallback( |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 187 | Dependency.get(NotificationRemoteInputManager.Callback.class), |
| 188 | mNotificationPanel.createRemoteInputDelegate()); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 189 | remoteInputManager.getController().addCallback( |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 190 | Dependency.get(NotificationShadeWindowController.class)); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 191 | |
| 192 | NotificationListContainer notifListContainer = (NotificationListContainer) stackScroller; |
Dave Mankoff | 71fca1a | 2019-12-19 14:16:32 -0500 | [diff] [blame] | 193 | initController.addPostInitTask(() -> { |
Gus Prevas | 26bc59b | 2018-12-19 11:26:39 -0500 | [diff] [blame] | 194 | NotificationEntryListener notificationEntryListener = new NotificationEntryListener() { |
| 195 | @Override |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 196 | public void onEntryRemoved( |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 197 | @Nullable NotificationEntry entry, |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 198 | NotificationVisibility visibility, |
Julia Reynolds | 138111f | 2020-02-26 11:17:39 -0500 | [diff] [blame] | 199 | boolean removedByUser, |
| 200 | int reason) { |
Ned Burns | ef2ef6c | 2019-01-02 16:48:08 -0500 | [diff] [blame] | 201 | StatusBarNotificationPresenter.this.onNotificationRemoved( |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 202 | entry.getKey(), entry.getSbn()); |
Gus Prevas | dca2be5 | 2018-12-21 11:25:10 -0500 | [diff] [blame] | 203 | if (removedByUser) { |
| 204 | maybeEndAmbientPulse(); |
| 205 | } |
Gus Prevas | 26bc59b | 2018-12-19 11:26:39 -0500 | [diff] [blame] | 206 | } |
| 207 | }; |
| 208 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 209 | mViewHierarchyManager.setUpWithPresenter(this, notifListContainer); |
Beverly | 95a0802ac | 2020-02-10 15:27:40 -0500 | [diff] [blame] | 210 | mEntryManager.setUpWithPresenter(this); |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 211 | mEntryManager.addNotificationEntryListener(notificationEntryListener); |
Gus Prevas | 5c84abb | 2018-12-28 16:41:49 -0500 | [diff] [blame] | 212 | mEntryManager.addNotificationLifetimeExtender(mHeadsUpManager); |
Ned Burns | 1016d96 | 2019-01-08 16:52:39 -0500 | [diff] [blame] | 213 | mEntryManager.addNotificationLifetimeExtender(mGutsManager); |
Gus Prevas | 5c84abb | 2018-12-28 16:41:49 -0500 | [diff] [blame] | 214 | mEntryManager.addNotificationLifetimeExtenders( |
| 215 | remoteInputManager.getLifetimeExtenders()); |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 216 | notificationInterruptStateProvider.addSuppressor(mInterruptSuppressor); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 217 | mLockscreenUserManager.setUpWithPresenter(this); |
| 218 | mMediaManager.setUpWithPresenter(this); |
Gus Prevas | 5b9098dc | 2018-12-21 17:07:15 -0500 | [diff] [blame] | 219 | mVisualStabilityManager.setUpWithPresenter(this); |
Ned Burns | 1016d96 | 2019-01-08 16:52:39 -0500 | [diff] [blame] | 220 | mGutsManager.setUpWithPresenter(this, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 221 | notifListContainer, mCheckSaveListener, mOnSettingsClickListener); |
Evan Laird | 3ceaa9b | 2019-08-05 17:11:54 -0400 | [diff] [blame] | 222 | // ForegroundServiceNotificationListener adds its listener in its constructor |
Gus Prevas | eb4e2e1 | 2018-12-28 14:57:59 -0500 | [diff] [blame] | 223 | // but we need to request it here in order for it to be instantiated. |
| 224 | // TODO: figure out how to do this correctly once Dependency.get() is gone. |
| 225 | Dependency.get(ForegroundServiceNotificationListener.class); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 226 | |
| 227 | onUserSwitched(mLockscreenUserManager.getCurrentUserId()); |
| 228 | }); |
Selim Cinek | 9ba78f1 | 2018-12-07 14:37:33 -0800 | [diff] [blame] | 229 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Selim Cinek | 9ba78f1 | 2018-12-07 14:37:33 -0800 | [diff] [blame] | 232 | @Override |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 233 | public void onDensityOrFontScaleChanged() { |
Selim Cinek | 9ba78f1 | 2018-12-07 14:37:33 -0800 | [diff] [blame] | 234 | MessagingMessage.dropCache(); |
| 235 | MessagingGroup.dropCache(); |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 236 | if (!Dependency.get(KeyguardUpdateMonitor.class).isSwitchingUser()) { |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 237 | updateNotificationsOnDensityOrFontScaleChanged(); |
| 238 | } else { |
| 239 | mReinflateNotificationsOnUserSwitched = true; |
| 240 | } |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 244 | public void onUiModeChanged() { |
Dave Mankoff | e229469 | 2019-08-14 11:53:13 -0400 | [diff] [blame] | 245 | if (!Dependency.get(KeyguardUpdateMonitor.class).isSwitchingUser()) { |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 246 | updateNotificationOnUiModeChanged(); |
| 247 | } else { |
| 248 | mDispatchUiModeChangeOnUserSwitched = true; |
| 249 | } |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Selim Cinek | dd26a7e | 2019-02-11 18:42:55 -0800 | [diff] [blame] | 252 | @Override |
| 253 | public void onOverlayChanged() { |
| 254 | onDensityOrFontScaleChanged(); |
| 255 | } |
| 256 | |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 257 | private void updateNotificationOnUiModeChanged() { |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 258 | List<NotificationEntry> userNotifications = |
| 259 | mEntryManager.getActiveNotificationsForCurrentUser(); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 260 | for (int i = 0; i < userNotifications.size(); i++) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 261 | NotificationEntry entry = userNotifications.get(i); |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 262 | ExpandableNotificationRow row = entry.getRow(); |
| 263 | if (row != null) { |
| 264 | row.onUiModeChanged(); |
| 265 | } |
| 266 | } |
| 267 | } |
| 268 | |
Ned Burns | 1016d96 | 2019-01-08 16:52:39 -0500 | [diff] [blame] | 269 | private void updateNotificationsOnDensityOrFontScaleChanged() { |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 270 | List<NotificationEntry> userNotifications = |
| 271 | mEntryManager.getActiveNotificationsForCurrentUser(); |
Ned Burns | 1016d96 | 2019-01-08 16:52:39 -0500 | [diff] [blame] | 272 | for (int i = 0; i < userNotifications.size(); i++) { |
| 273 | NotificationEntry entry = userNotifications.get(i); |
| 274 | entry.onDensityOrFontScaleChanged(); |
| 275 | boolean exposedGuts = entry.areGutsExposed(); |
| 276 | if (exposedGuts) { |
| 277 | mGutsManager.onDensityOrFontScaleChanged(entry); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
Selim Cinek | ab9c7b2 | 2018-12-11 18:15:47 -0800 | [diff] [blame] | 282 | @Override |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 283 | public boolean isCollapsing() { |
| 284 | return mNotificationPanel.isCollapsing() |
| 285 | || mActivityLaunchAnimator.isAnimationPending() |
| 286 | || mActivityLaunchAnimator.isAnimationRunning(); |
| 287 | } |
| 288 | |
Gus Prevas | dca2be5 | 2018-12-21 11:25:10 -0500 | [diff] [blame] | 289 | private void maybeEndAmbientPulse() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 290 | if (mNotificationPanel.hasPulsingNotifications() && |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 291 | !mHeadsUpManager.hasNotifications()) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 292 | // We were showing a pulse for a notification, but no notifications are pulsing anymore. |
| 293 | // Finish the pulse. |
| 294 | mDozeScrimController.pulseOutNow(); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | @Override |
| 299 | public void updateNotificationViews() { |
| 300 | // The function updateRowStates depends on both of these being non-null, so check them here. |
| 301 | // We may be called before they are set from DeviceProvisionedController's callback. |
| 302 | if (mScrimController == null) return; |
| 303 | |
| 304 | // Do not modify the notifications during collapse. |
| 305 | if (isCollapsing()) { |
| 306 | mShadeController.addPostCollapseAction(this::updateNotificationViews); |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | mViewHierarchyManager.updateNotificationViews(); |
| 311 | |
| 312 | mNotificationPanel.updateNotificationViews(); |
| 313 | } |
| 314 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 315 | public void onNotificationRemoved(String key, StatusBarNotification old) { |
| 316 | if (SPEW) Log.d(TAG, "removeNotification key=" + key + " old=" + old); |
| 317 | |
| 318 | if (old != null) { |
| 319 | if (CLOSE_PANEL_WHEN_EMPTIED && !hasActiveNotifications() |
| 320 | && !mNotificationPanel.isTracking() && !mNotificationPanel.isQsExpanded()) { |
| 321 | if (mStatusBarStateController.getState() == StatusBarState.SHADE) { |
| 322 | mCommandQueue.animateCollapsePanels(); |
| 323 | } else if (mStatusBarStateController.getState() == StatusBarState.SHADE_LOCKED |
| 324 | && !isCollapsing()) { |
Heemin Seog | 98df697 | 2019-12-05 13:01:38 -0800 | [diff] [blame] | 325 | mStatusBarStateController.setState(StatusBarState.KEYGUARD); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | } |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | public boolean hasActiveNotifications() { |
Evan Laird | 181de62 | 2019-10-24 09:53:02 -0400 | [diff] [blame] | 332 | return mEntryManager.hasActiveNotifications(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 333 | } |
| 334 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 335 | @Override |
| 336 | public void onUserSwitched(int newUserId) { |
| 337 | // Begin old BaseStatusBar.userSwitched |
| 338 | mHeadsUpManager.setUser(newUserId); |
| 339 | // End old BaseStatusBar.userSwitched |
| 340 | if (MULTIUSER_DEBUG) mNotificationPanelDebugText.setText("USER " + newUserId); |
| 341 | mCommandQueue.animateCollapsePanels(); |
Lucas Dupin | c12fad3 | 2019-05-14 20:59:17 +0000 | [diff] [blame] | 342 | if (mReinflateNotificationsOnUserSwitched) { |
| 343 | updateNotificationsOnDensityOrFontScaleChanged(); |
| 344 | mReinflateNotificationsOnUserSwitched = false; |
| 345 | } |
| 346 | if (mDispatchUiModeChangeOnUserSwitched) { |
| 347 | updateNotificationOnUiModeChanged(); |
| 348 | mDispatchUiModeChangeOnUserSwitched = false; |
| 349 | } |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 350 | updateNotificationViews(); |
| 351 | mMediaManager.clearCurrentMediaNotification(); |
Heemin Seog | ba6337f | 2019-12-10 15:34:37 -0800 | [diff] [blame] | 352 | mStatusBar.setLockscreenUser(newUserId); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 353 | updateMediaMetaData(true, false); |
| 354 | } |
| 355 | |
| 356 | @Override |
Kevin Han | 3742322 | 2020-03-10 16:05:07 -0700 | [diff] [blame] | 357 | public void onBindRow(ExpandableNotificationRow row) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 358 | row.setAboveShelfChangedListener(mAboveShelfObserver); |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 359 | row.setSecureStateProvider(mKeyguardStateController::canDismissLockScreen); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | @Override |
| 363 | public boolean isPresenterFullyCollapsed() { |
| 364 | return mNotificationPanel.isFullyCollapsed(); |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public void onActivated(ActivatableNotificationView view) { |
| 369 | onActivated(); |
| 370 | if (view != null) mNotificationPanel.setActivatedChild(view); |
| 371 | } |
| 372 | |
| 373 | public void onActivated() { |
| 374 | mLockscreenGestureLogger.write( |
| 375 | MetricsEvent.ACTION_LS_NOTE, |
| 376 | 0 /* lengthDp - N/A */, 0 /* velocityDp - N/A */); |
| 377 | mNotificationPanel.showTransientIndication(R.string.notification_tap_again); |
| 378 | ActivatableNotificationView previousView = mNotificationPanel.getActivatedChild(); |
| 379 | if (previousView != null) { |
| 380 | previousView.makeInactive(true /* animate */); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | @Override |
| 385 | public void onActivationReset(ActivatableNotificationView view) { |
| 386 | if (view == mNotificationPanel.getActivatedChild()) { |
| 387 | mNotificationPanel.setActivatedChild(null); |
Heemin Seog | 98df697 | 2019-12-05 13:01:38 -0800 | [diff] [blame] | 388 | mKeyguardIndicationController.hideTransientIndication(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
| 392 | @Override |
| 393 | public void updateMediaMetaData(boolean metaDataChanged, boolean allowEnterAnimation) { |
| 394 | mMediaManager.updateMediaMetaData(metaDataChanged, allowEnterAnimation); |
| 395 | } |
| 396 | |
| 397 | @Override |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 398 | public int getMaxNotificationsWhileLocked(boolean recompute) { |
| 399 | if (recompute) { |
| 400 | mMaxKeyguardNotifications = Math.max(1, |
| 401 | mNotificationPanel.computeMaxKeyguardNotifications( |
| 402 | mMaxAllowedKeyguardNotifications)); |
| 403 | return mMaxKeyguardNotifications; |
| 404 | } |
| 405 | return mMaxKeyguardNotifications; |
| 406 | } |
| 407 | |
| 408 | @Override |
| 409 | public void onUpdateRowStates() { |
| 410 | mNotificationPanel.onUpdateRowStates(); |
| 411 | } |
| 412 | |
| 413 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 414 | public void onExpandClicked(NotificationEntry clickedEntry, boolean nowExpanded) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 415 | mHeadsUpManager.setExpanded(clickedEntry, nowExpanded); |
Selim Cinek | 5454a0d | 2019-07-30 17:14:50 -0700 | [diff] [blame] | 416 | if (nowExpanded) { |
| 417 | if (mStatusBarStateController.getState() == StatusBarState.KEYGUARD) { |
| 418 | mShadeController.goToLockedShade(clickedEntry.getRow()); |
| 419 | } else if (clickedEntry.isSensitive() |
| 420 | && mDynamicPrivacyController.isInLockedDownShade()) { |
| 421 | mStatusBarStateController.setLeaveOpenOnKeyguardHide(true); |
| 422 | mActivityStarter.dismissKeyguardThenExecute(() -> false /* dismissAction */ |
| 423 | , null /* cancelRunnable */, false /* afterKeyguardGone */); |
| 424 | } |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | |
| 428 | @Override |
| 429 | public boolean isDeviceInVrMode() { |
| 430 | return mVrMode; |
| 431 | } |
| 432 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 433 | private void onLockedNotificationImportanceChange(OnDismissAction dismissAction) { |
| 434 | mStatusBarStateController.setLeaveOpenOnKeyguardHide(true); |
| 435 | mActivityStarter.dismissKeyguardThenExecute(dismissAction, null, |
| 436 | true /* afterKeyguardGone */); |
| 437 | } |
| 438 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 439 | private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() { |
| 440 | @Override |
| 441 | public void onVrStateChanged(boolean enabled) { |
| 442 | mVrMode = enabled; |
| 443 | } |
| 444 | }; |
| 445 | |
| 446 | private final CheckSaveListener mCheckSaveListener = new CheckSaveListener() { |
| 447 | @Override |
| 448 | public void checkSave(Runnable saveImportance, StatusBarNotification sbn) { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 449 | // If the user has security enabled, show challenge if the setting is changed. |
| 450 | if (mLockscreenUserManager.isLockscreenPublicMode(sbn.getUser().getIdentifier()) |
| 451 | && mKeyguardManager.isKeyguardLocked()) { |
| 452 | onLockedNotificationImportanceChange(() -> { |
| 453 | saveImportance.run(); |
| 454 | return true; |
| 455 | }); |
| 456 | } else { |
| 457 | saveImportance.run(); |
| 458 | } |
| 459 | } |
| 460 | }; |
| 461 | |
| 462 | private final OnSettingsClickListener mOnSettingsClickListener = new OnSettingsClickListener() { |
| 463 | @Override |
| 464 | public void onSettingsClick(String key) { |
| 465 | try { |
| 466 | mBarService.onNotificationSettingsViewed(key); |
| 467 | } catch (RemoteException e) { |
| 468 | // if we're here we're dead |
| 469 | } |
| 470 | } |
| 471 | }; |
Beverly Tai | d1e175c | 2020-03-10 16:37:04 +0000 | [diff] [blame] | 472 | |
| 473 | private final NotificationInterruptSuppressor mInterruptSuppressor = |
| 474 | new NotificationInterruptSuppressor() { |
| 475 | @Override |
| 476 | public String getName() { |
| 477 | return TAG; |
| 478 | } |
| 479 | |
| 480 | @Override |
| 481 | public boolean suppressAwakeHeadsUp(NotificationEntry entry) { |
| 482 | final StatusBarNotification sbn = entry.getSbn(); |
| 483 | if (mStatusBar.isOccluded()) { |
| 484 | boolean devicePublic = mLockscreenUserManager |
| 485 | .isLockscreenPublicMode(mLockscreenUserManager.getCurrentUserId()); |
| 486 | boolean userPublic = devicePublic |
| 487 | || mLockscreenUserManager.isLockscreenPublicMode(sbn.getUserId()); |
| 488 | boolean needsRedaction = mLockscreenUserManager.needsRedaction(entry); |
| 489 | if (userPublic && needsRedaction) { |
| 490 | // TODO(b/135046837): we can probably relax this with dynamic privacy |
| 491 | return true; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | if (!mCommandQueue.panelsEnabled()) { |
| 496 | if (DEBUG) { |
| 497 | Log.d(TAG, "No heads up: disabled panel : " + sbn.getKey()); |
| 498 | } |
| 499 | return true; |
| 500 | } |
| 501 | |
| 502 | if (sbn.getNotification().fullScreenIntent != null) { |
| 503 | // we don't allow head-up on the lockscreen (unless there's a |
| 504 | // "showWhenLocked" activity currently showing) if |
| 505 | // the potential HUN has a fullscreen intent |
| 506 | if (mKeyguardStateController.isShowing() && !mStatusBar.isOccluded()) { |
| 507 | if (DEBUG) { |
| 508 | Log.d(TAG, "No heads up: entry has fullscreen intent on lockscreen " |
| 509 | + sbn.getKey()); |
| 510 | } |
| 511 | return true; |
| 512 | } |
| 513 | |
| 514 | if (mAccessibilityManager.isTouchExplorationEnabled()) { |
| 515 | if (DEBUG) { |
| 516 | Log.d(TAG, "No heads up: accessible fullscreen: " + sbn.getKey()); |
| 517 | } |
| 518 | return true; |
| 519 | } |
| 520 | } |
| 521 | return false; |
| 522 | } |
| 523 | |
| 524 | @Override |
| 525 | public boolean suppressAwakeInterruptions(NotificationEntry entry) { |
| 526 | return isDeviceInVrMode(); |
| 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public boolean suppressInterruptions(NotificationEntry entry) { |
| 531 | return mStatusBar.areNotificationAlertsDisabled(); |
| 532 | } |
| 533 | }; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 534 | } |