From 22f530768a1e8afae85f7d03ebe949ed850d1abe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Falvai?= Date: Fri, 29 Nov 2024 13:24:36 +0100 Subject: [PATCH] Disable animations by default (#56) * Disable animations by default * Fix error handling --- README.md | 1 + adb/adb.go | 43 +++++++++++++++++++++++++++++++++++++++++++ main.go | 8 ++++++++ step.yml | 13 +++++++++++++ 4 files changed, 65 insertions(+) diff --git a/README.md b/README.md index 0c2018c..0cde804 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ You can also run this step directly with [Bitrise CLI](https://github.com/bitris | `api_level` | The device will run with the specified system image version. | required | `26` | | `tag` | Select OS tag to have the required toolset on the device. | required | `google_apis` | | `abi` | Select which ABI to use running the emulator. Availability depends on API level. Please use `sdkmanager --list` command to see the available ABIs. | required | `x86` | +| `disable_animations` | Disable animations on the emulator in order to make tests faster and more stable. Animations can be enabled/disabled from the test code too, so if your tests do need animations, set this step input to `no` and control the settings yourself. | required | `yes` | | `emulator_id` | Set the device's ID. (This will be the name under $HOME/.android/avd/) | required | `emulator` | | `create_command_flags` | Flags used when running the command to create the emulator. | | `--sdcard 2048M` | | `start_command_flags` | Flags used when running the command to start the emulator. | | `-camera-back none -camera-front none` | diff --git a/adb/adb.go b/adb/adb.go index 8199416..fd9c6d6 100644 --- a/adb/adb.go +++ b/adb/adb.go @@ -100,3 +100,46 @@ func (a *ADB) FindNewDevice(previousDeviceState Devices) (string, error) { return "", nil } + +func (a *ADB) DisableAnimations(serial string) error { + a.logger.Println() + a.logger.Infof("Disabling animations for %s", serial) + + adbPath := filepath.Join(a.androidHome, "platform-tools", "adb") + + cmd := a.cmdFactory.Create( + adbPath, + []string{"-s", serial, "shell", "settings", "put", "global", "window_animation_scale", "0"}, + nil, + ) + out, err := cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + a.logger.Warnf(out) + a.logger.Warnf("adb window_animation_scal=0: %s", err) + } + + cmd = a.cmdFactory.Create( + adbPath, + []string{"-s", serial, "shell", "settings", "put", "global", "transition_animation_scale", "0"}, + nil, + ) + out, err = cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + a.logger.Warnf(out) + a.logger.Warnf("adb transition_animation_scale=0: %s", err) + } + + cmd = a.cmdFactory.Create( + adbPath, + []string{"-s", serial, "shell", "settings", "put", "global", "animator_duration_scale", "0"}, + nil, + ) + out, err = cmd.RunAndReturnTrimmedCombinedOutput() + if err != nil { + a.logger.Warnf(out) + a.logger.Warnf("adb animator_duration_scale=0: %s", err) + } + + a.logger.Println() + return nil +} diff --git a/main.go b/main.go index d26327e..705ed7e 100755 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ type config struct { APILevel int `env:"api_level,required"` Tag string `env:"tag,opt[google_apis,google_apis_playstore,aosp_atd,google_atd,android-wear,android-tv,default]"` DeviceProfile string `env:"profile,required"` + DisableAnimations bool `env:"disable_animations,opt[yes,no]"` CreateCommandArgs string `env:"create_command_flags"` StartCommandArgs string `env:"start_command_flags"` ID string `env:"emulator_id,required"` @@ -208,6 +209,13 @@ func main() { serial := startEmulator(adbClient, emulatorPath, args, androidHome, runningDevicesBeforeBoot, 1) + if cfg.DisableAnimations { + err = adbClient.DisableAnimations(serial) + if err != nil { + failf("Failed to disable animations: %s", err) + } + } + if err := tools.ExportEnvironmentWithEnvman("BITRISE_EMULATOR_SERIAL", serial); err != nil { log.Warnf("Failed to export environment (BITRISE_EMULATOR_SERIAL), error: %s", err) } diff --git a/step.yml b/step.yml index 455403f..14b0f46 100755 --- a/step.yml +++ b/step.yml @@ -85,6 +85,19 @@ inputs: - armeabi-v7a - arm64-v8a - mips +- disable_animations: "yes" + opts: + category: Advanced + title: Disable animations + summary: Disable animations on the emulator in order to make tests faster and more stable. + description: |- + Disable animations on the emulator in order to make tests faster and more stable. + + Animations can be enabled/disabled from the test code too, so if your tests do need animations, set this step input to `no` and control the settings yourself. + is_required: true + value_options: + - "yes" + - "no" - emulator_id: emulator opts: category: Advanced