From 4d6d36f360f860718ac3c32e1fe0e8823d733ebe Mon Sep 17 00:00:00 2001 From: Jan Tomljanovic Date: Thu, 14 Jan 2021 13:50:53 +0000 Subject: [PATCH] Reset toast rate limiting when it is manually enabled. CTS tests can now use this to avoid hitting rate limits if there are multiple tests which have rate limiting enabled (toast in one tests won't count towards rate limiting in the other). Test: atest android.widget.cts.ToastTest Bug: 174841445 Change-Id: I0321e0aa6c8dab9c3ea99bbb5ca83b6fed822875 --- .../notification/NotificationManagerService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index ab5238f1ddbf7..4a6150f6ece47 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -3084,8 +3084,23 @@ public class NotificationManagerService extends SystemService { synchronized (mToastQueue) { int uid = Binder.getCallingUid(); + int userId = UserHandle.getUserId(uid); if (enable) { mToastRateLimitingDisabledUids.remove(uid); + try { + String[] packages = mPackageManager.getPackagesForUid(uid); + if (packages == null) { + Slog.e(TAG, "setToastRateLimitingEnabled method haven't found any " + + "packages for the given uid: " + uid + ", toast rate " + + "limiter not reset for that uid."); + return; + } + for (String pkg : packages) { + mToastRateLimiter.clear(userId, pkg); + } + } catch (RemoteException e) { + Slog.e(TAG, "Failed to reset toast rate limiter for given uid", e); + } } else { mToastRateLimitingDisabledUids.add(uid); }