utils.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. function wait_emulator_to_be_ready () {
  3. boot_completed=false
  4. while [ "$boot_completed" == false ]; do
  5. status=$(adb wait-for-device shell getprop sys.boot_completed | tr -d '\r')
  6. echo "Boot Status: $status"
  7. if [ "$status" == "1" ]; then
  8. boot_completed=true
  9. else
  10. sleep 1
  11. fi
  12. done
  13. }
  14. function change_language_if_needed() {
  15. if [ ! -z "${LANGUAGE// }" ] && [ ! -z "${COUNTRY// }" ]; then
  16. wait_emulator_to_be_ready
  17. echo "Language will be changed to ${LANGUAGE}-${COUNTRY}"
  18. adb root && adb shell "setprop persist.sys.language $LANGUAGE; setprop persist.sys.country $COUNTRY; stop; start" && adb unroot
  19. echo "Language is changed!"
  20. fi
  21. }
  22. function install_google_play () {
  23. wait_emulator_to_be_ready
  24. echo "Google Play Service will be installed"
  25. adb install -r "/root/google_play_services.apk"
  26. echo "Google Play Store will be installed"
  27. adb install -r "/root/google_play_store.apk"
  28. }
  29. function disable_animation () {
  30. # To improve performance
  31. adb shell "settings put global window_animation_scale 0.0"
  32. adb shell "settings put global transition_animation_scale 0.0"
  33. adb shell "settings put global animator_duration_scale 0.0"
  34. }
  35. function enable_proxy_if_needed () {
  36. if [ "$ENABLE_PROXY_ON_EMULATOR" = true ]; then
  37. if [ ! -z "${HTTP_PROXY// }" ]; then
  38. if [[ $HTTP_PROXY == *"http"* ]]; then
  39. protocol="$(echo $HTTP_PROXY | grep :// | sed -e's,^\(.*://\).*,\1,g')"
  40. proxy="$(echo ${HTTP_PROXY/$protocol/})"
  41. echo "[EMULATOR] - Proxy: $proxy"
  42. IFS=':' read -r -a p <<< "$proxy"
  43. echo "[EMULATOR] - Proxy-IP: ${p[0]}"
  44. echo "[EMULATOR] - Proxy-Port: ${p[1]}"
  45. wait_emulator_to_be_ready
  46. echo "Enable proxy on Android emulator. Please make sure that docker-container has internet access!"
  47. adb root
  48. echo "Set up the Proxy"
  49. adb shell "content update --uri content://telephony/carriers --bind proxy:s:"${p[0]}" --bind port:s:"${p[1]}" --where "mcc=310" --where "mnc=260""
  50. adb unroot
  51. else
  52. echo "Please use http:// in the beginning!"
  53. fi
  54. else
  55. echo "$HTTP_PROXY is not given! Please pass it through environment variable!"
  56. exit 1
  57. fi
  58. fi
  59. }
  60. enable_proxy_if_needed
  61. sleep 1
  62. change_language_if_needed
  63. sleep 1
  64. install_google_play
  65. disable_animation