Skip to content

Commit 6800a80

Browse files
Dianne HackbornAndroid Code Review
authored andcommitted
Merge "frameworks/base: Cap the number of toasts that a package can post."
2 parents 2f4698f + f9eb06c commit 6800a80

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

services/java/com/android/server/NotificationManagerService.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,24 @@ public void enqueueToast(String pkg, ITransientNotification callback, int durati
519519
record = mToastQueue.get(index);
520520
record.update(duration);
521521
} else {
522+
// Limit the number of toasts that any given package except the android
523+
// package can enqueue. Prevents DOS attacks and deals with leaks.
524+
if (!"android".equals(pkg)) {
525+
int count = 0;
526+
final int N = mToastQueue.size();
527+
for (int i=0; i<N; i++) {
528+
final ToastRecord r = mToastQueue.get(i);
529+
if (r.pkg.equals(pkg)) {
530+
count++;
531+
if (count >= MAX_PACKAGE_NOTIFICATIONS) {
532+
Slog.e(TAG, "Package has already posted " + count
533+
+ " toasts. Not showing more. Package=" + pkg);
534+
return;
535+
}
536+
}
537+
}
538+
}
539+
522540
record = new ToastRecord(callingPid, pkg, callback, duration);
523541
mToastQueue.add(record);
524542
index = mToastQueue.size() - 1;

0 commit comments

Comments
 (0)