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

Commit 693a2ae6 authored by Govinda Wasserman's avatar Govinda Wasserman Committed by Android (Google) Code Review
Browse files

Merge "Add Screen Capture common domain layer" into main

parents 7e110400 253fdc15
Loading
Loading
Loading
Loading
+66 −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.screencapture.common.domain.interactor

import android.content.ComponentName
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.runTest
import com.android.systemui.screencapture.common.data.repository.fakeScreenCaptureIconRepository
import com.android.systemui.screencapture.common.domain.model.ScreenCaptureRecentTask
import com.android.systemui.testKosmosNew
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

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

    private val kosmos = testKosmosNew()

    @Test
    fun loadIcon_returnsIconFromRepository() =
        kosmos.runTest {
            // Arrange
            val interactor = ScreenCaptureIconInteractor(fakeScreenCaptureIconRepository)
            val fakeComponent = ComponentName("FakePackage", "FakeClass")
            val fakeTask =
                ScreenCaptureRecentTask(
                    taskId = 1,
                    displayId = 2,
                    userId = 3,
                    component = fakeComponent,
                    backgroundColor = null,
                    splitBounds = null,
                )

            // Act
            val result = interactor.loadIcon(fakeTask)

            // Assert
            assertThat(fakeScreenCaptureIconRepository.loadAppIconCalls).hasSize(1)
            fakeScreenCaptureIconRepository.loadAppIconCalls.first().let {
                (component, userId, badged) ->
                assertThat(component).isEqualTo(fakeComponent)
                assertThat(userId).isEqualTo(3)
                assertThat(badged).isTrue()
            }
            assertThat(result).isEqualTo(fakeScreenCaptureIconRepository.fakeIcon)
        }
}
+66 −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.screencapture.common.domain.interactor

import android.content.ComponentName
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.runTest
import com.android.systemui.screencapture.common.data.repository.fakeScreenCaptureLabelRepository
import com.android.systemui.screencapture.common.domain.model.ScreenCaptureRecentTask
import com.android.systemui.testKosmosNew
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

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

    private val kosmos = testKosmosNew()

    @Test
    fun loadLabel_returnsLabelFromRepository() =
        kosmos.runTest {
            // Arrange
            val interactor = ScreenCaptureLabelInteractor(fakeScreenCaptureLabelRepository)
            val fakeComponent = ComponentName("FakePackage", "FakeClass")
            val fakeTask =
                ScreenCaptureRecentTask(
                    taskId = 1,
                    displayId = 2,
                    userId = 3,
                    component = fakeComponent,
                    backgroundColor = null,
                    splitBounds = null,
                )

            // Act
            val result = interactor.loadLabel(fakeTask)

            // Assert
            assertThat(fakeScreenCaptureLabelRepository.loadLabelCalls).hasSize(1)
            fakeScreenCaptureLabelRepository.loadLabelCalls.first().let {
                (component, userId, badged) ->
                assertThat(component).isEqualTo(fakeComponent)
                assertThat(userId).isEqualTo(3)
                assertThat(badged).isTrue()
            }
            assertThat(result).isEqualTo(fakeScreenCaptureLabelRepository.fakeLabel)
        }
}
+80 −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.screencapture.common.domain.interactor

