Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 16 | package com.android.systemui.statusbar.notification.row; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 17 | |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 18 | import static android.app.AppOpsManager.OP_CAMERA; |
| 19 | import static android.app.AppOpsManager.OP_RECORD_AUDIO; |
| 20 | import static android.app.AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 21 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 22 | import android.app.INotificationManager; |
| 23 | import android.app.NotificationChannel; |
| 24 | import android.content.Context; |
| 25 | import android.content.Intent; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 26 | import android.content.pm.LauncherApps; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 28 | import android.content.pm.ShortcutManager; |
Julia Reynolds | f5c0487 | 2018-02-13 09:54:04 -0500 | [diff] [blame] | 29 | import android.net.Uri; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 30 | import android.os.Bundle; |
Dave Mankoff | 5fe07f7 | 2019-11-19 22:14:41 -0500 | [diff] [blame] | 31 | import android.os.Handler; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 32 | import android.os.UserHandle; |
| 33 | import android.provider.Settings; |
| 34 | import android.service.notification.StatusBarNotification; |
| 35 | import android.util.ArraySet; |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 36 | import android.util.IconDrawableFactory; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 37 | import android.util.Log; |
| 38 | import android.view.HapticFeedbackConstants; |
| 39 | import android.view.View; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 40 | import android.view.accessibility.AccessibilityManager; |
| 41 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 43 | import com.android.internal.logging.MetricsLogger; |
| 44 | import com.android.internal.logging.nano.MetricsProto; |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 45 | import com.android.settingslib.notification.ConversationIconFactory; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 46 | import com.android.systemui.Dependency; |
| 47 | import com.android.systemui.Dumpable; |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 48 | import com.android.systemui.R; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 49 | import com.android.systemui.dagger.qualifiers.Background; |
Dave Mankoff | 00e8a2f | 2019-12-18 16:59:49 -0500 | [diff] [blame] | 50 | import com.android.systemui.dagger.qualifiers.Main; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 51 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 52 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 53 | import com.android.systemui.settings.CurrentUserContextTracker; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 54 | import com.android.systemui.statusbar.NotificationLifetimeExtender; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 55 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
| 56 | import com.android.systemui.statusbar.NotificationPresenter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 57 | import com.android.systemui.statusbar.StatusBarState; |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 58 | import com.android.systemui.statusbar.StatusBarStateControllerImpl; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 59 | import com.android.systemui.statusbar.notification.NotificationActivityStarter; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 60 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 61 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider; |
Sergey Nikolaienkov | f6ad632 | 2020-02-10 15:46:32 +0100 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.dagger.NotificationsModule; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 64 | import com.android.systemui.statusbar.notification.row.NotificationInfo.CheckSaveListener; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 65 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 66 | import com.android.systemui.statusbar.phone.StatusBar; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 67 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 68 | |
| 69 | import java.io.FileDescriptor; |
| 70 | import java.io.PrintWriter; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 71 | |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 72 | import javax.inject.Provider; |
| 73 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 74 | import dagger.Lazy; |
| 75 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 76 | /** |
| 77 | * Handles various NotificationGuts related tasks, such as binding guts to a row, opening and |
| 78 | * closing guts, and keeping track of the currently exposed notification guts. |
| 79 | */ |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 80 | public class NotificationGutsManager implements Dumpable, NotificationLifetimeExtender { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 81 | private static final String TAG = "NotificationGutsManager"; |
| 82 | |
| 83 | // Must match constant in Settings. Used to highlight preferences when linking to Settings. |
| 84 | private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key"; |
| 85 | |
| 86 | private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 87 | private final Context mContext; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 88 | private final VisualStabilityManager mVisualStabilityManager; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 89 | private final AccessibilityManager mAccessibilityManager; |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 90 | private final HighPriorityProvider mHighPriorityProvider; |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 91 | private final ChannelEditorDialogController mChannelEditorDialogController; |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 92 | |
| 93 | // Dependencies: |
| 94 | private final NotificationLockscreenUserManager mLockscreenUserManager = |
| 95 | Dependency.get(NotificationLockscreenUserManager.class); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 96 | private final StatusBarStateController mStatusBarStateController = |
| 97 | Dependency.get(StatusBarStateController.class); |
| 98 | private final DeviceProvisionedController mDeviceProvisionedController = |
| 99 | Dependency.get(DeviceProvisionedController.class); |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 100 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 101 | // which notification is currently being longpress-examined by the user |
| 102 | private NotificationGuts mNotificationGutsExposed; |
| 103 | private NotificationMenuRowPlugin.MenuItem mGutsMenuItem; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 104 | private NotificationSafeToRemoveCallback mNotificationLifetimeFinishedCallback; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 105 | private NotificationPresenter mPresenter; |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 106 | private NotificationActivityStarter mNotificationActivityStarter; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 107 | private NotificationListContainer mListContainer; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 108 | private CheckSaveListener mCheckSaveListener; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 109 | private OnSettingsClickListener mOnSettingsClickListener; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 110 | @VisibleForTesting |
| 111 | protected String mKeyToRemoveOnGutsClosed; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 112 | |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 113 | private final Lazy<StatusBar> mStatusBarLazy; |
Dave Mankoff | 5fe07f7 | 2019-11-19 22:14:41 -0500 | [diff] [blame] | 114 | private final Handler mMainHandler; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 115 | private final Handler mBgHandler; |
Selim Cinek | 56e6a32 | 2019-10-01 12:06:05 -0700 | [diff] [blame] | 116 | private Runnable mOpenRunnable; |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 117 | private final INotificationManager mNotificationManager; |
| 118 | private final LauncherApps mLauncherApps; |
| 119 | private final ShortcutManager mShortcutManager; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 120 | private final CurrentUserContextTracker mContextTracker; |
| 121 | private final Provider<PriorityOnboardingDialogController.Builder> mBuilderProvider; |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 122 | |
Sergey Nikolaienkov | f6ad632 | 2020-02-10 15:46:32 +0100 | [diff] [blame] | 123 | /** |
| 124 | * Injected constructor. See {@link NotificationsModule}. |
| 125 | */ |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 126 | public NotificationGutsManager(Context context, VisualStabilityManager visualStabilityManager, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 127 | Lazy<StatusBar> statusBarLazy, @Main Handler mainHandler, @Background Handler bgHandler, |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 128 | AccessibilityManager accessibilityManager, |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 129 | HighPriorityProvider highPriorityProvider, |
| 130 | INotificationManager notificationManager, |
| 131 | LauncherApps launcherApps, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 132 | ShortcutManager shortcutManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 133 | ChannelEditorDialogController channelEditorDialogController, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 134 | CurrentUserContextTracker contextTracker, |
| 135 | Provider<PriorityOnboardingDialogController.Builder> builderProvider) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 136 | mContext = context; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 137 | mVisualStabilityManager = visualStabilityManager; |
Dave Mankoff | 4dd47fa | 2019-11-07 10:44:48 -0500 | [diff] [blame] | 138 | mStatusBarLazy = statusBarLazy; |
Dave Mankoff | 5fe07f7 | 2019-11-19 22:14:41 -0500 | [diff] [blame] | 139 | mMainHandler = mainHandler; |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 140 | mBgHandler = bgHandler; |
Dave Mankoff | 5fe07f7 | 2019-11-19 22:14:41 -0500 | [diff] [blame] | 141 | mAccessibilityManager = accessibilityManager; |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 142 | mHighPriorityProvider = highPriorityProvider; |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 143 | mNotificationManager = notificationManager; |
| 144 | mLauncherApps = launcherApps; |
| 145 | mShortcutManager = shortcutManager; |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 146 | mContextTracker = contextTracker; |
| 147 | mBuilderProvider = builderProvider; |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 148 | mChannelEditorDialogController = channelEditorDialogController; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 149 | } |
| 150 | |
Eliot Courtney | 4a96b36 | 2017-12-14 19:38:52 +0900 | [diff] [blame] | 151 | public void setUpWithPresenter(NotificationPresenter presenter, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 152 | NotificationListContainer listContainer, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 153 | CheckSaveListener checkSave, OnSettingsClickListener onSettingsClick) { |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 154 | mPresenter = presenter; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 155 | mListContainer = listContainer; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 156 | mCheckSaveListener = checkSave; |
| 157 | mOnSettingsClickListener = onSettingsClick; |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 158 | } |
| 159 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 160 | public void setNotificationActivityStarter( |
| 161 | NotificationActivityStarter notificationActivityStarter) { |
| 162 | mNotificationActivityStarter = notificationActivityStarter; |
| 163 | } |
| 164 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 165 | public void onDensityOrFontScaleChanged(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 166 | setExposedGuts(entry.getGuts()); |
| 167 | bindGuts(entry.getRow()); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 168 | } |
| 169 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 170 | /** |
Nadia Benbernou | 4a99e93 | 2019-03-13 14:47:47 -0400 | [diff] [blame] | 171 | * Sends an intent to open the notification settings for a particular package and optional |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 172 | * channel. |
| 173 | */ |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 174 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args"; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 175 | private void startAppNotificationSettingsActivity(String packageName, final int appUid, |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 176 | final NotificationChannel channel, ExpandableNotificationRow row) { |
Nadia Benbernou | 4a99e93 | 2019-03-13 14:47:47 -0400 | [diff] [blame] | 177 | final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); |
| 178 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); |
| 179 | intent.putExtra(Settings.EXTRA_APP_UID, appUid); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 180 | |
Nadia Benbernou | 4a99e93 | 2019-03-13 14:47:47 -0400 | [diff] [blame] | 181 | if (channel != null) { |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 182 | final Bundle args = new Bundle(); |
Nadia Benbernou | 4a99e93 | 2019-03-13 14:47:47 -0400 | [diff] [blame] | 183 | intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, channel.getId()); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 184 | args.putString(EXTRA_FRAGMENT_ARG_KEY, channel.getId()); |
| 185 | intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
Nadia Benbernou | 4a99e93 | 2019-03-13 14:47:47 -0400 | [diff] [blame] | 186 | } |
| 187 | mNotificationActivityStarter.startNotificationGutsIntent(intent, appUid, row); |
| 188 | } |
| 189 | |
| 190 | private void startAppDetailsSettingsActivity(String packageName, final int appUid, |
| 191 | final NotificationChannel channel, ExpandableNotificationRow row) { |
Julia Reynolds | f5c0487 | 2018-02-13 09:54:04 -0500 | [diff] [blame] | 192 | final Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); |
| 193 | intent.setData(Uri.fromParts("package", packageName, null)); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 194 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); |
| 195 | intent.putExtra(Settings.EXTRA_APP_UID, appUid); |
| 196 | if (channel != null) { |
| 197 | intent.putExtra(EXTRA_FRAGMENT_ARG_KEY, channel.getId()); |
| 198 | } |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 199 | mNotificationActivityStarter.startNotificationGutsIntent(intent, appUid, row); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 200 | } |
| 201 | |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 202 | protected void startAppOpsSettingsActivity(String pkg, int uid, ArraySet<Integer> ops, |
| 203 | ExpandableNotificationRow row) { |
| 204 | if (ops.contains(OP_SYSTEM_ALERT_WINDOW)) { |
| 205 | if (ops.contains(OP_CAMERA) || ops.contains(OP_RECORD_AUDIO)) { |
Nadia Benbernou | 4a99e93 | 2019-03-13 14:47:47 -0400 | [diff] [blame] | 206 | startAppDetailsSettingsActivity(pkg, uid, null, row); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 207 | } else { |
Bernardo Rufino | 8fefb94 | 2019-11-25 19:51:09 +0000 | [diff] [blame] | 208 | Intent intent = new Intent(Settings.ACTION_MANAGE_APP_OVERLAY_PERMISSION); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 209 | intent.setData(Uri.fromParts("package", pkg, null)); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 210 | mNotificationActivityStarter.startNotificationGutsIntent(intent, uid, row); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 211 | } |
| 212 | } else if (ops.contains(OP_CAMERA) || ops.contains(OP_RECORD_AUDIO)) { |
| 213 | Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSIONS); |
| 214 | intent.putExtra(Intent.EXTRA_PACKAGE_NAME, pkg); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 215 | mNotificationActivityStarter.startNotificationGutsIntent(intent, uid, row); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Julia Reynolds | e03aa8f | 2020-06-02 11:21:38 -0400 | [diff] [blame] | 219 | private void startConversationSettingsActivity(int uid, ExpandableNotificationRow row) { |
| 220 | final Intent intent = new Intent(Settings.ACTION_CONVERSATION_SETTINGS); |
| 221 | mNotificationActivityStarter.startNotificationGutsIntent(intent, uid, row); |
| 222 | } |
| 223 | |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 224 | private boolean bindGuts(final ExpandableNotificationRow row) { |
| 225 | row.ensureGutsInflated(); |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 226 | return bindGuts(row, mGutsMenuItem); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 227 | } |
| 228 | |
TreeHugger Robot | ee8e1ae | 2019-01-18 19:26:40 +0000 | [diff] [blame] | 229 | @VisibleForTesting |
| 230 | protected boolean bindGuts(final ExpandableNotificationRow row, |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 231 | NotificationMenuRowPlugin.MenuItem item) { |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 232 | StatusBarNotification sbn = row.getEntry().getSbn(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 233 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 234 | row.setGutsView(item); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 235 | row.setTag(sbn.getPackageName()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 236 | row.getGuts().setClosedListener((NotificationGuts g) -> { |
Rohan Shah | 56eb091 | 2018-05-10 21:49:04 -0700 | [diff] [blame] | 237 | row.onGutsClosed(); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 238 | if (!g.willBeRemoved() && !row.isRemoved()) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 239 | mListContainer.onHeightChanged( |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 240 | row, !mPresenter.isPresenterFullyCollapsed() /* needsAnimation */); |
| 241 | } |
| 242 | if (mNotificationGutsExposed == g) { |
| 243 | mNotificationGutsExposed = null; |
| 244 | mGutsMenuItem = null; |
| 245 | } |
| 246 | String key = sbn.getKey(); |
| 247 | if (key.equals(mKeyToRemoveOnGutsClosed)) { |
| 248 | mKeyToRemoveOnGutsClosed = null; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 249 | if (mNotificationLifetimeFinishedCallback != null) { |
| 250 | mNotificationLifetimeFinishedCallback.onSafeToRemove(key); |
| 251 | } |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 252 | } |
| 253 | }); |
| 254 | |
| 255 | View gutsView = item.getGutsView(); |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 256 | try { |
| 257 | if (gutsView instanceof NotificationSnooze) { |
| 258 | initializeSnoozeView(row, (NotificationSnooze) gutsView); |
| 259 | } else if (gutsView instanceof AppOpsInfo) { |
| 260 | initializeAppOpsInfo(row, (AppOpsInfo) gutsView); |
| 261 | } else if (gutsView instanceof NotificationInfo) { |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 262 | initializeNotificationInfo(row, (NotificationInfo) gutsView); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 263 | } else if (gutsView instanceof NotificationConversationInfo) { |
| 264 | initializeConversationNotificationInfo( |
| 265 | row, (NotificationConversationInfo) gutsView); |
Julia Reynolds | 8582df5 | 2020-04-24 18:30:59 -0400 | [diff] [blame] | 266 | } else if (gutsView instanceof PartialConversationInfo) { |
| 267 | initializePartialConversationNotificationInfo(row, |
| 268 | (PartialConversationInfo) gutsView); |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 269 | } |
| 270 | return true; |
| 271 | } catch (Exception e) { |
| 272 | Log.e(TAG, "error binding guts", e); |
| 273 | return false; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 274 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 275 | } |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 276 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Sets up the {@link NotificationSnooze} inside the notification row's guts. |
| 279 | * |
| 280 | * @param row view to set up the guts for |
| 281 | * @param notificationSnoozeView view to set up/bind within {@code row} |
| 282 | */ |
| 283 | private void initializeSnoozeView( |
| 284 | final ExpandableNotificationRow row, |
| 285 | NotificationSnooze notificationSnoozeView) { |
| 286 | NotificationGuts guts = row.getGuts(); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 287 | StatusBarNotification sbn = row.getEntry().getSbn(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 288 | |
| 289 | notificationSnoozeView.setSnoozeListener(mListContainer.getSwipeActionHelper()); |
| 290 | notificationSnoozeView.setStatusBarNotification(sbn); |
Ned Burns | 47c98f1 | 2019-09-06 17:12:07 -0400 | [diff] [blame] | 291 | notificationSnoozeView.setSnoozeOptions(row.getEntry().getSnoozeCriteria()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 292 | guts.setHeightChangedListener((NotificationGuts g) -> { |
| 293 | mListContainer.onHeightChanged(row, row.isShown() /* needsAnimation */); |
| 294 | }); |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Sets up the {@link AppOpsInfo} inside the notification row's guts. |
| 299 | * |
| 300 | * @param row view to set up the guts for |
| 301 | * @param appOpsInfoView view to set up/bind within {@code row} |
| 302 | */ |
| 303 | private void initializeAppOpsInfo( |
| 304 | final ExpandableNotificationRow row, |
| 305 | AppOpsInfo appOpsInfoView) { |
| 306 | NotificationGuts guts = row.getGuts(); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 307 | StatusBarNotification sbn = row.getEntry().getSbn(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 308 | UserHandle userHandle = sbn.getUser(); |
| 309 | PackageManager pmUser = StatusBar.getPackageManagerForUser(mContext, |
| 310 | userHandle.getIdentifier()); |
| 311 | |
| 312 | AppOpsInfo.OnSettingsClickListener onSettingsClick = |
| 313 | (View v, String pkg, int uid, ArraySet<Integer> ops) -> { |
| 314 | mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_OPS_GUTS_SETTINGS); |
| 315 | guts.resetFalsingCheck(); |
| 316 | startAppOpsSettingsActivity(pkg, uid, ops, row); |
| 317 | }; |
| 318 | if (!row.getEntry().mActiveAppOps.isEmpty()) { |
| 319 | appOpsInfoView.bindGuts(pmUser, onSettingsClick, sbn, row.getEntry().mActiveAppOps); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 320 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 321 | } |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 322 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 323 | /** |
| 324 | * Sets up the {@link NotificationInfo} inside the notification row's guts. |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 325 | * @param row view to set up the guts for |
| 326 | * @param notificationInfoView view to set up/bind within {@code row} |
| 327 | */ |
| 328 | @VisibleForTesting |
| 329 | void initializeNotificationInfo( |
| 330 | final ExpandableNotificationRow row, |
Gus Prevas | 5a70a4e | 2018-11-26 17:16:05 -0500 | [diff] [blame] | 331 | NotificationInfo notificationInfoView) throws Exception { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 332 | NotificationGuts guts = row.getGuts(); |
Ned Burns | 1c2b85a4 | 2019-11-14 15:37:03 -0500 | [diff] [blame] | 333 | StatusBarNotification sbn = row.getEntry().getSbn(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 334 | String packageName = sbn.getPackageName(); |
| 335 | // Settings link is only valid for notifications that specify a non-system user |
| 336 | NotificationInfo.OnSettingsClickListener onSettingsClick = null; |
| 337 | UserHandle userHandle = sbn.getUser(); |
| 338 | PackageManager pmUser = StatusBar.getPackageManagerForUser( |
| 339 | mContext, userHandle.getIdentifier()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 340 | final NotificationInfo.OnAppSettingsClickListener onAppSettingsClick = |
| 341 | (View v, Intent intent) -> { |
| 342 | mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_APP_NOTE_SETTINGS); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 343 | guts.resetFalsingCheck(); |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 344 | mNotificationActivityStarter.startNotificationGutsIntent(intent, sbn.getUid(), |
| 345 | row); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 346 | }; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 347 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 348 | if (!userHandle.equals(UserHandle.ALL) |
| 349 | || mLockscreenUserManager.getCurrentUserId() == UserHandle.USER_SYSTEM) { |
| 350 | onSettingsClick = (View v, NotificationChannel channel, int appUid) -> { |
| 351 | mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_NOTE_INFO); |
| 352 | guts.resetFalsingCheck(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 353 | mOnSettingsClickListener.onSettingsClick(sbn.getKey()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 354 | startAppNotificationSettingsActivity(packageName, appUid, channel, row); |
| 355 | }; |
| 356 | } |
| 357 | |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 358 | notificationInfoView.bindNotification( |
| 359 | pmUser, |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 360 | mNotificationManager, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 361 | mVisualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 362 | mChannelEditorDialogController, |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 363 | packageName, |
Ned Burns | 296aec16 | 2019-09-04 17:30:59 -0400 | [diff] [blame] | 364 | row.getEntry().getChannel(), |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 365 | row.getUniqueChannels(), |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 366 | row.getEntry(), |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 367 | onSettingsClick, |
| 368 | onAppSettingsClick, |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 369 | mDeviceProvisionedController.isDeviceProvisioned(), |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 370 | row.getIsNonblockable(), |
Beverly | e558f1d | 2020-01-07 16:28:58 -0500 | [diff] [blame] | 371 | mHighPriorityProvider.isHighPriority(row.getEntry())); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /** |
Julia Reynolds | 8582df5 | 2020-04-24 18:30:59 -0400 | [diff] [blame] | 375 | * Sets up the {@link PartialConversationInfo} inside the notification row's guts. |
| 376 | * @param row view to set up the guts for |
| 377 | * @param notificationInfoView view to set up/bind within {@code row} |
| 378 | */ |
| 379 | @VisibleForTesting |
| 380 | void initializePartialConversationNotificationInfo( |
| 381 | final ExpandableNotificationRow row, |
| 382 | PartialConversationInfo notificationInfoView) throws Exception { |
| 383 | NotificationGuts guts = row.getGuts(); |
| 384 | StatusBarNotification sbn = row.getEntry().getSbn(); |
| 385 | String packageName = sbn.getPackageName(); |
| 386 | // Settings link is only valid for notifications that specify a non-system user |
| 387 | NotificationInfo.OnSettingsClickListener onSettingsClick = null; |
| 388 | UserHandle userHandle = sbn.getUser(); |
| 389 | PackageManager pmUser = StatusBar.getPackageManagerForUser( |
| 390 | mContext, userHandle.getIdentifier()); |
| 391 | |
| 392 | if (!userHandle.equals(UserHandle.ALL) |
| 393 | || mLockscreenUserManager.getCurrentUserId() == UserHandle.USER_SYSTEM) { |
| 394 | onSettingsClick = (View v, NotificationChannel channel, int appUid) -> { |
| 395 | mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_NOTE_INFO); |
| 396 | guts.resetFalsingCheck(); |
| 397 | mOnSettingsClickListener.onSettingsClick(sbn.getKey()); |
| 398 | startAppNotificationSettingsActivity(packageName, appUid, channel, row); |
| 399 | }; |
| 400 | } |
| 401 | |
| 402 | notificationInfoView.bindNotification( |
| 403 | pmUser, |
| 404 | mNotificationManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 405 | mChannelEditorDialogController, |
Julia Reynolds | 8582df5 | 2020-04-24 18:30:59 -0400 | [diff] [blame] | 406 | packageName, |
| 407 | row.getEntry().getChannel(), |
| 408 | row.getUniqueChannels(), |
| 409 | row.getEntry(), |
| 410 | onSettingsClick, |
| 411 | mDeviceProvisionedController.isDeviceProvisioned(), |
| 412 | row.getIsNonblockable()); |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * Sets up the {@link ConversationInfo} inside the notification row's guts. |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 417 | * @param row view to set up the guts for |
| 418 | * @param notificationInfoView view to set up/bind within {@code row} |
| 419 | */ |
| 420 | @VisibleForTesting |
| 421 | void initializeConversationNotificationInfo( |
| 422 | final ExpandableNotificationRow row, |
| 423 | NotificationConversationInfo notificationInfoView) throws Exception { |
| 424 | NotificationGuts guts = row.getGuts(); |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 425 | NotificationEntry entry = row.getEntry(); |
| 426 | StatusBarNotification sbn = entry.getSbn(); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 427 | String packageName = sbn.getPackageName(); |
| 428 | // Settings link is only valid for notifications that specify a non-system user |
| 429 | NotificationConversationInfo.OnSettingsClickListener onSettingsClick = null; |
| 430 | UserHandle userHandle = sbn.getUser(); |
| 431 | PackageManager pmUser = StatusBar.getPackageManagerForUser( |
| 432 | mContext, userHandle.getIdentifier()); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 433 | final NotificationConversationInfo.OnAppSettingsClickListener onAppSettingsClick = |
| 434 | (View v, Intent intent) -> { |
| 435 | mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_APP_NOTE_SETTINGS); |
| 436 | guts.resetFalsingCheck(); |
| 437 | mNotificationActivityStarter.startNotificationGutsIntent(intent, sbn.getUid(), |
| 438 | row); |
| 439 | }; |
| 440 | |
| 441 | final NotificationConversationInfo.OnSnoozeClickListener onSnoozeClickListener = |
| 442 | (View v, int hours) -> { |
| 443 | mListContainer.getSwipeActionHelper().snooze(sbn, hours); |
| 444 | }; |
| 445 | |
Julia Reynolds | e03aa8f | 2020-06-02 11:21:38 -0400 | [diff] [blame] | 446 | final NotificationConversationInfo.OnConversationSettingsClickListener |
| 447 | onConversationSettingsListener = |
| 448 | () -> { |
| 449 | startConversationSettingsActivity(sbn.getUid(), row); |
| 450 | }; |
| 451 | |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 452 | if (!userHandle.equals(UserHandle.ALL) |
| 453 | || mLockscreenUserManager.getCurrentUserId() == UserHandle.USER_SYSTEM) { |
| 454 | onSettingsClick = (View v, NotificationChannel channel, int appUid) -> { |
| 455 | mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_NOTE_INFO); |
| 456 | guts.resetFalsingCheck(); |
| 457 | mOnSettingsClickListener.onSettingsClick(sbn.getKey()); |
| 458 | startAppNotificationSettingsActivity(packageName, appUid, channel, row); |
| 459 | }; |
| 460 | } |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 461 | ConversationIconFactory iconFactoryLoader = new ConversationIconFactory(mContext, |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 462 | mLauncherApps, pmUser, IconDrawableFactory.newInstance(mContext, false), |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 463 | mContext.getResources().getDimensionPixelSize( |
| 464 | R.dimen.notification_guts_conversation_icon_size)); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 465 | |
| 466 | notificationInfoView.bindNotification( |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 467 | mShortcutManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 468 | pmUser, |
Steve Elliott | 46bb2a1 | 2020-03-17 11:04:09 -0400 | [diff] [blame] | 469 | mNotificationManager, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 470 | mVisualStabilityManager, |
| 471 | packageName, |
Evan Laird | 03c4445 | 2020-04-16 12:26:07 -0400 | [diff] [blame] | 472 | entry.getChannel(), |
| 473 | entry, |
| 474 | entry.getBubbleMetadata(), |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 475 | onSettingsClick, |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 476 | onSnoozeClickListener, |
Julia Reynolds | 01c9da4 | 2020-02-14 14:17:58 -0500 | [diff] [blame] | 477 | iconFactoryLoader, |
Evan Laird | 31ca547 | 2020-04-08 17:45:24 -0400 | [diff] [blame] | 478 | mContextTracker.getCurrentUserContext(), |
| 479 | mBuilderProvider, |
Steve Elliott | 6771f54 | 2020-05-26 13:31:10 -0400 | [diff] [blame] | 480 | mDeviceProvisionedController.isDeviceProvisioned(), |
| 481 | mMainHandler, |
Julia Reynolds | e03aa8f | 2020-06-02 11:21:38 -0400 | [diff] [blame] | 482 | mBgHandler, |
| 483 | onConversationSettingsListener); |
Julia Reynolds | 12ba4cf | 2020-01-10 16:01:38 -0500 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 487 | * Closes guts or notification menus that might be visible and saves any changes. |
| 488 | * |
| 489 | * @param removeLeavebehinds true if leavebehinds (e.g. snooze) should be closed. |
| 490 | * @param force true if guts should be closed regardless of state (used for snooze only). |
| 491 | * @param removeControls true if controls (e.g. info) should be closed. |
| 492 | * @param x if closed based on touch location, this is the x touch location. |
| 493 | * @param y if closed based on touch location, this is the y touch location. |
| 494 | * @param resetMenu if any notification menus that might be revealed should be closed. |
| 495 | */ |
| 496 | public void closeAndSaveGuts(boolean removeLeavebehinds, boolean force, boolean removeControls, |
| 497 | int x, int y, boolean resetMenu) { |
| 498 | if (mNotificationGutsExposed != null) { |
Selim Cinek | 56e6a32 | 2019-10-01 12:06:05 -0700 | [diff] [blame] | 499 | mNotificationGutsExposed.removeCallbacks(mOpenRunnable); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 500 | mNotificationGutsExposed.closeControls(removeLeavebehinds, removeControls, x, y, force); |
| 501 | } |
| 502 | if (resetMenu) { |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 503 | mListContainer.resetExposedMenuView(false /* animate */, true /* force */); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * Returns the exposed NotificationGuts or null if none are exposed. |
| 509 | */ |
| 510 | public NotificationGuts getExposedGuts() { |
| 511 | return mNotificationGutsExposed; |
| 512 | } |
| 513 | |
| 514 | public void setExposedGuts(NotificationGuts guts) { |
| 515 | mNotificationGutsExposed = guts; |
| 516 | } |
| 517 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 518 | public ExpandableNotificationRow.LongPressListener getNotificationLongClicker() { |
| 519 | return this::openGuts; |
| 520 | } |
| 521 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 522 | /** |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 523 | * Opens guts on the given ExpandableNotificationRow {@code view}. This handles opening guts for |
| 524 | * the normal half-swipe and long-press use cases via a circular reveal. When the blocking |
| 525 | * helper needs to be shown on the row, this will skip the circular reveal. |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 526 | * |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 527 | * @param view ExpandableNotificationRow to open guts on |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 528 | * @param x x coordinate of origin of circular reveal |
| 529 | * @param y y coordinate of origin of circular reveal |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 530 | * @param menuItem MenuItem the guts should display |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 531 | * @return true if guts was opened |
| 532 | */ |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 533 | public boolean openGuts( |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 534 | View view, |
| 535 | int x, |
| 536 | int y, |
| 537 | NotificationMenuRowPlugin.MenuItem menuItem) { |
Julia Reynolds | be37107 | 2020-05-28 11:32:01 -0400 | [diff] [blame] | 538 | if (menuItem.getGutsView() instanceof NotificationGuts.GutsContent) { |
| 539 | NotificationGuts.GutsContent gutsView = |
| 540 | (NotificationGuts.GutsContent) menuItem.getGutsView(); |
| 541 | if (gutsView.needsFalsingProtection()) { |
| 542 | if (mStatusBarStateController instanceof StatusBarStateControllerImpl) { |
| 543 | ((StatusBarStateControllerImpl) mStatusBarStateController) |
| 544 | .setLeaveOpenOnKeyguardHide(true); |
| 545 | } |
| 546 | |
| 547 | Runnable r = () -> mMainHandler.post( |
| 548 | () -> openGutsInternal(view, x, y, menuItem)); |
| 549 | |
| 550 | mStatusBarLazy.get().executeRunnableDismissingKeyguard( |
| 551 | r, |
| 552 | null /* cancelAction */, |
| 553 | false /* dismissShade */, |
| 554 | true /* afterKeyguardGone */, |
| 555 | true /* deferred */); |
| 556 | |
| 557 | return true; |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 558 | } |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 559 | } |
| 560 | return openGutsInternal(view, x, y, menuItem); |
| 561 | } |
| 562 | |
| 563 | @VisibleForTesting |
| 564 | boolean openGutsInternal( |
| 565 | View view, |
| 566 | int x, |
| 567 | int y, |
| 568 | NotificationMenuRowPlugin.MenuItem menuItem) { |
| 569 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 570 | if (!(view instanceof ExpandableNotificationRow)) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 571 | return false; |
| 572 | } |
| 573 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 574 | if (view.getWindowToken() == null) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 575 | Log.e(TAG, "Trying to show notification guts, but not attached to window"); |
| 576 | return false; |
| 577 | } |
| 578 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 579 | final ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 580 | view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 581 | if (row.areGutsExposed()) { |
| 582 | closeAndSaveGuts(false /* removeLeavebehind */, false /* force */, |
| 583 | true /* removeControls */, -1 /* x */, -1 /* y */, |
| 584 | true /* resetMenu */); |
| 585 | return false; |
| 586 | } |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 587 | |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 588 | row.ensureGutsInflated(); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 589 | NotificationGuts guts = row.getGuts(); |
Julia Reynolds | 4131e78 | 2018-08-22 09:45:24 -0400 | [diff] [blame] | 590 | mNotificationGutsExposed = guts; |
| 591 | if (!bindGuts(row, menuItem)) { |
| 592 | // exception occurred trying to fill in all the data, bail. |
| 593 | return false; |
| 594 | } |
| 595 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 596 | |
| 597 | // Assume we are a status_bar_notification_row |
| 598 | if (guts == null) { |
| 599 | // This view has no guts. Examples are the more card or the dismiss all view |
| 600 | return false; |
| 601 | } |
| 602 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 603 | // ensure that it's laid but not visible until actually laid out |
| 604 | guts.setVisibility(View.INVISIBLE); |
| 605 | // Post to ensure the the guts are properly laid out. |
Selim Cinek | 56e6a32 | 2019-10-01 12:06:05 -0700 | [diff] [blame] | 606 | mOpenRunnable = new Runnable() { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 607 | @Override |
| 608 | public void run() { |
| 609 | if (row.getWindowToken() == null) { |
Rohan Shah | ae5fdf0 | 2018-05-09 18:59:44 -0700 | [diff] [blame] | 610 | Log.e(TAG, "Trying to show notification guts in post(), but not attached to " |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 611 | + "window"); |
| 612 | return; |
| 613 | } |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 614 | guts.setVisibility(View.VISIBLE); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 615 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 616 | final boolean needsFalsingProtection = |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 617 | (mStatusBarStateController.getState() == StatusBarState.KEYGUARD && |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 618 | !mAccessibilityManager.isTouchExplorationEnabled()); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 619 | |
| 620 | guts.openControls( |
| 621 | !row.isBlockingHelperShowing(), |
| 622 | x, |
| 623 | y, |
| 624 | needsFalsingProtection, |
Rohan Shah | 56eb091 | 2018-05-10 21:49:04 -0700 | [diff] [blame] | 625 | row::onGutsOpened); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 626 | |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 627 | row.closeRemoteInput(); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 628 | mListContainer.onHeightChanged(row, true /* needsAnimation */); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 629 | mGutsMenuItem = menuItem; |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 630 | } |
Selim Cinek | 56e6a32 | 2019-10-01 12:06:05 -0700 | [diff] [blame] | 631 | }; |
| 632 | guts.post(mOpenRunnable); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 633 | return true; |
| 634 | } |
| 635 | |
| 636 | @Override |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 637 | public void setCallback(NotificationSafeToRemoveCallback callback) { |
| 638 | mNotificationLifetimeFinishedCallback = callback; |
| 639 | } |
| 640 | |
| 641 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 642 | public boolean shouldExtendLifetime(NotificationEntry entry) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 643 | return entry != null |
| 644 | &&(mNotificationGutsExposed != null |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 645 | && entry.getGuts() != null |
| 646 | && mNotificationGutsExposed == entry.getGuts() |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 647 | && !mNotificationGutsExposed.isLeavebehind()); |
| 648 | } |
| 649 | |
| 650 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 651 | public void setShouldManageLifetime(NotificationEntry entry, boolean shouldExtend) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 652 | if (shouldExtend) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 653 | mKeyToRemoveOnGutsClosed = entry.getKey(); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 654 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 655 | Log.d(TAG, "Keeping notification because it's showing guts. " + entry.getKey()); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 656 | } |
| 657 | } else { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 658 | if (mKeyToRemoveOnGutsClosed != null |
| 659 | && mKeyToRemoveOnGutsClosed.equals(entry.getKey())) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 660 | mKeyToRemoveOnGutsClosed = null; |
| 661 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 662 | Log.d(TAG, "Notification that was kept for guts was updated. " |
| 663 | + entry.getKey()); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | @Override |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 670 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
Eliot Courtney | 0932228 | 2017-11-09 15:31:19 +0900 | [diff] [blame] | 671 | pw.println("NotificationGutsManager state:"); |
| 672 | pw.print(" mKeyToRemoveOnGutsClosed: "); |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 673 | pw.println(mKeyToRemoveOnGutsClosed); |
| 674 | } |
Julia Reynolds | 84dc96b | 2017-11-14 09:51:01 -0500 | [diff] [blame] | 675 | |
| 676 | public interface OnSettingsClickListener { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 677 | public void onSettingsClick(String key); |
Julia Reynolds | 84dc96b | 2017-11-14 09:51:01 -0500 | [diff] [blame] | 678 | } |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 679 | } |