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
This commit is contained in:
Jan Tomljanovic
2021-01-14 13:50:53 +00:00
parent cc2aedf5fe
commit 4d6d36f360

View File

@@ -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);
}