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