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