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