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