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