Loading services/core/java/com/android/server/display/notifications/DisplayNotificationManager.java +5 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.app.Notification; import android.app.NotificationManager; import android.content.Context; import android.content.res.Resources; import android.os.UserHandle; import android.util.Slog; import com.android.internal.R; Loading Loading @@ -197,7 +198,8 @@ public class DisplayNotificationManager implements ConnectedDisplayUsbErrorsDete return; } mNotificationManager.cancel(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID); mNotificationManager.cancelAsUser(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID, UserHandle.CURRENT); } /** Loading @@ -210,8 +212,8 @@ public class DisplayNotificationManager implements ConnectedDisplayUsbErrorsDete return; } mNotificationManager.notify(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID, notification); mNotificationManager.notifyAsUser(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID, notification, UserHandle.CURRENT); } /** Loading services/tests/displayservicetests/src/com/android/server/display/notifications/DisplayNotificationManagerTest.java +10 −3 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static org.mockito.Mockito.when; import android.app.Notification; import android.app.NotificationManager; import android.os.UserHandle; import androidx.test.core.app.ApplicationProvider; import androidx.test.filters.SmallTest; Loading Loading @@ -70,6 +71,8 @@ public class DisplayNotificationManagerTest { private ArgumentCaptor<Integer> mNotifyNoteIdCaptor; @Captor private ArgumentCaptor<Notification> mNotifyAsUserNotificationCaptor; @Captor private ArgumentCaptor<UserHandle> mNotifyAsUserCaptor; /** Setup tests. */ @Before Loading Loading @@ -127,7 +130,8 @@ public class DisplayNotificationManagerTest { dnm.onDisplayPortLinkTrainingFailure(); dnm.onCableNotCapableDisplayPort(); dnm.onHighTemperatureExternalDisplayNotAllowed(); verify(mMockedNotificationManager, never()).notify(anyString(), anyInt(), any()); verify(mMockedNotificationManager, never()).notifyAsUser(anyString(), anyInt(), any(), any()); } @Test Loading Loading @@ -175,10 +179,11 @@ public class DisplayNotificationManagerTest { } private void assertExpectedNotification() { verify(mMockedNotificationManager).notify( verify(mMockedNotificationManager).notifyAsUser( mNotifyTagCaptor.capture(), mNotifyNoteIdCaptor.capture(), mNotifyAsUserNotificationCaptor.capture()); mNotifyAsUserNotificationCaptor.capture(), mNotifyAsUserCaptor.capture()); assertThat(mNotifyTagCaptor.getValue()).isEqualTo("DisplayNotificationManager"); assertThat((int) mNotifyNoteIdCaptor.getValue()).isEqualTo(1); final var notification = mNotifyAsUserNotificationCaptor.getValue(); Loading @@ -188,5 +193,7 @@ public class DisplayNotificationManagerTest { assertThat(notification.flags & FLAG_ONGOING_EVENT).isEqualTo(0); assertThat(notification.when).isEqualTo(0); assertThat(notification.getTimeoutAfter()).isEqualTo(30000L); final var user = mNotifyAsUserCaptor.getValue(); assertThat(user).isEqualTo(UserHandle.CURRENT); } } Loading
services/core/java/com/android/server/display/notifications/DisplayNotificationManager.java +5 −3 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import android.app.Notification; import android.app.NotificationManager; import android.content.Context; import android.content.res.Resources; import android.os.UserHandle; import android.util.Slog; import com.android.internal.R; Loading Loading @@ -197,7 +198,8 @@ public class DisplayNotificationManager implements ConnectedDisplayUsbErrorsDete return; } mNotificationManager.cancel(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID); mNotificationManager.cancelAsUser(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID, UserHandle.CURRENT); } /** Loading @@ -210,8 +212,8 @@ public class DisplayNotificationManager implements ConnectedDisplayUsbErrorsDete return; } mNotificationManager.notify(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID, notification); mNotificationManager.notifyAsUser(DISPLAY_NOTIFICATION_TAG, DISPLAY_NOTIFICATION_ID, notification, UserHandle.CURRENT); } /** Loading
services/tests/displayservicetests/src/com/android/server/display/notifications/DisplayNotificationManagerTest.java +10 −3 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import static org.mockito.Mockito.when; import android.app.Notification; import android.app.NotificationManager; import android.os.UserHandle; import androidx.test.core.app.ApplicationProvider; import androidx.test.filters.SmallTest; Loading Loading @@ -70,6 +71,8 @@ public class DisplayNotificationManagerTest { private ArgumentCaptor<Integer> mNotifyNoteIdCaptor; @Captor private ArgumentCaptor<Notification> mNotifyAsUserNotificationCaptor; @Captor private ArgumentCaptor<UserHandle> mNotifyAsUserCaptor; /** Setup tests. */ @Before Loading Loading @@ -127,7 +130,8 @@ public class DisplayNotificationManagerTest { dnm.onDisplayPortLinkTrainingFailure(); dnm.onCableNotCapableDisplayPort(); dnm.onHighTemperatureExternalDisplayNotAllowed(); verify(mMockedNotificationManager, never()).notify(anyString(), anyInt(), any()); verify(mMockedNotificationManager, never()).notifyAsUser(anyString(), anyInt(), any(), any()); } @Test Loading Loading @@ -175,10 +179,11 @@ public class DisplayNotificationManagerTest { } private void assertExpectedNotification() { verify(mMockedNotificationManager).notify( verify(mMockedNotificationManager).notifyAsUser( mNotifyTagCaptor.capture(), mNotifyNoteIdCaptor.capture(), mNotifyAsUserNotificationCaptor.capture()); mNotifyAsUserNotificationCaptor.capture(), mNotifyAsUserCaptor.capture()); assertThat(mNotifyTagCaptor.getValue()).isEqualTo("DisplayNotificationManager"); assertThat((int) mNotifyNoteIdCaptor.getValue()).isEqualTo(1); final var notification = mNotifyAsUserNotificationCaptor.getValue(); Loading @@ -188,5 +193,7 @@ public class DisplayNotificationManagerTest { assertThat(notification.flags & FLAG_ONGOING_EVENT).isEqualTo(0); assertThat(notification.when).isEqualTo(0); assertThat(notification.getTimeoutAfter()).isEqualTo(30000L); final var user = mNotifyAsUserCaptor.getValue(); assertThat(user).isEqualTo(UserHandle.CURRENT); } }