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

Commit efd5e043 authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge "Create DisplayWindowPropertiesInteractor" into main

parents 115142b2 c2bccdaf
Loading
Loading
Loading
Loading
+61 −0
Original line number Original line 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 Original line 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.data.repository.FocusedDisplayRepositoryImpl
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractor
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractor
import com.android.systemui.display.domain.interactor.ConnectedDisplayInteractorImpl
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.RearDisplayStateInteractor
import com.android.systemui.display.domain.interactor.RearDisplayStateInteractorImpl
import com.android.systemui.display.domain.interactor.RearDisplayStateInteractorImpl
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
@@ -41,7 +42,7 @@ import dagger.multibindings.ClassKey
import dagger.multibindings.IntoMap
import dagger.multibindings.IntoMap


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