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; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 26 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 27 | import android.app.Notification; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 28 | import android.app.NotificationChannel; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 29 | import android.app.NotificationChannelGroup; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 30 | import android.content.Context; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 31 | import android.content.Intent; |
| 32 | import android.content.pm.ActivityInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 33 | import android.content.pm.ApplicationInfo; |
| 34 | import android.content.pm.PackageInfo; |
| 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; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 38 | import android.os.RemoteException; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 39 | import android.service.notification.StatusBarNotification; |
| 40 | import android.text.TextUtils; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 41 | import android.util.AttributeSet; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 42 | import android.view.View; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 43 | import android.view.ViewGroup; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 44 | import android.view.accessibility.AccessibilityEvent; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 45 | import android.widget.ImageView; |
| 46 | import android.widget.LinearLayout; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 47 | import android.widget.TextView; |
| 48 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 49 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 50 | import com.android.internal.logging.MetricsLogger; |
| 51 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 52 | import com.android.settingslib.Utils; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 53 | import com.android.systemui.Dependency; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 54 | import com.android.systemui.Interpolators; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 55 | import com.android.systemui.R; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 56 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 57 | import java.util.List; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 58 | import java.util.Set; |
| 59 | |
| 60 | /** |
| 61 | * The guts of a notification revealed when performing a long press. |
| 62 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 63 | public class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 64 | private static final String TAG = "InfoGuts"; |
| 65 | |
| 66 | private INotificationManager mINotificationManager; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 67 | private PackageManager mPm; |
| 68 | |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 69 | private String mPkg; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 70 | private String mAppName; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 71 | private int mAppUid; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 72 | private int mNumNotificationChannels; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 73 | private NotificationChannel mSingleNotificationChannel; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 74 | private int mStartingUserImportance; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 75 | private int mChosenImportance; |
| 76 | private boolean mIsSingleDefaultChannel; |
| 77 | private boolean mNonblockable; |
| 78 | private StatusBarNotification mSbn; |
| 79 | private AnimatorSet mExpandAnimation; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 80 | private boolean mIsForeground; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 81 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 82 | private CheckSaveListener mCheckSaveListener; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 83 | private OnSettingsClickListener mOnSettingsClickListener; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 84 | private OnAppSettingsClickListener mAppSettingsClickListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 85 | private NotificationGuts mGutsContainer; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 86 | |
| 87 | /** Whether this view is being shown as part of the blocking helper */ |
| 88 | private boolean mIsForBlockingHelper; |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 89 | private boolean mNegativeUserSentiment; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 90 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 91 | private OnClickListener mOnKeepShowing = this::closeControls; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 92 | |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 93 | private OnClickListener mOnStopMinNotifications = v -> { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 94 | swapContent(false); |
| 95 | }; |
| 96 | |
| 97 | private OnClickListener mOnUndo = v -> { |
| 98 | swapContent(true); |
| 99 | }; |
| 100 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 101 | public NotificationInfo(Context context, AttributeSet attrs) { |
| 102 | super(context, attrs); |
| 103 | } |
| 104 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 105 | // Specify a CheckSaveListener to override when/if the user's changes are committed. |
| 106 | public interface CheckSaveListener { |
| 107 | // Invoked when importance has changed and the NotificationInfo wants to try to save it. |
| 108 | // Listener should run saveImportance unless the change should be canceled. |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 109 | void checkSave(Runnable saveImportance, StatusBarNotification sbn); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 112 | public interface OnSettingsClickListener { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 113 | void onClick(View v, NotificationChannel channel, int appUid); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 116 | public interface OnAppSettingsClickListener { |
| 117 | void onClick(View v, Intent intent); |
| 118 | } |
| 119 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 120 | @VisibleForTesting |
| 121 | void bindNotification( |
| 122 | final PackageManager pm, |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 123 | final INotificationManager iNotificationManager, |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 124 | final String pkg, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 125 | final NotificationChannel notificationChannel, |
| 126 | final int numChannels, |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 127 | final StatusBarNotification sbn, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 128 | final CheckSaveListener checkSaveListener, |
| 129 | final OnSettingsClickListener onSettingsClick, |
| 130 | final OnAppSettingsClickListener onAppSettingsClick, |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 131 | final Set<String> nonBlockablePkgs) |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 132 | throws RemoteException { |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 133 | bindNotification(pm, iNotificationManager, pkg, notificationChannel, numChannels, sbn, |
| 134 | checkSaveListener, onSettingsClick, onAppSettingsClick, nonBlockablePkgs, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 135 | false /* isBlockingHelper */, |
| 136 | false /* isUserSentimentNegative */); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 137 | } |
| 138 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 139 | public void bindNotification( |
| 140 | PackageManager pm, |
| 141 | INotificationManager iNotificationManager, |
| 142 | String pkg, |
| 143 | NotificationChannel notificationChannel, |
| 144 | int numChannels, |
| 145 | StatusBarNotification sbn, |
| 146 | CheckSaveListener checkSaveListener, |
| 147 | OnSettingsClickListener onSettingsClick, |
| 148 | OnAppSettingsClickListener onAppSettingsClick, |
| 149 | Set<String> nonBlockablePkgs, |
| 150 | boolean isForBlockingHelper, |
| 151 | boolean isUserSentimentNegative) |
| 152 | throws RemoteException { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 153 | mINotificationManager = iNotificationManager; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 154 | mPkg = pkg; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 155 | mNumNotificationChannels = numChannels; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 156 | mSbn = sbn; |
| 157 | mPm = pm; |
| 158 | mAppSettingsClickListener = onAppSettingsClick; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 159 | mAppName = mPkg; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 160 | mCheckSaveListener = checkSaveListener; |
| 161 | mOnSettingsClickListener = onSettingsClick; |
| 162 | mSingleNotificationChannel = notificationChannel; |
| 163 | mStartingUserImportance = mChosenImportance = mSingleNotificationChannel.getImportance(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 164 | mNegativeUserSentiment = isUserSentimentNegative; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 165 | mIsForeground = |
| 166 | (mSbn.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 167 | mIsForBlockingHelper = isForBlockingHelper; |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame^] | 168 | mAppUid = mSbn.getUid(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 169 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 170 | int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 171 | pkg, mAppUid, false /* includeDeleted */); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 172 | if (mNumNotificationChannels == 0) { |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 173 | throw new IllegalArgumentException("bindNotification requires at least one channel"); |
| 174 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 175 | // Special behavior for the Default channel if no other channels have been defined. |
| 176 | mIsSingleDefaultChannel = mNumNotificationChannels == 1 |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame^] | 177 | && mSingleNotificationChannel.getId().equals( |
| 178 | NotificationChannel.DEFAULT_CHANNEL_ID) |
| 179 | && numTotalChannels == 1; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 180 | } |
| 181 | |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 182 | try { |
| 183 | final PackageInfo pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES); |
| 184 | if (Utils.isSystemPackage(getResources(), pm, pkgInfo)) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 185 | if (mSingleNotificationChannel != null |
| 186 | && !mSingleNotificationChannel.isBlockableSystem()) { |
| 187 | mNonblockable = true; |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | } catch (PackageManager.NameNotFoundException e) { |
| 191 | // unlikely. |
| 192 | } |
| 193 | if (nonBlockablePkgs != null) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 194 | mNonblockable |= nonBlockablePkgs.contains(pkg); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 195 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 196 | mNonblockable |= (mNumNotificationChannels > 1); |
Geoffrey Pitsch | b43486a | 2017-06-01 13:45:59 -0400 | [diff] [blame] | 197 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 198 | bindHeader(); |
| 199 | bindPrompt(); |
| 200 | bindButtons(); |
| 201 | } |
| 202 | |
| 203 | private void bindHeader() throws RemoteException { |
| 204 | // Package name |
| 205 | Drawable pkgicon = null; |
| 206 | ApplicationInfo info; |
| 207 | try { |
| 208 | info = mPm.getApplicationInfo(mPkg, |
| 209 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 210 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 211 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 212 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 213 | if (info != null) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 214 | mAppName = String.valueOf(mPm.getApplicationLabel(info)); |
| 215 | pkgicon = mPm.getApplicationIcon(info); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 216 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 217 | } catch (PackageManager.NameNotFoundException e) { |
| 218 | // app is gone, just show package name and generic icon |
| 219 | pkgicon = mPm.getDefaultActivityIcon(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 220 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 221 | ((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon); |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 222 | ((TextView) findViewById(R.id.pkgname)).setText(mAppName); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 223 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 224 | // Set group information if this channel has an associated group. |
| 225 | CharSequence groupName = null; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 226 | if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) { |
| 227 | final NotificationChannelGroup notificationChannelGroup = |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 228 | mINotificationManager.getNotificationChannelGroupForPackage( |
| 229 | mSingleNotificationChannel.getGroup(), mPkg, mAppUid); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 230 | if (notificationChannelGroup != null) { |
| 231 | groupName = notificationChannelGroup.getName(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 232 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 233 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 234 | TextView groupNameView = findViewById(R.id.group_name); |
| 235 | TextView groupDividerView = findViewById(R.id.pkg_group_divider); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 236 | if (groupName != null) { |
| 237 | groupNameView.setText(groupName); |
| 238 | groupNameView.setVisibility(View.VISIBLE); |
| 239 | groupDividerView.setVisibility(View.VISIBLE); |
| 240 | } else { |
| 241 | groupNameView.setVisibility(View.GONE); |
| 242 | groupDividerView.setVisibility(View.GONE); |
| 243 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 244 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 245 | // Settings button. |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 246 | final View settingsButton = findViewById(R.id.info); |
| 247 | if (mAppUid >= 0 && mOnSettingsClickListener != null) { |
Geoffrey Pitsch | 029a3fa | 2017-03-30 13:01:57 -0400 | [diff] [blame] | 248 | settingsButton.setVisibility(View.VISIBLE); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 249 | final int appUidF = mAppUid; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 250 | settingsButton.setOnClickListener( |
| 251 | (View view) -> { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 252 | mOnSettingsClickListener.onClick(view, |
| 253 | mNumNotificationChannels > 1 ? null : mSingleNotificationChannel, |
| 254 | appUidF); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 255 | }); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 256 | } else { |
| 257 | settingsButton.setVisibility(View.GONE); |
| 258 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 259 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 260 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 261 | private void bindPrompt() { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 262 | final TextView blockPrompt = findViewById(R.id.block_prompt); |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 263 | bindName(); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 264 | if (mNonblockable) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 265 | blockPrompt.setText(R.string.notification_unblockable_desc); |
| 266 | } else { |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 267 | if (mNegativeUserSentiment) { |
| 268 | blockPrompt.setText(R.string.inline_blocking_helper); |
| 269 | } else if (mIsSingleDefaultChannel || mNumNotificationChannels > 1) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 270 | blockPrompt.setText(R.string.inline_keep_showing_app); |
| 271 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 272 | blockPrompt.setText(R.string.inline_keep_showing); |
| 273 | } |
| 274 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Julia Reynolds | 0ef7d84 | 2018-01-24 17:50:31 -0500 | [diff] [blame] | 277 | private void bindName() { |
| 278 | final TextView channelName = findViewById(R.id.channel_name); |
| 279 | if (mIsSingleDefaultChannel || mNumNotificationChannels > 1) { |
| 280 | channelName.setVisibility(View.GONE); |
| 281 | } else { |
| 282 | channelName.setText(mSingleNotificationChannel.getName()); |
| 283 | } |
| 284 | } |
| 285 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 286 | private boolean hasImportanceChanged() { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 287 | return mSingleNotificationChannel != null && mStartingUserImportance != mChosenImportance; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 288 | } |
| 289 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 290 | private void saveImportance() { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 291 | if (mNonblockable) { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 292 | return; |
| 293 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 294 | MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 295 | mChosenImportance - mStartingUserImportance); |
| 296 | mSingleNotificationChannel.setImportance(mChosenImportance); |
Julia Reynolds | 8ceb579 | 2017-04-11 11:32:44 -0400 | [diff] [blame] | 297 | mSingleNotificationChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 298 | try { |
| 299 | mINotificationManager.updateNotificationChannelForPackage( |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 300 | mPkg, mAppUid, mSingleNotificationChannel); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 301 | } catch (RemoteException e) { |
| 302 | // :( |
| 303 | } |
| 304 | } |
| 305 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 306 | private void bindButtons() { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 307 | // Set up stay-in-notification actions |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 308 | View block = findViewById(R.id.block); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 309 | TextView keep = findViewById(R.id.keep); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 310 | View minimize = findViewById(R.id.minimize); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 311 | |
| 312 | findViewById(R.id.undo).setOnClickListener(mOnUndo); |
| 313 | block.setOnClickListener(mOnStopMinNotifications); |
| 314 | keep.setOnClickListener(mOnKeepShowing); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 315 | minimize.setOnClickListener(mOnStopMinNotifications); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 316 | |
| 317 | if (mNonblockable) { |
| 318 | keep.setText(R.string.notification_done); |
| 319 | block.setVisibility(GONE); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 320 | minimize.setVisibility(GONE); |
| 321 | } else if (mIsForeground) { |
| 322 | block.setVisibility(GONE); |
| 323 | minimize.setVisibility(VISIBLE); |
| 324 | } else if (!mIsForeground) { |
| 325 | block.setVisibility(VISIBLE); |
| 326 | minimize.setVisibility(GONE); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 329 | // Set up app settings link |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 330 | TextView settingsLinkView = findViewById(R.id.app_settings); |
| 331 | Intent settingsIntent = getAppSettingsIntent(mPm, mPkg, mSingleNotificationChannel, |
| 332 | mSbn.getId(), mSbn.getTag()); |
| 333 | if (settingsIntent != null |
| 334 | && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) { |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 335 | settingsLinkView.setVisibility(VISIBLE); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 336 | settingsLinkView.setText(mContext.getString(R.string.notification_app_settings, |
| 337 | mSbn.getNotification().getSettingsText())); |
| 338 | settingsLinkView.setOnClickListener((View view) -> { |
| 339 | mAppSettingsClickListener.onClick(view, settingsIntent); |
| 340 | }); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 341 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 342 | settingsLinkView.setVisibility(View.GONE); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 346 | private void swapContent(boolean showPrompt) { |
| 347 | if (mExpandAnimation != null) { |
| 348 | mExpandAnimation.cancel(); |
| 349 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 350 | |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 351 | View prompt = findViewById(R.id.prompt); |
| 352 | ViewGroup confirmation = findViewById(R.id.confirmation); |
| 353 | TextView confirmationText = findViewById(R.id.confirmation_text); |
| 354 | View header = findViewById(R.id.header); |
| 355 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 356 | if (showPrompt) { |
| 357 | mChosenImportance = mStartingUserImportance; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 358 | } else if (mIsForeground) { |
| 359 | mChosenImportance = IMPORTANCE_MIN; |
| 360 | confirmationText.setText(R.string.notification_channel_minimized); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 361 | } else { |
| 362 | mChosenImportance = IMPORTANCE_NONE; |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 363 | confirmationText.setText(R.string.notification_channel_disabled); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 364 | } |
| 365 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 366 | ObjectAnimator promptAnim = ObjectAnimator.ofFloat(prompt, View.ALPHA, |
| 367 | prompt.getAlpha(), showPrompt ? 1f : 0f); |
| 368 | promptAnim.setInterpolator(showPrompt ? Interpolators.ALPHA_IN : Interpolators.ALPHA_OUT); |
| 369 | ObjectAnimator confirmAnim = ObjectAnimator.ofFloat(confirmation, View.ALPHA, |
| 370 | confirmation.getAlpha(), showPrompt ? 0f : 1f); |
| 371 | confirmAnim.setInterpolator(showPrompt ? Interpolators.ALPHA_OUT : Interpolators.ALPHA_IN); |
| 372 | |
| 373 | prompt.setVisibility(showPrompt ? VISIBLE : GONE); |
| 374 | confirmation.setVisibility(showPrompt ? GONE : VISIBLE); |
Julia Reynolds | e034148 | 2018-03-08 14:42:50 -0500 | [diff] [blame] | 375 | header.setVisibility(showPrompt ? VISIBLE : GONE); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 376 | |
| 377 | mExpandAnimation = new AnimatorSet(); |
| 378 | mExpandAnimation.playTogether(promptAnim, confirmAnim); |
| 379 | mExpandAnimation.setDuration(150); |
| 380 | mExpandAnimation.addListener(new AnimatorListenerAdapter() { |
| 381 | boolean cancelled = false; |
| 382 | |
| 383 | @Override |
| 384 | public void onAnimationCancel(Animator animation) { |
| 385 | cancelled = true; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 386 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 387 | |
| 388 | @Override |
| 389 | public void onAnimationEnd(Animator animation) { |
| 390 | if (!cancelled) { |
| 391 | prompt.setVisibility(showPrompt ? VISIBLE : GONE); |
| 392 | confirmation.setVisibility(showPrompt ? GONE : VISIBLE); |
| 393 | } |
| 394 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 395 | }); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 396 | mExpandAnimation.start(); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 397 | } |
| 398 | |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 399 | @Override |
| 400 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 401 | super.onInitializeAccessibilityEvent(event); |
| 402 | if (mGutsContainer != null && |
| 403 | event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 404 | if (mGutsContainer.isExposed()) { |
| 405 | event.getText().add(mContext.getString( |
| 406 | R.string.notification_channel_controls_opened_accessibility, mAppName)); |
| 407 | } else { |
| 408 | event.getText().add(mContext.getString( |
| 409 | R.string.notification_channel_controls_closed_accessibility, mAppName)); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 414 | private Intent getAppSettingsIntent(PackageManager pm, String packageName, |
| 415 | NotificationChannel channel, int id, String tag) { |
| 416 | Intent intent = new Intent(Intent.ACTION_MAIN) |
| 417 | .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES) |
| 418 | .setPackage(packageName); |
| 419 | final List<ResolveInfo> resolveInfos = pm.queryIntentActivities( |
| 420 | intent, |
| 421 | PackageManager.MATCH_DEFAULT_ONLY |
| 422 | ); |
| 423 | if (resolveInfos == null || resolveInfos.size() == 0 || resolveInfos.get(0) == null) { |
| 424 | return null; |
| 425 | } |
| 426 | final ActivityInfo activityInfo = resolveInfos.get(0).activityInfo; |
| 427 | intent.setClassName(activityInfo.packageName, activityInfo.name); |
| 428 | if (channel != null) { |
| 429 | intent.putExtra(Notification.EXTRA_CHANNEL_ID, channel.getId()); |
| 430 | } |
| 431 | intent.putExtra(Notification.EXTRA_NOTIFICATION_ID, id); |
| 432 | intent.putExtra(Notification.EXTRA_NOTIFICATION_TAG, tag); |
| 433 | return intent; |
| 434 | } |
| 435 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 436 | @VisibleForTesting |
| 437 | void closeControls(View v) { |
| 438 | if (mIsForBlockingHelper) { |
| 439 | NotificationBlockingHelperManager manager = |
| 440 | Dependency.get(NotificationBlockingHelperManager.class); |
| 441 | manager.dismissCurrentBlockingHelper(); |
| 442 | } else { |
| 443 | int[] parentLoc = new int[2]; |
| 444 | int[] targetLoc = new int[2]; |
| 445 | mGutsContainer.getLocationOnScreen(parentLoc); |
| 446 | v.getLocationOnScreen(targetLoc); |
| 447 | final int centerX = v.getWidth() / 2; |
| 448 | final int centerY = v.getHeight() / 2; |
| 449 | final int x = targetLoc[0] - parentLoc[0] + centerX; |
| 450 | final int y = targetLoc[1] - parentLoc[1] + centerY; |
| 451 | mGutsContainer.closeControls(x, y, true /* save */, false /* force */); |
| 452 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 453 | } |
| 454 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 455 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 456 | public void setGutsParent(NotificationGuts guts) { |
| 457 | mGutsContainer = guts; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | @Override |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 461 | public boolean willBeRemoved() { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 462 | return hasImportanceChanged(); |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | @Override |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 466 | public View getContentView() { |
| 467 | return this; |
| 468 | } |
| 469 | |
| 470 | @Override |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 471 | public boolean handleCloseControls(boolean save, boolean force) { |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 472 | // Save regardless of the importance so we can lock the importance field if the user wants |
| 473 | // to keep getting notifications |
| 474 | if (save) { |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 475 | if (mCheckSaveListener != null) { |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 476 | mCheckSaveListener.checkSave(this::saveImportance, mSbn); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 477 | } else { |
| 478 | saveImportance(); |
| 479 | } |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 480 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 481 | return false; |
| 482 | } |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 483 | |
| 484 | @Override |
| 485 | public int getActualHeight() { |
| 486 | return getHeight(); |
| 487 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 488 | } |