import android.content.ComponentName
import android.graphics.Rect
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.collectValues
import com.android.systemui.kosmos.runTest
import com.android.systemui.mediaprojection.appselector.data.RecentTask
import com.android.systemui.screencapture.common.data.repository.fakeScreenCaptureRecentTaskRepository
import com.android.systemui.screencapture.common.domain.model.ScreenCaptureRecentTask
import com.android.systemui.testKosmosNew
import com.android.wm.shell.shared.split.SplitBounds
import com.android.wm.shell.shared.split.SplitScreenConstants
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

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

    private val kosmos = testKosmosNew()

    @Test
    fun recentTasks_emitsRecentTasks() =
        kosmos.runTest {
            // Arrange
            val interactor =
                ScreenCaptureRecentTaskInteractor(fakeScreenCaptureRecentTaskRepository)
            val fakeTopComponent = ComponentName("FakeTopPackage", "FakeTopClass")
            val fakeBaseComponent = ComponentName("FakeBasePackage", "FakeBaseClass")
            val fakeSplitBounds =
                SplitBounds(
                    /* leftTopBounds= */ Rect(1, 1, 1, 1),
                    /* rightBottomBounds= */ Rect(2, 2, 2, 2),
                    /* leftTopTaskId= */ 4,
                    /* rightBottomTaskId= */ 5,
                    /* snapPosition= */ SplitScreenConstants.SNAP_TO_2_33_66,
                )
            val fakeTask =
                RecentTask(
                    taskId = 1,
                    displayId = 2,
                    userId = 3,
                    topActivityComponent = fakeTopComponent,
                    baseIntentComponent = fakeBaseComponent,
                    colorBackground = 0x99123456.toInt(),
                    isForegroundTask = true,
                    userType = RecentTask.UserType.STANDARD,
                    splitBounds = fakeSplitBounds,
                )

            // Act
            val result by collectValues(interactor.recentTasks)
            fakeScreenCaptureRecentTaskRepository.setRecentTasks(fakeTask)

            // Assert
            assertThat(result).hasSize(2)
            assertThat(result[0]).isNull()
            assertThat(result[1]).containsExactly(ScreenCaptureRecentTask(task = fakeTask))
        }
}
+58 −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.screencapture.common.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.runTest
import com.android.systemui.screencapture.common.data.repository.fakeScreenCaptureThumbnailRepository
import com.android.systemui.screencapture.common.domain.model.ScreenCaptureRecentTask
import com.android.systemui.testKosmosNew
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

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

    private val kosmos = testKosmosNew()

    @Test
    fun loadThumbnail_returnsThumbnailFromRepository() =
        kosmos.runTest {
            // Arrange
            val interactor = ScreenCaptureThumbnailInteractor(fakeScreenCaptureThumbnailRepository)
            val fakeTask =
                ScreenCaptureRecentTask(
                    taskId = 1,
                    displayId = 2,
                    userId = 3,
                    component = null,
                    backgroundColor = null,
                    splitBounds = null,
                )

            // Act
            val result = interactor.loadThumbnail(fakeTask)

            // Assert
            assertThat(fakeScreenCaptureThumbnailRepository.loadThumbnailCalls).containsExactly(1)
            assertThat(result).isEqualTo(fakeScreenCaptureThumbnailRepository.fakeThumbnail)
        }
}
+74 −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.screencapture.common.domain.model

import android.content.ComponentName
import android.graphics.Rect
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.mediaprojection.appselector.data.RecentTask
import com.android.wm.shell.shared.split.SplitBounds
import com.android.wm.shell.shared.split.SplitScreenConstants
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

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

    @Test
    fun constructor_usesRecentTaskFields() {
        // Arrange
        val fakeTopComponent = ComponentName("FakeTopPackage", "FakeTopClass")
        val fakeBaseComponent = ComponentName("FakeBaseBackage", "FakeBaseClass")
        val fakeSplitBounds =
            SplitBounds(
                /* leftTopBounds= */ Rect(1, 1, 1, 1),
                /* rightBottomBounds= */ Rect(2, 2, 2, 2),
                /* leftTopTaskId= */ 4,
                /* rightBottomTaskId= */ 5,
                /* snapPosition= */ SplitScreenConstants.SNAP_TO_2_33_66,
            )
        val fakeTask =
            RecentTask(
                taskId = 1,
                displayId = 2,
                userId = 3,
                topActivityComponent = fakeTopComponent,
                baseIntentComponent = fakeBaseComponent,
                colorBackground = 0x99123456.toInt(),
                isForegroundTask = true,
                userType = RecentTask.UserType.STANDARD,
                splitBounds = fakeSplitBounds,
            )

        // Act
        val result = ScreenCaptureRecentTask(fakeTask)

        // Assert
        with(result) {
            assertThat(taskId).isEqualTo(1)
            assertThat(displayId).isEqualTo(2)
            assertThat(userId).isEqualTo(3)
            assertThat(component).isEqualTo(fakeBaseComponent)
            assertThat(backgroundColor).isEqualTo(0x99123456.toInt())
            assertThat(splitBounds).isEqualTo(fakeSplitBounds)
        }
    }
}
Loading