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