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