Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 18 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 20 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 22 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 23 | import static com.android.systemui.Interpolators.FAST_OUT_SLOW_IN; |
| 24 | |
| 25 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 26 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 27 | import android.animation.Animator; |
| 28 | import android.animation.AnimatorListenerAdapter; |
| 29 | import android.animation.AnimatorSet; |
| 30 | import android.animation.ObjectAnimator; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 31 | import android.annotation.IntDef; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 32 | import android.annotation.Nullable; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 33 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 34 | import android.app.Notification; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 35 | import android.app.NotificationChannel; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 36 | import android.app.NotificationChannelGroup; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 37 | import android.content.Context; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 38 | import android.content.Intent; |
| 39 | import android.content.pm.ActivityInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 40 | import android.content.pm.ApplicationInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 41 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 42 | import android.content.pm.ResolveInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 43 | import android.graphics.drawable.Drawable; |
William Brockman | 75cf66a | 2018-12-21 13:25:01 -0500 | [diff] [blame] | 44 | import android.metrics.LogMaker; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 45 | import android.os.Handler; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 46 | import android.os.RemoteException; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 47 | import android.service.notification.StatusBarNotification; |
| 48 | import android.text.TextUtils; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 49 | import android.transition.ChangeBounds; |
| 50 | import android.transition.Fade; |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 51 | import android.transition.TransitionManager; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 52 | import android.transition.TransitionSet; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 53 | import android.util.AttributeSet; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 54 | import android.util.Log; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 55 | import android.view.View; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 56 | import android.view.ViewGroup; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 57 | import android.view.accessibility.AccessibilityEvent; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 58 | import android.widget.ImageView; |
| 59 | import android.widget.LinearLayout; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 60 | import android.widget.TextView; |
| 61 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 62 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 63 | import com.android.internal.logging.MetricsLogger; |
| 64 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 65 | import com.android.systemui.Dependency; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 66 | import com.android.systemui.Interpolators; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 67 | import com.android.systemui.R; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 69 | import com.android.systemui.statusbar.notification.logging.NotificationCounters; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 70 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 71 | import java.lang.annotation.Retention; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 72 | import java.util.List; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 73 | import java.util.Set; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 76 | * The guts of a notification revealed when performing a long press. This also houses the blocking |
| 77 | * helper affordance that allows a user to keep/stop notifications after swiping one away. |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 78 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 79 | public class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 80 | private static final String TAG = "InfoGuts"; |
| 81 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 82 | @IntDef(prefix = { "ACTION_" }, value = { |
| 83 | ACTION_NONE, |
| 84 | ACTION_UNDO, |
| 85 | ACTION_TOGGLE_SILENT, |
| 86 | ACTION_BLOCK, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 87 | }) |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 88 | public @interface NotificationInfoAction { |
| 89 | } |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 90 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 91 | public static final int ACTION_NONE = 0; |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 92 | static final int ACTION_UNDO = 1; |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 93 | // standard controls |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 94 | static final int ACTION_TOGGLE_SILENT = 2; |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 95 | // unused |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 96 | static final int ACTION_BLOCK = 3; |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 97 | // blocking helper |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 98 | static final int ACTION_DELIVER_SILENTLY = 4; |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 99 | // standard controls |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 100 | private static final int ACTION_ALERT = 5; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 101 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 102 | private TextView mPriorityDescriptionView; |
| 103 | private TextView mSilentDescriptionView; |
Dan Sandler | 0ed0229 | 2019-05-14 19:18:35 -0400 | [diff] [blame] | 104 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 105 | private INotificationManager mINotificationManager; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 106 | private PackageManager mPm; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 107 | private MetricsLogger mMetricsLogger; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 108 | private VisualStabilityManager mVisualStabilityManager; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 109 | private ChannelEditorDialogController mChannelEditorDialogController; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 110 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 111 | private String mPackageName; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 112 | private String mAppName; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 113 | private int mAppUid; |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 114 | private String mDelegatePkg; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 115 | private int mNumUniqueChannelsInRow; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 116 | private Set<NotificationChannel> mUniqueChannelsInRow; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 117 | private NotificationChannel mSingleNotificationChannel; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 118 | private int mStartingChannelImportance; |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 119 | private boolean mWasShownHighPriority; |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 120 | private boolean mPressedApply; |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 121 | private boolean mPresentingChannelEditorDialog = false; |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 122 | |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 123 | /** |
| 124 | * The last importance level chosen by the user. Null if the user has not chosen an importance |
| 125 | * level; non-null once the user takes an action which indicates an explicit preference. |
| 126 | */ |
| 127 | @Nullable private Integer mChosenImportance; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 128 | private boolean mIsSingleDefaultChannel; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 129 | private boolean mIsNonblockable; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 130 | private StatusBarNotification mSbn; |
| 131 | private AnimatorSet mExpandAnimation; |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 132 | private boolean mIsDeviceProvisioned; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 133 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 134 | private CheckSaveListener mCheckSaveListener; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 135 | private OnSettingsClickListener mOnSettingsClickListener; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 136 | private OnAppSettingsClickListener mAppSettingsClickListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 137 | private NotificationGuts mGutsContainer; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 138 | private Drawable mPkgIcon; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 139 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 140 | /** Whether this view is being shown as part of the blocking helper. */ |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 141 | private boolean mIsForBlockingHelper; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 142 | |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 143 | /** |
| 144 | * String that describes how the user exit or quit out of this view, also used as a counter tag. |
| 145 | */ |
| 146 | private String mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 147 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 148 | // used by standard ui |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 149 | private OnClickListener mOnAlert = v -> { |
| 150 | mExitReason = NotificationCounters.BLOCKING_HELPER_KEEP_SHOWING; |
| 151 | mChosenImportance = IMPORTANCE_DEFAULT; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 152 | applyAlertingBehavior(BEHAVIOR_ALERTING, true /* userTriggered */); |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 153 | }; |
| 154 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 155 | // used by standard ui |
| 156 | private OnClickListener mOnSilent = v -> { |
| 157 | mExitReason = NotificationCounters.BLOCKING_HELPER_DELIVER_SILENTLY; |
| 158 | mChosenImportance = IMPORTANCE_LOW; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 159 | applyAlertingBehavior(BEHAVIOR_SILENT, true /* userTriggered */); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | // used by standard ui |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 163 | private OnClickListener mOnDismissSettings = v -> { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 164 | mPressedApply = true; |
Evan Laird | 7956fe8 | 2019-05-30 17:14:57 -0400 | [diff] [blame] | 165 | closeControls(v, true); |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 166 | }; |
| 167 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 168 | // used by blocking helper |
| 169 | private OnClickListener mOnKeepShowing = v -> { |
| 170 | mExitReason = NotificationCounters.BLOCKING_HELPER_KEEP_SHOWING; |
Evan Laird | 7956fe8 | 2019-05-30 17:14:57 -0400 | [diff] [blame] | 171 | closeControls(v, true); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 172 | mMetricsLogger.write(getLogMaker().setCategory( |
| 173 | MetricsEvent.NOTIFICATION_BLOCKING_HELPER) |
| 174 | .setType(MetricsEvent.TYPE_ACTION) |
| 175 | .setSubtype(MetricsEvent.BLOCKING_HELPER_CLICK_STAY_SILENT)); |
| 176 | }; |
| 177 | |
| 178 | // used by blocking helper |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 179 | private OnClickListener mOnDeliverSilently = v -> { |
| 180 | handleSaveImportance( |
| 181 | ACTION_DELIVER_SILENTLY, MetricsEvent.BLOCKING_HELPER_CLICK_STAY_SILENT); |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | private void handleSaveImportance(int action, int metricsSubtype) { |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 185 | Runnable saveImportance = () -> { |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 186 | saveImportanceAndExitReason(action); |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 187 | if (mIsForBlockingHelper) { |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 188 | swapContent(action, true /* animate */); |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 189 | mMetricsLogger.write(getLogMaker() |
| 190 | .setCategory(MetricsEvent.NOTIFICATION_BLOCKING_HELPER) |
| 191 | .setType(MetricsEvent.TYPE_ACTION) |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 192 | .setSubtype(metricsSubtype)); |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 193 | } |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 194 | }; |
| 195 | if (mCheckSaveListener != null) { |
| 196 | mCheckSaveListener.checkSave(saveImportance, mSbn); |
| 197 | } else { |
| 198 | saveImportance.run(); |
| 199 | } |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 200 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 201 | |
| 202 | private OnClickListener mOnUndo = v -> { |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 203 | // Reset exit counter that we'll log and record an undo event separately (not an exit event) |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 204 | mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED; |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 205 | if (mIsForBlockingHelper) { |
| 206 | logBlockingHelperCounter(NotificationCounters.BLOCKING_HELPER_UNDO); |
| 207 | mMetricsLogger.write(getLogMaker().setCategory( |
| 208 | MetricsEvent.NOTIFICATION_BLOCKING_HELPER) |
| 209 | .setType(MetricsEvent.TYPE_DISMISS) |
| 210 | .setSubtype(MetricsEvent.BLOCKING_HELPER_CLICK_UNDO)); |
| 211 | } else { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 212 | // TODO: this can't happen? |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 213 | mMetricsLogger.write(importanceChangeLogMaker().setType(MetricsEvent.TYPE_DISMISS)); |
| 214 | } |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 215 | saveImportanceAndExitReason(ACTION_UNDO); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 216 | swapContent(ACTION_UNDO, true /* animate */); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 217 | }; |
| 218 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 219 | public NotificationInfo(Context context, AttributeSet attrs) { |
| 220 | super(context, attrs); |
| 221 | } |
| 222 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 223 | @Override |
| 224 | protected void onFinishInflate() { |
| 225 | super.onFinishInflate(); |
| 226 | |
| 227 | mPriorityDescriptionView = findViewById(R.id.alert_summary); |
| 228 | mSilentDescriptionView = findViewById(R.id.silence_summary); |
| 229 | } |
| 230 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 231 | // Specify a CheckSaveListener to override when/if the user's changes are committed. |
| 232 | public interface CheckSaveListener { |
| 233 | // Invoked when importance has changed and the NotificationInfo wants to try to save it. |
| 234 | // Listener should run saveImportance unless the change should be canceled. |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 235 | void checkSave(Runnable saveImportance, StatusBarNotification sbn); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 236 | } |
| 237 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 238 | public interface OnSettingsClickListener { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 239 | void onClick(View v, NotificationChannel channel, int appUid); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 242 | public interface OnAppSettingsClickListener { |
| 243 | void onClick(View v, Intent intent); |
| 244 | } |
| 245 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 246 | @VisibleForTesting |
| 247 | void bindNotification( |
| 248 | final PackageManager pm, |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 249 | final INotificationManager iNotificationManager, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 250 | final VisualStabilityManager visualStabilityManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 251 | final String pkg, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 252 | final NotificationChannel notificationChannel, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 253 | final Set<NotificationChannel> uniqueChannelsInRow, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 254 | final StatusBarNotification sbn, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 255 | final CheckSaveListener checkSaveListener, |
| 256 | final OnSettingsClickListener onSettingsClick, |
| 257 | final OnAppSettingsClickListener onAppSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 258 | boolean isDeviceProvisioned, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 259 | boolean isNonblockable, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 260 | int importance, |
| 261 | boolean wasShownHighPriority) |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 262 | throws RemoteException { |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 263 | bindNotification(pm, iNotificationManager, visualStabilityManager, pkg, notificationChannel, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 264 | uniqueChannelsInRow, sbn, checkSaveListener, onSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 265 | onAppSettingsClick, isDeviceProvisioned, isNonblockable, |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 266 | false /* isBlockingHelper */, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 267 | importance, wasShownHighPriority); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 268 | } |
| 269 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 270 | public void bindNotification( |
| 271 | PackageManager pm, |
| 272 | INotificationManager iNotificationManager, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 273 | VisualStabilityManager visualStabilityManager, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 274 | String pkg, |
| 275 | NotificationChannel notificationChannel, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 276 | Set<NotificationChannel> uniqueChannelsInRow, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 277 | StatusBarNotification sbn, |
| 278 | CheckSaveListener checkSaveListener, |
| 279 | OnSettingsClickListener onSettingsClick, |
| 280 | OnAppSettingsClickListener onAppSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 281 | boolean isDeviceProvisioned, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 282 | boolean isNonblockable, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 283 | boolean isForBlockingHelper, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 284 | int importance, |
| 285 | boolean wasShownHighPriority) |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 286 | throws RemoteException { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 287 | mINotificationManager = iNotificationManager; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 288 | mMetricsLogger = Dependency.get(MetricsLogger.class); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 289 | mVisualStabilityManager = visualStabilityManager; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 290 | mChannelEditorDialogController = Dependency.get(ChannelEditorDialogController.class); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 291 | mPackageName = pkg; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 292 | mUniqueChannelsInRow = uniqueChannelsInRow; |
| 293 | mNumUniqueChannelsInRow = uniqueChannelsInRow.size(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 294 | mSbn = sbn; |
| 295 | mPm = pm; |
| 296 | mAppSettingsClickListener = onAppSettingsClick; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 297 | mAppName = mPackageName; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 298 | mCheckSaveListener = checkSaveListener; |
| 299 | mOnSettingsClickListener = onSettingsClick; |
| 300 | mSingleNotificationChannel = notificationChannel; |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 301 | mStartingChannelImportance = mSingleNotificationChannel.getImportance(); |
| 302 | mWasShownHighPriority = wasShownHighPriority; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 303 | mIsNonblockable = isNonblockable; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 304 | mIsForBlockingHelper = isForBlockingHelper; |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 305 | mAppUid = mSbn.getUid(); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 306 | mDelegatePkg = mSbn.getOpPkg(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 307 | mIsDeviceProvisioned = isDeviceProvisioned; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 308 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 309 | int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 310 | pkg, mAppUid, false /* includeDeleted */); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 311 | if (mNumUniqueChannelsInRow == 0) { |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 312 | throw new IllegalArgumentException("bindNotification requires at least one channel"); |
| 313 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 314 | // Special behavior for the Default channel if no other channels have been defined. |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 315 | mIsSingleDefaultChannel = mNumUniqueChannelsInRow == 1 |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 316 | && mSingleNotificationChannel.getId().equals( |
| 317 | NotificationChannel.DEFAULT_CHANNEL_ID) |
| 318 | && numTotalChannels == 1; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 319 | } |
| 320 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 321 | bindHeader(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 322 | bindChannelDetails(); |
| 323 | |
| 324 | if (mIsForBlockingHelper) { |
| 325 | bindBlockingHelper(); |
| 326 | } else { |
| 327 | bindInlineControls(); |
| 328 | } |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 329 | |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 330 | mMetricsLogger.write(notificationControlsLogMaker()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 331 | } |
| 332 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 333 | private void bindBlockingHelper() { |
| 334 | findViewById(R.id.inline_controls).setVisibility(GONE); |
| 335 | findViewById(R.id.blocking_helper).setVisibility(VISIBLE); |
| 336 | |
| 337 | findViewById(R.id.undo).setOnClickListener(mOnUndo); |
| 338 | |
| 339 | View turnOffButton = findViewById(R.id.blocking_helper_turn_off_notifications); |
| 340 | turnOffButton.setOnClickListener(getSettingsOnClickListener()); |
| 341 | turnOffButton.setVisibility(turnOffButton.hasOnClickListeners() ? VISIBLE : GONE); |
| 342 | |
| 343 | TextView keepShowing = findViewById(R.id.keep_showing); |
| 344 | keepShowing.setOnClickListener(mOnKeepShowing); |
| 345 | |
| 346 | View deliverSilently = findViewById(R.id.deliver_silently); |
| 347 | deliverSilently.setOnClickListener(mOnDeliverSilently); |
| 348 | } |
| 349 | |
| 350 | private void bindInlineControls() { |
| 351 | findViewById(R.id.inline_controls).setVisibility(VISIBLE); |
| 352 | findViewById(R.id.blocking_helper).setVisibility(GONE); |
| 353 | |
| 354 | if (mIsNonblockable) { |
| 355 | findViewById(R.id.non_configurable_text).setVisibility(VISIBLE); |
| 356 | findViewById(R.id.non_configurable_multichannel_text).setVisibility(GONE); |
| 357 | findViewById(R.id.interruptiveness_settings).setVisibility(GONE); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 358 | ((TextView) findViewById(R.id.done)).setText(R.string.inline_done_button); |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 359 | findViewById(R.id.turn_off_notifications).setVisibility(GONE); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 360 | } else if (mNumUniqueChannelsInRow > 1) { |
| 361 | findViewById(R.id.non_configurable_text).setVisibility(GONE); |
| 362 | findViewById(R.id.interruptiveness_settings).setVisibility(GONE); |
| 363 | findViewById(R.id.non_configurable_multichannel_text).setVisibility(VISIBLE); |
| 364 | } else { |
| 365 | findViewById(R.id.non_configurable_text).setVisibility(GONE); |
| 366 | findViewById(R.id.non_configurable_multichannel_text).setVisibility(GONE); |
| 367 | findViewById(R.id.interruptiveness_settings).setVisibility(VISIBLE); |
| 368 | } |
| 369 | |
| 370 | View turnOffButton = findViewById(R.id.turn_off_notifications); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 371 | turnOffButton.setOnClickListener(getTurnOffNotificationsClickListener()); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 372 | turnOffButton.setVisibility(turnOffButton.hasOnClickListeners() && !mIsNonblockable |
| 373 | ? VISIBLE : GONE); |
| 374 | |
| 375 | View done = findViewById(R.id.done); |
| 376 | done.setOnClickListener(mOnDismissSettings); |
| 377 | |
| 378 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 379 | View silent = findViewById(R.id.silence); |
| 380 | View alert = findViewById(R.id.alert); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 381 | silent.setOnClickListener(mOnSilent); |
| 382 | alert.setOnClickListener(mOnAlert); |
| 383 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 384 | applyAlertingBehavior( |
| 385 | mWasShownHighPriority ? BEHAVIOR_ALERTING : BEHAVIOR_SILENT, |
| 386 | false /* userTriggered */); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | private void bindHeader() { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 390 | // Package name |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 391 | mPkgIcon = null; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 392 | ApplicationInfo info; |
| 393 | try { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 394 | info = mPm.getApplicationInfo( |
| 395 | mPackageName, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 396 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 397 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 398 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 399 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 400 | if (info != null) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 401 | mAppName = String.valueOf(mPm.getApplicationLabel(info)); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 402 | mPkgIcon = mPm.getApplicationIcon(info); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 403 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 404 | } catch (PackageManager.NameNotFoundException e) { |
| 405 | // app is gone, just show package name and generic icon |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 406 | mPkgIcon = mPm.getDefaultActivityIcon(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 407 | } |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 408 | ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(mPkgIcon); |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 409 | ((TextView) findViewById(R.id.pkgname)).setText(mAppName); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 410 | |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 411 | // Delegate |
| 412 | bindDelegate(); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 413 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 414 | // Set up app settings link (i.e. Customize) |
| 415 | View settingsLinkView = findViewById(R.id.app_settings); |
| 416 | Intent settingsIntent = getAppSettingsIntent(mPm, mPackageName, |
| 417 | mSingleNotificationChannel, |
| 418 | mSbn.getId(), mSbn.getTag()); |
| 419 | if (settingsIntent != null |
| 420 | && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) { |
| 421 | settingsLinkView.setVisibility(VISIBLE); |
| 422 | settingsLinkView.setOnClickListener((View view) -> { |
| 423 | mAppSettingsClickListener.onClick(view, settingsIntent); |
| 424 | }); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 425 | } else { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 426 | settingsLinkView.setVisibility(View.GONE); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 427 | } |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 428 | |
| 429 | // System Settings button. |
| 430 | final View settingsButton = findViewById(R.id.info); |
| 431 | settingsButton.setOnClickListener(getSettingsOnClickListener()); |
| 432 | settingsButton.setVisibility(settingsButton.hasOnClickListeners() ? VISIBLE : GONE); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 435 | private OnClickListener getSettingsOnClickListener() { |
| 436 | if (mAppUid >= 0 && mOnSettingsClickListener != null && mIsDeviceProvisioned) { |
| 437 | final int appUidF = mAppUid; |
| 438 | return ((View view) -> { |
| 439 | logBlockingHelperCounter( |
| 440 | NotificationCounters.BLOCKING_HELPER_NOTIF_SETTINGS); |
| 441 | mOnSettingsClickListener.onClick(view, |
| 442 | mNumUniqueChannelsInRow > 1 ? null : mSingleNotificationChannel, |
| 443 | appUidF); |
| 444 | }); |
| 445 | } |
| 446 | return null; |
| 447 | } |
| 448 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 449 | private OnClickListener getTurnOffNotificationsClickListener() { |
| 450 | return ((View view) -> { |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 451 | if (!mPresentingChannelEditorDialog && mChannelEditorDialogController != null) { |
| 452 | mPresentingChannelEditorDialog = true; |
| 453 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 454 | mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid, |
| 455 | mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener); |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 456 | mChannelEditorDialogController.setOnFinishListener(() -> { |
| 457 | mPresentingChannelEditorDialog = false; |
| 458 | closeControls(this, false); |
| 459 | }); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 460 | mChannelEditorDialogController.show(); |
| 461 | } |
| 462 | }); |
| 463 | } |
| 464 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 465 | private void bindChannelDetails() throws RemoteException { |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 466 | bindName(); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 467 | bindGroup(); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | private void bindName() { |
| 471 | final TextView channelName = findViewById(R.id.channel_name); |
| 472 | if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { |
| 473 | channelName.setVisibility(View.GONE); |
| 474 | } else { |
| 475 | channelName.setText(mSingleNotificationChannel.getName()); |
| 476 | } |
Julia Reynolds | ac98aea | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 477 | } |
| 478 | |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 479 | private void bindDelegate() { |
| 480 | TextView delegateView = findViewById(R.id.delegate_name); |
| 481 | TextView dividerView = findViewById(R.id.pkg_divider); |
| 482 | |
| 483 | CharSequence delegatePkg = null; |
| 484 | if (!TextUtils.equals(mPackageName, mDelegatePkg)) { |
| 485 | // this notification was posted by a delegate! |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 486 | delegateView.setVisibility(View.VISIBLE); |
| 487 | dividerView.setVisibility(View.VISIBLE); |
| 488 | } else { |
| 489 | delegateView.setVisibility(View.GONE); |
| 490 | dividerView.setVisibility(View.GONE); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | private void bindGroup() throws RemoteException { |
| 495 | // Set group information if this channel has an associated group. |
| 496 | CharSequence groupName = null; |
| 497 | if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) { |
| 498 | final NotificationChannelGroup notificationChannelGroup = |
| 499 | mINotificationManager.getNotificationChannelGroupForPackage( |
| 500 | mSingleNotificationChannel.getGroup(), mPackageName, mAppUid); |
| 501 | if (notificationChannelGroup != null) { |
| 502 | groupName = notificationChannelGroup.getName(); |
| 503 | } |
| 504 | } |
| 505 | TextView groupNameView = findViewById(R.id.group_name); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 506 | if (groupName != null) { |
| 507 | groupNameView.setText(groupName); |
| 508 | groupNameView.setVisibility(View.VISIBLE); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 509 | } else { |
| 510 | groupNameView.setVisibility(View.GONE); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 514 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 515 | @VisibleForTesting |
| 516 | void logBlockingHelperCounter(String counterTag) { |
| 517 | if (mIsForBlockingHelper) { |
| 518 | mMetricsLogger.count(counterTag, 1); |
| 519 | } |
| 520 | } |
| 521 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 522 | private void saveImportance() { |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 523 | if (!mIsNonblockable |
| 524 | || mExitReason != NotificationCounters.BLOCKING_HELPER_STOP_NOTIFICATIONS) { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 525 | if (mChosenImportance == null) { |
| 526 | mChosenImportance = mStartingChannelImportance; |
| 527 | } |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 528 | updateImportance(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 529 | } |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /** |
| 533 | * Commits the updated importance values on the background thread. |
| 534 | */ |
| 535 | private void updateImportance() { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 536 | if (mChosenImportance != null) { |
| 537 | mMetricsLogger.write(importanceChangeLogMaker()); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 538 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 539 | int newImportance = mChosenImportance; |
| 540 | if (mStartingChannelImportance != IMPORTANCE_UNSPECIFIED) { |
| 541 | if ((mWasShownHighPriority && mChosenImportance >= IMPORTANCE_DEFAULT) |
| 542 | || (!mWasShownHighPriority && mChosenImportance < IMPORTANCE_DEFAULT)) { |
| 543 | newImportance = mStartingChannelImportance; |
| 544 | } |
| 545 | } |
| 546 | |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 547 | Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER)); |
| 548 | bgHandler.post( |
| 549 | new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid, |
| 550 | mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null, |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 551 | mStartingChannelImportance, newImportance)); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 552 | mVisualStabilityManager.temporarilyAllowReordering(); |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 553 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 556 | private void applyAlertingBehavior(@AlertingBehavior int behavior, boolean userTriggered) { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 557 | if (userTriggered) { |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 558 | TransitionSet transition = new TransitionSet(); |
| 559 | transition.setOrdering(TransitionSet.ORDERING_TOGETHER); |
| 560 | transition.addTransition(new Fade(Fade.OUT)) |
| 561 | .addTransition(new ChangeBounds()) |
| 562 | .addTransition( |
| 563 | new Fade(Fade.IN) |
| 564 | .setStartDelay(150) |
| 565 | .setDuration(200) |
| 566 | .setInterpolator(FAST_OUT_SLOW_IN)); |
| 567 | transition.setDuration(350); |
| 568 | transition.setInterpolator(FAST_OUT_SLOW_IN); |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 569 | TransitionManager.beginDelayedTransition(this, transition); |
| 570 | } |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 571 | |
| 572 | View alert = findViewById(R.id.alert); |
| 573 | View silence = findViewById(R.id.silence); |
| 574 | |
| 575 | switch (behavior) { |
| 576 | case BEHAVIOR_ALERTING: |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 577 | mPriorityDescriptionView.setVisibility(VISIBLE); |
| 578 | mSilentDescriptionView.setVisibility(GONE); |
Julia Reynolds | daab21a | 2019-06-05 14:30:05 -0400 | [diff] [blame] | 579 | post(() -> { |
| 580 | alert.setSelected(true); |
| 581 | silence.setSelected(false); |
| 582 | }); |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 583 | break; |
| 584 | case BEHAVIOR_SILENT: |
Julia Reynolds | daab21a | 2019-06-05 14:30:05 -0400 | [diff] [blame] | 585 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 586 | mSilentDescriptionView.setVisibility(VISIBLE); |
| 587 | mPriorityDescriptionView.setVisibility(GONE); |
Julia Reynolds | daab21a | 2019-06-05 14:30:05 -0400 | [diff] [blame] | 588 | post(() -> { |
| 589 | alert.setSelected(false); |
| 590 | silence.setSelected(true); |
| 591 | }); |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 592 | break; |
| 593 | default: |
| 594 | throw new IllegalArgumentException("Unrecognized alerting behavior: " + behavior); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 595 | } |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 596 | |
| 597 | boolean isAChange = mWasShownHighPriority != (behavior == BEHAVIOR_ALERTING); |
| 598 | TextView done = findViewById(R.id.done); |
| 599 | done.setText(isAChange ? R.string.inline_ok_button : R.string.inline_done_button); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 600 | } |
| 601 | |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 602 | private void saveImportanceAndExitReason(@NotificationInfoAction int action) { |
| 603 | switch (action) { |
| 604 | case ACTION_UNDO: |
| 605 | mChosenImportance = mStartingChannelImportance; |
| 606 | break; |
| 607 | case ACTION_DELIVER_SILENTLY: |
| 608 | mExitReason = NotificationCounters.BLOCKING_HELPER_DELIVER_SILENTLY; |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 609 | mChosenImportance = mWasShownHighPriority |
| 610 | ? IMPORTANCE_LOW : mStartingChannelImportance; |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 611 | break; |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 612 | default: |
| 613 | throw new IllegalArgumentException(); |
| 614 | } |
| 615 | } |
| 616 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 617 | // only used for blocking helper |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 618 | private void swapContent(@NotificationInfoAction int action, boolean animate) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 619 | if (mExpandAnimation != null) { |
| 620 | mExpandAnimation.cancel(); |
| 621 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 622 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 623 | View blockingHelper = findViewById(R.id.blocking_helper); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 624 | ViewGroup confirmation = findViewById(R.id.confirmation); |
| 625 | TextView confirmationText = findViewById(R.id.confirmation_text); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 626 | |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 627 | saveImportanceAndExitReason(action); |
| 628 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 629 | switch (action) { |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 630 | case ACTION_UNDO: |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 631 | break; |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 632 | case ACTION_DELIVER_SILENTLY: |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 633 | confirmationText.setText(R.string.notification_channel_silenced); |
| 634 | break; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 635 | default: |
| 636 | throw new IllegalArgumentException(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 637 | } |
| 638 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 639 | boolean isUndo = action == ACTION_UNDO; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 640 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 641 | blockingHelper.setVisibility(isUndo ? VISIBLE : GONE); |
| 642 | findViewById(R.id.channel_info).setVisibility(isUndo ? VISIBLE : GONE); |
| 643 | findViewById(R.id.header).setVisibility(isUndo ? VISIBLE : GONE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 644 | confirmation.setVisibility(isUndo ? GONE : VISIBLE); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 645 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 646 | if (animate) { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 647 | ObjectAnimator promptAnim = ObjectAnimator.ofFloat(blockingHelper, View.ALPHA, |
| 648 | blockingHelper.getAlpha(), isUndo ? 1f : 0f); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 649 | promptAnim.setInterpolator(isUndo ? Interpolators.ALPHA_IN : Interpolators.ALPHA_OUT); |
| 650 | ObjectAnimator confirmAnim = ObjectAnimator.ofFloat(confirmation, View.ALPHA, |
| 651 | confirmation.getAlpha(), isUndo ? 0f : 1f); |
| 652 | confirmAnim.setInterpolator(isUndo ? Interpolators.ALPHA_OUT : Interpolators.ALPHA_IN); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 653 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 654 | mExpandAnimation = new AnimatorSet(); |
| 655 | mExpandAnimation.playTogether(promptAnim, confirmAnim); |
| 656 | mExpandAnimation.setDuration(150); |
| 657 | mExpandAnimation.addListener(new AnimatorListenerAdapter() { |
| 658 | boolean mCancelled = false; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 659 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 660 | @Override |
| 661 | public void onAnimationCancel(Animator animation) { |
| 662 | mCancelled = true; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 663 | } |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 664 | |
| 665 | @Override |
| 666 | public void onAnimationEnd(Animator animation) { |
| 667 | if (!mCancelled) { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 668 | blockingHelper.setVisibility(isUndo ? VISIBLE : GONE); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 669 | confirmation.setVisibility(isUndo ? GONE : VISIBLE); |
| 670 | } |
| 671 | } |
| 672 | }); |
| 673 | mExpandAnimation.start(); |
| 674 | } |
Rohan Shah | 142e2da | 2018-06-14 13:14:18 -0700 | [diff] [blame] | 675 | |
| 676 | // Since we're swapping/update the content, reset the timeout so the UI can't close |
| 677 | // immediately after the update. |
| 678 | if (mGutsContainer != null) { |
| 679 | mGutsContainer.resetFalsingCheck(); |
| 680 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 681 | } |
| 682 | |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 683 | @Override |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 684 | public void onFinishedClosing() { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 685 | if (mChosenImportance != null) { |
| 686 | mStartingChannelImportance = mChosenImportance; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 687 | } |
| 688 | mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED; |
| 689 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 690 | if (mIsForBlockingHelper) { |
| 691 | bindBlockingHelper(); |
| 692 | } else { |
| 693 | bindInlineControls(); |
| 694 | } |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 695 | |
| 696 | mMetricsLogger.write(notificationControlsLogMaker().setType(MetricsEvent.TYPE_CLOSE)); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | @Override |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 700 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 701 | super.onInitializeAccessibilityEvent(event); |
| 702 | if (mGutsContainer != null && |
| 703 | event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 704 | if (mGutsContainer.isExposed()) { |
| 705 | event.getText().add(mContext.getString( |
| 706 | R.string.notification_channel_controls_opened_accessibility, mAppName)); |
| 707 | } else { |
| 708 | event.getText().add(mContext.getString( |
| 709 | R.string.notification_channel_controls_closed_accessibility, mAppName)); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 714 | private Intent getAppSettingsIntent(PackageManager pm, String packageName, |
| 715 | NotificationChannel channel, int id, String tag) { |
| 716 | Intent intent = new Intent(Intent.ACTION_MAIN) |
| 717 | .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES) |
| 718 | .setPackage(packageName); |
| 719 | final List<ResolveInfo> resolveInfos = pm.queryIntentActivities( |
| 720 | intent, |
| 721 | PackageManager.MATCH_DEFAULT_ONLY |
| 722 | ); |
| 723 | if (resolveInfos == null || resolveInfos.size() == 0 || resolveInfos.get(0) == null) { |
| 724 | return null; |
| 725 | } |
| 726 | final ActivityInfo activityInfo = resolveInfos.get(0).activityInfo; |
| 727 | intent.setClassName(activityInfo.packageName, activityInfo.name); |
| 728 | if (channel != null) { |
| 729 | intent.putExtra(Notification.EXTRA_CHANNEL_ID, channel.getId()); |
| 730 | } |
| 731 | intent.putExtra(Notification.EXTRA_NOTIFICATION_ID, id); |
| 732 | intent.putExtra(Notification.EXTRA_NOTIFICATION_TAG, tag); |
| 733 | return intent; |
| 734 | } |
| 735 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 736 | /** |
| 737 | * Closes the controls and commits the updated importance values (indirectly). If this view is |
| 738 | * being used to show the blocking helper, this will immediately dismiss the blocking helper and |
| 739 | * commit the updated importance. |
| 740 | * |
| 741 | * <p><b>Note,</b> this will only get called once the view is dismissing. This means that the |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 742 | * user does not have the ability to undo the action anymore. See |
| 743 | * {@link #swapContent(boolean, boolean)} for where undo is handled. |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 744 | */ |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 745 | @VisibleForTesting |
Evan Laird | 7956fe8 | 2019-05-30 17:14:57 -0400 | [diff] [blame] | 746 | void closeControls(View v, boolean save) { |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 747 | int[] parentLoc = new int[2]; |
| 748 | int[] targetLoc = new int[2]; |
| 749 | mGutsContainer.getLocationOnScreen(parentLoc); |
| 750 | v.getLocationOnScreen(targetLoc); |
| 751 | final int centerX = v.getWidth() / 2; |
| 752 | final int centerY = v.getHeight() / 2; |
| 753 | final int x = targetLoc[0] - parentLoc[0] + centerX; |
| 754 | final int y = targetLoc[1] - parentLoc[1] + centerY; |
Evan Laird | 7956fe8 | 2019-05-30 17:14:57 -0400 | [diff] [blame] | 755 | mGutsContainer.closeControls(x, y, save, false /* force */); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 756 | } |
| 757 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 758 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 759 | public void setGutsParent(NotificationGuts guts) { |
| 760 | mGutsContainer = guts; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | @Override |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 764 | public boolean willBeRemoved() { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 765 | return false; |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | @Override |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 769 | public boolean shouldBeSaved() { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 770 | return mPressedApply; |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | @Override |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 774 | public View getContentView() { |
| 775 | return this; |
| 776 | } |
| 777 | |
| 778 | @Override |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 779 | public boolean handleCloseControls(boolean save, boolean force) { |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 780 | if (mPresentingChannelEditorDialog && mChannelEditorDialogController != null) { |
| 781 | mPresentingChannelEditorDialog = false; |
| 782 | // No need for the finish listener because we're closing |
| 783 | mChannelEditorDialogController.setOnFinishListener(null); |
| 784 | mChannelEditorDialogController.close(); |
| 785 | } |
| 786 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 787 | // Save regardless of the importance so we can lock the importance field if the user wants |
| 788 | // to keep getting notifications |
| 789 | if (save) { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 790 | saveImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 791 | } |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 792 | logBlockingHelperCounter(mExitReason); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 793 | return false; |
| 794 | } |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 795 | |
| 796 | @Override |
| 797 | public int getActualHeight() { |
| 798 | return getHeight(); |
| 799 | } |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 800 | |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 801 | @VisibleForTesting |
| 802 | public boolean isAnimating() { |
| 803 | return mExpandAnimation != null && mExpandAnimation.isRunning(); |
| 804 | } |
| 805 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 806 | /** |
| 807 | * Runnable to either update the given channel (with a new importance value) or, if no channel |
| 808 | * is provided, update notifications enabled state for the package. |
| 809 | */ |
| 810 | private static class UpdateImportanceRunnable implements Runnable { |
| 811 | private final INotificationManager mINotificationManager; |
| 812 | private final String mPackageName; |
| 813 | private final int mAppUid; |
| 814 | private final @Nullable NotificationChannel mChannelToUpdate; |
| 815 | private final int mCurrentImportance; |
| 816 | private final int mNewImportance; |
| 817 | |
| 818 | |
| 819 | public UpdateImportanceRunnable(INotificationManager notificationManager, |
| 820 | String packageName, int appUid, @Nullable NotificationChannel channelToUpdate, |
| 821 | int currentImportance, int newImportance) { |
| 822 | mINotificationManager = notificationManager; |
| 823 | mPackageName = packageName; |
| 824 | mAppUid = appUid; |
| 825 | mChannelToUpdate = channelToUpdate; |
| 826 | mCurrentImportance = currentImportance; |
| 827 | mNewImportance = newImportance; |
| 828 | } |
| 829 | |
| 830 | @Override |
| 831 | public void run() { |
| 832 | try { |
| 833 | if (mChannelToUpdate != null) { |
| 834 | mChannelToUpdate.setImportance(mNewImportance); |
| 835 | mChannelToUpdate.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
| 836 | mINotificationManager.updateNotificationChannelForPackage( |
| 837 | mPackageName, mAppUid, mChannelToUpdate); |
| 838 | } else { |
| 839 | // For notifications with more than one channel, update notification enabled |
| 840 | // state. If the importance was lowered, we disable notifications. |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 841 | mINotificationManager.setNotificationsEnabledWithImportanceLockForPackage( |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 842 | mPackageName, mAppUid, mNewImportance >= mCurrentImportance); |
| 843 | } |
| 844 | } catch (RemoteException e) { |
| 845 | Log.e(TAG, "Unable to update notification importance", e); |
| 846 | } |
| 847 | } |
| 848 | } |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 849 | |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 850 | /** |
| 851 | * Returns a LogMaker with all available notification information. |
| 852 | * Caller should set category, type, and maybe subtype, before passing it to mMetricsLogger. |
| 853 | * @return LogMaker |
| 854 | */ |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 855 | private LogMaker getLogMaker() { |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 856 | // The constructor requires a category, so also do it in the other branch for consistency. |
| 857 | return mSbn == null ? new LogMaker(MetricsEvent.NOTIFICATION_BLOCKING_HELPER) |
| 858 | : mSbn.getLogMaker().setCategory(MetricsEvent.NOTIFICATION_BLOCKING_HELPER); |
| 859 | } |
| 860 | |
| 861 | /** |
| 862 | * Returns an initialized LogMaker for logging importance changes. |
| 863 | * The caller may override the type before passing it to mMetricsLogger. |
| 864 | * @return LogMaker |
| 865 | */ |
| 866 | private LogMaker importanceChangeLogMaker() { |
| 867 | Integer chosenImportance = |
| 868 | mChosenImportance != null ? mChosenImportance : mStartingChannelImportance; |
| 869 | return getLogMaker().setCategory(MetricsEvent.ACTION_SAVE_IMPORTANCE) |
| 870 | .setType(MetricsEvent.TYPE_ACTION) |
| 871 | .setSubtype(chosenImportance - mStartingChannelImportance); |
| 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Returns an initialized LogMaker for logging open/close of the info display. |
| 876 | * The caller may override the type before passing it to mMetricsLogger. |
| 877 | * @return LogMaker |
| 878 | */ |
| 879 | private LogMaker notificationControlsLogMaker() { |
| 880 | return getLogMaker().setCategory(MetricsEvent.ACTION_NOTE_CONTROLS) |
| 881 | .setType(MetricsEvent.TYPE_OPEN) |
| 882 | .setSubtype(mIsForBlockingHelper ? MetricsEvent.BLOCKING_HELPER_DISPLAY |
| 883 | : MetricsEvent.BLOCKING_HELPER_UNKNOWN); |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 884 | } |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 885 | |
| 886 | @Retention(SOURCE) |
| 887 | @IntDef({BEHAVIOR_ALERTING, BEHAVIOR_SILENT}) |
| 888 | private @interface AlertingBehavior {} |
| 889 | private static final int BEHAVIOR_ALERTING = 0; |
| 890 | private static final int BEHAVIOR_SILENT = 1; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 891 | } |