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