From f9fc2e0d1ebafd05d29d929c146d3edf5578c06e Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 12 Jan 2022 14:05:35 -0800 Subject: [PATCH] Use hasSentValidBubble in settings This change makes it such that bubble settings will only be available once the app has sent a bubble notification. Test: atest BubbleSummaryPreferenceControllerTest Bug: 178387292 Change-Id: I459ffcedc4194d953e8b7170937e2eb5334d1422 --- .../settings/notification/NotificationBackend.java | 9 +++++++++ .../app/BubbleSummaryPreferenceController.java | 2 +- .../app/BubbleSummaryPreferenceControllerTest.java | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java index 4ef882ceb49..dbc36d0a7ca 100644 --- a/src/com/android/settings/notification/NotificationBackend.java +++ b/src/com/android/settings/notification/NotificationBackend.java @@ -361,6 +361,15 @@ public class NotificationBackend { } } + public boolean hasSentValidBubble(String pkg, int uid) { + try { + return sINM.hasSentValidBubble(pkg, uid); + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } + } + /** * Returns all notification channels associated with the package and uid that will bypass DND */ diff --git a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java index fb414ee7e38..51370b16bef 100644 --- a/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java +++ b/src/com/android/settings/notification/app/BubbleSummaryPreferenceController.java @@ -63,7 +63,7 @@ public class BubbleSummaryPreferenceController extends NotificationPreferenceCon return mAppRow != null; } } - return isGloballyEnabled() && mBackend.hasSentValidMsg(mAppRow.pkg, mAppRow.uid); + return isGloballyEnabled() && mBackend.hasSentValidBubble(mAppRow.pkg, mAppRow.uid); } @Override diff --git a/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java index 5859a3e63ee..75c53c12f45 100644 --- a/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/app/BubbleSummaryPreferenceControllerTest.java @@ -73,7 +73,7 @@ public class BubbleSummaryPreferenceControllerTest { MockitoAnnotations.initMocks(this); ShadowApplication shadowApplication = ShadowApplication.getInstance(); mContext = RuntimeEnvironment.application; - when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(true); + when(mBackend.hasSentValidBubble(anyString(), anyInt())).thenReturn(true); mAppRow = new NotificationBackend.AppRow(); mAppRow.pkg = "pkg"; mAppRow.uid = 0; @@ -103,10 +103,10 @@ public class BubbleSummaryPreferenceControllerTest { } @Test - public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentMsg_shouldReturnFalse() { + public void isAvailable_NOTIFICATION_BUBBLESisOn_neverSentBubble_shouldReturnFalse() { Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON); mController.onResume(mAppRow, null, null, null, null, null, null); - when(mBackend.hasSentValidMsg(anyString(), anyInt())).thenReturn(false); + when(mBackend.hasSentValidBubble(anyString(), anyInt())).thenReturn(false); assertFalse(mController.isAvailable()); }