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