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; |
| 20 | import static android.app.NotificationManager.IMPORTANCE_HIGH; |
| 21 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 22 | import static android.app.NotificationManager.IMPORTANCE_MIN; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 23 | import static android.app.NotificationManager.IMPORTANCE_NONE; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 24 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 25 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 26 | import android.animation.Animator; |
| 27 | import android.animation.AnimatorListenerAdapter; |
| 28 | import android.animation.AnimatorSet; |
| 29 | import android.animation.ObjectAnimator; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 30 | import android.annotation.IntDef; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 31 | import android.annotation.Nullable; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 32 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 33 | import android.app.Notification; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 34 | import android.app.NotificationChannel; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 35 | import android.app.NotificationChannelGroup; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 36 | import android.content.Context; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 37 | import android.content.Intent; |
| 38 | import android.content.pm.ActivityInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 39 | import android.content.pm.ApplicationInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 40 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 41 | import android.content.pm.ResolveInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 42 | import android.graphics.drawable.Drawable; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 43 | import android.os.Handler; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 44 | import android.os.RemoteException; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 45 | import android.service.notification.StatusBarNotification; |
| 46 | import android.text.TextUtils; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 47 | import android.util.AttributeSet; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 48 | import android.util.Log; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 49 | import android.view.View; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 50 | import android.view.ViewGroup; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 51 | import android.view.accessibility.AccessibilityEvent; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 52 | import android.widget.ImageView; |
| 53 | import android.widget.LinearLayout; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 54 | import android.widget.TextView; |
| 55 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 56 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 57 | import com.android.internal.logging.MetricsLogger; |
| 58 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 59 | import com.android.systemui.Dependency; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 60 | import com.android.systemui.Interpolators; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 61 | import com.android.systemui.R; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.logging.NotificationCounters; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 64 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 65 | import java.util.List; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 66 | |
| 67 | /** |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 68 | * The guts of a notification revealed when performing a long press. This also houses the blocking |
| 69 | * helper affordance that allows a user to keep/stop notifications after swiping one away. |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 70 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 71 | public class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 72 | private static final String TAG = "InfoGuts"; |
| 73 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 74 | @IntDef(prefix = { "ACTION_" }, value = { |
| 75 | ACTION_NONE, |
| 76 | ACTION_UNDO, |
| 77 | ACTION_TOGGLE_SILENT, |
| 78 | ACTION_BLOCK, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 79 | }) |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 80 | public @interface NotificationInfoAction { |
| 81 | } |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 82 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 83 | public static final int ACTION_NONE = 0; |
| 84 | public static final int ACTION_UNDO = 1; |
| 85 | public static final int ACTION_TOGGLE_SILENT = 2; |
| 86 | public static final int ACTION_BLOCK = 3; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 87 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 88 | private INotificationManager mINotificationManager; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 89 | private PackageManager mPm; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 90 | private MetricsLogger mMetricsLogger; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 91 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 92 | private String mPackageName; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 93 | private String mAppName; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 94 | private int mAppUid; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 95 | private int mNumUniqueChannelsInRow; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 96 | private NotificationChannel mSingleNotificationChannel; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 97 | private int mStartingChannelImportance; |
| 98 | private int mStartingChannelOrNotificationImportance; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 99 | private int mChosenImportance; |
| 100 | private boolean mIsSingleDefaultChannel; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 101 | private boolean mIsNonblockable; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 102 | private StatusBarNotification mSbn; |
| 103 | private AnimatorSet mExpandAnimation; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 104 | private boolean mIsForeground; |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 105 | private boolean mIsDeviceProvisioned; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 106 | private boolean mIsNoisy; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 107 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 108 | private CheckSaveListener mCheckSaveListener; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 109 | private OnSettingsClickListener mOnSettingsClickListener; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 110 | private OnAppSettingsClickListener mAppSettingsClickListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 111 | private NotificationGuts mGutsContainer; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 112 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 113 | /** Whether this view is being shown as part of the blocking helper. */ |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 114 | private boolean mIsForBlockingHelper; |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 115 | private boolean mNegativeUserSentiment; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 116 | |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 117 | /** |
| 118 | * String that describes how the user exit or quit out of this view, also used as a counter tag. |
| 119 | */ |
| 120 | private String mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 121 | |
| 122 | private OnClickListener mOnKeepShowing = v -> { |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 123 | mExitReason = NotificationCounters.BLOCKING_HELPER_KEEP_SHOWING; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 124 | closeControls(v); |
| 125 | }; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 126 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 127 | private OnClickListener mOnToggleSilent = v -> { |
| 128 | Runnable saveImportance = () -> { |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 129 | swapContent(ACTION_TOGGLE_SILENT, true /* animate */); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 130 | }; |
| 131 | if (mCheckSaveListener != null) { |
| 132 | mCheckSaveListener.checkSave(saveImportance, mSbn); |
| 133 | } else { |
| 134 | saveImportance.run(); |
| 135 | } |
| 136 | }; |
| 137 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 138 | private OnClickListener mOnStopOrMinimizeNotifications = v -> { |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 139 | Runnable saveImportance = () -> { |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 140 | swapContent(ACTION_BLOCK, true /* animate */); |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 141 | }; |
| 142 | if (mCheckSaveListener != null) { |
| 143 | mCheckSaveListener.checkSave(saveImportance, mSbn); |
| 144 | } else { |
| 145 | saveImportance.run(); |
| 146 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | private OnClickListener mOnUndo = v -> { |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 150 | // 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] | 151 | mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 152 | logBlockingHelperCounter(NotificationCounters.BLOCKING_HELPER_UNDO); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 153 | swapContent(ACTION_UNDO, true /* animate */); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 154 | }; |
| 155 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 156 | public NotificationInfo(Context context, AttributeSet attrs) { |
| 157 | super(context, attrs); |
| 158 | } |
| 159 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 160 | // Specify a CheckSaveListener to override when/if the user's changes are committed. |
| 161 | public interface CheckSaveListener { |
| 162 | // Invoked when importance has changed and the NotificationInfo wants to try to save it. |
| 163 | // Listener should run saveImportance unless the change should be canceled. |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 164 | void checkSave(Runnable saveImportance, StatusBarNotification sbn); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 165 | } |
| 166 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 167 | public interface OnSettingsClickListener { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 168 | void onClick(View v, NotificationChannel channel, int appUid); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 171 | public interface OnAppSettingsClickListener { |
| 172 | void onClick(View v, Intent intent); |
| 173 | } |
| 174 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 175 | @VisibleForTesting |
| 176 | void bindNotification( |
| 177 | final PackageManager pm, |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 178 | final INotificationManager iNotificationManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 179 | final String pkg, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 180 | final NotificationChannel notificationChannel, |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 181 | final int numUniqueChannelsInRow, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 182 | final StatusBarNotification sbn, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 183 | final CheckSaveListener checkSaveListener, |
| 184 | final OnSettingsClickListener onSettingsClick, |
| 185 | final OnAppSettingsClickListener onAppSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 186 | boolean isDeviceProvisioned, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 187 | boolean isNonblockable, |
| 188 | boolean isNoisy, |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 189 | int importance, |
| 190 | @NotificationInfoAction int action) |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 191 | throws RemoteException { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 192 | bindNotification(pm, iNotificationManager, pkg, notificationChannel, |
| 193 | numUniqueChannelsInRow, sbn, checkSaveListener, onSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 194 | onAppSettingsClick, isDeviceProvisioned, isNonblockable, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 195 | false /* isBlockingHelper */, false /* isUserSentimentNegative */, isNoisy, |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 196 | importance, action); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 199 | public void bindNotification( |
| 200 | PackageManager pm, |
| 201 | INotificationManager iNotificationManager, |
| 202 | String pkg, |
| 203 | NotificationChannel notificationChannel, |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 204 | int numUniqueChannelsInRow, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 205 | StatusBarNotification sbn, |
| 206 | CheckSaveListener checkSaveListener, |
| 207 | OnSettingsClickListener onSettingsClick, |
| 208 | OnAppSettingsClickListener onAppSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 209 | boolean isDeviceProvisioned, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 210 | boolean isNonblockable, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 211 | boolean isForBlockingHelper, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 212 | boolean isUserSentimentNegative, |
| 213 | boolean isNoisy, |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 214 | int importance, |
| 215 | @NotificationInfoAction int action) |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 216 | throws RemoteException { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 217 | mINotificationManager = iNotificationManager; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 218 | mMetricsLogger = Dependency.get(MetricsLogger.class); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 219 | mPackageName = pkg; |
| 220 | mNumUniqueChannelsInRow = numUniqueChannelsInRow; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 221 | mSbn = sbn; |
| 222 | mPm = pm; |
| 223 | mAppSettingsClickListener = onAppSettingsClick; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 224 | mAppName = mPackageName; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 225 | mCheckSaveListener = checkSaveListener; |
| 226 | mOnSettingsClickListener = onSettingsClick; |
| 227 | mSingleNotificationChannel = notificationChannel; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 228 | int channelImportance = mSingleNotificationChannel.getImportance(); |
| 229 | mStartingChannelImportance = mChosenImportance = channelImportance; |
| 230 | mStartingChannelOrNotificationImportance = |
| 231 | channelImportance == IMPORTANCE_UNSPECIFIED ? importance : channelImportance; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 232 | mNegativeUserSentiment = isUserSentimentNegative; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 233 | mIsNonblockable = isNonblockable; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 234 | mIsForeground = |
| 235 | (mSbn.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 236 | mIsForBlockingHelper = isForBlockingHelper; |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 237 | mAppUid = mSbn.getUid(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 238 | mIsDeviceProvisioned = isDeviceProvisioned; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 239 | mIsNoisy = isNoisy; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 240 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 241 | int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 242 | pkg, mAppUid, false /* includeDeleted */); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 243 | if (mNumUniqueChannelsInRow == 0) { |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 244 | throw new IllegalArgumentException("bindNotification requires at least one channel"); |
| 245 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 246 | // 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] | 247 | mIsSingleDefaultChannel = mNumUniqueChannelsInRow == 1 |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 248 | && mSingleNotificationChannel.getId().equals( |
| 249 | NotificationChannel.DEFAULT_CHANNEL_ID) |
| 250 | && numTotalChannels == 1; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 251 | } |
| 252 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 253 | bindHeader(); |
| 254 | bindPrompt(); |
| 255 | bindButtons(); |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 256 | |
| 257 | if (action != ACTION_NONE) { |
| 258 | swapContent(action, false /* don't animate */); |
| 259 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | private void bindHeader() throws RemoteException { |
| 263 | // Package name |
| 264 | Drawable pkgicon = null; |
| 265 | ApplicationInfo info; |
| 266 | try { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 267 | info = mPm.getApplicationInfo( |
| 268 | mPackageName, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 269 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 270 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 271 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 272 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 273 | if (info != null) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 274 | mAppName = String.valueOf(mPm.getApplicationLabel(info)); |
| 275 | pkgicon = mPm.getApplicationIcon(info); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 276 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 277 | } catch (PackageManager.NameNotFoundException e) { |
| 278 | // app is gone, just show package name and generic icon |
| 279 | pkgicon = mPm.getDefaultActivityIcon(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 280 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 281 | ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon); |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 282 | ((TextView) findViewById(R.id.pkgname)).setText(mAppName); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 283 | |
Julia Reynolds | ac98aea | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 284 | // Set group information if this channel has an associated group. |
| 285 | CharSequence groupName = null; |
| 286 | if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) { |
| 287 | final NotificationChannelGroup notificationChannelGroup = |
| 288 | mINotificationManager.getNotificationChannelGroupForPackage( |
| 289 | mSingleNotificationChannel.getGroup(), mPackageName, mAppUid); |
| 290 | if (notificationChannelGroup != null) { |
| 291 | groupName = notificationChannelGroup.getName(); |
| 292 | } |
| 293 | } |
| 294 | TextView groupNameView = findViewById(R.id.group_name); |
| 295 | TextView groupDividerView = findViewById(R.id.pkg_group_divider); |
| 296 | if (groupName != null) { |
| 297 | groupNameView.setText(groupName); |
| 298 | groupNameView.setVisibility(View.VISIBLE); |
| 299 | groupDividerView.setVisibility(View.VISIBLE); |
| 300 | } else { |
| 301 | groupNameView.setVisibility(View.GONE); |
| 302 | groupDividerView.setVisibility(View.GONE); |
| 303 | } |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 304 | |
| 305 | // Settings button. |
| 306 | final View settingsButton = findViewById(R.id.info); |
| 307 | if (mAppUid >= 0 && mOnSettingsClickListener != null && mIsDeviceProvisioned) { |
| 308 | settingsButton.setVisibility(View.VISIBLE); |
| 309 | final int appUidF = mAppUid; |
| 310 | settingsButton.setOnClickListener( |
| 311 | (View view) -> { |
| 312 | logBlockingHelperCounter( |
| 313 | NotificationCounters.BLOCKING_HELPER_NOTIF_SETTINGS); |
| 314 | mOnSettingsClickListener.onClick(view, |
| 315 | mNumUniqueChannelsInRow > 1 ? null : mSingleNotificationChannel, |
| 316 | appUidF); |
| 317 | }); |
| 318 | } else { |
| 319 | settingsButton.setVisibility(View.GONE); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | private void bindPrompt() { |
| 324 | final TextView blockPrompt = findViewById(R.id.block_prompt); |
| 325 | bindName(); |
| 326 | if (mIsNonblockable) { |
| 327 | blockPrompt.setText(R.string.notification_unblockable_desc); |
| 328 | } else { |
| 329 | if (mNegativeUserSentiment) { |
| 330 | blockPrompt.setText(R.string.inline_blocking_helper); |
| 331 | } else if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { |
| 332 | blockPrompt.setText(R.string.inline_keep_showing_app); |
| 333 | } else { |
| 334 | blockPrompt.setText(R.string.inline_keep_showing); |
| 335 | } |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | private void bindName() { |
| 340 | final TextView channelName = findViewById(R.id.channel_name); |
| 341 | if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { |
| 342 | channelName.setVisibility(View.GONE); |
| 343 | } else { |
| 344 | channelName.setText(mSingleNotificationChannel.getName()); |
| 345 | } |
Julia Reynolds | ac98aea | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 348 | @VisibleForTesting |
| 349 | void logBlockingHelperCounter(String counterTag) { |
| 350 | if (mIsForBlockingHelper) { |
| 351 | mMetricsLogger.count(counterTag, 1); |
| 352 | } |
| 353 | } |
| 354 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 355 | private boolean hasImportanceChanged() { |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 356 | return mSingleNotificationChannel != null |
| 357 | && mStartingChannelImportance != mChosenImportance; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 358 | } |
| 359 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 360 | private void saveImportance() { |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 361 | if (!mIsNonblockable |
| 362 | || mExitReason != NotificationCounters.BLOCKING_HELPER_STOP_NOTIFICATIONS) { |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 363 | updateImportance(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 364 | } |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Commits the updated importance values on the background thread. |
| 369 | */ |
| 370 | private void updateImportance() { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 371 | MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 372 | mChosenImportance - mStartingChannelImportance); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 373 | |
| 374 | Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER)); |
| 375 | bgHandler.post(new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid, |
| 376 | mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 377 | mStartingChannelImportance, mChosenImportance)); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 380 | private void bindButtons() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 381 | // Set up stay-in-notification actions |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 382 | View block = findViewById(R.id.block); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 383 | TextView keep = findViewById(R.id.keep); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 384 | TextView silent = findViewById(R.id.toggle_silent); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 385 | View minimize = findViewById(R.id.minimize); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 386 | |
| 387 | findViewById(R.id.undo).setOnClickListener(mOnUndo); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 388 | block.setOnClickListener(mOnStopOrMinimizeNotifications); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 389 | keep.setOnClickListener(mOnKeepShowing); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 390 | silent.setOnClickListener(mOnToggleSilent); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 391 | minimize.setOnClickListener(mOnStopOrMinimizeNotifications); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 392 | |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 393 | if (mIsNonblockable) { |
Rohan Shah | 53529aa | 2018-04-12 00:14:50 -0400 | [diff] [blame] | 394 | keep.setText(android.R.string.ok); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 395 | block.setVisibility(GONE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 396 | silent.setVisibility(GONE); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 397 | minimize.setVisibility(GONE); |
| 398 | } else if (mIsForeground) { |
| 399 | block.setVisibility(GONE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 400 | silent.setVisibility(GONE); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 401 | minimize.setVisibility(VISIBLE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 402 | } else { |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 403 | block.setVisibility(VISIBLE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 404 | boolean showToggleSilent = mIsNoisy |
| 405 | && NotificationUtils.useNewInterruptionModel(mContext); |
| 406 | silent.setVisibility(showToggleSilent ? VISIBLE : GONE); |
| 407 | boolean isCurrentlyAlerting = |
| 408 | mStartingChannelOrNotificationImportance >= IMPORTANCE_DEFAULT; |
| 409 | silent.setText(isCurrentlyAlerting |
| 410 | ? R.string.inline_silent_button_silent |
| 411 | : R.string.inline_silent_button_alert); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 412 | minimize.setVisibility(GONE); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 413 | } |
| 414 | |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 415 | // Set up app settings link (i.e. Customize) |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 416 | TextView settingsLinkView = findViewById(R.id.app_settings); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 417 | Intent settingsIntent = getAppSettingsIntent(mPm, mPackageName, mSingleNotificationChannel, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 418 | mSbn.getId(), mSbn.getTag()); |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 419 | if (!mIsForBlockingHelper |
| 420 | && settingsIntent != null |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 421 | && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) { |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 422 | settingsLinkView.setVisibility(VISIBLE); |
Rohan Shah | 7c6b37a | 2018-03-30 21:07:45 +0000 | [diff] [blame] | 423 | settingsLinkView.setText(mContext.getString(R.string.notification_app_settings)); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 424 | settingsLinkView.setOnClickListener((View view) -> { |
| 425 | mAppSettingsClickListener.onClick(view, settingsIntent); |
| 426 | }); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 427 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 428 | settingsLinkView.setVisibility(View.GONE); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 432 | private void swapContent(@NotificationInfoAction int action, boolean animate) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 433 | if (mExpandAnimation != null) { |
| 434 | mExpandAnimation.cancel(); |
| 435 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 436 | |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 437 | View prompt = findViewById(R.id.prompt); |
| 438 | ViewGroup confirmation = findViewById(R.id.confirmation); |
| 439 | TextView confirmationText = findViewById(R.id.confirmation_text); |
| 440 | View header = findViewById(R.id.header); |
| 441 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 442 | switch (action) { |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 443 | case ACTION_UNDO: |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 444 | mChosenImportance = mStartingChannelImportance; |
| 445 | break; |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 446 | case ACTION_TOGGLE_SILENT: |
| 447 | mExitReason = NotificationCounters.BLOCKING_HELPER_TOGGLE_SILENT; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 448 | if (mStartingChannelOrNotificationImportance >= IMPORTANCE_DEFAULT) { |
| 449 | mChosenImportance = IMPORTANCE_LOW; |
| 450 | confirmationText.setText(R.string.notification_channel_silenced); |
| 451 | } else { |
| 452 | mChosenImportance = IMPORTANCE_HIGH; |
| 453 | confirmationText.setText(R.string.notification_channel_unsilenced); |
| 454 | } |
| 455 | break; |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 456 | case ACTION_BLOCK: |
| 457 | mExitReason = NotificationCounters.BLOCKING_HELPER_STOP_NOTIFICATIONS; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 458 | if (mIsForeground) { |
| 459 | mChosenImportance = IMPORTANCE_MIN; |
| 460 | confirmationText.setText(R.string.notification_channel_minimized); |
| 461 | } else { |
| 462 | mChosenImportance = IMPORTANCE_NONE; |
| 463 | confirmationText.setText(R.string.notification_channel_disabled); |
| 464 | } |
| 465 | break; |
| 466 | default: |
| 467 | throw new IllegalArgumentException(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 468 | } |
| 469 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 470 | boolean isUndo = action == ACTION_UNDO; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 471 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 472 | prompt.setVisibility(isUndo ? VISIBLE : GONE); |
| 473 | confirmation.setVisibility(isUndo ? GONE : VISIBLE); |
| 474 | header.setVisibility(isUndo ? VISIBLE : GONE); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 475 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 476 | if (animate) { |
| 477 | ObjectAnimator promptAnim = ObjectAnimator.ofFloat(prompt, View.ALPHA, |
| 478 | prompt.getAlpha(), isUndo ? 1f : 0f); |
| 479 | promptAnim.setInterpolator(isUndo ? Interpolators.ALPHA_IN : Interpolators.ALPHA_OUT); |
| 480 | ObjectAnimator confirmAnim = ObjectAnimator.ofFloat(confirmation, View.ALPHA, |
| 481 | confirmation.getAlpha(), isUndo ? 0f : 1f); |
| 482 | confirmAnim.setInterpolator(isUndo ? Interpolators.ALPHA_OUT : Interpolators.ALPHA_IN); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 483 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 484 | mExpandAnimation = new AnimatorSet(); |
| 485 | mExpandAnimation.playTogether(promptAnim, confirmAnim); |
| 486 | mExpandAnimation.setDuration(150); |
| 487 | mExpandAnimation.addListener(new AnimatorListenerAdapter() { |
| 488 | boolean mCancelled = false; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 489 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 490 | @Override |
| 491 | public void onAnimationCancel(Animator animation) { |
| 492 | mCancelled = true; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 493 | } |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame^] | 494 | |
| 495 | @Override |
| 496 | public void onAnimationEnd(Animator animation) { |
| 497 | if (!mCancelled) { |
| 498 | prompt.setVisibility(isUndo ? VISIBLE : GONE); |
| 499 | confirmation.setVisibility(isUndo ? GONE : VISIBLE); |
| 500 | } |
| 501 | } |
| 502 | }); |
| 503 | mExpandAnimation.start(); |
| 504 | } |
Rohan Shah | 142e2da | 2018-06-14 13:14:18 -0700 | [diff] [blame] | 505 | |
| 506 | // Since we're swapping/update the content, reset the timeout so the UI can't close |
| 507 | // immediately after the update. |
| 508 | if (mGutsContainer != null) { |
| 509 | mGutsContainer.resetFalsingCheck(); |
| 510 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 513 | @Override |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 514 | public void onFinishedClosing() { |
| 515 | mStartingChannelImportance = mChosenImportance; |
| 516 | if (mChosenImportance != IMPORTANCE_UNSPECIFIED) { |
| 517 | mStartingChannelOrNotificationImportance = mChosenImportance; |
| 518 | } |
| 519 | mExitReason = NotificationCounters.BLOCKING_HELPER_DISMISSED; |
| 520 | |
| 521 | View prompt = findViewById(R.id.prompt); |
| 522 | ViewGroup confirmation = findViewById(R.id.confirmation); |
| 523 | View header = findViewById(R.id.header); |
| 524 | prompt.setVisibility(VISIBLE); |
| 525 | prompt.setAlpha(1f); |
| 526 | confirmation.setVisibility(GONE); |
| 527 | confirmation.setAlpha(1f); |
| 528 | header.setVisibility(VISIBLE); |
| 529 | header.setAlpha(1f); |
| 530 | } |
| 531 | |
| 532 | @Override |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 533 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 534 | super.onInitializeAccessibilityEvent(event); |
| 535 | if (mGutsContainer != null && |
| 536 | event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 537 | if (mGutsContainer.isExposed()) { |
| 538 | event.getText().add(mContext.getString( |
| 539 | R.string.notification_channel_controls_opened_accessibility, mAppName)); |
| 540 | } else { |
| 541 | event.getText().add(mContext.getString( |
| 542 | R.string.notification_channel_controls_closed_accessibility, mAppName)); |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 547 | private Intent getAppSettingsIntent(PackageManager pm, String packageName, |
| 548 | NotificationChannel channel, int id, String tag) { |
| 549 | Intent intent = new Intent(Intent.ACTION_MAIN) |
| 550 | .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES) |
| 551 | .setPackage(packageName); |
| 552 | final List<ResolveInfo> resolveInfos = pm.queryIntentActivities( |
| 553 | intent, |
| 554 | PackageManager.MATCH_DEFAULT_ONLY |
| 555 | ); |
| 556 | if (resolveInfos == null || resolveInfos.size() == 0 || resolveInfos.get(0) == null) { |
| 557 | return null; |
| 558 | } |
| 559 | final ActivityInfo activityInfo = resolveInfos.get(0).activityInfo; |
| 560 | intent.setClassName(activityInfo.packageName, activityInfo.name); |
| 561 | if (channel != null) { |
| 562 | intent.putExtra(Notification.EXTRA_CHANNEL_ID, channel.getId()); |
| 563 | } |
| 564 | intent.putExtra(Notification.EXTRA_NOTIFICATION_ID, id); |
| 565 | intent.putExtra(Notification.EXTRA_NOTIFICATION_TAG, tag); |
| 566 | return intent; |
| 567 | } |
| 568 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 569 | /** |
| 570 | * Closes the controls and commits the updated importance values (indirectly). If this view is |
| 571 | * being used to show the blocking helper, this will immediately dismiss the blocking helper and |
| 572 | * commit the updated importance. |
| 573 | * |
| 574 | * <p><b>Note,</b> this will only get called once the view is dismissing. This means that the |
| 575 | * user does not have the ability to undo the action anymore. See {@link #swapContent(boolean)} |
| 576 | * for where undo is handled. |
| 577 | */ |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 578 | @VisibleForTesting |
| 579 | void closeControls(View v) { |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 580 | int[] parentLoc = new int[2]; |
| 581 | int[] targetLoc = new int[2]; |
| 582 | mGutsContainer.getLocationOnScreen(parentLoc); |
| 583 | v.getLocationOnScreen(targetLoc); |
| 584 | final int centerX = v.getWidth() / 2; |
| 585 | final int centerY = v.getHeight() / 2; |
| 586 | final int x = targetLoc[0] - parentLoc[0] + centerX; |
| 587 | final int y = targetLoc[1] - parentLoc[1] + centerY; |
| 588 | mGutsContainer.closeControls(x, y, true /* save */, false /* force */); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 589 | } |
| 590 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 591 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 592 | public void setGutsParent(NotificationGuts guts) { |
| 593 | mGutsContainer = guts; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | @Override |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 597 | public boolean willBeRemoved() { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 598 | return hasImportanceChanged(); |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | @Override |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 602 | public boolean shouldBeSaved() { |
| 603 | return hasImportanceChanged(); |
| 604 | } |
| 605 | |
| 606 | @Override |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 607 | public View getContentView() { |
| 608 | return this; |
| 609 | } |
| 610 | |
| 611 | @Override |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 612 | public boolean handleCloseControls(boolean save, boolean force) { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 613 | // Save regardless of the importance so we can lock the importance field if the user wants |
| 614 | // to keep getting notifications |
| 615 | if (save) { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 616 | saveImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 617 | } |
Rohan Shah | dd588c7 | 2018-05-09 20:32:15 -0700 | [diff] [blame] | 618 | logBlockingHelperCounter(mExitReason); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 619 | return false; |
| 620 | } |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 621 | |
| 622 | @Override |
| 623 | public int getActualHeight() { |
| 624 | return getHeight(); |
| 625 | } |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 626 | |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 627 | @VisibleForTesting |
| 628 | public boolean isAnimating() { |
| 629 | return mExpandAnimation != null && mExpandAnimation.isRunning(); |
| 630 | } |
| 631 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 632 | /** |
| 633 | * Runnable to either update the given channel (with a new importance value) or, if no channel |
| 634 | * is provided, update notifications enabled state for the package. |
| 635 | */ |
| 636 | private static class UpdateImportanceRunnable implements Runnable { |
| 637 | private final INotificationManager mINotificationManager; |
| 638 | private final String mPackageName; |
| 639 | private final int mAppUid; |
| 640 | private final @Nullable NotificationChannel mChannelToUpdate; |
| 641 | private final int mCurrentImportance; |
| 642 | private final int mNewImportance; |
| 643 | |
| 644 | |
| 645 | public UpdateImportanceRunnable(INotificationManager notificationManager, |
| 646 | String packageName, int appUid, @Nullable NotificationChannel channelToUpdate, |
| 647 | int currentImportance, int newImportance) { |
| 648 | mINotificationManager = notificationManager; |
| 649 | mPackageName = packageName; |
| 650 | mAppUid = appUid; |
| 651 | mChannelToUpdate = channelToUpdate; |
| 652 | mCurrentImportance = currentImportance; |
| 653 | mNewImportance = newImportance; |
| 654 | } |
| 655 | |
| 656 | @Override |
| 657 | public void run() { |
| 658 | try { |
| 659 | if (mChannelToUpdate != null) { |
| 660 | mChannelToUpdate.setImportance(mNewImportance); |
| 661 | mChannelToUpdate.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
| 662 | mINotificationManager.updateNotificationChannelForPackage( |
| 663 | mPackageName, mAppUid, mChannelToUpdate); |
| 664 | } else { |
| 665 | // For notifications with more than one channel, update notification enabled |
| 666 | // state. If the importance was lowered, we disable notifications. |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 667 | mINotificationManager.setNotificationsEnabledWithImportanceLockForPackage( |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 668 | mPackageName, mAppUid, mNewImportance >= mCurrentImportance); |
| 669 | } |
| 670 | } catch (RemoteException e) { |
| 671 | Log.e(TAG, "Unable to update notification importance", e); |
| 672 | } |
| 673 | } |
| 674 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 675 | } |