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