Created
January 25, 2021 01:19
-
-
Save c84c/01a38cd7fc84d26b07122716b95e7b62 to your computer and use it in GitHub Desktop.
Script to run Vodafone DreamLab app on Android emulator (Linux)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# | |
# run_dreamlab_android_emulator.sh | |
# | |
# Script to start Vodafone DreamLab app on Android emulator to run projects | |
# supported by DreamLab. | |
# | |
# Run this script when you want to support cancer research with your Linux PC | |
# and without the limitation of DreamLab app (AC charger connected). | |
# | |
# Before run this script perform this steps: | |
# - Create an Android Virtual Device with pre-installed PlayStore and set name | |
# in MY_AVD_NAME variable (eg. MY_AVD_NAME="Pixel_4_API_29") | |
# - Start created AVD | |
# - Start Play Store (inserting Google credentials) | |
# - Install Vodafone DreamLab | |
# https://play.google.com/store/apps/details?id=au.com.vodafone.dreamlabapp | |
# - Start Vodafone DreamLab to select a project to support | |
# - Stop emulator | |
# - Adjust MY_AVD_NAME and ANDROID_SDK_PATH variables. | |
# - Run this script to support cancer research! | |
# | |
set -e | |
# MY_AVD_NAME: set avd name | |
MY_AVD_NAME="Pixel_4_API_29" | |
# ANDROID_SDK_PATH: set Android Sdk path | |
ANDROID_SDK_PATH="$HOME/Android/Sdk" | |
# global vars for emulator | |
EMULATOR_LIB_PATH="$ANDROID_SDK_PATH/emulator/lib64" | |
QT_EMU_LIB="$ANDROID_SDK_PATH/emulator/lib64/qt/lib" | |
export LD_LIBRARY_PATH="$QT_EMU_LIB:$EMULATOR_LIB_PATH:$LD_LIBRARY_PATH" | |
EMULATOR="$ANDROID_SDK_PATH/emulator/qemu/linux-x86_64/qemu-system-x86_64" | |
ADB="$ANDROID_SDK_PATH/platform-tools/adb" | |
echo "Ensure adb is started" | |
$ADB start-server | |
echo "Clean pending operation" | |
rm -f $HOME/.android/avd/$MY_AVD_NAME.avd/*.lock | |
echo "Starting emulator ... " | |
$EMULATOR \ | |
-no-snapshot \ | |
-ranchu \ | |
-cores 4 \ | |
-memory 2048 \ | |
-netdelay none \ | |
-netfast \ | |
-netspeed full \ | |
-no-boot-anim \ | |
-no-window \ | |
-no-audio \ | |
-camera-back none \ | |
-camera-front none \ | |
-avd $MY_AVD_NAME \ | |
&>/dev/null & | |
EMULATOR_PID=$! | |
# wait device is ready | |
$ADB wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done; input keyevent 82' | |
echo "Emulator ready!" | |
# get device serial matching avd name | |
DEVICE_SERIAL="" | |
for line in $($ADB devices | grep emulator | cut -f1); do | |
# get AVD name from adb emu shell | |
AVD_NAME=$($ADB -s $line emu avd name | head -1 | dos2unix ) | |
if [[ "$MY_AVD_NAME" == "$AVD_NAME" ]] ; then | |
DEVICE_SERIAL=$line | |
fi | |
done | |
# set AC powered | |
echo "Set AC powered DONE!" | |
$ADB shell dumpsys battery set ac 1 | |
# set battery charging | |
echo "Set battery state CHARGING DONE!" | |
$ADB shell dumpsys battery set status 3 | |
echo "Starting Vodafone DreamLab ..." | |
# start au.com.vodafone.dreamlabapp simulating tap | |
$ADB shell monkey -p "au.com.vodafone.dreamlabapp" -c "android.intent.category.LAUNCHER" 1 &>/dev/null | |
echo "Started Vodafone DreamLab!" | |
sleep 10 | |
echo "Lock screen to decrease CPU usage" | |
$ADB shell input keyevent 26 &>/dev/null | |
trap_handler() | |
{ | |
echo "Exiting tasks ..." | |
# kill emulator | |
$ADB -s "$line" emu kill | |
echo "Emulator killed" | |
#$ADB kill-server | |
#echo "adb server killed" | |
} | |
# wait SIGINT to kill script | |
echo "Waiting exit signal (Ctrl+c or SIGTERM)..." | |
trap trap_handler SIGINT SIGTERM | |
wait $EMULATOR_PID | |
sleep 3 | |
echo "Bye Bye" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment