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

Commit c2bccdaf authored by Chris Göllner's avatar Chris Göllner
Browse files

Create DisplayWindowPropertiesInteractor

Created so that the UI layer can retrieve display window properties,
without depending directly on the data layer.

For now only contains a method to retrieve the properties for the
TYPE_STATUS_BAR window type.

Test: DisplayWindowPropertiesInteractorImplTest
Bug: 369337701
Flag: EXEMPT class not used on its own yet
Change-Id: I61a2d5342d5922aedeab248a315e82fc0871f244
parent 0f5e234f
Loading
Loading
Loading
Loading
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.domain.interactor

import android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR
import android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR
import android.view.layoutInflater
import android.view.windowManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.display.data.repository.fakeDisplayWindowPropertiesRepository
import com.android.systemui.display.shared.model.DisplayWindowProperties
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

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

    private val kosmos = testKosmos()
    private val repo = kosmos.fakeDisplayWindowPropertiesRepository

    private val underTest = kosmos.displayWindowPropertiesInteractor

    @Test
    fun getForStatusBar_returnsPropertiesWithCorrectWindowType() {
        val displayId = 123
        val statusBarWindowProperties = createDisplayWindowProperties(displayId, TYPE_STATUS_BAR)
        val navBarWindowProperties = createDisplayWindowProperties(displayId, TYPE_NAVIGATION_BAR)
        repo.insert(statusBarWindowProperties)
        repo.insert(navBarWindowProperties)

        assertThat(underTest.getForStatusBar(displayId)).isEqualTo(statusBarWindowProperties)
    }

    private fun createDisplayWindowProperties(displayId: Int, windowType: Int) =
        DisplayWindowProperties(
            displayId,
            windowType,
            context,
            kosmos.windowManager,
            kosmos.layoutInflater,
        )
}
+2 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.display.data.repository.FocusedDisplayRepository
import com.android.systemui.display.data.repository.FocusedDisplayRepositoryImpl
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractor
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractorImpl
import com.android.systemui.display.domain.interactor.DisplayWindowPropertiesInteractorModule
import com.android.systemui.display.domain.interactor.RearDisplayStateInteractor
import com.android.systemui.display.domain.interactor.RearDisplayStateInteractorImpl
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
@@ -41,7 +42,7 @@ import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap

/** Module binding display related classes. */
@Module
@Module(includes = [DisplayWindowPropertiesInteractorModule::class])
interface DisplayModule {
    @Binds
    fun bindConnectedDisplayInteractor(
+55 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.domain.interactor

import android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.display.data.repository.DisplayWindowPropertiesRepository
import com.android.systemui.display.shared.model.DisplayWindowProperties
import dagger.Binds
import dagger.Module
import javax.inject.Inject

/** Provides per display instances of [DisplayWindowProperties]. */
interface DisplayWindowPropertiesInteractor {

    /**
     * Returns a [DisplayWindowProperties] instance for a given display id, to be used for the
     * status bar.
     *
     * @throws IllegalArgumentException if no display with the given display id exists.
     */
    fun getForStatusBar(displayId: Int): DisplayWindowProperties
}

@SysUISingleton
class DisplayWindowPropertiesInteractorImpl
@Inject
constructor(private val repo: DisplayWindowPropertiesRepository) :
    DisplayWindowPropertiesInteractor {

    override fun getForStatusBar(displayId: Int): DisplayWindowProperties {
        return repo.get(displayId, TYPE_STATUS_BAR)
    }
}

@Module
interface DisplayWindowPropertiesInteractorModule {

    @Binds
    fun interactor(impl: DisplayWindowPropertiesInteractorImpl): DisplayWindowPropertiesInteractor
}
+23 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.domain.interactor

import com.android.systemui.display.data.repository.displayWindowPropertiesRepository
import com.android.systemui.kosmos.Kosmos

val Kosmos.displayWindowPropertiesInteractor by
    Kosmos.Fixture { DisplayWindowPropertiesInteractorImpl(displayWindowPropertiesRepository) }