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

Commit ef3a92e0 authored by András Kurucz's avatar András Kurucz
Browse files

Remove the NotificationsLiveDataStoreRefactor flag

NotifLiveDataStore has been replaced by ActiveNotificationsInteractor,
and all remaining usages were migrated behing the NotifLiveDataStoreRefactor
flag.

Bug: 424001722
Test: smoke test the new NotificationLogger
Test: check lights out mode
Flag: EXEMPT mechanical refactor
Change-Id: Ia07ba4c7bccd1696bceb8e61d6f693971c356379
parent 52cba2b7
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -377,7 +377,6 @@ filegroup {
        "tests/src/**/systemui/statusbar/notification/collection/coordinator/ViewConfigCoordinatorTest.kt",
        "tests/src/**/systemui/statusbar/notification/collection/coordinator/StackCoordinatorTest.kt",
        "tests/src/**/systemui/statusbar/notification/collection/coordinator/ShadeEventCoordinatorTest.kt",
        "tests/src/**/systemui/statusbar/notification/collection/coordinator/DataStoreCoordinatorTest.kt",
        "tests/src/**/systemui/statusbar/notification/collection/coordinator/RowAppearanceCoordinatorTest.kt",
        "tests/src/**/systemui/statusbar/notification/RoundableTest.kt",
        "tests/src/**/systemui/stylus/StylusUsiPowerUiTest.kt",
+0 −8
Original line number Diff line number Diff line
@@ -140,14 +140,6 @@ flag {
    }
}

flag {
    name: "notifications_live_data_store_refactor"
    namespace: "systemui"
    description: "Replaces NotifLiveDataStore with ActiveNotificationListRepository, and updates consumers. "
        "Should not bring any behavior changes."
    bug: "308623704"
}

