diff options
| author | 2024-08-19 13:48:10 +0000 | |
|---|---|---|
| committer | 2024-08-19 13:48:10 +0000 | |
| commit | 5d80231405a7839b60be5aa85b0c316c73eccc8a (patch) | |
| tree | 893cf034c9c087fe556345d7c130b28fe69f06d0 | |
| parent | d8fe193f58e4291a9699221d4cfdec8837ec54c5 (diff) | |
| parent | eb618a7395e53f7113d5976eab626288b9521879 (diff) | |
Merge "User CURRENT for display notification" into main
2 files changed, 15 insertions, 6 deletions
diff --git a/services/core/java/com/android/server/display/notifications/DisplayNotificationManager.java b/services/core/java/com/android/server/display/notifications/DisplayNotificationManager.java index 280a7e1e0521..8a8440ba956a 100644 --- a/services/core/java/com/android/server/display/notifications/DisplayNotificationManager.java +++ b/services/core/java/com/android/server/display/notifications/DisplayNotificationManager.java @@ -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; @@ -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); } /** @@ -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); } /** diff --git a/services/tests/displayservicetests/src/com/android/server/display/notifications/DisplayNotificationManagerTest.java b/services/tests/displayservicetests/src/com/android/server/display/notifications/DisplayNotificationManagerTest.java index d6c8ceb7ea6f..97c12bb6ef33 100644 --- a/services/tests/displayservicetests/src/com/android/server/display/notifications/DisplayNotificationManagerTest.java +++ b/services/tests/displayservicetests/src/com/android/server/display/notifications/DisplayNotificationManagerTest.java @@ -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; @@ -70,6 +71,8 @@ public class DisplayNotificationManagerTest { private ArgumentCaptor<Integer> mNotifyNoteIdCaptor; @Captor private ArgumentCaptor<Notification> mNotifyAsUserNotificationCaptor; + @Captor + private ArgumentCaptor<UserHandle> mNotifyAsUserCaptor; /** Setup tests. */ @Before @@ -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 @@ -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(); @@ -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); } } |