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