flag {
   name: "notification_transparent_header_fix"
   namespace: "systemui"
+0 −168
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.collection

import android.testing.TestableLooper.RunWithLooper
import androidx.lifecycle.Observer
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.eq
import org.mockito.Mockito.inOrder
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions

@SmallTest
@RunWith(AndroidJUnit4::class)
@RunWithLooper
@android.platform.test.annotations.EnabledOnRavenwood
class NotifLiveDataImplTest : SysuiTestCase() {

    private val executor = FakeExecutor(FakeSystemClock())
    private val liveDataImpl: NotifLiveDataImpl<Int> = NotifLiveDataImpl("tst", 9, executor)
    private val syncObserver: Observer<Int> = mock()
    private val asyncObserver: Observer<Int> = mock()

    @Before
    fun setup() {
        allowTestableLooperAsMainThread()
        liveDataImpl.addSyncObserver(syncObserver)
        liveDataImpl.addAsyncObserver(asyncObserver)
    }

    @Test
    fun testGetInitialValue() {
        assertThat(liveDataImpl.value).isEqualTo(9)
    }

    @Test
    fun testGetModifiedValue() {
        liveDataImpl.value = 13
        assertThat(liveDataImpl.value).isEqualTo(13)
    }

    @Test
    fun testGetsModifiedValueFromWithinSyncObserver() {
        liveDataImpl.addSyncObserver { intVal ->
            assertThat(intVal).isEqualTo(13)
            assertThat(liveDataImpl.value).isEqualTo(13)
        }
        liveDataImpl.value = 13
    }

    @Test
    fun testDoesNotAlertsRemovedObservers() {
        liveDataImpl.removeObserver(syncObserver)
        liveDataImpl.removeObserver(asyncObserver)

        liveDataImpl.value = 13

        // There should be no runnables on the executor
        assertThat(executor.runAllReady()).isEqualTo(0)

        // And observers should not be called
        verifyNoMoreInteractions(syncObserver, asyncObserver)
    }

    @Test
    fun testDoesNotAsyncObserversRemovedSinceChange() {
        liveDataImpl.value = 13
        liveDataImpl.removeObserver(asyncObserver)

        // There should be a runnable that will get executed...
        assertThat(executor.runAllReady()).isEqualTo(1)

        // ...but async observers should not be called
        verifyNoMoreInteractions(asyncObserver)
    }

    @Test
    fun testAlertsObservers() {
        liveDataImpl.value = 13

        // Verify that the synchronous observer is called immediately
        verify(syncObserver).onChanged(eq(13))
        verifyNoMoreInteractions(syncObserver, asyncObserver)

        // Verify that the asynchronous observer is called when the executor runs
        assertThat(executor.runAllReady()).isEqualTo(1)
        verify(asyncObserver).onChanged(eq(13))
        verifyNoMoreInteractions(syncObserver, asyncObserver)
    }

    @Test
    fun testAlertsObserversFromDispatcher() {
        // GIVEN that we use setValueAndProvideDispatcher()
        val dispatcher = liveDataImpl.setValueAndProvideDispatcher(13)

        // VERIFY that nothing is done before the dispatcher is called
        assertThat(executor.numPending()).isEqualTo(0)
        verifyNoMoreInteractions(syncObserver, asyncObserver)

        // WHEN the dispatcher is invoked...
        dispatcher.invoke()

        // Verify that the synchronous observer is called immediately
        verify(syncObserver).onChanged(eq(13))
        verifyNoMoreInteractions(syncObserver, asyncObserver)

        // Verify that the asynchronous observer is called when the executor runs
        assertThat(executor.runAllReady()).isEqualTo(1)
        verify(asyncObserver).onChanged(eq(13))
        verifyNoMoreInteractions(syncObserver, asyncObserver)
    }

    @Test
    fun testSkipsAllObserversIfValueDidNotChange() {
        liveDataImpl.value = 9
        // Does not add a runnable
        assertThat(executor.runAllReady()).isEqualTo(0)
        // Setting the current value does not call synchronous observers
        verifyNoMoreInteractions(syncObserver, asyncObserver)
    }

    @Test
    fun testSkipsAsyncObserversWhenValueTogglesBack() {
        liveDataImpl.value = 13
        liveDataImpl.value = 11
        liveDataImpl.value = 9

        // Synchronous observers will receive every change event immediately
        inOrder(syncObserver).apply {
            verify(syncObserver).onChanged(eq(13))
            verify(syncObserver).onChanged(eq(11))
            verify(syncObserver).onChanged(eq(9))
        }
        verifyNoMoreInteractions(syncObserver, asyncObserver)

        // Running the first runnable on the queue will just emit the most recent value
        assertThat(executor.runNextReady()).isTrue()
        verify(asyncObserver).onChanged(eq(9))
        verifyNoMoreInteractions(syncObserver, asyncObserver)

        // Running the next 2 runnable will have no effect
        assertThat(executor.runAllReady()).isEqualTo(2)
        verifyNoMoreInteractions(syncObserver, asyncObserver)
    }
}
+0 −105
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.collection

import android.testing.TestableLooper.RunWithLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.concurrency.FakeExecutor
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import java.lang.UnsupportedOperationException

@SmallTest
@RunWith(AndroidJUnit4::class)
@RunWithLooper
class NotifLiveDataStoreImplTest : SysuiTestCase() {

    private val executor = FakeExecutor(FakeSystemClock())
    private val liveDataStoreImpl = NotifLiveDataStoreImpl(executor)

    @Before
    fun setup() {
        allowTestableLooperAsMainThread()
    }

    @Test
    fun testAllObserversSeeConsistentValues() {
        val entry1 = NotificationEntryBuilder().setId(1).build()
        val entry2 = NotificationEntryBuilder().setId(2).build()
        val observer: (Any) -> Unit = {
            assertThat(liveDataStoreImpl.hasActiveNotifs.value).isEqualTo(true)
            assertThat(liveDataStoreImpl.activeNotifCount.value).isEqualTo(2)
            assertThat(liveDataStoreImpl.activeNotifList.value).isEqualTo(listOf(entry1, entry2))
        }
        liveDataStoreImpl.hasActiveNotifs.addSyncObserver(observer)
        liveDataStoreImpl.hasActiveNotifs.addAsyncObserver(observer)
        liveDataStoreImpl.activeNotifCount.addSyncObserver(observer)
        liveDataStoreImpl.activeNotifCount.addAsyncObserver(observer)
        liveDataStoreImpl.activeNotifList.addSyncObserver(observer)
        liveDataStoreImpl.activeNotifList.addAsyncObserver(observer)
        liveDataStoreImpl.setActiveNotifList(listOf(entry1, entry2))
        executor.runAllReady()
    }

    @Test
    fun testOriginalListIsCopied() {
        val entry1 = NotificationEntryBuilder().setId(1).build()
        val entry2 = NotificationEntryBuilder().setId(2).build()
        val mutableInputList = mutableListOf(entry1, entry2)
        val observer: (Any) -> Unit = {
            mutableInputList.clear()
            assertThat(liveDataStoreImpl.hasActiveNotifs.value).isEqualTo(true)
            assertThat(liveDataStoreImpl.activeNotifCount.value).isEqualTo(2)
            assertThat(liveDataStoreImpl.activeNotifList.value).isEqualTo(listOf(entry1, entry2))
        }
        liveDataStoreImpl.hasActiveNotifs.addSyncObserver(observer)
        liveDataStoreImpl.hasActiveNotifs.addAsyncObserver(observer)
        liveDataStoreImpl.activeNotifCount.addSyncObserver(observer)
        liveDataStoreImpl.activeNotifCount.addAsyncObserver(observer)
        liveDataStoreImpl.activeNotifList.addSyncObserver(observer)
        liveDataStoreImpl.activeNotifList.addAsyncObserver(observer)
        liveDataStoreImpl.setActiveNotifList(mutableInputList)
        executor.runAllReady()
    }

    @Test
    fun testProvidedListIsUnmodifiable() {
        val entry1 = NotificationEntryBuilder().setId(1).build()
        val entry2 = NotificationEntryBuilder().setId(2).build()
        val observer: (List<NotificationEntry>) -> Unit = { providedValue ->
            val provided = providedValue as MutableList<NotificationEntry>
            Assert.assertThrows(UnsupportedOperationException::class.java) {
                provided.clear()
            }
            val current = liveDataStoreImpl.activeNotifList.value as MutableList<NotificationEntry>
            Assert.assertThrows(UnsupportedOperationException::class.java) {
                current.clear()
            }
            assertThat(liveDataStoreImpl.activeNotifList.value).isEqualTo(listOf(entry1, entry2))
        }
        liveDataStoreImpl.activeNotifList.addSyncObserver(observer)
        liveDataStoreImpl.activeNotifList.addAsyncObserver(observer)
        liveDataStoreImpl.setActiveNotifList(mutableListOf(entry1, entry2))
        executor.runAllReady()
    }
}
+0 −29
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.collection

import com.android.systemui.util.mockito.mock
import org.mockito.Mockito.`when` as whenever

/** Creates a mock which returns mocks for the NotifLiveDataImpl fields. */
fun createNotifLiveDataStoreImplMock(): NotifLiveDataStoreImpl {
    val dataStoreImpl: NotifLiveDataStoreImpl = mock()
    whenever(dataStoreImpl.hasActiveNotifs).thenReturn(mock())
    whenever(dataStoreImpl.activeNotifCount).thenReturn(mock())
    whenever(dataStoreImpl.activeNotifList).thenReturn(mock())
    return dataStoreImpl
}
Loading