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