diff options
| author | 2018-04-12 13:48:49 -0400 | |
|---|---|---|
| committer | 2018-04-12 13:48:49 -0400 | |
| commit | e273f08c0bdd6bb6549a7da5bb50f9d33698d256 (patch) | |
| tree | 3d9da21bf5e7397aef00ea137d9f9f978a36c9eb | |
| parent | eac2da20b0ff67ae7c52f815090a982f0544e1c4 (diff) | |
Add method to get blocked app count
So we can sure it in settings
Test: runtest systemui-notification
Bug: 73018368
Change-Id: Ib0185e97f8e1cec1864ca1e4efb23bf8db097901
4 files changed, 42 insertions, 0 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 5461c0c9118e..0f2a11a496bf 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -86,6 +86,7 @@ interface INotificationManager ParceledListSlice getNotificationChannelGroups(String pkg); boolean onlyHasDefaultChannel(String pkg, int uid); ParceledListSlice getRecentNotifyingAppsForUser(int userId); + int getBlockedAppCount(int userId); // TODO: Remove this when callers have been migrated to the equivalent // INotificationListener method. diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 55f51c265775..c6886da55dfc 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2394,6 +2394,12 @@ public class NotificationManagerService extends SystemService { } @Override + public int getBlockedAppCount(int userId) { + checkCallerIsSystem(); + return mRankingHelper.getBlockedAppCount(userId); + } + + @Override public void clearData(String packageName, int uid, boolean fromApp) throws RemoteException { checkCallerIsSystem(); diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index c2ec79b8b9f4..89bd6608f53d 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -1011,6 +1011,21 @@ public class RankingHelper implements RankingConfig { return blockedCount; } + public int getBlockedAppCount(int userId) { + int count = 0; + synchronized (mRecords) { + final int N = mRecords.size(); + for (int i = 0; i < N; i++) { + final Record r = mRecords.valueAt(i); + if (userId == UserHandle.getUserId(r.uid) + && r.importance == IMPORTANCE_NONE) { + count++; + } + } + } + return count; + } + /** * Sets importance. */ diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java index 78aa9653e2b8..bda6b8a50a3d 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java @@ -1733,4 +1733,24 @@ public class RankingHelperTest extends UiServiceTestCase { mHelper.createNotificationChannel(PKG, 1000, update, true, false); assertFalse(mHelper.getNotificationChannel(PKG, 1000, "A", false).canBypassDnd()); } + + @Test + public void testGetBlockedAppCount_noApps() { + assertEquals(0, mHelper.getBlockedAppCount(0)); + } + + @Test + public void testGetBlockedAppCount_noAppsForUserId() { + mHelper.setEnabled(PKG, 100, false); + assertEquals(0, mHelper.getBlockedAppCount(9)); + } + + @Test + public void testGetBlockedAppCount_appsForUserId() { + mHelper.setEnabled(PKG, 1020, false); + mHelper.setEnabled(PKG, 1030, false); + mHelper.setEnabled(PKG, 1060, false); + mHelper.setEnabled(PKG, 1000, true); + assertEquals(3, mHelper.getBlockedAppCount(0)); + } } |