From 5837a4628c767f92499cf474d7183db70ad598f2 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Tue, 16 Jul 2024 15:13:11 +0100 Subject: [PATCH] Add Repository for RecentOrientedState and DeviceProfile - DeviceProfile have java fields that cannot be mocked, nor can be freely instantiated, so I've to use FakeInvariantDeviceProfileTest to give me some predefined DeviceProfile for testing Bug: 343101424 Test: RecentsOrientedStateRepositoryTest Test: RecentsDeviceProfileRepositoryTest Flag: com.android.launcher3.enable_refactor_task_thumbnail Change-Id: Iaa34ef60a418eb336859d260f5808b263de6b4f7 --- .../data/RecentsDeviceProfileRepository.kt | 36 +++++++++++++++ .../data/RecentsRotationStateRepository.kt | 35 +++++++++++++++ .../android/quickstep/views/RecentsView.java | 10 +++++ .../RecentsDeviceProfileRepositoryTest.kt | 44 +++++++++++++++++++ .../RecentsRotationStateRepositoryTest.kt | 41 +++++++++++++++++ .../FakeInvariantDeviceProfileTest.kt | 17 ++++--- 6 files changed, 174 insertions(+), 9 deletions(-) create mode 100644 quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepository.kt create mode 100644 quickstep/src/com/android/quickstep/recents/data/RecentsRotationStateRepository.kt create mode 100644 quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepositoryTest.kt create mode 100644 quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsRotationStateRepositoryTest.kt diff --git a/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepository.kt b/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepository.kt new file mode 100644 index 0000000000..adf904cd0c --- /dev/null +++ b/quickstep/src/com/android/quickstep/recents/data/RecentsDeviceProfileRepository.kt @@ -0,0 +1,36 @@ +/* + * 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.quickstep.recents.data + +import com.android.quickstep.views.RecentsViewContainer + +/** + * Repository for shrink down version of [com.android.launcher3.DeviceProfile] that only contains + * data related to Recents. + */ +class RecentsDeviceProfileRepository(private val container: RecentsViewContainer) { + + fun getRecentsDeviceProfile() = + with(container.deviceProfile) { RecentsDeviceProfile(isLargeScreen = isTablet) } + + /** + * Container to hold [com.android.launcher3.DeviceProfile] related to Recents. + * + * @property isLargeScreen whether the current device posture has a large screen + */ + data class RecentsDeviceProfile(val isLargeScreen: Boolean) +} diff --git a/quickstep/src/com/android/quickstep/recents/data/RecentsRotationStateRepository.kt b/quickstep/src/com/android/quickstep/recents/data/RecentsRotationStateRepository.kt new file mode 100644 index 0000000000..6ead704058 --- /dev/null +++ b/quickstep/src/com/android/quickstep/recents/data/RecentsRotationStateRepository.kt @@ -0,0 +1,35 @@ +/* + * 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.quickstep.recents.data + +import com.android.quickstep.util.RecentsOrientedState + +/** + * Repository for [RecentsRotationState] which holds orientation/rotation related information + * related to Recents + */ +class RecentsRotationStateRepository(private val state: RecentsOrientedState) { + fun getRecentsRotationState() = + with(state) { RecentsRotationState(activityRotation = recentsActivityRotation) } + + /** + * Container to hold orientation/rotation related information related to Recents. + * + * @property activityRotation rotation of the activity hosting RecentsView + */ + data class RecentsRotationState(val activityRotation: Int) +} diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 32738096b5..d888eb9e36 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -191,6 +191,8 @@ import com.android.quickstep.TaskViewUtils; import com.android.quickstep.TopTaskTracker; import com.android.quickstep.ViewUtils; import com.android.quickstep.orientation.RecentsPagedOrientationHandler; +import com.android.quickstep.recents.data.RecentsDeviceProfileRepository; +import com.android.quickstep.recents.data.RecentsRotationStateRepository; import com.android.quickstep.recents.data.TasksRepository; import com.android.quickstep.recents.viewmodel.RecentsViewData; import com.android.quickstep.util.ActiveGestureErrorDetector; @@ -465,6 +467,10 @@ public abstract class RecentsView mSizeStrategy; @@ -822,8 +828,12 @@ public abstract class RecentsView() + + private val systemUnderTest = RecentsDeviceProfileRepository(recentsViewContainer) + + @Test + fun deviceProfileMappedCorrectly() { + initializeVarsForTablet() + val tabletDeviceProfile = newDP() + whenever(recentsViewContainer.deviceProfile).thenReturn(tabletDeviceProfile) + + assertThat(systemUnderTest.getRecentsDeviceProfile()) + .isEqualTo(RecentsDeviceProfileRepository.RecentsDeviceProfile(isLargeScreen = true)) + } +} diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsRotationStateRepositoryTest.kt b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsRotationStateRepositoryTest.kt new file mode 100644 index 0000000000..1f4da2641b --- /dev/null +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/recents/data/RecentsRotationStateRepositoryTest.kt @@ -0,0 +1,41 @@ +/* + * 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.quickstep.recents.data + +import android.view.Surface.ROTATION_90 +import com.android.quickstep.util.RecentsOrientedState +import com.google.common.truth.Truth.assertThat +import org.junit.Test +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever + +/** Test for [RecentsRotationStateRepository] */ +class RecentsRotationStateRepositoryTest { + private val recentsOrientedState = mock() + + private val systemUnderTest = RecentsRotationStateRepository(recentsOrientedState) + + @Test + fun orientedStateMappedCorrectly() { + whenever(recentsOrientedState.recentsActivityRotation).thenReturn(ROTATION_90) + + assertThat(systemUnderTest.getRecentsRotationState()) + .isEqualTo( + RecentsRotationStateRepository.RecentsRotationState(activityRotation = ROTATION_90) + ) + } +} diff --git a/tests/multivalentTests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt b/tests/multivalentTests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt index 0538870132..954dc8fb59 100644 --- a/tests/multivalentTests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt +++ b/tests/multivalentTests/src/com/android/launcher3/FakeInvariantDeviceProfileTest.kt @@ -47,14 +47,13 @@ import org.mockito.kotlin.whenever abstract class FakeInvariantDeviceProfileTest { protected lateinit var context: Context - protected var inv: InvariantDeviceProfile? = null - protected val info: Info = mock() - protected var windowBounds: WindowBounds? = null - protected var isMultiWindowMode: Boolean = false - protected var transposeLayoutWithOrientation: Boolean = false - protected var useTwoPanels: Boolean = false - protected var isGestureMode: Boolean = true - protected var isTransientTaskbar: Boolean = true + protected lateinit var inv: InvariantDeviceProfile + protected val info = mock() + protected lateinit var windowBounds: WindowBounds + private var transposeLayoutWithOrientation = false + private var useTwoPanels = false + private var isGestureMode = true + private var isTransientTaskbar = true @Rule @JvmField val limitDevicesRule = LimitDevicesRule() @@ -73,7 +72,7 @@ abstract class FakeInvariantDeviceProfileTest { info, windowBounds, SparseArray(), - isMultiWindowMode, + /*isMultiWindowMode=*/ false, transposeLayoutWithOrientation, useTwoPanels, isGestureMode,