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