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