| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.wm.shell.bubbles; |
| 17 |
|
| 18 |
import static android.app.ActivityTaskManager.INVALID_TASK_ID; |
| 19 |
import static android.os.AsyncTask.Status.FINISHED; |
| 20 |
|
| 21 |
import static com.android.internal.annotations.VisibleForTesting.Visibility.PRIVATE; |
| 22 |
|
| 23 |
import android.annotation.DimenRes; |
| 24 |
import android.annotation.NonNull; |
| 25 |
import android.annotation.Nullable; |
| 26 |
import android.app.Notification; |
| 27 |
import android.app.PendingIntent; |
| 28 |
import android.app.Person; |
| 29 |
import android.content.Context; |
| 30 |
import android.content.Intent; |
| 31 |
import android.content.LocusId; |
| 32 |
import android.content.pm.ApplicationInfo; |
| 33 |
import android.content.pm.PackageManager; |
| 34 |
import android.content.pm.ShortcutInfo; |
| 35 |
import android.content.res.Resources; |
| 36 |
import android.graphics.Bitmap; |
| 37 |
import android.graphics.Path; |
| 38 |
import android.graphics.drawable.Drawable; |
| 39 |
import android.graphics.drawable.Icon; |
| 40 |
import android.os.Parcelable; |
| 41 |
import android.os.UserHandle; |
| 42 |
import android.provider.Settings; |
| 43 |
import android.service.notification.StatusBarNotification; |
| 44 |
import android.text.TextUtils; |
| 45 |
import android.util.Log; |
| 46 |
|
| 47 |
import com.android.internal.annotations.VisibleForTesting; |
| 48 |
import com.android.internal.logging.InstanceId; |
| 49 |
|
| 50 |
import java.io.PrintWriter; |
| 51 |
import java.util.List; |
| 52 |
import java.util.Objects; |
| 53 |
import java.util.concurrent.Executor; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
@VisibleForTesting |
| 59 |
public class Bubble implements BubbleViewProvider { |
| 60 |
private static final String TAG = "Bubble"; |
| 61 |
|
| 62 |
public static final String KEY_APP_BUBBLE = "key_app_bubble"; |
| 63 |
|
| 64 |
private final String mKey; |
| 65 |
@Nullable |
| 66 |
private final String mGroupKey; |
| 67 |
@Nullable |
| 68 |
private final LocusId mLocusId; |
| 69 |
|
| 70 |
private final Executor mMainExecutor; |
| 71 |
|
| 72 |
private long mLastUpdated; |
| 73 |
private long mLastAccessed; |
| 74 |
|
| 75 |
@Nullable |
| 76 |
private Bubbles.BubbleMetadataFlagListener mBubbleMetadataFlagListener; |
| 77 |
|
| 78 |
|
| 79 |
private boolean mShowBubbleUpdateDot = true; |
| 80 |
|
| 81 |
|
| 82 |
private boolean mSuppressFlyout; |
| 83 |
|
| 84 |
|
| 85 |
private String mAppName; |
| 86 |
private ShortcutInfo mShortcutInfo; |
| 87 |
private String mMetadataShortcutId; |
| 88 |
private BadgedImageView mIconView; |
| 89 |
private BubbleExpandedView mExpandedView; |
| 90 |
|
| 91 |
private BubbleViewInfoTask mInflationTask; |
| 92 |
private boolean mInflateSynchronously; |
| 93 |
private boolean mPendingIntentCanceled; |
| 94 |
private boolean mIsImportantConversation; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public static class FlyoutMessage { |
| 100 |
@Nullable public Icon senderIcon; |
| 101 |
@Nullable public Drawable senderAvatar; |
| 102 |
@Nullable public CharSequence senderName; |
| 103 |
@Nullable public CharSequence message; |
| 104 |
@Nullable public boolean isGroupChat; |
| 105 |
} |
| 106 |
|
| 107 |
private FlyoutMessage mFlyoutMessage; |
| 108 |
|
| 109 |
private Bitmap mBubbleBitmap; |
| 110 |
|
| 111 |
private Bitmap mBadgeBitmap; |
| 112 |
|
| 113 |
private Bitmap mRawBadgeBitmap; |
| 114 |
private int mDotColor; |
| 115 |
private Path mDotPath; |
| 116 |
private int mFlags; |
| 117 |
|
| 118 |
@NonNull |
| 119 |
private UserHandle mUser; |
| 120 |
@NonNull |
| 121 |
private String mPackageName; |
| 122 |
@Nullable |
| 123 |
private String mTitle; |
| 124 |
@Nullable |
| 125 |
private Icon mIcon; |
| 126 |
private boolean mIsBubble; |
| 127 |
private boolean mIsTextChanged; |
| 128 |
private boolean mIsClearable; |
| 129 |
private boolean mShouldSuppressNotificationDot; |
| 130 |
private boolean mShouldSuppressNotificationList; |
| 131 |
private boolean mShouldSuppressPeek; |
| 132 |
private int mDesiredHeight; |
| 133 |
@DimenRes |
| 134 |
private int mDesiredHeightResId; |
| 135 |
private int mTaskId; |
| 136 |
|
| 137 |
|
| 138 |
@Nullable |
| 139 |
private InstanceId mInstanceId; |
| 140 |
@Nullable |
| 141 |
private String mChannelId; |
| 142 |
private int mNotificationId; |
| 143 |
private int mAppUid = -1; |
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
@Nullable |
| 156 |
private PendingIntent mIntent; |
| 157 |
private boolean mIntentActive; |
| 158 |
@Nullable |
| 159 |
private PendingIntent.CancelListener mIntentCancelListener; |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
@Nullable |
| 166 |
private PendingIntent mDeleteIntent; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
@Nullable |
| 174 |
private Intent mAppIntent; |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
@VisibleForTesting(visibility = PRIVATE) |
| 181 |
public Bubble(@NonNull final String key, @NonNull final ShortcutInfo shortcutInfo, |
| 182 |
final int desiredHeight, final int desiredHeightResId, @Nullable final String title, |
| 183 |
int taskId, @Nullable final String locus, Executor mainExecutor, |
| 184 |
final Bubbles.BubbleMetadataFlagListener listener) { |
| 185 |
Objects.requireNonNull(key); |
| 186 |
Objects.requireNonNull(shortcutInfo); |
| 187 |
mMetadataShortcutId = shortcutInfo.getId(); |
| 188 |
mShortcutInfo = shortcutInfo; |
| 189 |
mKey = key; |
| 190 |
mGroupKey = null; |
| 191 |
mLocusId = locus != null ? new LocusId(locus) : null; |
| 192 |
mFlags = 0; |
| 193 |
mUser = shortcutInfo.getUserHandle(); |
| 194 |
mPackageName = shortcutInfo.getPackage(); |
| 195 |
mIcon = shortcutInfo.getIcon(); |
| 196 |
mDesiredHeight = desiredHeight; |
| 197 |
mDesiredHeightResId = desiredHeightResId; |
| 198 |
mTitle = title; |
| 199 |
mShowBubbleUpdateDot = false; |
| 200 |
mMainExecutor = mainExecutor; |
| 201 |
mTaskId = taskId; |
| 202 |
mBubbleMetadataFlagListener = listener; |
| 203 |
} |
| 204 |
|
| 205 |
public Bubble(Intent intent, |
| 206 |
UserHandle user, |
| 207 |
Executor mainExecutor) { |
| 208 |
mKey = KEY_APP_BUBBLE; |
| 209 |
mGroupKey = null; |
| 210 |
mLocusId = null; |
| 211 |
mFlags = 0; |
| 212 |
mUser = user; |
| 213 |
mShowBubbleUpdateDot = false; |
| 214 |
mMainExecutor = mainExecutor; |
| 215 |
mTaskId = INVALID_TASK_ID; |
| 216 |
mAppIntent = intent; |
| 217 |
mDesiredHeight = Integer.MAX_VALUE; |
| 218 |
mPackageName = intent.getPackage(); |
| 219 |
} |
| 220 |
|
| 221 |
@VisibleForTesting(visibility = PRIVATE) |
| 222 |
public Bubble(@NonNull final BubbleEntry entry, |
| 223 |
final Bubbles.BubbleMetadataFlagListener listener, |
| 224 |
final Bubbles.PendingIntentCanceledListener intentCancelListener, |
| 225 |
Executor mainExecutor) { |
| 226 |
mKey = entry.getKey(); |
| 227 |
mGroupKey = entry.getGroupKey(); |
| 228 |
mLocusId = entry.getLocusId(); |
| 229 |
mBubbleMetadataFlagListener = listener; |
| 230 |
mIntentCancelListener = intent -> { |
| 231 |
if (mIntent != null) { |
| 232 |
mIntent.unregisterCancelListener(mIntentCancelListener); |
| 233 |
} |
| 234 |
mainExecutor.execute(() -> { |
| 235 |
intentCancelListener.onPendingIntentCanceled(this); |
| 236 |
}); |
| 237 |
}; |
| 238 |
mMainExecutor = mainExecutor; |
| 239 |
mTaskId = INVALID_TASK_ID; |
| 240 |
setEntry(entry); |
| 241 |
} |
| 242 |
|
| 243 |
@Override |
| 244 |
public String getKey() { |
| 245 |
return mKey; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
public String getGroupKey() { |
| 253 |
return mGroupKey; |
| 254 |
} |
| 255 |
|
| 256 |
public LocusId getLocusId() { |
| 257 |
return mLocusId; |
| 258 |
} |
| 259 |
|
| 260 |
public UserHandle getUser() { |
| 261 |
return mUser; |
| 262 |
} |
| 263 |
|
| 264 |
@NonNull |
| 265 |
public String getPackageName() { |
| 266 |
return mPackageName; |
| 267 |
} |
| 268 |
|
| 269 |
@Override |
| 270 |
public Bitmap getBubbleIcon() { |
| 271 |
return mBubbleBitmap; |
| 272 |
} |
| 273 |
|
| 274 |
@Override |
| 275 |
public Bitmap getAppBadge() { |
| 276 |
return mBadgeBitmap; |
| 277 |
} |
| 278 |
|
| 279 |
@Override |
| 280 |
public Bitmap getRawAppBadge() { |
| 281 |
return mRawBadgeBitmap; |
| 282 |
} |
| 283 |
|
| 284 |
@Override |
| 285 |
public int getDotColor() { |
| 286 |
return mDotColor; |
| 287 |
} |
| 288 |
|
| 289 |
@Override |
| 290 |
public Path getDotPath() { |
| 291 |
return mDotPath; |
| 292 |
} |
| 293 |
|
| 294 |
@Nullable |
| 295 |
public String getAppName() { |
| 296 |
return mAppName; |
| 297 |
} |
| 298 |
|
| 299 |
@Nullable |
| 300 |
public ShortcutInfo getShortcutInfo() { |
| 301 |
return mShortcutInfo; |
| 302 |
} |
| 303 |
|
| 304 |
@Nullable |
| 305 |
@Override |
| 306 |
public BadgedImageView getIconView() { |
| 307 |
return mIconView; |
| 308 |
} |
| 309 |
|
| 310 |
@Override |
| 311 |
@Nullable |
| 312 |
public BubbleExpandedView getExpandedView() { |
| 313 |
return mExpandedView; |
| 314 |
} |
| 315 |
|
| 316 |
@Nullable |
| 317 |
public String getTitle() { |
| 318 |
return mTitle; |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
String getShortcutId() { |
| 325 |
return getShortcutInfo() != null |
| 326 |
? getShortcutInfo().getId() |
| 327 |
: getMetadataShortcutId(); |
| 328 |
} |
| 329 |
|
| 330 |
String getMetadataShortcutId() { |
| 331 |
return mMetadataShortcutId; |
| 332 |
} |
| 333 |
|
| 334 |
boolean hasMetadataShortcutId() { |
| 335 |
return (mMetadataShortcutId != null && !mMetadataShortcutId.isEmpty()); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
void cleanupExpandedView() { |
| 343 |
if (mExpandedView != null) { |
| 344 |
mExpandedView.cleanUpExpandedState(); |
| 345 |
mExpandedView = null; |
| 346 |
} |
| 347 |
if (mIntent != null) { |
| 348 |
mIntent.unregisterCancelListener(mIntentCancelListener); |
| 349 |
} |
| 350 |
mIntentActive = false; |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
void cleanupViews() { |
| 357 |
cleanupExpandedView(); |
| 358 |
mIconView = null; |
| 359 |
} |
| 360 |
|
| 361 |
void setPendingIntentCanceled() { |
| 362 |
mPendingIntentCanceled = true; |
| 363 |
} |
| 364 |
|
| 365 |
boolean getPendingIntentCanceled() { |
| 366 |
return mPendingIntentCanceled; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
@VisibleForTesting |
| 374 |
void setInflateSynchronously(boolean inflateSynchronously) { |
| 375 |
mInflateSynchronously = inflateSynchronously; |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
@VisibleForTesting |
| 383 |
void setTextChangedForTest(boolean textChanged) { |
| 384 |
mIsTextChanged = textChanged; |
| 385 |
} |
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
void inflate(BubbleViewInfoTask.Callback callback, |
| 398 |
Context context, |
| 399 |
BubbleController controller, |
| 400 |
BubbleStackView stackView, |
| 401 |
BubbleIconFactory iconFactory, |
| 402 |
BubbleBadgeIconFactory badgeIconFactory, |
| 403 |
boolean skipInflation) { |
| 404 |
if (isBubbleLoading()) { |
| 405 |
mInflationTask.cancel(true ); |
| 406 |
} |
| 407 |
mInflationTask = new BubbleViewInfoTask(this, |
| 408 |
context, |
| 409 |
controller, |
| 410 |
stackView, |
| 411 |
iconFactory, |
| 412 |
badgeIconFactory, |
| 413 |
skipInflation, |
| 414 |
callback, |
| 415 |
mMainExecutor); |
| 416 |
if (mInflateSynchronously) { |
| 417 |
mInflationTask.onPostExecute(mInflationTask.doInBackground()); |
| 418 |
} else { |
| 419 |
mInflationTask.execute(); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
private boolean isBubbleLoading() { |
| 424 |
return mInflationTask != null && mInflationTask.getStatus() != FINISHED; |
| 425 |
} |
| 426 |
|
| 427 |
boolean isInflated() { |
| 428 |
return mIconView != null && mExpandedView != null; |
| 429 |
} |
| 430 |
|
| 431 |
void stopInflation() { |
| 432 |
if (mInflationTask == null) { |
| 433 |
return; |
| 434 |
} |
| 435 |
mInflationTask.cancel(true ); |
| 436 |
} |
| 437 |
|
| 438 |
void setViewInfo(BubbleViewInfoTask.BubbleViewInfo info) { |
| 439 |
if (!isInflated()) { |
| 440 |
mIconView = info.imageView; |
| 441 |
mExpandedView = info.expandedView; |
| 442 |
} |
| 443 |
|
| 444 |
mShortcutInfo = info.shortcutInfo; |
| 445 |
mAppName = info.appName; |
| 446 |
if (mTitle == null) { |
| 447 |
mTitle = mAppName; |
| 448 |
} |
| 449 |
mFlyoutMessage = info.flyoutMessage; |
| 450 |
|
| 451 |
mBadgeBitmap = info.badgeBitmap; |
| 452 |
mRawBadgeBitmap = info.mRawBadgeBitmap; |
| 453 |
mBubbleBitmap = info.bubbleBitmap; |
| 454 |
|
| 455 |
mDotColor = info.dotColor; |
| 456 |
mDotPath = info.dotPath; |
| 457 |
|
| 458 |
if (mExpandedView != null) { |
| 459 |
mExpandedView.update(this ); |
| 460 |
} |
| 461 |
if (mIconView != null) { |
| 462 |
mIconView.setRenderedBubble(this ); |
| 463 |
} |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
@Override |
| 475 |
public void setTaskViewVisibility(boolean visibility) { |
| 476 |
if (mExpandedView != null) { |
| 477 |
mExpandedView.setContentVisibility(visibility); |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
void setEntry(@NonNull final BubbleEntry entry) { |
| 485 |
Objects.requireNonNull(entry); |
| 486 |
boolean showingDotPreviously = showDot(); |
| 487 |
mLastUpdated = entry.getStatusBarNotification().getPostTime(); |
| 488 |
mIsBubble = entry.getStatusBarNotification().getNotification().isBubbleNotification(); |
| 489 |
mPackageName = entry.getStatusBarNotification().getPackageName(); |
| 490 |
mUser = entry.getStatusBarNotification().getUser(); |
| 491 |
mTitle = getTitle(entry); |
| 492 |
mChannelId = entry.getStatusBarNotification().getNotification().getChannelId(); |
| 493 |
mNotificationId = entry.getStatusBarNotification().getId(); |
| 494 |
mAppUid = entry.getStatusBarNotification().getUid(); |
| 495 |
mInstanceId = entry.getStatusBarNotification().getInstanceId(); |
| 496 |
mFlyoutMessage = extractFlyoutMessage(entry); |
| 497 |
if (entry.getRanking() != null) { |
| 498 |
mShortcutInfo = entry.getRanking().getConversationShortcutInfo(); |
| 499 |
mIsTextChanged = entry.getRanking().isTextChanged(); |
| 500 |
if (entry.getRanking().getChannel() != null) { |
| 501 |
mIsImportantConversation = |
| 502 |
entry.getRanking().getChannel().isImportantConversation(); |
| 503 |
} |
| 504 |
} |
| 505 |
if (entry.getBubbleMetadata() != null) { |
| 506 |
mMetadataShortcutId = entry.getBubbleMetadata().getShortcutId(); |
| 507 |
mFlags = entry.getBubbleMetadata().getFlags(); |
| 508 |
mDesiredHeight = entry.getBubbleMetadata().getDesiredHeight(); |
| 509 |
mDesiredHeightResId = entry.getBubbleMetadata().getDesiredHeightResId(); |
| 510 |
mIcon = entry.getBubbleMetadata().getIcon(); |
| 511 |
|
| 512 |
if (!mIntentActive || mIntent == null) { |
| 513 |
if (mIntent != null) { |
| 514 |
mIntent.unregisterCancelListener(mIntentCancelListener); |
| 515 |
} |
| 516 |
mIntent = entry.getBubbleMetadata().getIntent(); |
| 517 |
if (mIntent != null) { |
| 518 |
mIntent.registerCancelListener(mIntentCancelListener); |
| 519 |
} |
| 520 |
} else if (mIntent != null && entry.getBubbleMetadata().getIntent() == null) { |
| 521 |
|
| 522 |
mIntent.unregisterCancelListener(mIntentCancelListener); |
| 523 |
mIntentActive = false; |
| 524 |
mIntent = null; |
| 525 |
} |
| 526 |
mDeleteIntent = entry.getBubbleMetadata().getDeleteIntent(); |
| 527 |
} |
| 528 |
|
| 529 |
mIsClearable = entry.isClearable(); |
| 530 |
mShouldSuppressNotificationDot = entry.shouldSuppressNotificationDot(); |
| 531 |
mShouldSuppressNotificationList = entry.shouldSuppressNotificationList(); |
| 532 |
mShouldSuppressPeek = entry.shouldSuppressPeek(); |
| 533 |
if (showingDotPreviously != showDot()) { |
| 534 |
|
| 535 |
setShowDot(showDot()); |
| 536 |
} |
| 537 |
} |
| 538 |
|
| 539 |
@Nullable |
| 540 |
Icon getIcon() { |
| 541 |
return mIcon; |
| 542 |
} |
| 543 |
|
| 544 |
boolean isTextChanged() { |
| 545 |
return mIsTextChanged; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
long getLastActivity() { |
| 552 |
return isAppBubble() ? Long.MAX_VALUE : Math.max(mLastUpdated, mLastAccessed); |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
void setIntentActive() { |
| 560 |
mIntentActive = true; |
| 561 |
} |
| 562 |
|
| 563 |
boolean isIntentActive() { |
| 564 |
return mIntentActive; |
| 565 |
} |
| 566 |
|
| 567 |
public InstanceId getInstanceId() { |
| 568 |
return mInstanceId; |
| 569 |
} |
| 570 |
|
| 571 |
@Nullable |
| 572 |
public String getChannelId() { |
| 573 |
return mChannelId; |
| 574 |
} |
| 575 |
|
| 576 |
public int getNotificationId() { |
| 577 |
return mNotificationId; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
@Override |
| 584 |
public int getTaskId() { |
| 585 |
return mExpandedView != null ? mExpandedView.getTaskId() : mTaskId; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
void markAsAccessedAt(long lastAccessedMillis) { |
| 592 |
mLastAccessed = lastAccessedMillis; |
| 593 |
setSuppressNotification(true); |
| 594 |
setShowDot(false ); |
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
void markUpdatedAt(long lastAccessedMillis) { |
| 601 |
mLastUpdated = lastAccessedMillis; |
| 602 |
} |
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
boolean showInShade() { |
| 608 |
return !shouldSuppressNotification() || !mIsClearable; |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
boolean isSuppressed() { |
| 615 |
return (mFlags & Notification.BubbleMetadata.FLAG_SUPPRESS_BUBBLE) != 0; |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
boolean isSuppressable() { |
| 623 |
return (mFlags & Notification.BubbleMetadata.FLAG_SUPPRESSABLE_BUBBLE) != 0; |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
boolean isImportantConversation() { |
| 630 |
return mIsImportantConversation; |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
@VisibleForTesting |
| 637 |
public void setSuppressNotification(boolean suppressNotification) { |
| 638 |
boolean prevShowInShade = showInShade(); |
| 639 |
if (suppressNotification) { |
| 640 |
mFlags |= Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
| 641 |
} else { |
| 642 |
mFlags &= ~Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION; |
| 643 |
} |
| 644 |
|
| 645 |
if (showInShade() != prevShowInShade && mBubbleMetadataFlagListener != null) { |
| 646 |
mBubbleMetadataFlagListener.onBubbleMetadataFlagChanged(this); |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
public void setSuppressBubble(boolean suppressBubble) { |
| 654 |
if (!isSuppressable()) { |
| 655 |
Log.e(TAG, "calling setSuppressBubble on " |
| 656 |
+ getKey() + " when bubble not suppressable"); |
| 657 |
return; |
| 658 |
} |
| 659 |
boolean prevSuppressed = isSuppressed(); |
| 660 |
if (suppressBubble) { |
| 661 |
mFlags |= Notification.BubbleMetadata.FLAG_SUPPRESS_BUBBLE; |
| 662 |
} else { |
| 663 |
mFlags &= ~Notification.BubbleMetadata.FLAG_SUPPRESS_BUBBLE; |
| 664 |
} |
| 665 |
if (prevSuppressed != suppressBubble && mBubbleMetadataFlagListener != null) { |
| 666 |
mBubbleMetadataFlagListener.onBubbleMetadataFlagChanged(this); |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
void setShowDot(boolean showDot) { |
| 674 |
mShowBubbleUpdateDot = showDot; |
| 675 |
|
| 676 |
if (mIconView != null) { |
| 677 |
mIconView.updateDotVisibility(true ); |
| 678 |
} |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
@Override |
| 685 |
public boolean showDot() { |
| 686 |
return mShowBubbleUpdateDot |
| 687 |
&& !mShouldSuppressNotificationDot |
| 688 |
&& !shouldSuppressNotification(); |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
@VisibleForTesting |
| 695 |
public boolean showFlyout() { |
| 696 |
return !mSuppressFlyout && !mShouldSuppressPeek |
| 697 |
&& !shouldSuppressNotification() |
| 698 |
&& !mShouldSuppressNotificationList; |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
void setSuppressFlyout(boolean suppressFlyout) { |
| 707 |
mSuppressFlyout = suppressFlyout; |
| 708 |
} |
| 709 |
|
| 710 |
FlyoutMessage getFlyoutMessage() { |
| 711 |
return mFlyoutMessage; |
| 712 |
} |
| 713 |
|
| 714 |
int getRawDesiredHeight() { |
| 715 |
return mDesiredHeight; |
| 716 |
} |
| 717 |
|
| 718 |
int getRawDesiredHeightResId() { |
| 719 |
return mDesiredHeightResId; |
| 720 |
} |
| 721 |
|
| 722 |
float getDesiredHeight(Context context) { |
| 723 |
boolean useRes = mDesiredHeightResId != 0; |
| 724 |
if (useRes) { |
| 725 |
return getDimenForPackageUser(context, mDesiredHeightResId, mPackageName, |
| 726 |
mUser.getIdentifier()); |
| 727 |
} else { |
| 728 |
return mDesiredHeight * context.getResources().getDisplayMetrics().density; |
| 729 |
} |
| 730 |
} |
| 731 |
|
| 732 |
String getDesiredHeightString() { |
| 733 |
boolean useRes = mDesiredHeightResId != 0; |
| 734 |
if (useRes) { |
| 735 |
return String.valueOf(mDesiredHeightResId); |
| 736 |
} else { |
| 737 |
return String.valueOf(mDesiredHeight); |
| 738 |
} |
| 739 |
} |
| 740 |
|
| 741 |
@Nullable |
| 742 |
PendingIntent getBubbleIntent() { |
| 743 |
return mIntent; |
| 744 |
} |
| 745 |
|
| 746 |
@Nullable |
| 747 |
PendingIntent getDeleteIntent() { |
| 748 |
return mDeleteIntent; |
| 749 |
} |
| 750 |
|
| 751 |
@Nullable |
| 752 |
Intent getAppBubbleIntent() { |
| 753 |
return mAppIntent; |
| 754 |
} |
| 755 |
|
| 756 |
boolean isAppBubble() { |
| 757 |
return KEY_APP_BUBBLE.equals(mKey); |
| 758 |
} |
| 759 |
|
| 760 |
Intent getSettingsIntent(final Context context) { |
| 761 |
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_BUBBLE_SETTINGS); |
| 762 |
intent.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName()); |
| 763 |
final int uid = getUid(context); |
| 764 |
if (uid != -1) { |
| 765 |
intent.putExtra(Settings.EXTRA_APP_UID, uid); |
| 766 |
} |
| 767 |
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); |
| 768 |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 769 |
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); |
| 770 |
return intent; |
| 771 |
} |
| 772 |
|
| 773 |
public int getAppUid() { |
| 774 |
return mAppUid; |
| 775 |
} |
| 776 |
|
| 777 |
private int getUid(final Context context) { |
| 778 |
if (mAppUid != -1) return mAppUid; |
| 779 |
final PackageManager pm = BubbleController.getPackageManagerForUser(context, |
| 780 |
mUser.getIdentifier()); |
| 781 |
if (pm == null) return -1; |
| 782 |
try { |
| 783 |
final ApplicationInfo info = pm.getApplicationInfo(mShortcutInfo.getPackage(), 0); |
| 784 |
return info.uid; |
| 785 |
} catch (PackageManager.NameNotFoundException e) { |
| 786 |
Log.e(TAG, "cannot find uid", e); |
| 787 |
} |
| 788 |
return -1; |
| 789 |
} |
| 790 |
|
| 791 |
private int getDimenForPackageUser(Context context, int resId, String pkg, int userId) { |
| 792 |
Resources r; |
| 793 |
if (pkg != null) { |
| 794 |
try { |
| 795 |
if (userId == UserHandle.USER_ALL) { |
| 796 |
userId = UserHandle.USER_SYSTEM; |
| 797 |
} |
| 798 |
r = context.createContextAsUser(UserHandle.of(userId), 0) |
| 799 |
.getPackageManager().getResourcesForApplication(pkg); |
| 800 |
return r.getDimensionPixelSize(resId); |
| 801 |
} catch (PackageManager.NameNotFoundException ex) { |
| 802 |
|
| 803 |
} catch (Resources.NotFoundException e) { |
| 804 |
|
| 805 |
Log.e(TAG, "Couldn't find desired height res id", e); |
| 806 |
} |
| 807 |
} |
| 808 |
return 0; |
| 809 |
} |
| 810 |
|
| 811 |
private boolean shouldSuppressNotification() { |
| 812 |
return isEnabled(Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION); |
| 813 |
} |
| 814 |
|
| 815 |
public boolean shouldAutoExpand() { |
| 816 |
return isEnabled(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE); |
| 817 |
} |
| 818 |
|
| 819 |
@VisibleForTesting |
| 820 |
public void setShouldAutoExpand(boolean shouldAutoExpand) { |
| 821 |
boolean prevAutoExpand = shouldAutoExpand(); |
| 822 |
if (shouldAutoExpand) { |
| 823 |
enable(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE); |
| 824 |
} else { |
| 825 |
disable(Notification.BubbleMetadata.FLAG_AUTO_EXPAND_BUBBLE); |
| 826 |
} |
| 827 |
if (prevAutoExpand != shouldAutoExpand && mBubbleMetadataFlagListener != null) { |
| 828 |
mBubbleMetadataFlagListener.onBubbleMetadataFlagChanged(this); |
| 829 |
} |
| 830 |
} |
| 831 |
|
| 832 |
public void setIsBubble(final boolean isBubble) { |
| 833 |
mIsBubble = isBubble; |
| 834 |
} |
| 835 |
|
| 836 |
public boolean isBubble() { |
| 837 |
return mIsBubble; |
| 838 |
} |
| 839 |
|
| 840 |
public void enable(int option) { |
| 841 |
mFlags |= option; |
| 842 |
} |
| 843 |
|
| 844 |
public void disable(int option) { |
| 845 |
mFlags &= ~option; |
| 846 |
} |
| 847 |
|
| 848 |
public boolean isEnabled(int option) { |
| 849 |
return (mFlags & option) != 0; |
| 850 |
} |
| 851 |
|
| 852 |
public int getFlags() { |
| 853 |
return mFlags; |
| 854 |
} |
| 855 |
|
| 856 |
@Override |
| 857 |
public String toString() { |
| 858 |
return "Bubble{" + mKey + '}'; |
| 859 |
} |
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
public void dump(@NonNull PrintWriter pw) { |
| 865 |
pw.print("key: "); pw.println(mKey); |
| 866 |
pw.print(" showInShade: "); pw.println(showInShade()); |
| 867 |
pw.print(" showDot: "); pw.println(showDot()); |
| 868 |
pw.print(" showFlyout: "); pw.println(showFlyout()); |
| 869 |
pw.print(" lastActivity: "); pw.println(getLastActivity()); |
| 870 |
pw.print(" desiredHeight: "); pw.println(getDesiredHeightString()); |
| 871 |
pw.print(" suppressNotif: "); pw.println(shouldSuppressNotification()); |
| 872 |
pw.print(" autoExpand: "); pw.println(shouldAutoExpand()); |
| 873 |
pw.print(" isClearable: "); pw.println(mIsClearable); |
| 874 |
pw.println(" bubbleMetadataFlagListener null: " + (mBubbleMetadataFlagListener == null)); |
| 875 |
if (mExpandedView != null) { |
| 876 |
mExpandedView.dump(pw); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
@Override |
| 881 |
public boolean equals(Object o) { |
| 882 |
if (this == o) return true; |
| 883 |
if (!(o instanceof Bubble)) return false; |
| 884 |
Bubble bubble = (Bubble) o; |
| 885 |
return Objects.equals(mKey, bubble.mKey); |
| 886 |
} |
| 887 |
|
| 888 |
@Override |
| 889 |
public int hashCode() { |
| 890 |
return Objects.hash(mKey); |
| 891 |
} |
| 892 |
|
| 893 |
@Nullable |
| 894 |
private static String getTitle(@NonNull final BubbleEntry e) { |
| 895 |
final CharSequence titleCharSeq = e.getStatusBarNotification() |
| 896 |
.getNotification().extras.getCharSequence(Notification.EXTRA_TITLE); |
| 897 |
return titleCharSeq == null ? null : titleCharSeq.toString(); |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
@NonNull |
| 905 |
static Bubble.FlyoutMessage extractFlyoutMessage(BubbleEntry entry) { |
| 906 |
Objects.requireNonNull(entry); |
| 907 |
final Notification underlyingNotif = entry.getStatusBarNotification().getNotification(); |
| 908 |
final Class<? extends Notification.Style> style = underlyingNotif.getNotificationStyle(); |
| 909 |
|
| 910 |
Bubble.FlyoutMessage bubbleMessage = new Bubble.FlyoutMessage(); |
| 911 |
bubbleMessage.isGroupChat = underlyingNotif.extras.getBoolean( |
| 912 |
Notification.EXTRA_IS_GROUP_CONVERSATION); |
| 913 |
try { |
| 914 |
if (Notification.BigTextStyle.class.equals(style)) { |
| 915 |
|
| 916 |
|
| 917 |
CharSequence bigText = |
| 918 |
underlyingNotif.extras.getCharSequence(Notification.EXTRA_BIG_TEXT); |
| 919 |
bubbleMessage.message = !TextUtils.isEmpty(bigText) |
| 920 |
? bigText |
| 921 |
: underlyingNotif.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 922 |
return bubbleMessage; |
| 923 |
} else if (Notification.MessagingStyle.class.equals(style)) { |
| 924 |
final List<Notification.MessagingStyle.Message> messages = |
| 925 |
Notification.MessagingStyle.Message.getMessagesFromBundleArray( |
| 926 |
(Parcelable[]) underlyingNotif.extras.get( |
| 927 |
Notification.EXTRA_MESSAGES)); |
| 928 |
|
| 929 |
final Notification.MessagingStyle.Message latestMessage = |
| 930 |
Notification.MessagingStyle.findLatestIncomingMessage(messages); |
| 931 |
if (latestMessage != null) { |
| 932 |
bubbleMessage.message = latestMessage.getText(); |
| 933 |
Person sender = latestMessage.getSenderPerson(); |
| 934 |
bubbleMessage.senderName = sender != null ? sender.getName() : null; |
| 935 |
bubbleMessage.senderAvatar = null; |
| 936 |
bubbleMessage.senderIcon = sender != null ? sender.getIcon() : null; |
| 937 |
return bubbleMessage; |
| 938 |
} |
| 939 |
} else if (Notification.InboxStyle.class.equals(style)) { |
| 940 |
CharSequence[] lines = |
| 941 |
underlyingNotif.extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES); |
| 942 |
|
| 943 |
|
| 944 |
if (lines != null && lines.length > 0) { |
| 945 |
bubbleMessage.message = lines[lines.length - 1]; |
| 946 |
return bubbleMessage; |
| 947 |
} |
| 948 |
} else if (Notification.MediaStyle.class.equals(style)) { |
| 949 |
|
| 950 |
return bubbleMessage; |
| 951 |
} else { |
| 952 |
|
| 953 |
bubbleMessage.message = |
| 954 |
underlyingNotif.extras.getCharSequence(Notification.EXTRA_TEXT); |
| 955 |
return bubbleMessage; |
| 956 |
} |
| 957 |
} catch (ClassCastException | NullPointerException | ArrayIndexOutOfBoundsException e) { |
| 958 |
|
| 959 |
|
| 960 |
e.printStackTrace(); |
| 961 |
} |
| 962 |
|
| 963 |
return bubbleMessage; |
| 964 |
} |
| 965 |
} |