Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb618a73 authored by Oleg Blinnikov's avatar Oleg Blinnikov
Browse files

User CURRENT for display notification

Bug: 359853027
Change-Id: Ib9d05791e63304a9603344896243cf99412e1f39
Test: atest DisplayNotificationManagerTest
Flag: com.android.server.display.feature.flags.enable_connected_display_error_handling
parent 22482c23
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+10 −3
Original line number Diff line number Diff line
@@ -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);
    }
}