Merge "Add missing lock" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b0375bd924
@@ -6568,7 +6568,7 @@ public class NotificationManagerService extends SystemService {
|
||||
|
||||
// limit the number of non-fgs outstanding notificationrecords an app can have
|
||||
if (!n.isForegroundService()) {
|
||||
int count = getNotificationCountLocked(pkg, userId, id, tag);
|
||||
int count = getNotificationCount(pkg, userId, id, tag);
|
||||
if (count >= MAX_PACKAGE_NOTIFICATIONS) {
|
||||
mUsageStats.registerOverCountQuota(pkg);
|
||||
Slog.e(TAG, "Package has already posted or enqueued " + count
|
||||
@@ -6647,28 +6647,29 @@ public class NotificationManagerService extends SystemService {
|
||||
return true;
|
||||
}
|
||||
|
||||
@GuardedBy("mNotificationLock")
|
||||
protected int getNotificationCountLocked(String pkg, int userId, int excludedId,
|
||||
protected int getNotificationCount(String pkg, int userId, int excludedId,
|
||||
String excludedTag) {
|
||||
int count = 0;
|
||||
final int N = mNotificationList.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
final NotificationRecord existing = mNotificationList.get(i);
|
||||
if (existing.getSbn().getPackageName().equals(pkg)
|
||||
&& existing.getSbn().getUserId() == userId) {
|
||||
if (existing.getSbn().getId() == excludedId
|
||||
&& TextUtils.equals(existing.getSbn().getTag(), excludedTag)) {
|
||||
continue;
|
||||
synchronized (mNotificationLock) {
|
||||
final int N = mNotificationList.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
final NotificationRecord existing = mNotificationList.get(i);
|
||||
if (existing.getSbn().getPackageName().equals(pkg)
|
||||
&& existing.getSbn().getUserId() == userId) {
|
||||
if (existing.getSbn().getId() == excludedId
|
||||
&& TextUtils.equals(existing.getSbn().getTag(), excludedTag)) {
|
||||
continue;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
final int M = mEnqueuedNotifications.size();
|
||||
for (int i = 0; i < M; i++) {
|
||||
final NotificationRecord existing = mEnqueuedNotifications.get(i);
|
||||
if (existing.getSbn().getPackageName().equals(pkg)
|
||||
&& existing.getSbn().getUserId() == userId) {
|
||||
count++;
|
||||
final int M = mEnqueuedNotifications.size();
|
||||
for (int i = 0; i < M; i++) {
|
||||
final NotificationRecord existing = mEnqueuedNotifications.get(i);
|
||||
if (existing.getSbn().getPackageName().equals(pkg)
|
||||
&& existing.getSbn().getUserId() == userId) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
|
||||
@@ -3394,16 +3394,16 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
|
||||
// anything that's currently enqueued or posted
|
||||
int userId = UserHandle.getUserId(mUid);
|
||||
assertEquals(40,
|
||||
mService.getNotificationCountLocked(PKG, userId, 0, null));
|
||||
mService.getNotificationCount(PKG, userId, 0, null));
|
||||
assertEquals(40,
|
||||
mService.getNotificationCountLocked(PKG, userId, 0, "tag2"));
|
||||
mService.getNotificationCount(PKG, userId, 0, "tag2"));
|
||||
|
||||
// return all for package "a" - "banana" tag isn't used
|
||||
assertEquals(2,
|
||||
mService.getNotificationCountLocked("a", userId, 0, "banana"));
|
||||
mService.getNotificationCount("a", userId, 0, "banana"));
|
||||
|
||||
// exclude a known notification - it's excluded from only the posted list, not enqueued
|
||||
assertEquals(39, mService.getNotificationCountLocked(
|
||||
assertEquals(39, mService.getNotificationCount(
|
||||
PKG, userId, sampleIdToExclude, sampleTagToExclude));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user