Skip to content

Commit

Permalink
NT-2128: Emulator scripts (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkariang committed Jul 27, 2021
1 parent ddfb83f commit 58c71f8
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ slack.properties

# temporarily ignore prerelease script
prerelease.sh
script/emulator/sdcard.img
script/emulator/sdcard.img.qcow2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions script/emulator/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PlayStore.enabled=false
abi.type=x86
avd.ini.encoding=UTF-8
hw.cpu.arch=x86
hw.sdCard=yes
image.sysdir.1=system-images/android-30/google_apis/x86/
sdcard.path=sdcard.img
tag.display=Google APIs
skin.name=1080x2220
hw.lcd.density=440
hw.keyboard=yes
25 changes: 25 additions & 0 deletions script/emulator/create_emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

if $ANDROID_HOME/tools/android list avd | grep -q Pixel_3a_API_30; then
echo "There is an existing an emulator to run screenshot tests"
exit 0;
fi

echo "Creating a brand new SDCard..."
rm -rf sdcard.img
$ANDROID_HOME/emulator/mksdcard -l e 1G sdcard.img
echo "SDCard created!"

echo "Downloading the image to create the emulator..."
echo no | $ANDROID_HOME/tools/bin/sdkmanager "system-images;android-30;google_apis;x86"
echo "Image downloaded!"

echo "Creating the emulator to run screenshot tests..."
echo no | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_3a_API_30 -k "system-images;android-30;google_apis;x86" --force --sdcard sdcard.img
echo "Emulator created!"


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cp $DIR/config.ini ~/.android/avd/Pixel_3a_API_30.avd/config.ini
cp sdcard.img ~/.android/avd/Pixel_3a_API_30.avd/sdcard.img
cp sdcard.img.qcow2 ~/.android/avd/Pixel_3a_API_30.avd/sdcard.img.qcow2
6 changes: 6 additions & 0 deletions script/emulator/disable_animations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

$ANDROID_HOME/platform-tools/adb wait-for-device
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 0
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 0
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 0
6 changes: 6 additions & 0 deletions script/emulator/enable_animations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

$ANDROID_HOME/platform-tools/adb wait-for-device
$ANDROID_HOME/platform-tools/adb shell settings put global window_animation_scale 1
$ANDROID_HOME/platform-tools/adb shell settings put global transition_animation_scale 1
$ANDROID_HOME/platform-tools/adb shell settings put global animator_duration_scale 1
7 changes: 7 additions & 0 deletions script/emulator/reboot_emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Rebooting emulator..."
$ANDROID_HOME/platform-tools/adb -e reboot
$DIR/wait_for_emulator.sh
echo "Emulator rebooted!"
13 changes: 13 additions & 0 deletions script/emulator/screenshot_config_emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash


DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo "Specific configuration to avoid Facebook Screenshot library to fail on API devices higher than 27"
$ANDROID_HOME/platform-tools/adb wait-for-device
$ANDROID_HOME/platform-tools/adb shell settings put global hidden_api_policy_p_apps 1
$ANDROID_HOME/platform-tools/adb shell settings put global hidden_api_policy_pre_p_apps 1
$ANDROID_HOME/platform-tools/adb shell settings put global hidden_api_policy 1

echo "Rebooting emulator to apply the configuration"
$ANDROID_HOME/platform-tools/adb wait-for-device
27 changes: 27 additions & 0 deletions script/emulator/start_emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if ! $ANDROID_HOME/tools/android list avd | grep -q Pixel_3a_API_30; then
echo "No emulator for screenshot tests found, creating one..."
$DIR/create_emulator.sh
fi

if $ANDROID_HOME/platform-tools/adb devices -l | grep -q emulator; then
echo "Emulator already running"
exit 0
fi

echo "Starting emulator..."
echo "no" | $ANDROID_HOME/emulator/emulator "-avd" "Pixel_3a_API_30" "-no-audio" "-no-boot-anim" "-gpu" "swiftshader_indirect"&
$DIR/wait_for_emulator.sh

echo "Emulator ready, disabling animations!"
$DIR/disable_animations.sh
$DIR/wait_for_emulator.sh

echo "Emulator ready, configuring for Screenshot Testing!"
$DIR/screenshot_config_emulator.sh
$DIR/wait_for_emulator.sh

echo "Emulator started and ready to rock!"
5 changes: 5 additions & 0 deletions script/emulator/stop_emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo "Stopping emulator..."
$ANDROID_HOME/platform-tools/adb emu kill
echo "Emulator stopped!"
6 changes: 6 additions & 0 deletions script/emulator/wait_for_emulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "Waiting until emulator is completely booted"
while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done
echo "Done"
echo "Emulator is ready"

0 comments on commit 58c71f8

Please sign in to comment.