Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP require flat mode to rotate foldable emulators #1957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -44,11 +44,9 @@ internal class BookModeAction() :
Log.d(TAG, "FoldingFeature orientation needs to be rotated.")
// TODO(b/296910911) On physical devices, changing screen orientation requires the device to
// be in FLAT mode. Open the fold, update orientation, and then restore the half-folded state.
if (!isTestDeviceAnEmulator()) {
Log.d(TAG, "Temporarily setting device to flat mode so that device can be rotated.")
BaseSingleFoldDeviceAction(DeviceMode.FLAT, FoldingFeature.State.FLAT)
.perform(deviceController)
}
Log.d(TAG, "Temporarily setting device to flat mode so that device can be rotated.")
BaseSingleFoldDeviceAction(DeviceMode.FLAT, FoldingFeature.State.FLAT)
.perform(deviceController)

val orientationToRotateTo =
if (
Expand Down
Expand Up @@ -36,6 +36,9 @@ import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry
import androidx.test.runner.lifecycle.Stage
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import androidx.test.espresso.device.common.executeShellCommand
import androidx.test.espresso.device.common.getMapOfDeviceStateNamesToIdentifiers
import androidx.test.platform.device.UnsupportedDeviceOperationException

/** Action to set the test device to the provided screen orientation. */
internal class ScreenOrientationAction(val screenOrientation: ScreenOrientation) : DeviceAction {
Expand Down Expand Up @@ -74,6 +77,17 @@ internal class ScreenOrientationAction(val screenOrientation: ScreenOrientation)
deviceController.setScreenOrientation(screenOrientation.getOrientation())
return
}

// TODO(b/296910911) Support setting screen orientation on folded devices
val supportedDeviceStates = getMapOfDeviceStateNamesToIdentifiers()
if (supportedDeviceStates.isNotEmpty()) {
val currentDeviceStateIdentifier = executeShellCommand("cmd device_state print-state").trim()
if (currentDeviceStateIdentifier != getMapOfDeviceStateNamesToIdentifiers().get("OPENED")) {
throw UnsupportedDeviceOperationException(
"Setting screen orientation is not suported on foldable devices that are not in flat mode."
)
}
}

var startingAccelRotationSetting = getAccelerometerRotationSetting()
val currentActivity = getResumedActivityOrNull()
Expand Down
Expand Up @@ -43,12 +43,10 @@ internal class TabletopModeAction() :
} else if (super.foldingFeatureOrientation != FoldingFeature.Orientation.HORIZONTAL) {
Log.d(TAG, "FoldingFeature orientation needs to be rotated.")
// TODO(b/296910911) On physical devices, changing screen orientation requires the device to
// be in FLAT mode. Open the fold, update orientation, and then restore the half-folded state.
if (!isTestDeviceAnEmulator()) {
Log.d(TAG, "Temporarily setting device to flat mode so that device can be rotated.")
BaseSingleFoldDeviceAction(DeviceMode.FLAT, FoldingFeature.State.FLAT)
.perform(deviceController)
}
// be in FLAT mode. Open the fold, update orientation, and then restore the half-folded state.{
Log.d(TAG, "Temporarily setting device to flat mode so that device can be rotated.")
BaseSingleFoldDeviceAction(DeviceMode.FLAT, FoldingFeature.State.FLAT)
.perform(deviceController)

val orientationToRotateTo =
if (
Expand Down
Expand Up @@ -81,16 +81,7 @@ class PhysicalDeviceController() : DeviceController {
)
}

// TODO(b/296910911) Support setting screen orientation on folded devices
val supportedDeviceStates = getMapOfDeviceStateNamesToIdentifiers()
if (supportedDeviceStates.isNotEmpty()) {
val currentDeviceStateIdentifier = executeShellCommand("cmd device_state print-state").trim()
if (currentDeviceStateIdentifier != getMapOfDeviceStateNamesToIdentifiers().get("OPENED")) {
throw UnsupportedDeviceOperationException(
"Setting screen orientation is not suported on physical foldable devices that are not in flat mode."
)
}
}


// System user_rotation values must be one of the Surface rotation constants and these values
// can indicate different orientations on different devices, since we check if the device is
Expand Down