diff --git a/README_CUSTOM_CONFIG.md b/README_CUSTOM_CONFIG.md index 11186f0b..aad2f8da 100644 --- a/README_CUSTOM_CONFIG.md +++ b/README_CUSTOM_CONFIG.md @@ -1,11 +1,12 @@ Proxy ----- -You can enable proxy inside container by passing following environment variables: +You can enable proxy inside container and Android emulator by passing following environment variables: -- HTTP_PROXY="\" -- HTTPS_PROXY="\" +- HTTP_PROXY="http://\:" +- HTTPS_PROXY=""http://\:" - NO_PROXY="localhost" +- ENABLE_PROXY_ON_EMULATOR=true Language -------- diff --git a/src/app.py b/src/app.py index a6f24746..ed767bef 100644 --- a/src/app.py +++ b/src/app.py @@ -204,9 +204,9 @@ def run(): cfg.write('\ndisk.dataPartition.size={dp}'.format(dp=dp_size)) if is_first_run: - cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -wipe-data -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args) + cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -wipe-data -writable-system -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args) else: - cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -verbose {custom_args}'.format(name=avd_name, custom_args=custom_args) + cmd = 'emulator/emulator @{name} -gpu swiftshader_indirect -accel on -verbose -writable-system {custom_args}'.format(name=avd_name, custom_args=custom_args) appium = convert_str_to_bool(str(os.getenv('APPIUM', False))) if appium: subprocess.Popen(cmd.split()) diff --git a/src/utils.sh b/src/utils.sh index 7d33229a..0169fbcd 100755 --- a/src/utils.sh +++ b/src/utils.sh @@ -38,6 +38,45 @@ function disable_animation () { adb shell "settings put global animator_duration_scale 0.0" } +function enable_proxy_if_needed () { + if [ "$ENABLE_PROXY_ON_EMULATOR" = true ]; then + if [ ! -z "${HTTP_PROXY// }" ]; then + if [[ $HTTP_PROXY == *"http"* ]]; then + protocol="$(echo $HTTP_PROXY | grep :// | sed -e's,^\(.*://\).*,\1,g')" + proxy="$(echo ${HTTP_PROXY/$protocol/})" + echo "[EMULATOR] - Proxy: $proxy" + + IFS=':' read -r -a p <<< "$proxy" + + echo "[EMULATOR] - Proxy-IP: ${p[0]}" + echo "[EMULATOR] - Proxy-Port: ${p[1]}" + + wait_emulator_to_be_ready + echo "Enable proxy on Android emulator. Please make sure that docker-container has internet access!" + adb root + + echo "Mount system to read write access" + adb shell "mount -o rw,remount /system" + + echo "Updateing Proxy" + + adb shell "content update --uri content://telephony/carriers --bind proxy:s:"${p[0]}" --bind port:s:"${p[1]}" --where "mcc=310" --where "mnc=260"" + + echo "remount system back to read only" + adb shell "mount -o ro,remount /system" + adb unroot + else + echo "Please use http:// in the beginning!" + fi + else + echo "$HTTP_PROXY is not given! Please pass it through environment variable!" + exit 1 + fi + fi +} + +enable_proxy_if_needed +sleep 1 change_language_if_needed sleep 1 install_google_play