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