Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 18 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 19 | import static android.app.NotificationManager.IMPORTANCE_DEFAULT; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 20 | import static android.app.NotificationManager.IMPORTANCE_LOW; |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 21 | import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 22 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 23 | import static com.android.systemui.Interpolators.FAST_OUT_SLOW_IN; |
| 24 | |
| 25 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 26 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 27 | import android.annotation.IntDef; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 28 | import android.annotation.Nullable; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 29 | import android.app.INotificationManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 30 | import android.app.Notification; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 31 | import android.app.NotificationChannel; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 32 | import android.app.NotificationChannelGroup; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 33 | import android.content.Context; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 34 | import android.content.Intent; |
| 35 | import android.content.pm.ActivityInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 36 | import android.content.pm.ApplicationInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 38 | import android.content.pm.ResolveInfo; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 39 | import android.graphics.drawable.Drawable; |
William Brockman | 75cf66a | 2018-12-21 13:25:01 -0500 | [diff] [blame] | 40 | import android.metrics.LogMaker; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 41 | import android.os.Handler; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 42 | import android.os.RemoteException; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 43 | import android.service.notification.StatusBarNotification; |
| 44 | import android.text.TextUtils; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 45 | import android.transition.ChangeBounds; |
| 46 | import android.transition.Fade; |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 47 | import android.transition.TransitionManager; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 48 | import android.transition.TransitionSet; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 49 | import android.util.AttributeSet; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 50 | import android.util.Log; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 51 | import android.view.View; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 52 | import android.view.accessibility.AccessibilityEvent; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 53 | import android.widget.ImageView; |
| 54 | import android.widget.LinearLayout; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 55 | import android.widget.TextView; |
| 56 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 57 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 58 | import com.android.internal.logging.MetricsLogger; |
| 59 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 60 | import com.android.systemui.Dependency; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 61 | import com.android.systemui.R; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 62 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 63 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 64 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 65 | import java.lang.annotation.Retention; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 66 | import java.util.List; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 67 | import java.util.Set; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 68 | |
| 69 | /** |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 70 | * The guts of a notification revealed when performing a long press. |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 71 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 72 | public class NotificationInfo extends LinearLayout implements NotificationGuts.GutsContent { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 73 | private static final String TAG = "InfoGuts"; |
Selim Cinek | a5a4ee4 | 2020-05-21 15:38:32 -0700 | [diff] [blame] | 74 | private int mActualHeight; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 75 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 76 | @IntDef(prefix = { "ACTION_" }, value = { |
| 77 | ACTION_NONE, |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 78 | ACTION_TOGGLE_ALERT, |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 79 | ACTION_TOGGLE_SILENT, |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 80 | }) |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 81 | public @interface NotificationInfoAction { |
| 82 | } |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 83 | |
Gus Prevas | 894d915 | 2018-11-12 13:51:40 -0500 | [diff] [blame] | 84 | public static final int ACTION_NONE = 0; |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 85 | // standard controls |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 86 | static final int ACTION_TOGGLE_SILENT = 2; |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 87 | // standard controls |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 88 | private static final int ACTION_TOGGLE_ALERT = 5; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 89 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 90 | private TextView mPriorityDescriptionView; |
| 91 | private TextView mSilentDescriptionView; |
Dan Sandler | 0ed0229 | 2019-05-14 19:18:35 -0400 | [diff] [blame] | 92 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 93 | private INotificationManager mINotificationManager; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 94 | private PackageManager mPm; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 95 | private MetricsLogger mMetricsLogger; |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 96 | private VisualStabilityManager mVisualStabilityManager; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 97 | private ChannelEditorDialogController mChannelEditorDialogController; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 98 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 99 | private String mPackageName; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 100 | private String mAppName; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 101 | private int mAppUid; |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 102 | private String mDelegatePkg; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 103 | private int mNumUniqueChannelsInRow; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 104 | private Set<NotificationChannel> mUniqueChannelsInRow; |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 105 | private NotificationChannel mSingleNotificationChannel; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 106 | private int mStartingChannelImportance; |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 107 | private boolean mWasShownHighPriority; |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 108 | private boolean mPressedApply; |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 109 | private boolean mPresentingChannelEditorDialog = false; |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 110 | |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 111 | /** |
| 112 | * The last importance level chosen by the user. Null if the user has not chosen an importance |
| 113 | * level; non-null once the user takes an action which indicates an explicit preference. |
| 114 | */ |
| 115 | @Nullable private Integer mChosenImportance; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 116 | private boolean mIsSingleDefaultChannel; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 117 | private boolean mIsNonblockable; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 118 | private StatusBarNotification mSbn; |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 119 | private boolean mIsDeviceProvisioned; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 120 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 121 | private OnSettingsClickListener mOnSettingsClickListener; |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 122 | private OnAppSettingsClickListener mAppSettingsClickListener; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 123 | private NotificationGuts mGutsContainer; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 124 | private Drawable mPkgIcon; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 125 | |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 126 | @VisibleForTesting |
| 127 | boolean mSkipPost = false; |
| 128 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 129 | // used by standard ui |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 130 | private OnClickListener mOnAlert = v -> { |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 131 | mChosenImportance = IMPORTANCE_DEFAULT; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 132 | applyAlertingBehavior(BEHAVIOR_ALERTING, true /* userTriggered */); |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 133 | }; |
| 134 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 135 | // used by standard ui |
| 136 | private OnClickListener mOnSilent = v -> { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 137 | mChosenImportance = IMPORTANCE_LOW; |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 138 | applyAlertingBehavior(BEHAVIOR_SILENT, true /* userTriggered */); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | // used by standard ui |
Nadia Benbernou | b66516c | 2019-03-06 11:01:53 -0500 | [diff] [blame] | 142 | private OnClickListener mOnDismissSettings = v -> { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 143 | mPressedApply = true; |
Dave Mankoff | c97a0e6 | 2020-06-01 12:13:05 -0400 | [diff] [blame] | 144 | mGutsContainer.closeControls(v, true); |
Nadia Benbernou | 3b4a93a | 2019-02-06 16:16:47 -0500 | [diff] [blame] | 145 | }; |
| 146 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 147 | public NotificationInfo(Context context, AttributeSet attrs) { |
| 148 | super(context, attrs); |
| 149 | } |
| 150 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 151 | @Override |
| 152 | protected void onFinishInflate() { |
| 153 | super.onFinishInflate(); |
| 154 | |
| 155 | mPriorityDescriptionView = findViewById(R.id.alert_summary); |
| 156 | mSilentDescriptionView = findViewById(R.id.silence_summary); |
| 157 | } |
| 158 | |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 159 | // Specify a CheckSaveListener to override when/if the user's changes are committed. |
| 160 | public interface CheckSaveListener { |
| 161 | // Invoked when importance has changed and the NotificationInfo wants to try to save it. |
| 162 | // Listener should run saveImportance unless the change should be canceled. |
Eliot Courtney | 47098cb | 2017-10-18 17:30:30 +0900 | [diff] [blame] | 163 | void checkSave(Runnable saveImportance, StatusBarNotification sbn); |
Geoffrey Pitsch | 5278d3d | 2017-03-29 13:39:10 -0400 | [diff] [blame] | 164 | } |
| 165 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 166 | public interface OnSettingsClickListener { |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 167 | void onClick(View v, NotificationChannel channel, int appUid); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 170 | public interface OnAppSettingsClickListener { |
| 171 | void onClick(View v, Intent intent); |
| 172 | } |
| 173 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 174 | public void bindNotification( |
| 175 | PackageManager pm, |
| 176 | INotificationManager iNotificationManager, |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 177 | VisualStabilityManager visualStabilityManager, |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 178 | ChannelEditorDialogController channelEditorDialogController, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 179 | String pkg, |
| 180 | NotificationChannel notificationChannel, |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 181 | Set<NotificationChannel> uniqueChannelsInRow, |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 182 | NotificationEntry entry, |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 183 | OnSettingsClickListener onSettingsClick, |
| 184 | OnAppSettingsClickListener onAppSettingsClick, |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 185 | boolean isDeviceProvisioned, |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 186 | boolean isNonblockable, |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 187 | boolean wasShownHighPriority) |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 188 | throws RemoteException { |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 189 | mINotificationManager = iNotificationManager; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 190 | mMetricsLogger = Dependency.get(MetricsLogger.class); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 191 | mVisualStabilityManager = visualStabilityManager; |
Evan Laird | 18bd6e6 | 2019-08-30 16:39:25 -0400 | [diff] [blame] | 192 | mChannelEditorDialogController = channelEditorDialogController; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 193 | mPackageName = pkg; |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 194 | mUniqueChannelsInRow = uniqueChannelsInRow; |
| 195 | mNumUniqueChannelsInRow = uniqueChannelsInRow.size(); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 196 | mSbn = entry.getSbn(); |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 197 | mPm = pm; |
| 198 | mAppSettingsClickListener = onAppSettingsClick; |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 199 | mAppName = mPackageName; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 200 | mOnSettingsClickListener = onSettingsClick; |
| 201 | mSingleNotificationChannel = notificationChannel; |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 202 | mStartingChannelImportance = mSingleNotificationChannel.getImportance(); |
| 203 | mWasShownHighPriority = wasShownHighPriority; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 204 | mIsNonblockable = isNonblockable; |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 205 | mAppUid = mSbn.getUid(); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 206 | mDelegatePkg = mSbn.getOpPkg(); |
Julia Reynolds | 35765d8 | 2018-08-17 11:39:19 -0400 | [diff] [blame] | 207 | mIsDeviceProvisioned = isDeviceProvisioned; |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 208 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 209 | int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage( |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 210 | pkg, mAppUid, false /* includeDeleted */); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 211 | if (mNumUniqueChannelsInRow == 0) { |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 212 | throw new IllegalArgumentException("bindNotification requires at least one channel"); |
| 213 | } else { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 214 | // Special behavior for the Default channel if no other channels have been defined. |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 215 | mIsSingleDefaultChannel = mNumUniqueChannelsInRow == 1 |
Rohan Shah | dbd64e7 | 2018-03-28 14:46:50 -0700 | [diff] [blame] | 216 | && mSingleNotificationChannel.getId().equals( |
| 217 | NotificationChannel.DEFAULT_CHANNEL_ID) |
| 218 | && numTotalChannels == 1; |
Geoffrey Pitsch | d034d29 | 2017-05-12 11:59:20 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 221 | bindHeader(); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 222 | bindChannelDetails(); |
| 223 | |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 224 | bindInlineControls(); |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 225 | |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 226 | mMetricsLogger.write(notificationControlsLogMaker()); |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 229 | private void bindInlineControls() { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 230 | if (mIsNonblockable) { |
| 231 | findViewById(R.id.non_configurable_text).setVisibility(VISIBLE); |
| 232 | findViewById(R.id.non_configurable_multichannel_text).setVisibility(GONE); |
| 233 | findViewById(R.id.interruptiveness_settings).setVisibility(GONE); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 234 | ((TextView) findViewById(R.id.done)).setText(R.string.inline_done_button); |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 235 | findViewById(R.id.turn_off_notifications).setVisibility(GONE); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 236 | } else if (mNumUniqueChannelsInRow > 1) { |
| 237 | findViewById(R.id.non_configurable_text).setVisibility(GONE); |
| 238 | findViewById(R.id.interruptiveness_settings).setVisibility(GONE); |
| 239 | findViewById(R.id.non_configurable_multichannel_text).setVisibility(VISIBLE); |
| 240 | } else { |
| 241 | findViewById(R.id.non_configurable_text).setVisibility(GONE); |
| 242 | findViewById(R.id.non_configurable_multichannel_text).setVisibility(GONE); |
| 243 | findViewById(R.id.interruptiveness_settings).setVisibility(VISIBLE); |
| 244 | } |
| 245 | |
| 246 | View turnOffButton = findViewById(R.id.turn_off_notifications); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 247 | turnOffButton.setOnClickListener(getTurnOffNotificationsClickListener()); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 248 | turnOffButton.setVisibility(turnOffButton.hasOnClickListeners() && !mIsNonblockable |
| 249 | ? VISIBLE : GONE); |
| 250 | |
| 251 | View done = findViewById(R.id.done); |
| 252 | done.setOnClickListener(mOnDismissSettings); |
Dave Mankoff | c97a0e6 | 2020-06-01 12:13:05 -0400 | [diff] [blame] | 253 | done.setAccessibilityDelegate(mGutsContainer.getAccessibilityDelegate()); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 254 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 255 | View silent = findViewById(R.id.silence); |
| 256 | View alert = findViewById(R.id.alert); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 257 | silent.setOnClickListener(mOnSilent); |
| 258 | alert.setOnClickListener(mOnAlert); |
| 259 | |
Julia Reynolds | c3e922b | 2020-01-16 16:12:56 -0500 | [diff] [blame] | 260 | int behavior = mWasShownHighPriority |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 261 | ? BEHAVIOR_ALERTING |
| 262 | : BEHAVIOR_SILENT; |
| 263 | applyAlertingBehavior(behavior, false /* userTriggered */); |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | private void bindHeader() { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 267 | // Package name |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 268 | mPkgIcon = null; |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 269 | ApplicationInfo info; |
| 270 | try { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 271 | info = mPm.getApplicationInfo( |
| 272 | mPackageName, |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 273 | PackageManager.MATCH_UNINSTALLED_PACKAGES |
| 274 | | PackageManager.MATCH_DISABLED_COMPONENTS |
| 275 | | PackageManager.MATCH_DIRECT_BOOT_UNAWARE |
| 276 | | PackageManager.MATCH_DIRECT_BOOT_AWARE); |
| 277 | if (info != null) { |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 278 | mAppName = String.valueOf(mPm.getApplicationLabel(info)); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 279 | mPkgIcon = mPm.getApplicationIcon(info); |
Geoffrey Pitsch | ee8c81e | 2017-03-23 11:38:56 -0400 | [diff] [blame] | 280 | } |
Julia Reynolds | 437cdb1 | 2018-01-03 12:27:24 -0500 | [diff] [blame] | 281 | } catch (PackageManager.NameNotFoundException e) { |
| 282 | // app is gone, just show package name and generic icon |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 283 | mPkgIcon = mPm.getDefaultActivityIcon(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 284 | } |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 285 | ((ImageView) findViewById(R.id.pkg_icon)).setImageDrawable(mPkgIcon); |
| 286 | ((TextView) findViewById(R.id.pkg_name)).setText(mAppName); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 287 | |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 288 | // Delegate |
| 289 | bindDelegate(); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 290 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 291 | // Set up app settings link (i.e. Customize) |
| 292 | View settingsLinkView = findViewById(R.id.app_settings); |
| 293 | Intent settingsIntent = getAppSettingsIntent(mPm, mPackageName, |
| 294 | mSingleNotificationChannel, |
| 295 | mSbn.getId(), mSbn.getTag()); |
| 296 | if (settingsIntent != null |
| 297 | && !TextUtils.isEmpty(mSbn.getNotification().getSettingsText())) { |
| 298 | settingsLinkView.setVisibility(VISIBLE); |
| 299 | settingsLinkView.setOnClickListener((View view) -> { |
| 300 | mAppSettingsClickListener.onClick(view, settingsIntent); |
| 301 | }); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 302 | } else { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 303 | settingsLinkView.setVisibility(View.GONE); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 304 | } |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 305 | |
| 306 | // System Settings button. |
| 307 | final View settingsButton = findViewById(R.id.info); |
| 308 | settingsButton.setOnClickListener(getSettingsOnClickListener()); |
| 309 | settingsButton.setVisibility(settingsButton.hasOnClickListeners() ? VISIBLE : GONE); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 312 | private OnClickListener getSettingsOnClickListener() { |
| 313 | if (mAppUid >= 0 && mOnSettingsClickListener != null && mIsDeviceProvisioned) { |
| 314 | final int appUidF = mAppUid; |
| 315 | return ((View view) -> { |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 316 | mOnSettingsClickListener.onClick(view, |
| 317 | mNumUniqueChannelsInRow > 1 ? null : mSingleNotificationChannel, |
| 318 | appUidF); |
| 319 | }); |
| 320 | } |
| 321 | return null; |
| 322 | } |
| 323 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 324 | private OnClickListener getTurnOffNotificationsClickListener() { |
| 325 | return ((View view) -> { |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 326 | if (!mPresentingChannelEditorDialog && mChannelEditorDialogController != null) { |
| 327 | mPresentingChannelEditorDialog = true; |
| 328 | |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 329 | mChannelEditorDialogController.prepareDialogForApp(mAppName, mPackageName, mAppUid, |
| 330 | mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener); |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 331 | mChannelEditorDialogController.setOnFinishListener(() -> { |
| 332 | mPresentingChannelEditorDialog = false; |
Dave Mankoff | c97a0e6 | 2020-06-01 12:13:05 -0400 | [diff] [blame] | 333 | mGutsContainer.closeControls(this, false); |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 334 | }); |
Evan Laird | 47dc454 | 2019-04-24 15:10:52 -0400 | [diff] [blame] | 335 | mChannelEditorDialogController.show(); |
| 336 | } |
| 337 | }); |
| 338 | } |
| 339 | |
Julia Reynolds | 52a2737 | 2019-04-03 11:00:17 -0400 | [diff] [blame] | 340 | private void bindChannelDetails() throws RemoteException { |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 341 | bindName(); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 342 | bindGroup(); |
Daniel Sandler | d0a52b6 | 2018-10-31 20:13:22 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | private void bindName() { |
| 346 | final TextView channelName = findViewById(R.id.channel_name); |
| 347 | if (mIsSingleDefaultChannel || mNumUniqueChannelsInRow > 1) { |
| 348 | channelName.setVisibility(View.GONE); |
| 349 | } else { |
| 350 | channelName.setText(mSingleNotificationChannel.getName()); |
| 351 | } |
Julia Reynolds | ac98aea | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 352 | } |
| 353 | |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 354 | private void bindDelegate() { |
| 355 | TextView delegateView = findViewById(R.id.delegate_name); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 356 | |
| 357 | CharSequence delegatePkg = null; |
| 358 | if (!TextUtils.equals(mPackageName, mDelegatePkg)) { |
| 359 | // this notification was posted by a delegate! |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 360 | delegateView.setVisibility(View.VISIBLE); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 361 | } else { |
| 362 | delegateView.setVisibility(View.GONE); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | private void bindGroup() throws RemoteException { |
| 367 | // Set group information if this channel has an associated group. |
| 368 | CharSequence groupName = null; |
| 369 | if (mSingleNotificationChannel != null && mSingleNotificationChannel.getGroup() != null) { |
| 370 | final NotificationChannelGroup notificationChannelGroup = |
| 371 | mINotificationManager.getNotificationChannelGroupForPackage( |
| 372 | mSingleNotificationChannel.getGroup(), mPackageName, mAppUid); |
| 373 | if (notificationChannelGroup != null) { |
| 374 | groupName = notificationChannelGroup.getName(); |
| 375 | } |
| 376 | } |
| 377 | TextView groupNameView = findViewById(R.id.group_name); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 378 | if (groupName != null) { |
| 379 | groupNameView.setText(groupName); |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 380 | groupNameView.setVisibility(VISIBLE); |
Julia Reynolds | 268647a | 2018-10-25 16:54:27 -0400 | [diff] [blame] | 381 | } else { |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 382 | groupNameView.setVisibility(GONE); |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 386 | private void saveImportance() { |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 387 | if (!mIsNonblockable) { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 388 | if (mChosenImportance == null) { |
| 389 | mChosenImportance = mStartingChannelImportance; |
| 390 | } |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 391 | updateImportance(); |
Geoffrey Pitsch | d0856f0 | 2017-02-16 10:51:18 -0500 | [diff] [blame] | 392 | } |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /** |
| 396 | * Commits the updated importance values on the background thread. |
| 397 | */ |
| 398 | private void updateImportance() { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 399 | if (mChosenImportance != null) { |
| 400 | mMetricsLogger.write(importanceChangeLogMaker()); |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 401 | |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 402 | int newImportance = mChosenImportance; |
| 403 | if (mStartingChannelImportance != IMPORTANCE_UNSPECIFIED) { |
| 404 | if ((mWasShownHighPriority && mChosenImportance >= IMPORTANCE_DEFAULT) |
| 405 | || (!mWasShownHighPriority && mChosenImportance < IMPORTANCE_DEFAULT)) { |
| 406 | newImportance = mStartingChannelImportance; |
| 407 | } |
| 408 | } |
| 409 | |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 410 | Handler bgHandler = new Handler(Dependency.get(Dependency.BG_LOOPER)); |
| 411 | bgHandler.post( |
| 412 | new UpdateImportanceRunnable(mINotificationManager, mPackageName, mAppUid, |
| 413 | mNumUniqueChannelsInRow == 1 ? mSingleNotificationChannel : null, |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 414 | mStartingChannelImportance, newImportance)); |
Ned Burns | 9512e0c | 2019-05-30 19:36:04 -0400 | [diff] [blame] | 415 | mVisualStabilityManager.temporarilyAllowReordering(); |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 416 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 419 | @Override |
| 420 | public boolean post(Runnable action) { |
| 421 | if (mSkipPost) { |
| 422 | action.run(); |
| 423 | return true; |
| 424 | } else { |
| 425 | return super.post(action); |
| 426 | } |
| 427 | } |
| 428 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 429 | private void applyAlertingBehavior(@AlertingBehavior int behavior, boolean userTriggered) { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 430 | if (userTriggered) { |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 431 | TransitionSet transition = new TransitionSet(); |
| 432 | transition.setOrdering(TransitionSet.ORDERING_TOGETHER); |
| 433 | transition.addTransition(new Fade(Fade.OUT)) |
| 434 | .addTransition(new ChangeBounds()) |
| 435 | .addTransition( |
| 436 | new Fade(Fade.IN) |
| 437 | .setStartDelay(150) |
| 438 | .setDuration(200) |
| 439 | .setInterpolator(FAST_OUT_SLOW_IN)); |
| 440 | transition.setDuration(350); |
| 441 | transition.setInterpolator(FAST_OUT_SLOW_IN); |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 442 | TransitionManager.beginDelayedTransition(this, transition); |
| 443 | } |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 444 | |
| 445 | View alert = findViewById(R.id.alert); |
| 446 | View silence = findViewById(R.id.silence); |
| 447 | |
| 448 | switch (behavior) { |
| 449 | case BEHAVIOR_ALERTING: |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 450 | mPriorityDescriptionView.setVisibility(VISIBLE); |
| 451 | mSilentDescriptionView.setVisibility(GONE); |
Julia Reynolds | daab21a | 2019-06-05 14:30:05 -0400 | [diff] [blame] | 452 | post(() -> { |
| 453 | alert.setSelected(true); |
| 454 | silence.setSelected(false); |
| 455 | }); |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 456 | break; |
Julia Reynolds | daab21a | 2019-06-05 14:30:05 -0400 | [diff] [blame] | 457 | |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 458 | case BEHAVIOR_SILENT: |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 459 | mSilentDescriptionView.setVisibility(VISIBLE); |
| 460 | mPriorityDescriptionView.setVisibility(GONE); |
Julia Reynolds | daab21a | 2019-06-05 14:30:05 -0400 | [diff] [blame] | 461 | post(() -> { |
| 462 | alert.setSelected(false); |
| 463 | silence.setSelected(true); |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 464 | }); |
| 465 | break; |
| 466 | |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 467 | default: |
| 468 | throw new IllegalArgumentException("Unrecognized alerting behavior: " + behavior); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 469 | } |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 470 | |
| 471 | boolean isAChange = mWasShownHighPriority != (behavior == BEHAVIOR_ALERTING); |
| 472 | TextView done = findViewById(R.id.done); |
Julia Reynolds | c3e922b | 2020-01-16 16:12:56 -0500 | [diff] [blame] | 473 | done.setText(isAChange |
Mady Mellor | 53162c1 | 2019-10-22 17:12:59 -0700 | [diff] [blame] | 474 | ? R.string.inline_ok_button |
| 475 | : R.string.inline_done_button); |
Julia Reynolds | 8728d00 | 2019-04-19 15:46:13 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 478 | @Override |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 479 | public void onFinishedClosing() { |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 480 | if (mChosenImportance != null) { |
| 481 | mStartingChannelImportance = mChosenImportance; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 482 | } |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 483 | |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 484 | bindInlineControls(); |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 485 | |
| 486 | mMetricsLogger.write(notificationControlsLogMaker().setType(MetricsEvent.TYPE_CLOSE)); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | @Override |
Julia Reynolds | be37107 | 2020-05-28 11:32:01 -0400 | [diff] [blame] | 490 | public boolean needsFalsingProtection() { |
| 491 | return true; |
| 492 | } |
| 493 | |
| 494 | @Override |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 495 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 496 | super.onInitializeAccessibilityEvent(event); |
| 497 | if (mGutsContainer != null && |
| 498 | event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { |
| 499 | if (mGutsContainer.isExposed()) { |
| 500 | event.getText().add(mContext.getString( |
| 501 | R.string.notification_channel_controls_opened_accessibility, mAppName)); |
| 502 | } else { |
| 503 | event.getText().add(mContext.getString( |
| 504 | R.string.notification_channel_controls_closed_accessibility, mAppName)); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
Julia Reynolds | 3aedded | 2017-03-31 14:42:09 -0400 | [diff] [blame] | 509 | private Intent getAppSettingsIntent(PackageManager pm, String packageName, |
| 510 | NotificationChannel channel, int id, String tag) { |
| 511 | Intent intent = new Intent(Intent.ACTION_MAIN) |
| 512 | .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES) |
| 513 | .setPackage(packageName); |
| 514 | final List<ResolveInfo> resolveInfos = pm.queryIntentActivities( |
| 515 | intent, |
| 516 | PackageManager.MATCH_DEFAULT_ONLY |
| 517 | ); |
| 518 | if (resolveInfos == null || resolveInfos.size() == 0 || resolveInfos.get(0) == null) { |
| 519 | return null; |
| 520 | } |
| 521 | final ActivityInfo activityInfo = resolveInfos.get(0).activityInfo; |
| 522 | intent.setClassName(activityInfo.packageName, activityInfo.name); |
| 523 | if (channel != null) { |
| 524 | intent.putExtra(Notification.EXTRA_CHANNEL_ID, channel.getId()); |
| 525 | } |
| 526 | intent.putExtra(Notification.EXTRA_NOTIFICATION_ID, id); |
| 527 | intent.putExtra(Notification.EXTRA_NOTIFICATION_TAG, tag); |
| 528 | return intent; |
| 529 | } |
| 530 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 531 | @Override |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 532 | public void setGutsParent(NotificationGuts guts) { |
| 533 | mGutsContainer = guts; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | @Override |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 537 | public boolean willBeRemoved() { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 538 | return false; |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | @Override |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 542 | public boolean shouldBeSaved() { |
Julia Reynolds | 4d1dd79 | 2019-04-29 11:48:29 -0400 | [diff] [blame] | 543 | return mPressedApply; |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | @Override |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 547 | public View getContentView() { |
| 548 | return this; |
| 549 | } |
| 550 | |
| 551 | @Override |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 552 | public boolean handleCloseControls(boolean save, boolean force) { |
Evan Laird | 03cf350 | 2019-05-31 16:46:48 -0400 | [diff] [blame] | 553 | if (mPresentingChannelEditorDialog && mChannelEditorDialogController != null) { |
| 554 | mPresentingChannelEditorDialog = false; |
| 555 | // No need for the finish listener because we're closing |
| 556 | mChannelEditorDialogController.setOnFinishListener(null); |
| 557 | mChannelEditorDialogController.close(); |
| 558 | } |
| 559 | |
Julia Reynolds | c65656a | 2018-02-12 09:55:14 -0500 | [diff] [blame] | 560 | // Save regardless of the importance so we can lock the importance field if the user wants |
| 561 | // to keep getting notifications |
| 562 | if (save) { |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 563 | saveImportance(); |
Geoffrey Pitsch | df44b60 | 2017-02-03 13:31:50 -0500 | [diff] [blame] | 564 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 565 | return false; |
| 566 | } |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 567 | |
| 568 | @Override |
| 569 | public int getActualHeight() { |
Selim Cinek | a5a4ee4 | 2020-05-21 15:38:32 -0700 | [diff] [blame] | 570 | // Because we're animating the bounds, getHeight will return the small height at the |
| 571 | // beginning of the animation. Instead we'd want it to already return the end value |
| 572 | return mActualHeight; |
| 573 | } |
| 574 | |
| 575 | @Override |
| 576 | protected void onLayout(boolean changed, int l, int t, int r, int b) { |
| 577 | super.onLayout(changed, l, t, r, b); |
| 578 | mActualHeight = getHeight(); |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 579 | } |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 580 | |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 581 | @VisibleForTesting |
| 582 | public boolean isAnimating() { |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 583 | return false; |
Gus Prevas | 533836a | 2018-09-24 17:15:32 -0400 | [diff] [blame] | 584 | } |
| 585 | |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Runnable to either update the given channel (with a new importance value) or, if no channel |
| 588 | * is provided, update notifications enabled state for the package. |
| 589 | */ |
| 590 | private static class UpdateImportanceRunnable implements Runnable { |
| 591 | private final INotificationManager mINotificationManager; |
| 592 | private final String mPackageName; |
| 593 | private final int mAppUid; |
| 594 | private final @Nullable NotificationChannel mChannelToUpdate; |
| 595 | private final int mCurrentImportance; |
| 596 | private final int mNewImportance; |
| 597 | |
| 598 | |
| 599 | public UpdateImportanceRunnable(INotificationManager notificationManager, |
| 600 | String packageName, int appUid, @Nullable NotificationChannel channelToUpdate, |
| 601 | int currentImportance, int newImportance) { |
| 602 | mINotificationManager = notificationManager; |
| 603 | mPackageName = packageName; |
| 604 | mAppUid = appUid; |
| 605 | mChannelToUpdate = channelToUpdate; |
| 606 | mCurrentImportance = currentImportance; |
| 607 | mNewImportance = newImportance; |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | public void run() { |
| 612 | try { |
| 613 | if (mChannelToUpdate != null) { |
| 614 | mChannelToUpdate.setImportance(mNewImportance); |
| 615 | mChannelToUpdate.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE); |
| 616 | mINotificationManager.updateNotificationChannelForPackage( |
| 617 | mPackageName, mAppUid, mChannelToUpdate); |
| 618 | } else { |
| 619 | // For notifications with more than one channel, update notification enabled |
| 620 | // state. If the importance was lowered, we disable notifications. |
Rohan Shah | 590e1b2 | 2018-04-10 23:48:47 -0400 | [diff] [blame] | 621 | mINotificationManager.setNotificationsEnabledWithImportanceLockForPackage( |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 622 | mPackageName, mAppUid, mNewImportance >= mCurrentImportance); |
| 623 | } |
| 624 | } catch (RemoteException e) { |
| 625 | Log.e(TAG, "Unable to update notification importance", e); |
| 626 | } |
| 627 | } |
| 628 | } |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 629 | |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 630 | /** |
| 631 | * Returns a LogMaker with all available notification information. |
| 632 | * Caller should set category, type, and maybe subtype, before passing it to mMetricsLogger. |
| 633 | * @return LogMaker |
| 634 | */ |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 635 | private LogMaker getLogMaker() { |
Will Brockman | a399f02 | 2019-01-30 10:59:36 -0500 | [diff] [blame] | 636 | // The constructor requires a category, so also do it in the other branch for consistency. |
| 637 | return mSbn == null ? new LogMaker(MetricsEvent.NOTIFICATION_BLOCKING_HELPER) |
| 638 | : mSbn.getLogMaker().setCategory(MetricsEvent.NOTIFICATION_BLOCKING_HELPER); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Returns an initialized LogMaker for logging importance changes. |
| 643 | * The caller may override the type before passing it to mMetricsLogger. |
| 644 | * @return LogMaker |
| 645 | */ |
| 646 | private LogMaker importanceChangeLogMaker() { |
| 647 | Integer chosenImportance = |
| 648 | mChosenImportance != null ? mChosenImportance : mStartingChannelImportance; |
| 649 | return getLogMaker().setCategory(MetricsEvent.ACTION_SAVE_IMPORTANCE) |
| 650 | .setType(MetricsEvent.TYPE_ACTION) |
| 651 | .setSubtype(chosenImportance - mStartingChannelImportance); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Returns an initialized LogMaker for logging open/close of the info display. |
| 656 | * The caller may override the type before passing it to mMetricsLogger. |
| 657 | * @return LogMaker |
| 658 | */ |
| 659 | private LogMaker notificationControlsLogMaker() { |
| 660 | return getLogMaker().setCategory(MetricsEvent.ACTION_NOTE_CONTROLS) |
| 661 | .setType(MetricsEvent.TYPE_OPEN) |
Julia Reynolds | 143441a | 2020-03-03 08:57:42 -0500 | [diff] [blame] | 662 | .setSubtype(MetricsEvent.BLOCKING_HELPER_UNKNOWN); |
Eyal Posener | a9cf9c7 | 2018-12-18 16:23:54 +0200 | [diff] [blame] | 663 | } |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 664 | |
| 665 | @Retention(SOURCE) |
Julia Reynolds | c3e922b | 2020-01-16 16:12:56 -0500 | [diff] [blame] | 666 | @IntDef({BEHAVIOR_ALERTING, BEHAVIOR_SILENT}) |
Ned Burns | 369f147 | 2019-05-22 21:07:26 -0400 | [diff] [blame] | 667 | private @interface AlertingBehavior {} |
| 668 | private static final int BEHAVIOR_ALERTING = 0; |
| 669 | private static final int BEHAVIOR_SILENT = 1; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 670 | } |