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