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

Commit d472c01f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "launcher_receive_display_id_flags" into main

* changes:
  Propagate the display id with SysUIState changes to launcher
  Fix SceneContainer SysUI state override for multiple displays
  Introduce PerDisplayInstanceRepository (and use it for SysUIState)
parents 9f0d4b06 21f53177
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.display.data.repository

import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SmallTest
class PerDisplayInstanceRepositoryImplTest : SysuiTestCase() {

    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val testScope = kosmos.testScope
    private val fakeDisplayRepository = kosmos.displayRepository
    private val fakePerDisplayInstanceProviderWithTeardown =
        kosmos.fakePerDisplayInstanceProviderWithTeardown

    private val underTest: PerDisplayInstanceRepositoryImpl<TestPerDisplayInstance> =
        kosmos.fakePerDisplayInstanceRepository

    @Before
    fun addDisplays() = runBlocking {
        fakeDisplayRepository += createDisplay(DEFAULT_DISPLAY_ID)
        fakeDisplayRepository += createDisplay(NON_DEFAULT_DISPLAY_ID)
    }

    @Test
    fun forDisplay_defaultDisplay_multipleCalls_returnsSameInstance() =
        testScope.runTest {
            val instance = underTest[DEFAULT_DISPLAY_ID]

            assertThat(underTest[DEFAULT_DISPLAY_ID]).isSameInstanceAs(instance)
        }

    @Test
    fun forDisplay_nonDefaultDisplay_multipleCalls_returnsSameInstance() =
        testScope.runTest {
            val instance = underTest[NON_DEFAULT_DISPLAY_ID]

            assertThat(underTest[NON_DEFAULT_DISPLAY_ID]).isSameInstanceAs(instance)
        }

    @Test
    fun forDisplay_nonDefaultDisplay_afterDisplayRemoved_returnsNewInstance() =
        testScope.runTest {
            val instance = underTest[NON_DEFAULT_DISPLAY_ID]

            fakeDisplayRepository -= NON_DEFAULT_DISPLAY_ID
            fakeDisplayRepository += createDisplay(NON_DEFAULT_DISPLAY_ID)

            assertThat(underTest[NON_DEFAULT_DISPLAY_ID]).isNotSameInstanceAs(instance)
        }

    @Test
    fun forDisplay_nonExistingDisplayId_returnsNull() =
        testScope.runTest { assertThat(underTest[NON_EXISTING_DISPLAY_ID]).isNull() }

    @Test
    fun forDisplay_afterDisplayRemoved_destroyInstanceInvoked() =
        testScope.runTest {
            val instance = underTest[NON_DEFAULT_DISPLAY_ID]

            fakeDisplayRepository -= NON_DEFAULT_DISPLAY_ID

            assertThat(fakePerDisplayInstanceProviderWithTeardown.destroyed)
                .containsExactly(instance)
        }

    @Test
    fun forDisplay_withoutDisplayRemoval_destroyInstanceIsNotInvoked() =
        testScope.runTest {
            underTest[NON_DEFAULT_DISPLAY_ID]

            assertThat(fakePerDisplayInstanceProviderWithTeardown.destroyed).isEmpty()
        }

    private fun createDisplay(displayId: Int): Display =
        display(type = Display.TYPE_INTERNAL, id = displayId)

    companion object {
        private const val DEFAULT_DISPLAY_ID = Display.DEFAULT_DISPLAY
        private const val NON_DEFAULT_DISPLAY_ID = DEFAULT_DISPLAY_ID + 1
        private const val NON_EXISTING_DISPLAY_ID = DEFAULT_DISPLAY_ID + 2
    }
}
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.model

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.scene.shared.model.fakeSceneDataSource
import com.android.systemui.shade.data.repository.fakeShadeDisplaysRepository
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
@EnableSceneContainer
class SceneContainerPluginTest : SysuiTestCase() {
    private val kosmos = testKosmos()

    private val shadeDisplayRepository = kosmos.fakeShadeDisplaysRepository
    private val sceneDataSource = kosmos.fakeSceneDataSource

    private val underTest = kosmos.sceneContainerPlugin

    @Test
    @EnableFlags(Flags.FLAG_SHADE_WINDOW_GOES_AROUND)
    fun flagValueOverride_differentDisplayId_alwaysFalse() {
        sceneDataSource.changeScene(Scenes.Shade)

        shadeDisplayRepository.setDisplayId(1)

        assertThat(
                underTest.flagValueOverride(
                    flag = SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE,
                    displayId = 2,
                )
            )
            .isFalse()
    }

