From de55e0f58bc9ee38c4ae96124b9709cf33d826c2 Mon Sep 17 00:00:00 2001 From: John McIntosh Date: Sat, 2 Nov 2024 09:09:59 -0500 Subject: [PATCH] Add android support for setting orientation I do not have an android setup and have not tested this yet. This implementation is based off conventions in `AndroidDriver.kt` for interacting with `adb` and this reference for what commands should be run https://stackoverflow.com/q/25864385. --- .../src/main/java/maestro/drivers/AndroidDriver.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt b/maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt index c66967979f..613d02d135 100644 --- a/maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt +++ b/maestro-client/src/main/java/maestro/drivers/AndroidDriver.kt @@ -602,7 +602,15 @@ class AndroidDriver( } override fun setOrientation(orientation: DeviceOrientation) { - // TODO(jmac) Implement and test + // Disable accelerometer based rotation before overriding orientation + dadb.shell("settings put system accelerometer_rotation 0") + + when(orientation) { + DeviceOrientation.PORTRAIT -> dadb.shell("settings put system user_rotation 0") + DeviceOrientation.LANDSCAPE_LEFT -> dadb.shell("settings put system user_rotation 1") + DeviceOrientation.UPSIDE_DOWN -> dadb.shell("settings put system user_rotation 2") + DeviceOrientation.LANDSCAPE_RIGHT -> dadb.shell("settings put system user_rotation 3") + } } override fun eraseText(charactersToErase: Int) {