Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | package com.android.systemui.bubbles; |
| 17 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 18 | import static android.os.AsyncTask.Status.FINISHED; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 19 | import static android.view.Display.INVALID_DISPLAY; |
| 20 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 21 | import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE; |
| 22 | |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 23 | import android.annotation.DimenRes; |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 24 | import android.annotation.NonNull; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 25 | import android.annotation.Nullable; |
| 26 | import android.app.Notification; |
| 27 | import android.app.PendingIntent; |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 28 | import android.content.Context; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 29 | import android.content.Intent; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 30 | import android.content.pm.ApplicationInfo; |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 31 | import android.content.pm.PackageManager; |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 32 | import android.content.pm.ShortcutInfo; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 33 | import android.content.res.Resources; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
| 35 | import android.graphics.Path; |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 36 | import android.graphics.drawable.Drawable; |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 37 | import android.graphics.drawable.Icon; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 38 | import android.os.UserHandle; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 39 | import android.provider.Settings; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 40 | import android.util.Log; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 41 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 42 | import com.android.internal.annotations.VisibleForTesting; |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 43 | import com.android.internal.logging.InstanceId; |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 44 | import com.android.systemui.shared.system.SysUiStatsLog; |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 45 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 46 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 47 | import java.io.FileDescriptor; |
| 48 | import java.io.PrintWriter; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 49 | import java.util.Objects; |
| 50 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 51 | /** |
| 52 | * Encapsulates the data and UI elements of a bubble. |
| 53 | */ |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 54 | class Bubble implements BubbleViewProvider { |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 55 | private static final String TAG = "Bubble"; |
| 56 | |
Mark Renouf | 85e0a90 | 2019-04-05 15:51:51 -0400 | [diff] [blame] | 57 | private final String mKey; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 58 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 59 | private long mLastUpdated; |
| 60 | private long mLastAccessed; |
Mady Mellor | 7f23490 | 2019-10-20 12:06:29 -0700 | [diff] [blame] | 61 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 62 | @Nullable |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 63 | private BubbleController.NotificationSuppressionChangedListener mSuppressionListener; |
| 64 | |
| 65 | /** Whether the bubble should show a dot for the notification indicating updated content. */ |
| 66 | private boolean mShowBubbleUpdateDot = true; |
| 67 | |
| 68 | /** Whether flyout text should be suppressed, regardless of any other flags or state. */ |
| 69 | private boolean mSuppressFlyout; |
| 70 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 71 | // Items that are typically loaded later |
| 72 | private String mAppName; |
| 73 | private ShortcutInfo mShortcutInfo; |
Lyn Han | efbaa97 | 2020-06-23 14:59:39 -0700 | [diff] [blame] | 74 | private String mMetadataShortcutId; |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 75 | private BadgedImageView mIconView; |
| 76 | private BubbleExpandedView mExpandedView; |
| 77 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 78 | private BubbleViewInfoTask mInflationTask; |
| 79 | private boolean mInflateSynchronously; |
Lyn Han | 6cb4e5f | 2020-04-27 15:11:18 -0700 | [diff] [blame] | 80 | private boolean mPendingIntentCanceled; |
Santhosh Thangaraj | c39224b | 2020-06-18 10:05:54 -0700 | [diff] [blame] | 81 | private boolean mIsImportantConversation; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 82 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 83 | /** |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 84 | * Presentational info about the flyout. |
| 85 | */ |
| 86 | public static class FlyoutMessage { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 87 | @Nullable public Icon senderIcon; |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 88 | @Nullable public Drawable senderAvatar; |
| 89 | @Nullable public CharSequence senderName; |
| 90 | @Nullable public CharSequence message; |
| 91 | @Nullable public boolean isGroupChat; |
| 92 | } |
| 93 | |
| 94 | private FlyoutMessage mFlyoutMessage; |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 95 | private Drawable mBadgedAppIcon; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 96 | private Bitmap mBadgedImage; |
| 97 | private int mDotColor; |
| 98 | private Path mDotPath; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 99 | private int mFlags; |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 100 | |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 101 | @NonNull |
| 102 | private UserHandle mUser; |
| 103 | @NonNull |
| 104 | private String mPackageName; |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 105 | @Nullable |
| 106 | private String mTitle; |
| 107 | @Nullable |
| 108 | private Icon mIcon; |
| 109 | private boolean mIsBubble; |
| 110 | private boolean mIsVisuallyInterruptive; |
| 111 | private boolean mIsClearable; |
| 112 | private boolean mShouldSuppressNotificationDot; |
| 113 | private boolean mShouldSuppressNotificationList; |
| 114 | private boolean mShouldSuppressPeek; |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 115 | private int mDesiredHeight; |
| 116 | @DimenRes |
| 117 | private int mDesiredHeightResId; |
| 118 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 119 | /** for logging **/ |
| 120 | @Nullable |
| 121 | private InstanceId mInstanceId; |
| 122 | @Nullable |
| 123 | private String mChannelId; |
| 124 | private int mNotificationId; |
| 125 | private int mAppUid = -1; |
| 126 | |
| 127 | @Nullable |
| 128 | private PendingIntent mIntent; |
| 129 | @Nullable |
| 130 | private PendingIntent mDeleteIntent; |
| 131 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 132 | /** |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 133 | * Create a bubble with limited information based on given {@link ShortcutInfo}. |
| 134 | * Note: Currently this is only being used when the bubble is persisted to disk. |
| 135 | */ |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 136 | Bubble(@NonNull final String key, @NonNull final ShortcutInfo shortcutInfo, |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 137 | final int desiredHeight, final int desiredHeightResId, @Nullable final String title) { |
Pinyao Ting | 6a8fab0 | 2020-05-21 14:30:21 -0700 | [diff] [blame] | 138 | Objects.requireNonNull(key); |
| 139 | Objects.requireNonNull(shortcutInfo); |
Josh Tsuji | 050b48d | 2020-06-24 14:22:13 -0400 | [diff] [blame] | 140 | mMetadataShortcutId = shortcutInfo.getId(); |
Pinyao Ting | d4c1ba9 | 2020-05-04 20:29:56 -0700 | [diff] [blame] | 141 | mShortcutInfo = shortcutInfo; |
Pinyao Ting | 6a8fab0 | 2020-05-21 14:30:21 -0700 | [diff] [blame] | 142 | mKey = key; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 143 | mFlags = 0; |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 144 | mUser = shortcutInfo.getUserHandle(); |
| 145 | mPackageName = shortcutInfo.getPackage(); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 146 | mIcon = shortcutInfo.getIcon(); |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 147 | mDesiredHeight = desiredHeight; |
| 148 | mDesiredHeightResId = desiredHeightResId; |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 149 | mTitle = title; |
Mady Mellor | 1c264ea | 2020-06-17 16:52:57 -0700 | [diff] [blame] | 150 | mShowBubbleUpdateDot = false; |
Pinyao Ting | d4c1ba9 | 2020-05-04 20:29:56 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 153 | /** Used in tests when no UI is required. */ |
| 154 | @VisibleForTesting(visibility = PRIVATE) |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 155 | Bubble(@NonNull final NotificationEntry e, |
| 156 | @Nullable final BubbleController.NotificationSuppressionChangedListener listener) { |
| 157 | Objects.requireNonNull(e); |
Pinyao Ting | 6a8fab0 | 2020-05-21 14:30:21 -0700 | [diff] [blame] | 158 | mKey = e.getKey(); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 159 | mSuppressionListener = listener; |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 160 | setEntry(e); |
Mark Renouf | 85e0a90 | 2019-04-05 15:51:51 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 163 | @Override |
Mark Renouf | 85e0a90 | 2019-04-05 15:51:51 -0400 | [diff] [blame] | 164 | public String getKey() { |
| 165 | return mKey; |
| 166 | } |
| 167 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 168 | public UserHandle getUser() { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 169 | return mUser; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 172 | @NonNull |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 173 | public String getPackageName() { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 174 | return mPackageName; |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 177 | @Override |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 178 | public Bitmap getBadgedImage() { |
| 179 | return mBadgedImage; |
| 180 | } |
| 181 | |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 182 | public Drawable getBadgedAppIcon() { |
| 183 | return mBadgedAppIcon; |
| 184 | } |
| 185 | |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 186 | @Override |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 187 | public int getDotColor() { |
| 188 | return mDotColor; |
| 189 | } |
| 190 | |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 191 | @Override |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 192 | public Path getDotPath() { |
| 193 | return mDotPath; |
| 194 | } |
| 195 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 196 | @Nullable |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 197 | public String getAppName() { |
| 198 | return mAppName; |
| 199 | } |
| 200 | |
Mady Mellor | b547e5e | 2019-12-02 10:15:56 -0800 | [diff] [blame] | 201 | @Nullable |
| 202 | public ShortcutInfo getShortcutInfo() { |
| 203 | return mShortcutInfo; |
| 204 | } |
| 205 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 206 | @Nullable |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 207 | @Override |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 208 | public BadgedImageView getIconView() { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 209 | return mIconView; |
| 210 | } |
| 211 | |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 212 | @Override |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 213 | @Nullable |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 214 | public BubbleExpandedView getExpandedView() { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 215 | return mExpandedView; |
| 216 | } |
| 217 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 218 | @Nullable |
| 219 | public String getTitle() { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 220 | return mTitle; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Lyn Han | efbaa97 | 2020-06-23 14:59:39 -0700 | [diff] [blame] | 223 | String getMetadataShortcutId() { |
| 224 | return mMetadataShortcutId; |
| 225 | } |
| 226 | |
| 227 | boolean hasMetadataShortcutId() { |
| 228 | return (mMetadataShortcutId != null && !mMetadataShortcutId.isEmpty()); |
| 229 | } |
| 230 | |
Mady Mellor | e967e96 | 2020-03-26 17:36:44 -0700 | [diff] [blame] | 231 | /** |
| 232 | * Call when the views should be removed, ensure this is called to clean up ActivityView |
| 233 | * content. |
| 234 | */ |
| 235 | void cleanupViews() { |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 236 | if (mExpandedView != null) { |
| 237 | mExpandedView.cleanUpExpandedState(); |
Mady Mellor | e967e96 | 2020-03-26 17:36:44 -0700 | [diff] [blame] | 238 | mExpandedView = null; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 239 | } |
Mady Mellor | e967e96 | 2020-03-26 17:36:44 -0700 | [diff] [blame] | 240 | mIconView = null; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 241 | } |
| 242 | |
Lyn Han | 6cb4e5f | 2020-04-27 15:11:18 -0700 | [diff] [blame] | 243 | void setPendingIntentCanceled() { |
| 244 | mPendingIntentCanceled = true; |
| 245 | } |
| 246 | |
| 247 | boolean getPendingIntentCanceled() { |
| 248 | return mPendingIntentCanceled; |
| 249 | } |
| 250 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 251 | /** |
| 252 | * Sets whether to perform inflation on the same thread as the caller. This method should only |
| 253 | * be used in tests, not in production. |
| 254 | */ |
| 255 | @VisibleForTesting |
| 256 | void setInflateSynchronously(boolean inflateSynchronously) { |
| 257 | mInflateSynchronously = inflateSynchronously; |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Starts a task to inflate & load any necessary information to display a bubble. |
| 262 | * |
| 263 | * @param callback the callback to notify one the bubble is ready to be displayed. |
| 264 | * @param context the context for the bubble. |
| 265 | * @param stackView the stackView the bubble is eventually added to. |
| 266 | * @param iconFactory the iconfactory use to create badged images for the bubble. |
| 267 | */ |
| 268 | void inflate(BubbleViewInfoTask.Callback callback, |
| 269 | Context context, |
| 270 | BubbleStackView stackView, |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 271 | BubbleIconFactory iconFactory, |
| 272 | boolean skipInflation) { |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 273 | if (isBubbleLoading()) { |
| 274 | mInflationTask.cancel(true /* mayInterruptIfRunning */); |
Mark Renouf | 85e0a90 | 2019-04-05 15:51:51 -0400 | [diff] [blame] | 275 | } |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 276 | mInflationTask = new BubbleViewInfoTask(this, |
| 277 | context, |
| 278 | stackView, |
| 279 | iconFactory, |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 280 | skipInflation, |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 281 | callback); |
| 282 | if (mInflateSynchronously) { |
| 283 | mInflationTask.onPostExecute(mInflationTask.doInBackground()); |
| 284 | } else { |
| 285 | mInflationTask.execute(); |
| 286 | } |
| 287 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 288 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 289 | private boolean isBubbleLoading() { |
| 290 | return mInflationTask != null && mInflationTask.getStatus() != FINISHED; |
| 291 | } |
Lyn Han | 6c40fe7 | 2019-05-08 14:06:33 -0700 | [diff] [blame] | 292 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 293 | boolean isInflated() { |
Mady Mellor | e967e96 | 2020-03-26 17:36:44 -0700 | [diff] [blame] | 294 | return mIconView != null && mExpandedView != null; |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 297 | void stopInflation() { |
| 298 | if (mInflationTask == null) { |
| 299 | return; |
| 300 | } |
Mady Mellor | e967e96 | 2020-03-26 17:36:44 -0700 | [diff] [blame] | 301 | mInflationTask.cancel(true /* mayInterruptIfRunning */); |
| 302 | cleanupViews(); |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 305 | void setViewInfo(BubbleViewInfoTask.BubbleViewInfo info) { |
| 306 | if (!isInflated()) { |
| 307 | mIconView = info.imageView; |
| 308 | mExpandedView = info.expandedView; |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | mShortcutInfo = info.shortcutInfo; |
| 312 | mAppName = info.appName; |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 313 | mFlyoutMessage = info.flyoutMessage; |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 314 | |
Joshua Tsuji | 6855cab | 2020-04-16 01:05:39 -0400 | [diff] [blame] | 315 | mBadgedAppIcon = info.badgedAppIcon; |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 316 | mBadgedImage = info.badgedBubbleImage; |
| 317 | mDotColor = info.dotColor; |
| 318 | mDotPath = info.dotPath; |
| 319 | |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 320 | if (mExpandedView != null) { |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 321 | mExpandedView.update(this /* bubble */); |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 322 | } |
| 323 | if (mIconView != null) { |
Mady Mellor | 458a626 | 2020-06-07 21:09:19 -0700 | [diff] [blame] | 324 | mIconView.setRenderedBubble(this /* bubble */); |
Lyn Han | 18cdc1c | 2020-03-18 19:12:42 -0700 | [diff] [blame] | 325 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 326 | } |
| 327 | |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 328 | /** |
| 329 | * Set visibility of bubble in the expanded state. |
| 330 | * |
| 331 | * @param visibility {@code true} if the expanded bubble should be visible on the screen. |
| 332 | * |
| 333 | * Note that this contents visibility doesn't affect visibility at {@link android.view.View}, |
| 334 | * and setting {@code false} actually means rendering the expanded view in transparent. |
| 335 | */ |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 336 | @Override |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 337 | public void setContentVisibility(boolean visibility) { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 338 | if (mExpandedView != null) { |
| 339 | mExpandedView.setContentVisibility(visibility); |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 343 | /** |
| 344 | * Sets the entry associated with this bubble. |
| 345 | */ |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 346 | void setEntry(@NonNull final NotificationEntry entry) { |
| 347 | Objects.requireNonNull(entry); |
| 348 | Objects.requireNonNull(entry.getSbn()); |
Ned Burns | 00b4b2d | 2019-10-17 22:09:27 -0400 | [diff] [blame] | 349 | mLastUpdated = entry.getSbn().getPostTime(); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 350 | mIsBubble = entry.getSbn().getNotification().isBubbleNotification(); |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 351 | mPackageName = entry.getSbn().getPackageName(); |
| 352 | mUser = entry.getSbn().getUser(); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 353 | mTitle = getTitle(entry); |
| 354 | mIsClearable = entry.isClearable(); |
| 355 | mShouldSuppressNotificationDot = entry.shouldSuppressNotificationDot(); |
| 356 | mShouldSuppressNotificationList = entry.shouldSuppressNotificationList(); |
| 357 | mShouldSuppressPeek = entry.shouldSuppressPeek(); |
| 358 | mChannelId = entry.getSbn().getNotification().getChannelId(); |
| 359 | mNotificationId = entry.getSbn().getId(); |
| 360 | mAppUid = entry.getSbn().getUid(); |
| 361 | mInstanceId = entry.getSbn().getInstanceId(); |
| 362 | mFlyoutMessage = BubbleViewInfoTask.extractFlyoutMessage(entry); |
Lyn Han | efbaa97 | 2020-06-23 14:59:39 -0700 | [diff] [blame] | 363 | mShortcutInfo = (entry.getRanking() != null ? entry.getRanking().getShortcutInfo() : null); |
| 364 | mMetadataShortcutId = (entry.getBubbleMetadata() != null |
| 365 | ? entry.getBubbleMetadata().getShortcutId() : null); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 366 | if (entry.getRanking() != null) { |
| 367 | mIsVisuallyInterruptive = entry.getRanking().visuallyInterruptive(); |
| 368 | } |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 369 | if (entry.getBubbleMetadata() != null) { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 370 | mFlags = entry.getBubbleMetadata().getFlags(); |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 371 | mDesiredHeight = entry.getBubbleMetadata().getDesiredHeight(); |
| 372 | mDesiredHeightResId = entry.getBubbleMetadata().getDesiredHeightResId(); |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 373 | mIcon = entry.getBubbleMetadata().getIcon(); |
| 374 | mIntent = entry.getBubbleMetadata().getIntent(); |
| 375 | mDeleteIntent = entry.getBubbleMetadata().getDeleteIntent(); |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 376 | } |
Santhosh Thangaraj | c39224b | 2020-06-18 10:05:54 -0700 | [diff] [blame] | 377 | mIsImportantConversation = |
| 378 | entry.getChannel() == null ? false : entry.getChannel().isImportantConversation(); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 379 | } |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 380 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 381 | @Nullable |
| 382 | Icon getIcon() { |
| 383 | return mIcon; |
| 384 | } |
| 385 | |
| 386 | boolean isVisuallyInterruptive() { |
| 387 | return mIsVisuallyInterruptive; |
| 388 | } |
| 389 | |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 390 | /** |
Mady Mellor | a55133d | 2020-05-01 15:11:10 -0700 | [diff] [blame] | 391 | * @return the last time this bubble was updated or accessed, whichever is most recent. |
Mark Renouf | ba5ab51 | 2019-05-02 15:21:01 -0400 | [diff] [blame] | 392 | */ |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 393 | long getLastActivity() { |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 394 | return Math.max(mLastUpdated, mLastAccessed); |
| 395 | } |
| 396 | |
| 397 | /** |
Lyn Han | 6cb4e5f | 2020-04-27 15:11:18 -0700 | [diff] [blame] | 398 | * @return if the bubble was ever expanded |
| 399 | */ |
| 400 | boolean getWasAccessed() { |
| 401 | return mLastAccessed != 0L; |
| 402 | } |
| 403 | |
| 404 | /** |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 405 | * @return the display id of the virtual display on which bubble contents is drawn. |
| 406 | */ |
Lyn Han | 9f66c3b | 2020-03-05 23:59:29 -0800 | [diff] [blame] | 407 | @Override |
| 408 | public int getDisplayId() { |
Mady Mellor | ed99c27 | 2019-06-13 15:58:30 -0700 | [diff] [blame] | 409 | return mExpandedView != null ? mExpandedView.getVirtualDisplayId() : INVALID_DISPLAY; |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 410 | } |
| 411 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 412 | public InstanceId getInstanceId() { |
| 413 | return mInstanceId; |
| 414 | } |
| 415 | |
| 416 | @Nullable |
| 417 | public String getChannelId() { |
| 418 | return mChannelId; |
| 419 | } |
| 420 | |
| 421 | public int getNotificationId() { |
| 422 | return mNotificationId; |
| 423 | } |
| 424 | |
Issei Suzuki | cac2a50 | 2019-04-16 16:52:50 +0200 | [diff] [blame] | 425 | /** |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 426 | * Should be invoked whenever a Bubble is accessed (selected while expanded). |
| 427 | */ |
| 428 | void markAsAccessedAt(long lastAccessedMillis) { |
| 429 | mLastAccessed = lastAccessedMillis; |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 430 | setSuppressNotification(true); |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 431 | setShowDot(false /* show */); |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
Lyn Han | b58c756 | 2020-01-07 14:29:20 -0800 | [diff] [blame] | 435 | * Should be invoked whenever a Bubble is promoted from overflow. |
| 436 | */ |
| 437 | void markUpdatedAt(long lastAccessedMillis) { |
| 438 | mLastUpdated = lastAccessedMillis; |
| 439 | } |
| 440 | |
| 441 | /** |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 442 | * Whether this notification should be shown in the shade. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 443 | */ |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 444 | boolean showInShade() { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 445 | return !shouldSuppressNotification() || !mIsClearable; |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | /** |
Santhosh Thangaraj | c39224b | 2020-06-18 10:05:54 -0700 | [diff] [blame] | 449 | * Whether this notification conversation is important. |
| 450 | */ |
| 451 | boolean isImportantConversation() { |
| 452 | return mIsImportantConversation; |
| 453 | } |
| 454 | |
| 455 | /** |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 456 | * Sets whether this notification should be suppressed in the shade. |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 457 | */ |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 458 | void setSuppressNotification(boolean suppressNotification) { |
| 459 | boolean prevShowInShade = showInShade(); |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 460 | if (suppressNotification) { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 461 | mFlags |= Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 462 | } else { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 463 | mFlags &= ~Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 464 | } |
Mady Mellor | f44b683 | 2020-01-14 13:26:14 -0800 | [diff] [blame] | 465 | |
| 466 | if (showInShade() != prevShowInShade && mSuppressionListener != null) { |
| 467 | mSuppressionListener.onBubbleNotificationSuppressionChange(this); |
| 468 | } |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /** |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 472 | * Sets whether the bubble for this notification should show a dot indicating updated content. |
| 473 | */ |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 474 | void setShowDot(boolean showDot) { |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 475 | mShowBubbleUpdateDot = showDot; |
Joshua Tsuji | 2ed260e | 2020-03-26 14:26:01 -0400 | [diff] [blame] | 476 | |
| 477 | if (mIconView != null) { |
| 478 | mIconView.updateDotVisibility(true /* animate */); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 479 | } |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Whether the bubble for this notification should show a dot indicating updated content. |
| 484 | */ |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 485 | @Override |
| 486 | public boolean showDot() { |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 487 | return mShowBubbleUpdateDot |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 488 | && !mShouldSuppressNotificationDot |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 489 | && !shouldSuppressNotification(); |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Whether the flyout for the bubble should be shown. |
| 494 | */ |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 495 | boolean showFlyout() { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 496 | return !mSuppressFlyout && !mShouldSuppressPeek |
Mady Mellor | b25f906 | 2019-12-09 12:12:57 -0800 | [diff] [blame] | 497 | && !shouldSuppressNotification() |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 498 | && !mShouldSuppressNotificationList; |
Mark Renouf | c19b473 | 2019-06-26 12:08:33 -0400 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Set whether the flyout text for the bubble should be shown when an update is received. |
| 503 | * |
| 504 | * @param suppressFlyout whether the flyout text is shown |
| 505 | */ |
| 506 | void setSuppressFlyout(boolean suppressFlyout) { |
| 507 | mSuppressFlyout = suppressFlyout; |
Mady Mellor | df48d0a | 2019-06-25 18:26:46 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Mady Mellor | df898fd | 2020-01-09 09:26:36 -0800 | [diff] [blame] | 510 | FlyoutMessage getFlyoutMessage() { |
| 511 | return mFlyoutMessage; |
| 512 | } |
| 513 | |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 514 | int getRawDesiredHeight() { |
| 515 | return mDesiredHeight; |
| 516 | } |
| 517 | |
| 518 | int getRawDesiredHeightResId() { |
| 519 | return mDesiredHeightResId; |
| 520 | } |
| 521 | |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 522 | float getDesiredHeight(Context context) { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 523 | boolean useRes = mDesiredHeightResId != 0; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 524 | if (useRes) { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 525 | return getDimenForPackageUser(context, mDesiredHeightResId, mPackageName, |
| 526 | mUser.getIdentifier()); |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 527 | } else { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 528 | return mDesiredHeight * context.getResources().getDisplayMetrics().density; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 532 | String getDesiredHeightString() { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 533 | boolean useRes = mDesiredHeightResId != 0; |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 534 | if (useRes) { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 535 | return String.valueOf(mDesiredHeightResId); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 536 | } else { |
Pinyao Ting | b073b76 | 2020-06-04 11:15:03 -0700 | [diff] [blame] | 537 | return String.valueOf(mDesiredHeight); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 541 | @Nullable |
| 542 | PendingIntent getBubbleIntent() { |
| 543 | return mIntent; |
Mady Mellor | 3df7ab0 | 2019-12-09 15:07:10 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 546 | @Nullable |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 547 | PendingIntent getDeleteIntent() { |
| 548 | return mDeleteIntent; |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 551 | Intent getSettingsIntent(final Context context) { |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 552 | final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); |
| 553 | intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName()); |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 554 | final int uid = getUid(context); |
| 555 | if (uid != -1) { |
| 556 | intent.putExtra(Settings.EXTRA_APP_UID, uid); |
| 557 | } |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 558 | intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 559 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 560 | intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 561 | return intent; |
| 562 | } |
| 563 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 564 | public int getAppUid() { |
| 565 | return mAppUid; |
| 566 | } |
| 567 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 568 | private int getUid(final Context context) { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 569 | if (mAppUid != -1) return mAppUid; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 570 | final PackageManager pm = context.getPackageManager(); |
| 571 | if (pm == null) return -1; |
| 572 | try { |
| 573 | final ApplicationInfo info = pm.getApplicationInfo(mShortcutInfo.getPackage(), 0); |
| 574 | return info.uid; |
| 575 | } catch (PackageManager.NameNotFoundException e) { |
| 576 | Log.e(TAG, "cannot find uid", e); |
| 577 | } |
| 578 | return -1; |
| 579 | } |
| 580 | |
Mady Mellor | 99a30260 | 2019-06-14 11:39:56 -0700 | [diff] [blame] | 581 | private int getDimenForPackageUser(Context context, int resId, String pkg, int userId) { |
| 582 | PackageManager pm = context.getPackageManager(); |
| 583 | Resources r; |
| 584 | if (pkg != null) { |
| 585 | try { |
| 586 | if (userId == UserHandle.USER_ALL) { |
| 587 | userId = UserHandle.USER_SYSTEM; |
| 588 | } |
| 589 | r = pm.getResourcesForApplicationAsUser(pkg, userId); |
| 590 | return r.getDimensionPixelSize(resId); |
| 591 | } catch (PackageManager.NameNotFoundException ex) { |
| 592 | // Uninstalled, don't care |
| 593 | } catch (Resources.NotFoundException e) { |
| 594 | // Invalid res id, return 0 and user our default |
| 595 | Log.e(TAG, "Couldn't find desired height res id", e); |
| 596 | } |
| 597 | } |
| 598 | return 0; |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 601 | private boolean shouldSuppressNotification() { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 602 | return isEnabled(Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION); |
Mady Mellor | ce23c46 | 2019-06-17 17:30:07 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 605 | public boolean shouldAutoExpand() { |
| 606 | return isEnabled(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE); |
Mady Mellor | 7634301 | 2020-05-13 11:02:50 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | void setShouldAutoExpand(boolean shouldAutoExpand) { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 610 | if (shouldAutoExpand) { |
| 611 | enable(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE); |
| 612 | } else { |
| 613 | disable(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | public void setIsBubble(final boolean isBubble) { |
| 618 | mIsBubble = isBubble; |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 621 | public boolean isBubble() { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 622 | return mIsBubble; |
Pinyao Ting | 3c93061 | 2020-05-19 00:26:03 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | public void enable(int option) { |
| 626 | mFlags |= option; |
| 627 | } |
| 628 | |
| 629 | public void disable(int option) { |
| 630 | mFlags &= ~option; |
| 631 | } |
| 632 | |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 633 | public boolean isEnabled(int option) { |
| 634 | return (mFlags & option) != 0; |
| 635 | } |
| 636 | |
Mark Renouf | 9ba6cea | 2019-04-17 11:53:50 -0400 | [diff] [blame] | 637 | @Override |
| 638 | public String toString() { |
| 639 | return "Bubble{" + mKey + '}'; |
| 640 | } |
| 641 | |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 642 | /** |
| 643 | * Description of current bubble state. |
| 644 | */ |
| 645 | public void dump( |
| 646 | @NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) { |
| 647 | pw.print("key: "); pw.println(mKey); |
Mady Mellor | b8aaf97 | 2019-11-26 10:28:00 -0800 | [diff] [blame] | 648 | pw.print(" showInShade: "); pw.println(showInShade()); |
| 649 | pw.print(" showDot: "); pw.println(showDot()); |
| 650 | pw.print(" showFlyout: "); pw.println(showFlyout()); |
Mady Mellor | 70cba7bb | 2019-07-02 15:06:07 -0700 | [diff] [blame] | 651 | pw.print(" desiredHeight: "); pw.println(getDesiredHeightString()); |
| 652 | pw.print(" suppressNotif: "); pw.println(shouldSuppressNotification()); |
| 653 | pw.print(" autoExpand: "); pw.println(shouldAutoExpand()); |
| 654 | } |
| 655 | |
Mark Renouf | 71a3af6 | 2019-04-08 15:02:54 -0400 | [diff] [blame] | 656 | @Override |
| 657 | public boolean equals(Object o) { |
| 658 | if (this == o) return true; |
| 659 | if (!(o instanceof Bubble)) return false; |
| 660 | Bubble bubble = (Bubble) o; |
| 661 | return Objects.equals(mKey, bubble.mKey); |
| 662 | } |
| 663 | |
| 664 | @Override |
| 665 | public int hashCode() { |
| 666 | return Objects.hash(mKey); |
| 667 | } |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 668 | |
Lyn Han | cd4f87e | 2020-02-19 20:33:45 -0800 | [diff] [blame] | 669 | @Override |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 670 | public void logUIEvent(int bubbleCount, int action, float normalX, float normalY, int index) { |
Pinyao Ting | 175a5b8 | 2020-06-15 23:41:14 +0000 | [diff] [blame] | 671 | SysUiStatsLog.write(SysUiStatsLog.BUBBLE_UI_CHANGED, |
| 672 | mPackageName, |
| 673 | mChannelId, |
| 674 | mNotificationId, |
| 675 | index, |
| 676 | bubbleCount, |
| 677 | action, |
| 678 | normalX, |
| 679 | normalY, |
| 680 | showInShade(), |
| 681 | false /* isOngoing (unused) */, |
| 682 | false /* isAppForeground (unused) */); |
| 683 | } |
| 684 | |
| 685 | @Nullable |
| 686 | private static String getTitle(@NonNull final NotificationEntry e) { |
| 687 | final CharSequence titleCharSeq = e.getSbn().getNotification().extras.getCharSequence( |
| 688 | Notification.EXTRA_TITLE); |
| 689 | return titleCharSeq == null ? null : titleCharSeq.toString(); |
Lyn Han | 3cd75d7 | 2020-02-15 19:10:12 -0800 | [diff] [blame] | 690 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 691 | } |