    @Test
    @EnableFlags(Flags.FLAG_SHADE_WINDOW_GOES_AROUND)
    fun flagValueOverride_sameDisplayId_returnsTrue() {
        sceneDataSource.changeScene(Scenes.Shade)

        shadeDisplayRepository.setDisplayId(1)

        assertThat(
                underTest.flagValueOverride(
                    flag = SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE,
                    displayId = 1,
                )
            )
            .isTrue()
    }

    @Test
    @DisableFlags(Flags.FLAG_SHADE_WINDOW_GOES_AROUND)
    fun flagValueOverride_differentDisplayId_shadeGoesAroundFlagOff_returnsTrue() {
        sceneDataSource.changeScene(Scenes.Shade)

        shadeDisplayRepository.setDisplayId(1)

        assertThat(
                underTest.flagValueOverride(
                    flag = SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE,
                    displayId = 2,
                )
            )
            .isTrue()
    }
}
+19 −4
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.systemui.model;

import static android.view.Display.DEFAULT_DISPLAY;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
@@ -29,8 +32,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.systemui.SysuiTestCase;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.kosmos.KosmosJavaAdapter;
import com.android.systemui.settings.DisplayTracker;

import org.junit.Before;
import org.junit.Test;
@@ -48,11 +51,11 @@ public class SysUiStateTest extends SysuiTestCase {
    private KosmosJavaAdapter mKosmos;
    private SysUiState.SysUiStateCallback mCallback;
    private SysUiState mFlagsContainer;
    private DisplayTracker mDisplayTracker;
    private SceneContainerPlugin mSceneContainerPlugin;
    private DumpManager mDumpManager;

    private SysUiState createInstance(int displayId) {
        var sysuiState = new SysUiStateImpl(displayId, mSceneContainerPlugin);
        var sysuiState = new SysUiStateImpl(displayId, mSceneContainerPlugin, mDumpManager);
        sysuiState.addCallback(mCallback);
        return sysuiState;
    }
@@ -60,10 +63,10 @@ public class SysUiStateTest extends SysuiTestCase {
    @Before
    public void setup() {
        mKosmos = new KosmosJavaAdapter(this);
        mDisplayTracker = mKosmos.getDisplayTracker();
        mFlagsContainer = mKosmos.getSysuiState();
        mSceneContainerPlugin = mKosmos.getSceneContainerPlugin();
        mCallback = mock(SysUiState.SysUiStateCallback.class);
        mDumpManager = mock(DumpManager.class);
        mFlagsContainer = createInstance(DEFAULT_DISPLAY);
    }

@@ -139,6 +142,18 @@ public class SysUiStateTest extends SysuiTestCase {
        verify(mCallback, never()).onSystemUiStateChanged(FLAG_1);
    }

    @Test
    public void init_registersWithDumpManager() {
        verify(mDumpManager).registerNormalDumpable(any(), eq(mFlagsContainer));
    }

    @Test
    public void destroy_unregistersWithDumpManager() {
        mFlagsContainer.destroy();

        verify(mDumpManager).unregisterDumpable(anyString());
    }

    private void setFlags(int... flags) {
        setFlags(mFlagsContainer, flags);
    }
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ oneway interface ILauncherProxy {
    /**
     * Sent when some system ui state changes.
     */
    void onSystemUiStateChanged(long stateFlags) = 16;
    void onSystemUiStateChanged(long stateFlags, int displayId) = 16;

    /**
     * Sent when suggested rotation button could be shown
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.dagger

import com.android.systemui.display.data.repository.DefaultDisplayOnlyInstanceRepositoryImpl
import com.android.systemui.display.data.repository.PerDisplayInstanceRepositoryImpl
import com.android.systemui.display.data.repository.PerDisplayRepository
import com.android.systemui.model.SysUIStateInstanceProvider
import com.android.systemui.model.SysUiState
import com.android.systemui.shade.shared.flag.ShadeWindowGoesAround
import dagger.Module
import dagger.Provides

/** This module is meant to contain all the code to create the various [PerDisplayRepository<>]. */
@Module
class PerDisplayRepositoriesModule {

    @SysUISingleton
    @Provides
    fun provideSysUiStateRepository(
        repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<SysUiState>,
        instanceProvider: SysUIStateInstanceProvider,
    ): PerDisplayRepository<SysUiState> {
        val debugName = "SysUiStatePerDisplayRepo"
        return if (ShadeWindowGoesAround.isEnabled) {
            repositoryFactory.create(debugName, instanceProvider)
        } else {
            DefaultDisplayOnlyInstanceRepositoryImpl(debugName, instanceProvider)
        }
    }
}
Loading