Skip to content

Commit

Permalink
Disable animations by default (#56)
Browse files Browse the repository at this point in the history
* Disable animations by default

* Fix error handling
  • Loading branch information
ofalvai authored Nov 29, 2024
1 parent 6311920 commit 22f5307
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
43 changes: 43 additions & 0 deletions adb/adb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}
Expand Down
13 changes: 13 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22f5307

Please sign in to comment.