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