Eliot Courtney | e77edea | 2017-11-15 14:25:21 +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 | */ |
| 16 | package com.android.systemui.statusbar; |
| 17 | |
| 18 | import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY; |
| 19 | |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 20 | import static com.android.systemui.Dependency.MAIN_HANDLER_NAME; |
| 21 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Ned Burns | 1dd6b40 | 2019-01-02 15:25:23 -0500 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 24 | import android.app.ActivityManager; |
Sunny Goyal | 0279453 | 2018-08-22 15:18:37 -0700 | [diff] [blame] | 25 | import android.app.ActivityOptions; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 26 | import android.app.KeyguardManager; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 27 | import android.app.Notification; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 28 | import android.app.PendingIntent; |
| 29 | import android.app.RemoteInput; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 32 | import android.os.Handler; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 33 | import android.os.RemoteException; |
| 34 | import android.os.ServiceManager; |
| 35 | import android.os.SystemClock; |
| 36 | import android.os.SystemProperties; |
| 37 | import android.os.UserManager; |
| 38 | import android.service.notification.StatusBarNotification; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 39 | import android.text.TextUtils; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 40 | import android.util.ArraySet; |
| 41 | import android.util.Log; |
Sunny Goyal | 43c9704 | 2018-08-23 15:21:26 -0700 | [diff] [blame] | 42 | import android.util.Pair; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 43 | import android.view.MotionEvent; |
| 44 | import android.view.View; |
| 45 | import android.view.ViewGroup; |
| 46 | import android.view.ViewParent; |
| 47 | import android.widget.RemoteViews; |
| 48 | import android.widget.TextView; |
| 49 | |
| 50 | import com.android.internal.annotations.VisibleForTesting; |
| 51 | import com.android.internal.statusbar.IStatusBarService; |
Dieter Hsu | d39f0d5 | 2018-04-14 02:08:30 +0800 | [diff] [blame] | 52 | import com.android.internal.statusbar.NotificationVisibility; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 53 | import com.android.systemui.Dumpable; |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 54 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 55 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 56 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 57 | import com.android.systemui.statusbar.notification.collection.NotificationEntry.EditedSuggestionInfo; |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 58 | import com.android.systemui.statusbar.notification.logging.NotificationLogger; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 60 | import com.android.systemui.statusbar.phone.ShadeController; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 61 | import com.android.systemui.statusbar.policy.RemoteInputView; |
| 62 | |
| 63 | import java.io.FileDescriptor; |
| 64 | import java.io.PrintWriter; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 66 | import java.util.Set; |
| 67 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 68 | import javax.inject.Inject; |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 69 | import javax.inject.Named; |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 70 | import javax.inject.Singleton; |
| 71 | |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 72 | import dagger.Lazy; |
| 73 | |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 74 | /** |
| 75 | * Class for handling remote input state over a set of notifications. This class handles things |
| 76 | * like keeping notifications temporarily that were cancelled as a response to a remote input |
| 77 | * interaction, keeping track of notifications to remove when NotificationPresenter is collapsed, |
| 78 | * and handling clicks on remote views. |
| 79 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 80 | @Singleton |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 81 | public class NotificationRemoteInputManager implements Dumpable { |
| 82 | public static final boolean ENABLE_REMOTE_INPUT = |
| 83 | SystemProperties.getBoolean("debug.enable_remote_input", true); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 84 | public static boolean FORCE_REMOTE_INPUT_HISTORY = |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 85 | SystemProperties.getBoolean("debug.force_remoteinput_history", true); |
| 86 | private static final boolean DEBUG = false; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 87 | private static final String TAG = "NotifRemoteInputManager"; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * How long to wait before auto-dismissing a notification that was kept for remote input, and |
| 91 | * has now sent a remote input. We auto-dismiss, because the app may not see a reason to cancel |
| 92 | * these given that they technically don't exist anymore. We wait a bit in case the app issues |
| 93 | * an update. |
| 94 | */ |
| 95 | private static final int REMOTE_INPUT_KEPT_ENTRY_AUTO_CANCEL_DELAY = 200; |
| 96 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Notifications that are already removed but are kept around because we want to show the |
| 99 | * remote input history. See {@link RemoteInputHistoryExtender} and |
| 100 | * {@link SmartReplyHistoryExtender}. |
| 101 | */ |
| 102 | protected final ArraySet<String> mKeysKeptForRemoteInputHistory = new ArraySet<>(); |
| 103 | |
| 104 | /** |
| 105 | * Notifications that are already removed but are kept around because the remote input is |
| 106 | * actively being used (i.e. user is typing in it). See {@link RemoteInputActiveExtender}. |
| 107 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 108 | protected final ArraySet<NotificationEntry> mEntriesKeptForRemoteInputActive = |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 109 | new ArraySet<>(); |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 110 | |
| 111 | // Dependencies: |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 112 | private final NotificationLockscreenUserManager mLockscreenUserManager; |
| 113 | private final SmartReplyController mSmartReplyController; |
| 114 | private final NotificationEntryManager mEntryManager; |
| 115 | private final Handler mMainHandler; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 116 | |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 117 | private final Lazy<ShadeController> mShadeController; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 118 | |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 119 | protected final Context mContext; |
| 120 | private final UserManager mUserManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 121 | private final KeyguardManager mKeyguardManager; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 122 | |
| 123 | protected RemoteInputController mRemoteInputController; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 124 | protected NotificationLifetimeExtender.NotificationSafeToRemoveCallback |
| 125 | mNotificationLifetimeFinishedCallback; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 126 | protected IStatusBarService mBarService; |
| 127 | protected Callback mCallback; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 128 | protected final ArrayList<NotificationLifetimeExtender> mLifetimeExtenders = new ArrayList<>(); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 129 | |
| 130 | private final RemoteViews.OnClickHandler mOnClickHandler = new RemoteViews.OnClickHandler() { |
| 131 | |
| 132 | @Override |
| 133 | public boolean onClickHandler( |
Sunny Goyal | 43c9704 | 2018-08-23 15:21:26 -0700 | [diff] [blame] | 134 | View view, PendingIntent pendingIntent, RemoteViews.RemoteResponse response) { |
Michael Wright | e300104 | 2019-02-05 00:13:14 +0000 | [diff] [blame] | 135 | mShadeController.get().wakeUpIfDozing(SystemClock.uptimeMillis(), view, |
| 136 | "NOTIFICATION_CLICK"); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 137 | |
| 138 | if (handleRemoteInput(view, pendingIntent)) { |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | if (DEBUG) { |
| 143 | Log.v(TAG, "Notification click handler invoked for intent: " + pendingIntent); |
| 144 | } |
| 145 | logActionClick(view); |
| 146 | // The intent we are sending is for the application, which |
| 147 | // won't have permission to immediately start an activity after |
| 148 | // the user switches to home. We know it is safe to do at this |
| 149 | // point, so make sure new activity switches are now allowed. |
| 150 | try { |
| 151 | ActivityManager.getService().resumeAppSwitches(); |
| 152 | } catch (RemoteException e) { |
| 153 | } |
yoshiki iguchi | 67c166d | 2018-11-26 13:11:36 +0900 | [diff] [blame] | 154 | return mCallback.handleRemoteViewClick(view, pendingIntent, () -> { |
Sunny Goyal | 43c9704 | 2018-08-23 15:21:26 -0700 | [diff] [blame] | 155 | Pair<Intent, ActivityOptions> options = response.getLaunchOptions(view); |
| 156 | options.second.setLaunchWindowingMode( |
| 157 | WINDOWING_MODE_FULLSCREEN_OR_SPLIT_SCREEN_SECONDARY); |
| 158 | return RemoteViews.startPendingIntent(view, pendingIntent, options); |
| 159 | }); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | private void logActionClick(View view) { |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 163 | Integer actionIndex = (Integer) |
| 164 | view.getTag(com.android.internal.R.id.notification_action_index_tag); |
| 165 | if (actionIndex == null) { |
| 166 | Log.e(TAG, "Couldn't retrieve the actionIndex from the clicked button"); |
| 167 | return; |
| 168 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 169 | ViewParent parent = view.getParent(); |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 170 | StatusBarNotification statusBarNotification = getNotificationForParent(parent); |
| 171 | if (statusBarNotification == null) { |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 172 | Log.w(TAG, "Couldn't determine notification for click."); |
| 173 | return; |
| 174 | } |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 175 | String key = statusBarNotification.getKey(); |
| 176 | int buttonIndex = -1; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 177 | // If this is a default template, determine the index of the button. |
| 178 | if (view.getId() == com.android.internal.R.id.action0 && |
| 179 | parent != null && parent instanceof ViewGroup) { |
| 180 | ViewGroup actionGroup = (ViewGroup) parent; |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 181 | buttonIndex = actionGroup.indexOfChild(view); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 182 | } |
Dieter Hsu | d39f0d5 | 2018-04-14 02:08:30 +0800 | [diff] [blame] | 183 | final int count = mEntryManager.getNotificationData().getActiveNotifications().size(); |
| 184 | final int rank = mEntryManager.getNotificationData().getRank(key); |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 185 | final Notification.Action action = |
| 186 | statusBarNotification.getNotification().actions[actionIndex]; |
Gustav Sennton | f892fe9 | 2019-01-22 15:31:42 +0000 | [diff] [blame] | 187 | NotificationVisibility.NotificationLocation location = |
| 188 | NotificationLogger.getNotificationLocation( |
| 189 | mEntryManager.getNotificationData().get(key)); |
| 190 | final NotificationVisibility nv = |
| 191 | NotificationVisibility.obtain(key, rank, count, true, location); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 192 | try { |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 193 | mBarService.onNotificationActionClick(key, buttonIndex, action, nv, false); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 194 | } catch (RemoteException e) { |
| 195 | // Ignore |
| 196 | } |
| 197 | } |
| 198 | |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 199 | private StatusBarNotification getNotificationForParent(ViewParent parent) { |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 200 | while (parent != null) { |
| 201 | if (parent instanceof ExpandableNotificationRow) { |
Tony Mak | 7d4b3a5 | 2018-11-27 17:29:36 +0000 | [diff] [blame] | 202 | return ((ExpandableNotificationRow) parent).getStatusBarNotification(); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 203 | } |
| 204 | parent = parent.getParent(); |
| 205 | } |
| 206 | return null; |
| 207 | } |
| 208 | |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 209 | private boolean handleRemoteInput(View view, PendingIntent pendingIntent) { |
| 210 | if (mCallback.shouldHandleRemoteInput(view, pendingIntent)) { |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | Object tag = view.getTag(com.android.internal.R.id.remote_input_tag); |
| 215 | RemoteInput[] inputs = null; |
| 216 | if (tag instanceof RemoteInput[]) { |
| 217 | inputs = (RemoteInput[]) tag; |
| 218 | } |
| 219 | |
| 220 | if (inputs == null) { |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | RemoteInput input = null; |
| 225 | |
| 226 | for (RemoteInput i : inputs) { |
| 227 | if (i.getAllowFreeFormInput()) { |
| 228 | input = i; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if (input == null) { |
| 233 | return false; |
| 234 | } |
| 235 | |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 236 | return activateRemoteInput(view, inputs, input, pendingIntent, |
| 237 | null /* editedSuggestionInfo */); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 238 | } |
| 239 | }; |
| 240 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 241 | @Inject |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 242 | public NotificationRemoteInputManager( |
| 243 | Context context, |
| 244 | NotificationLockscreenUserManager lockscreenUserManager, |
| 245 | SmartReplyController smartReplyController, |
| 246 | NotificationEntryManager notificationEntryManager, |
| 247 | Lazy<ShadeController> shadeController, |
| 248 | @Named(MAIN_HANDLER_NAME) Handler mainHandler) { |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 249 | mContext = context; |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 250 | mLockscreenUserManager = lockscreenUserManager; |
| 251 | mSmartReplyController = smartReplyController; |
| 252 | mEntryManager = notificationEntryManager; |
| 253 | mShadeController = shadeController; |
| 254 | mMainHandler = mainHandler; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 255 | mBarService = IStatusBarService.Stub.asInterface( |
| 256 | ServiceManager.getService(Context.STATUS_BAR_SERVICE)); |
| 257 | mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 258 | addLifetimeExtenders(); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 259 | mKeyguardManager = context.getSystemService(KeyguardManager.class); |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 260 | |
| 261 | notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() { |
| 262 | @Override |
| 263 | public void onEntryRemoved( |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 264 | @Nullable NotificationEntry entry, |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 265 | NotificationVisibility visibility, |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 266 | boolean removedByUser) { |
Ned Burns | 1dd6b40 | 2019-01-02 15:25:23 -0500 | [diff] [blame] | 267 | if (removedByUser && entry != null) { |
Ned Burns | ef2ef6c | 2019-01-02 16:48:08 -0500 | [diff] [blame] | 268 | onPerformRemoveNotification(entry, entry.key); |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | }); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 272 | } |
| 273 | |
Gus Prevas | 21437b3 | 2018-12-05 10:36:13 -0500 | [diff] [blame] | 274 | /** Initializes this component with the provided dependencies. */ |
| 275 | public void setUpWithCallback(Callback callback, RemoteInputController.Delegate delegate) { |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 276 | mCallback = callback; |
| 277 | mRemoteInputController = new RemoteInputController(delegate); |
| 278 | mRemoteInputController.addCallback(new RemoteInputController.Callback() { |
| 279 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 280 | public void onRemoteInputSent(NotificationEntry entry) { |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 281 | if (FORCE_REMOTE_INPUT_HISTORY |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 282 | && isNotificationKeptForRemoteInputHistory(entry.key)) { |
| 283 | mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.key); |
| 284 | } else if (mEntriesKeptForRemoteInputActive.contains(entry)) { |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 285 | // We're currently holding onto this notification, but from the apps point of |
| 286 | // view it is already canceled, so we'll need to cancel it on the apps behalf |
| 287 | // after sending - unless the app posts an update in the mean time, so wait a |
| 288 | // bit. |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 289 | mMainHandler.postDelayed(() -> { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 290 | if (mEntriesKeptForRemoteInputActive.remove(entry)) { |
| 291 | mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.key); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 292 | } |
| 293 | }, REMOTE_INPUT_KEPT_ENTRY_AUTO_CANCEL_DELAY); |
| 294 | } |
Amith Yamasani | 129b481 | 2018-02-08 13:55:59 -0800 | [diff] [blame] | 295 | try { |
| 296 | mBarService.onNotificationDirectReplied(entry.notification.getKey()); |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 297 | if (entry.editedSuggestionInfo != null) { |
| 298 | boolean modifiedBeforeSending = |
| 299 | !TextUtils.equals(entry.remoteInputText, |
| 300 | entry.editedSuggestionInfo.originalText); |
| 301 | mBarService.onNotificationSmartReplySent( |
| 302 | entry.notification.getKey(), |
| 303 | entry.editedSuggestionInfo.index, |
| 304 | entry.editedSuggestionInfo.originalText, |
| 305 | NotificationLogger |
| 306 | .getNotificationLocation(entry) |
| 307 | .toMetricsEventEnum(), |
| 308 | modifiedBeforeSending); |
| 309 | } |
Amith Yamasani | 129b481 | 2018-02-08 13:55:59 -0800 | [diff] [blame] | 310 | } catch (RemoteException e) { |
| 311 | // Nothing to do, system going down |
| 312 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 313 | } |
| 314 | }); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 315 | mSmartReplyController.setCallback((entry, reply) -> { |
| 316 | StatusBarNotification newSbn = |
| 317 | rebuildNotificationWithRemoteInput(entry, reply, true /* showSpinner */); |
| 318 | mEntryManager.updateNotification(newSbn, null /* ranking */); |
| 319 | }); |
| 320 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 321 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 322 | /** |
Milo Sredkov | b2af7f9 | 2018-12-04 15:22:18 +0000 | [diff] [blame] | 323 | * Activates a given {@link RemoteInput} |
| 324 | * |
| 325 | * @param view The view of the action button or suggestion chip that was tapped. |
| 326 | * @param inputs The remote inputs that need to be sent to the app. |
| 327 | * @param input The remote input that needs to be activated. |
| 328 | * @param pendingIntent The pending intent to be sent to the app. |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 329 | * @param editedSuggestionInfo The smart reply that should be inserted in the remote input, or |
| 330 | * {@code null} if the user is not editing a smart reply. |
Milo Sredkov | b2af7f9 | 2018-12-04 15:22:18 +0000 | [diff] [blame] | 331 | * @return Whether the {@link RemoteInput} was activated. |
| 332 | */ |
| 333 | public boolean activateRemoteInput(View view, RemoteInput[] inputs, RemoteInput input, |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 334 | PendingIntent pendingIntent, @Nullable EditedSuggestionInfo editedSuggestionInfo) { |
Milo Sredkov | b2af7f9 | 2018-12-04 15:22:18 +0000 | [diff] [blame] | 335 | |
| 336 | ViewParent p = view.getParent(); |
| 337 | RemoteInputView riv = null; |
| 338 | while (p != null) { |
| 339 | if (p instanceof View) { |
| 340 | View pv = (View) p; |
| 341 | if (pv.isRootNamespace()) { |
| 342 | riv = findRemoteInputView(pv); |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | p = p.getParent(); |
| 347 | } |
| 348 | ExpandableNotificationRow row = null; |
| 349 | while (p != null) { |
| 350 | if (p instanceof ExpandableNotificationRow) { |
| 351 | row = (ExpandableNotificationRow) p; |
| 352 | break; |
| 353 | } |
| 354 | p = p.getParent(); |
| 355 | } |
| 356 | |
| 357 | if (row == null) { |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | row.setUserExpanded(true); |
| 362 | |
| 363 | if (!mLockscreenUserManager.shouldAllowLockscreenRemoteInput()) { |
| 364 | final int userId = pendingIntent.getCreatorUserHandle().getIdentifier(); |
| 365 | if (mLockscreenUserManager.isLockscreenPublicMode(userId)) { |
| 366 | mCallback.onLockedRemoteInput(row, view); |
| 367 | return true; |
| 368 | } |
| 369 | if (mUserManager.getUserInfo(userId).isManagedProfile() |
| 370 | && mKeyguardManager.isDeviceLocked(userId)) { |
| 371 | mCallback.onLockedWorkRemoteInput(userId, row, view); |
| 372 | return true; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | if (riv == null) { |
| 377 | riv = findRemoteInputView(row.getPrivateLayout().getExpandedChild()); |
| 378 | if (riv == null) { |
| 379 | return false; |
| 380 | } |
| 381 | if (!row.getPrivateLayout().getExpandedChild().isShown()) { |
| 382 | mCallback.onMakeExpandedVisibleForRemoteInput(row, view); |
| 383 | return true; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | int width = view.getWidth(); |
| 388 | if (view instanceof TextView) { |
| 389 | // Center the reveal on the text which might be off-center from the TextView |
| 390 | TextView tv = (TextView) view; |
| 391 | if (tv.getLayout() != null) { |
| 392 | int innerWidth = (int) tv.getLayout().getLineWidth(0); |
| 393 | innerWidth += tv.getCompoundPaddingLeft() + tv.getCompoundPaddingRight(); |
| 394 | width = Math.min(width, innerWidth); |
| 395 | } |
| 396 | } |
| 397 | int cx = view.getLeft() + width / 2; |
| 398 | int cy = view.getTop() + view.getHeight() / 2; |
| 399 | int w = riv.getWidth(); |
| 400 | int h = riv.getHeight(); |
| 401 | int r = Math.max( |
| 402 | Math.max(cx + cy, cx + (h - cy)), |
| 403 | Math.max((w - cx) + cy, (w - cx) + (h - cy))); |
| 404 | |
| 405 | riv.setRevealParameters(cx, cy, r); |
| 406 | riv.setPendingIntent(pendingIntent); |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 407 | riv.setRemoteInput(inputs, input, editedSuggestionInfo); |
Milo Sredkov | b2af7f9 | 2018-12-04 15:22:18 +0000 | [diff] [blame] | 408 | riv.focusAnimated(); |
| 409 | |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | private RemoteInputView findRemoteInputView(View v) { |
| 414 | if (v == null) { |
| 415 | return null; |
| 416 | } |
| 417 | return (RemoteInputView) v.findViewWithTag(RemoteInputView.VIEW_TAG); |
| 418 | } |
| 419 | |
| 420 | /** |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 421 | * Adds all the notification lifetime extenders. Each extender represents a reason for the |
| 422 | * NotificationRemoteInputManager to keep a notification lifetime extended. |
| 423 | */ |
| 424 | protected void addLifetimeExtenders() { |
| 425 | mLifetimeExtenders.add(new RemoteInputHistoryExtender()); |
| 426 | mLifetimeExtenders.add(new SmartReplyHistoryExtender()); |
| 427 | mLifetimeExtenders.add(new RemoteInputActiveExtender()); |
| 428 | } |
| 429 | |
| 430 | public ArrayList<NotificationLifetimeExtender> getLifetimeExtenders() { |
| 431 | return mLifetimeExtenders; |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | public RemoteInputController getController() { |
| 435 | return mRemoteInputController; |
| 436 | } |
| 437 | |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 438 | @VisibleForTesting |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 439 | void onPerformRemoveNotification(NotificationEntry entry, final String key) { |
Gus Prevas | 772e532 | 2018-12-21 16:22:16 -0500 | [diff] [blame] | 440 | if (mKeysKeptForRemoteInputHistory.contains(key)) { |
| 441 | mKeysKeptForRemoteInputHistory.remove(key); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 442 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 443 | if (mRemoteInputController.isRemoteInputActive(entry)) { |
| 444 | mRemoteInputController.removeRemoteInput(entry, null); |
| 445 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 446 | } |
| 447 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 448 | public void onPanelCollapsed() { |
| 449 | for (int i = 0; i < mEntriesKeptForRemoteInputActive.size(); i++) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 450 | NotificationEntry entry = mEntriesKeptForRemoteInputActive.valueAt(i); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 451 | mRemoteInputController.removeRemoteInput(entry, null); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 452 | if (mNotificationLifetimeFinishedCallback != null) { |
| 453 | mNotificationLifetimeFinishedCallback.onSafeToRemove(entry.key); |
| 454 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 455 | } |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 456 | mEntriesKeptForRemoteInputActive.clear(); |
| 457 | } |
| 458 | |
| 459 | public boolean isNotificationKeptForRemoteInputHistory(String key) { |
| 460 | return mKeysKeptForRemoteInputHistory.contains(key); |
| 461 | } |
| 462 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 463 | public boolean shouldKeepForRemoteInputHistory(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 464 | if (entry.isDismissed()) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 465 | return false; |
| 466 | } |
| 467 | if (!FORCE_REMOTE_INPUT_HISTORY) { |
| 468 | return false; |
| 469 | } |
| 470 | return (mRemoteInputController.isSpinning(entry.key) || entry.hasJustSentRemoteInput()); |
| 471 | } |
| 472 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 473 | public boolean shouldKeepForSmartReplyHistory(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 474 | if (entry.isDismissed()) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 475 | return false; |
| 476 | } |
| 477 | if (!FORCE_REMOTE_INPUT_HISTORY) { |
| 478 | return false; |
| 479 | } |
| 480 | return mSmartReplyController.isSendingSmartReply(entry.key); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | public void checkRemoteInputOutside(MotionEvent event) { |
| 484 | if (event.getAction() == MotionEvent.ACTION_OUTSIDE // touch outside the source bar |
| 485 | && event.getX() == 0 && event.getY() == 0 // a touch outside both bars |
| 486 | && mRemoteInputController.isRemoteInputActive()) { |
| 487 | mRemoteInputController.closeRemoteInputs(); |
| 488 | } |
| 489 | } |
| 490 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 491 | @VisibleForTesting |
| 492 | StatusBarNotification rebuildNotificationForCanceledSmartReplies( |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 493 | NotificationEntry entry) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 494 | return rebuildNotificationWithRemoteInput(entry, null /* remoteInputTest */, |
| 495 | false /* showSpinner */); |
| 496 | } |
| 497 | |
| 498 | @VisibleForTesting |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 499 | StatusBarNotification rebuildNotificationWithRemoteInput(NotificationEntry entry, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 500 | CharSequence remoteInputText, boolean showSpinner) { |
| 501 | StatusBarNotification sbn = entry.notification; |
| 502 | |
| 503 | Notification.Builder b = Notification.Builder |
| 504 | .recoverBuilder(mContext, sbn.getNotification().clone()); |
| 505 | if (remoteInputText != null) { |
| 506 | CharSequence[] oldHistory = sbn.getNotification().extras |
| 507 | .getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY); |
| 508 | CharSequence[] newHistory; |
| 509 | if (oldHistory == null) { |
| 510 | newHistory = new CharSequence[1]; |
| 511 | } else { |
| 512 | newHistory = new CharSequence[oldHistory.length + 1]; |
| 513 | System.arraycopy(oldHistory, 0, newHistory, 1, oldHistory.length); |
| 514 | } |
| 515 | newHistory[0] = String.valueOf(remoteInputText); |
| 516 | b.setRemoteInputHistory(newHistory); |
| 517 | } |
| 518 | b.setShowRemoteInputSpinner(showSpinner); |
| 519 | b.setHideSmartReplies(true); |
| 520 | |
| 521 | Notification newNotification = b.build(); |
| 522 | |
| 523 | // Undo any compatibility view inflation |
| 524 | newNotification.contentView = sbn.getNotification().contentView; |
| 525 | newNotification.bigContentView = sbn.getNotification().bigContentView; |
| 526 | newNotification.headsUpContentView = sbn.getNotification().headsUpContentView; |
| 527 | |
| 528 | return new StatusBarNotification( |
| 529 | sbn.getPackageName(), |
| 530 | sbn.getOpPkg(), |
| 531 | sbn.getId(), |
| 532 | sbn.getTag(), |
| 533 | sbn.getUid(), |
| 534 | sbn.getInitialPid(), |
| 535 | newNotification, |
| 536 | sbn.getUser(), |
| 537 | sbn.getOverrideGroupKey(), |
| 538 | sbn.getPostTime()); |
| 539 | } |
| 540 | |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 541 | @Override |
| 542 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 543 | pw.println("NotificationRemoteInputManager state:"); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 544 | pw.print(" mKeysKeptForRemoteInputHistory: "); |
| 545 | pw.println(mKeysKeptForRemoteInputHistory); |
| 546 | pw.print(" mEntriesKeptForRemoteInputActive: "); |
| 547 | pw.println(mEntriesKeptForRemoteInputActive); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | public void bindRow(ExpandableNotificationRow row) { |
| 551 | row.setRemoteInputController(mRemoteInputController); |
| 552 | row.setRemoteViewClickHandler(mOnClickHandler); |
| 553 | } |
| 554 | |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 555 | @VisibleForTesting |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 556 | public Set<NotificationEntry> getEntriesKeptForRemoteInputActive() { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 557 | return mEntriesKeptForRemoteInputActive; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * NotificationRemoteInputManager has multiple reasons to keep notification lifetime extended |
| 562 | * so we implement multiple NotificationLifetimeExtenders |
| 563 | */ |
| 564 | protected abstract class RemoteInputExtender implements NotificationLifetimeExtender { |
| 565 | @Override |
| 566 | public void setCallback(NotificationSafeToRemoveCallback callback) { |
| 567 | if (mNotificationLifetimeFinishedCallback == null) { |
| 568 | mNotificationLifetimeFinishedCallback = callback; |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Notification is kept alive as it was cancelled in response to a remote input interaction. |
| 575 | * This allows us to show what you replied and allows you to continue typing into it. |
| 576 | */ |
| 577 | protected class RemoteInputHistoryExtender extends RemoteInputExtender { |
| 578 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 579 | public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 580 | return shouldKeepForRemoteInputHistory(entry); |
| 581 | } |
| 582 | |
| 583 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 584 | public void setShouldManageLifetime(NotificationEntry entry, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 585 | boolean shouldExtend) { |
| 586 | if (shouldExtend) { |
| 587 | CharSequence remoteInputText = entry.remoteInputText; |
| 588 | if (TextUtils.isEmpty(remoteInputText)) { |
| 589 | remoteInputText = entry.remoteInputTextWhenReset; |
| 590 | } |
| 591 | StatusBarNotification newSbn = rebuildNotificationWithRemoteInput(entry, |
| 592 | remoteInputText, false /* showSpinner */); |
| 593 | entry.onRemoteInputInserted(); |
| 594 | |
| 595 | if (newSbn == null) { |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | mEntryManager.updateNotification(newSbn, null); |
| 600 | |
| 601 | // Ensure the entry hasn't already been removed. This can happen if there is an |
| 602 | // inflation exception while updating the remote history |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 603 | if (entry.isRemoved()) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 604 | return; |
| 605 | } |
| 606 | |
| 607 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 608 | Log.d(TAG, "Keeping notification around after sending remote input " |
| 609 | + entry.key); |
| 610 | } |
| 611 | |
| 612 | mKeysKeptForRemoteInputHistory.add(entry.key); |
| 613 | } else { |
| 614 | mKeysKeptForRemoteInputHistory.remove(entry.key); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | /** |
| 620 | * Notification is kept alive for smart reply history. Similar to REMOTE_INPUT_HISTORY but with |
| 621 | * {@link SmartReplyController} specific logic |
| 622 | */ |
| 623 | protected class SmartReplyHistoryExtender extends RemoteInputExtender { |
| 624 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 625 | public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 626 | return shouldKeepForSmartReplyHistory(entry); |
| 627 | } |
| 628 | |
| 629 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 630 | public void setShouldManageLifetime(NotificationEntry entry, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 631 | boolean shouldExtend) { |
| 632 | if (shouldExtend) { |
| 633 | StatusBarNotification newSbn = rebuildNotificationForCanceledSmartReplies(entry); |
| 634 | |
| 635 | if (newSbn == null) { |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | mEntryManager.updateNotification(newSbn, null); |
| 640 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 641 | if (entry.isRemoved()) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 642 | return; |
| 643 | } |
| 644 | |
| 645 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 646 | Log.d(TAG, "Keeping notification around after sending smart reply " |
| 647 | + entry.key); |
| 648 | } |
| 649 | |
| 650 | mKeysKeptForRemoteInputHistory.add(entry.key); |
| 651 | } else { |
| 652 | mKeysKeptForRemoteInputHistory.remove(entry.key); |
| 653 | mSmartReplyController.stopSending(entry); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /** |
| 659 | * Notification is kept alive because the user is still using the remote input |
| 660 | */ |
| 661 | protected class RemoteInputActiveExtender extends RemoteInputExtender { |
| 662 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 663 | public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 664 | if (entry.isDismissed()) { |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 665 | return false; |
| 666 | } |
| 667 | return mRemoteInputController.isRemoteInputActive(entry); |
| 668 | } |
| 669 | |
| 670 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 671 | public void setShouldManageLifetime(NotificationEntry entry, |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 672 | boolean shouldExtend) { |
| 673 | if (shouldExtend) { |
| 674 | if (Log.isLoggable(TAG, Log.DEBUG)) { |
| 675 | Log.d(TAG, "Keeping notification around while remote input active " |
| 676 | + entry.key); |
| 677 | } |
| 678 | mEntriesKeptForRemoteInputActive.add(entry); |
| 679 | } else { |
| 680 | mEntriesKeptForRemoteInputActive.remove(entry); |
| 681 | } |
| 682 | } |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /** |
| 686 | * Callback for various remote input related events, or for providing information that |
| 687 | * NotificationRemoteInputManager needs to know to decide what to do. |
| 688 | */ |
| 689 | public interface Callback { |
| 690 | |
| 691 | /** |
| 692 | * Called when remote input was activated but the device is locked. |
| 693 | * |
| 694 | * @param row |
| 695 | * @param clicked |
| 696 | */ |
| 697 | void onLockedRemoteInput(ExpandableNotificationRow row, View clicked); |
| 698 | |
| 699 | /** |
| 700 | * Called when remote input was activated but the device is locked and in a managed profile. |
| 701 | * |
| 702 | * @param userId |
| 703 | * @param row |
| 704 | * @param clicked |
| 705 | */ |
| 706 | void onLockedWorkRemoteInput(int userId, ExpandableNotificationRow row, View clicked); |
| 707 | |
| 708 | /** |
| 709 | * Called when a row should be made expanded for the purposes of remote input. |
| 710 | * |
| 711 | * @param row |
| 712 | * @param clickedView |
| 713 | */ |
| 714 | void onMakeExpandedVisibleForRemoteInput(ExpandableNotificationRow row, View clickedView); |
| 715 | |
| 716 | /** |
| 717 | * Return whether or not remote input should be handled for this view. |
| 718 | * |
| 719 | * @param view |
| 720 | * @param pendingIntent |
| 721 | * @return true iff the remote input should be handled |
| 722 | */ |
| 723 | boolean shouldHandleRemoteInput(View view, PendingIntent pendingIntent); |
| 724 | |
| 725 | /** |
| 726 | * Performs any special handling for a remote view click. The default behaviour can be |
| 727 | * called through the defaultHandler parameter. |
| 728 | * |
yoshiki iguchi | 67c166d | 2018-11-26 13:11:36 +0900 | [diff] [blame] | 729 | * @param view |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 730 | * @param pendingIntent |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 731 | * @param defaultHandler |
| 732 | * @return true iff the click was handled |
| 733 | */ |
yoshiki iguchi | 67c166d | 2018-11-26 13:11:36 +0900 | [diff] [blame] | 734 | boolean handleRemoteViewClick(View view, PendingIntent pendingIntent, |
| 735 | ClickHandler defaultHandler); |
Eliot Courtney | e77edea | 2017-11-15 14:25:21 +0900 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Helper interface meant for passing the default on click behaviour to NotificationPresenter, |
| 740 | * so it may do its own handling before invoking the default behaviour. |
| 741 | */ |
| 742 | public interface ClickHandler { |
| 743 | /** |
| 744 | * Tries to handle a click on a remote view. |
| 745 | * |
| 746 | * @return true iff the click was handled |
| 747 | */ |
| 748 | boolean handleClick(); |
| 749 | } |
| 750 | } |