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