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